bgshih / aster

Recognizing cropped text in natural images.
MIT License
724 stars 195 forks source link

how to run batch inference #22

Open ChChwang opened 5 years ago

ChChwang commented 5 years ago

how to run batch inference

13070151771 commented 5 years ago

哈哈我也想知道

cbasavaraj commented 5 years ago

I am trying to do this myself, but I get a tf error:

            self.aster_input_images = tf.placeholder(
                dtype='uint8',
                shape=[None, None, None, 3])
            resized_image_tensors = tf.image.resize_images(
                tf.to_float(self.aster_input_images),
                [64, 256])

            aster_model_config, _, _ = get_aster_configs()
            aster = model_builder.build(aster_model_config, is_training=False)

            predictions_dict = aster.predict(resized_image_tensors)
            recognitions = aster.postprocess(predictions_dict)

The error is on this line: predictions_dict = aster.predict(resized_image_tensors)

and as follows: ValueError: The last dimension of the inputs toDenseshould be defined. FoundNone.

dsandii commented 5 years ago

@cbasavaraj I'm running into the same problem. Were you able to resolve it?

cbasavaraj commented 4 years ago

Hi, sorry for the late response, was traveling. I haven't looked at this code in over eight months, but looks like I finally ran it one image at a time. Pasting the relevant code here. Hope it helps!

Defining: `

        graph_aster = tf.Graph()
        with graph_aster.as_default():

            print('Defining ASTER...')
            self.aster_input_image = tf.placeholder(
                dtype='uint8',
                shape=[None, None, 3])
            resized_image_tensor = tf.image.resize_images(
                tf.to_float(self.aster_input_image),
                [64, 256])

            aster_model_config, _, _ = get_aster_configs()
            aster = model_builder.build(aster_model_config, is_training=False)

            predictions_dict = aster.predict(tf.expand_dims(resized_image_tensor, 0))
            recognitions = aster.postprocess(predictions_dict)

            recognition_text = recognitions['text'][0]
            recognition_score = recognitions['scores'][0]
            control_points = predictions_dict['control_points'],
            rectified_images = predictions_dict['rectified_images']

            self.aster_fetches = {
                'recognition_text': recognition_text,
                'recognition_score': recognition_score,
                'control_points': control_points,
                'rectified_images': rectified_images,
            }

            print('Loading ASTER from {}'.format(aster_model_path))

            self.tf_session_aster = tf.Session(config=tf_config)
            self.tf_session_aster.run([tf.global_variables_initializer(),
                                       tf.local_variables_initializer(),
                                       tf.tables_initializer()])

`

Inference: `

        for roi in rois:
            aster_fetches = self.tf_session_aster.run(self.aster_fetches,
                                                      feed_dict={self.aster_input_image: roi})
            word = aster_fetches['recognition_text'].decode('utf-8')
            words.append(word)
            prob = np.exp(aster_fetches['recognition_score'])
            probs.append(prob)
            roir = aster_fetches['rectified_images'][0]
            roir = (128 * (roir + 1.)).astype(np.uint8)
            roirs.append(roir)

`