models icon indicating copy to clipboard operation
models copied to clipboard

Tensorflow[attention_ocr] Use Pretrained Model for Detection

Open ibr123 opened this issue 9 years ago • 4 comments

Hi, I'm calling the function "create_base" which exists in the model.py which is the following

    class Model(object):    
     def create_base(self,
      images,
      labels_one_hot,
      scope='AttentionOcr_v1',
      reuse=None):

so when i run the following code

    import skimage.io as io
    import numpy as np
    import collections
    import os
    import tensorflow as tf
    import common_flags
    import model
    
    from tensorflow.python.platform import flags
    
    FLAGS = flags.FLAGS
    common_flags.define()
    
    images_placeholder = tf.placeholder(tf.float32, shape=[635, 1219])
    fn ='/home/ubuntu/tensorflow/6m.jpg'
    images = [io.imread(fn, dtype='float')]
    print(images)
    images_actual_data = np.stack(images)
    images_actual_data = 2.5*(images_actual_data - 0.5)  # normalize values
    
    
    #model = common_flags.create_model(69,23,1,68) # based on the trained model
    dataset = common_flags.create_dataset(split_name=FLAGS.split_name)
    modelout = common_flags.create_model(dataset.num_char_classes,
                                        dataset.max_sequence_length,
                                        dataset.num_of_views, dataset.null_code)
    endpoints = model.Model.create_base(images_placeholder, labels_one_hot=None)
    
    with tf.Session() as sess:
        init_fn = model.create_init_fn_to_restore('/nsfs/tensor_models/models/research/attention_ocr/python/inception_v3.ckpt', '')
        init_fn(sess)
        sess.run(tf.global_variables_initializer()) # tried to run sess.run(init_fn) here, but it fails
        predictions = sess.run(endpoints.predicted_chars, feed_dict={images_placeholder:images_actual_data.reshape(1,imHeight,imWidth,imChannel)})
        print predictions

i get the following error:

INFO 2017-11-20 15:08:46.000545: fsns.py: 130 Using FSNS dataset split_name=train dataset_dir=/nsfs/tensor_models/models/research/attention_ocr/python/datasets/data/fsns
 Traceback (most recent call last):
   File "run_tf.py", line 31, in <module>
     endpoints = model.Model.create_base(images_placeholder, labels_one_hot=None)
 TypeError: unbound method create_base() must be called with Model instance as first argument (got Tensor instance instead)

keep in mind that im using the model "inception_v3.ckpt" Thanks

ibr123 avatar Nov 20 '17 15:11 ibr123

I used the line of code endpoints = modelout.create_base(images_placeholder, labels_one_hot=None)

ibr123 avatar Nov 21 '17 15:11 ibr123

Hi @ibr123 Can this code be use to detect one image by my own trained model (trained by my own dataset )? I have a tough problem: model.create_init_fn_to_restore() sess.run(init_fn)

ghost avatar Nov 29 '17 08:11 ghost

I don't know actually, I still have a problem in the placeholder, if I gave it shape the width and height "shape=[635, 1219}" it says it data should be equal, if they are equal it will give another error. but the problem is that the shape is optional, so I can just ignore it but the eval.py it self freezes so this code freezes as well, but if you got any results please let me know :)

ibr123 avatar Nov 29 '17 15:11 ibr123

@ibr123 ok ,thank you very much for your answer.If I find the answer, I will contact you

ghost avatar Nov 30 '17 01:11 ghost