Closed tumusudheer closed 7 years ago
Hi, Can someone please help me on this issue. Thank you.
The error happens because you provide a tf.Tensor (data.images) instead of an actual data (numpy ndarray) to feed into the placeholder. But the good news are you don't need to create a placeholder at all to run the model on the FSNS test data, just use the data.images
directly:
dataset = common_flags.create_dataset(split_name='test')
data = data_provider.get_data(dataset, FLAGS.batch_size, augment=False, central_crop_size=common_flags.get_crop_size())
model = common_flags.create_model(dataset.num_char_classes,
dataset.max_sequence_length,
dataset.num_of_views, dataset.null_code)
endpoints = model.create_base(data.images, labels_one_hot=None)
with tf.Session() as sess:
...
predictions = sess.run(endpoints.predicted_chars)
Hi @alexgorban,
Thank you very much. I've tried your fix. But I'm getting different error now: tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value AttentionOcr_v1/conv_tower_fn/INCE/InceptionV3/Conv2d_1a_3x3/weights [[Node: AttentionOcr_v1/conv_tower_fn/INCE/InceptionV3/Conv2d_1a_3x3/weights/read = IdentityT=DT_FLOAT, _class=["loc:@AttentionOcr_v1/conv_tower_fn/INCE/InceptionV3/Conv2d_1a_3x3/weights"], _device="/job:localhost/replica:0/task:0/gpu:0"]]
Here is my code: ` dataset = common_flags.create_dataset(split_name='test')
data = data_provider.get_data(dataset, FLAGS.batch_size, augment=False, central_crop_size=common_flags.get_crop_size())
model = common_flags.create_model(dataset.num_char_classes,
dataset.max_sequence_length,
dataset.num_of_views, dataset.null_code)
endpoints = model.create_base(data.images, labels_one_hot=None)
init_fn = model.create_init_fn_to_restore(FLAGS.checkpoint, FLAGS.checkpoint_inception)
predictions = sess.run(endpoints.predicted_chars)
`
Please see the complete log here:
`DEBUG 2017-06-27 02:47:06.000249: model.py: 314 images: Tensor("shuffle_batch:0", shape=(32, 150, 600, 3), dtype=float32)
DEBUG 2017-06-27 02:47:06.000250: model.py: 319 Views=4 single view: Tensor("AttentionOcr_v1/split:0", shape=(32, 150, 150, 3), dtype=float32)
DEBUG 2017-06-27 02:47:06.000250: model.py: 186 Using final_endpoint=Mixed_5d
DEBUG 2017-06-27 02:47:06.000891: model.py: 186 Using final_endpoint=Mixed_5d
DEBUG 2017-06-27 02:47:07.000252: model.py: 186 Using final_endpoint=Mixed_5d
DEBUG 2017-06-27 02:47:07.000662: model.py: 186 Using final_endpoint=Mixed_5d
DEBUG 2017-06-27 02:47:08.000084: model.py: 325 Conv tower: Tensor("AttentionOcr_v1/conv_tower_fn/INCE/InceptionV3/Mixed_5d/concat:0", shape=(32, 16, 16, 288), dtype=float32)
DEBUG 2017-06-27 02:47:08.000086: model.py: 328 Pooled views: Tensor("AttentionOcr_v1/pool_views_fn/STCK/Reshape:0", shape=(32, 1024, 288), dtype=float32)
DEBUG 2017-06-27 02:47:08.000086: sequence_layers.py: 421 Use AttentionWithAutoregression as a layer class
DEBUG 2017-06-27 02:47:09.000189: model.py: 331 chars_logit: Tensor("AttentionOcr_v1/sequence_logit_fn/SQLR/concat:0", shape=(32, 37, 134), dtype=float32)
2017-06-27 02:47:09.209585: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-27 02:47:09.209596: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-27 02:47:09.209599: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-06-27 02:47:09.209602: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-27 02:47:09.209605: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
2017-06-27 02:47:09.422637: I tensorflow/core/common_runtime/gpu/gpu_device.cc:887] Found device 0 with properties:
name: GeForce GTX 1080
major: 6 minor: 1 memoryClockRate (GHz) 1.8095
pciBusID 0000:01:00.0
Total memory: 7.92GiB
Free memory: 7.80GiB
2017-06-27 02:47:09.422661: I tensorflow/core/common_runtime/gpu/gpu_device.cc:908] DMA: 0
2017-06-27 02:47:09.422665: I tensorflow/core/common_runtime/gpu/gpu_device.cc:918] 0: Y
2017-06-27 02:47:09.422670: I tensorflow/core/common_runtime/gpu/gpu_device.cc:977] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080, pci bus id: 0000:01:00.0)
INFO 2017-06-27 02:47:09.000447: model.py: 511 Request to re-store 116 weights from model.ckpt-399731
INFO 2017-06-27 02:47:09.000542: model.py: 511 Request to re-store 104 weights from /home/sudheer/Flipkart/Research/maneesh/tensor_flow/models/models/attention_ocr/python/pretrained_models/inception_v3.ckpt
2017-06-27 02:47:10.229472: W tensorflow/core/kernels/queue_base.cc:302] _0_shuffle_batch/random_shuffle_queue: Skipping cancelled dequeue attempt with queue not closed
Traceback (most recent call last):
File "test.py", line 70, in
Caused by op u'AttentionOcr_v1/conv_tower_fn/INCE/InceptionV3/Conv2d_1a_3x3/weights/read', defined at:
File "test.py", line 70, in
FailedPreconditionError (see above for traceback): Attempting to use uninitialized value AttentionOcr_v1/conv_tower_fn/INCE/InceptionV3/Conv2d_1a_3x3/weights [[Node: AttentionOcr_v1/conv_tower_fn/INCE/InceptionV3/Conv2d_1a_3x3/weights/read = IdentityT=DT_FLOAT, _class=["loc:@AttentionOcr_v1/conv_tower_fn/INCE/InceptionV3/Conv2d_1a_3x3/weights"], _device="/job:localhost/replica:0/task:0/gpu:0"]] [[Node: AttentionOcr_v1/predicted_chars/_3 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_7630_AttentionOcr_v1/predicted_chars", tensor_type=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"]()]] `
It looks like you created the initialization part of the graph referred by the init_fn
tensor, but you didn't actually used it. Try to call sess.run(init_fn)
before predictions = sess.run(endpoints.predicted_chars)
.
hi @alexgorban,
Thank you very much. I tried doing as you said, calling sess.run(init_fn)
with tf.Session() as sess:
init_fn = model.create_init_fn_to_restore(FLAGS.checkpoint, FLAGS.checkpoint_inception)
sess.run(init_fn)
predictions = sess.run(endpoints.predicted_chars)
I'm getting the following error: I must be very close to getting it working. I'm sorry as I'm a new user to TF. Please let me know how to resolve the following error.
Traceback (most recent call last):
File "test.py", line 74, in
Thank you in advance.
This question is better asked on StackOverflow since it is not a bug or feature request. There is also a larger community that reads questions there. Thanks!
System information
Describe the problem
I was trying to use the pretrained model of attention_ocr (model.ckpt-399731) on test data (fsn data). My idea was once I'm able to run it successfully, I can try it on my own images.
But when I followed the provided instructions to use pretrained model, I'm getting the following error:
Traceback (most recent call last): File "test.py", line 60, in <module> app.run() File "/home/sudheer/Flipkart/Research/maneesh/tensorflow_1.1/local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 48, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File "test.py", line 54, in main predictions = sess.run(endpoints.predicted_chars, feed_dict={img_data:data.images}) File "/home/sudheer/Flipkart/Research/maneesh/tensorflow_1.1/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 778, in run run_metadata_ptr) File "/home/sudheer/Flipkart/Research/maneesh/tensorflow_1.1/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 936, in _run raise TypeError('The value of a feed cannot be a tf.Tensor object. ' TypeError: The value of a feed cannot be a tf.Tensor object. Acceptable feed values include Python scalars, strings, lists, numpy ndarrays, or TensorHandles.
Here are the steps I followed:
img_data = tf.placeholder(tf.float32, shape=(32, 150, 600, 3), name='img_data')
endpoints = model.create_base(img_data, labels_one_hot=None)
init_fn = model.create_init_fn_to_restore(FLAGS.checkpoint, FLAGS.checkpoint_inception)
I'm getting the error in the last line when running predictions.
Source code
Please find the complete source code `def main(_):
`
Logs
Please find the complete stack trace:
INFO 2017-06-20 02:49:57.000398: fsns.py: 130 Using FSNS dataset split_name=test dataset_dir=/home/sudheer/Flipkart/Research/maneesh/tensor_flow/models/models/attention_ocr/python/datasets/data/fsns 2017-06-20 02:49:57.519862: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations. 2017-06-20 02:49:57.519882: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. 2017-06-20 02:49:57.519889: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations. 2017-06-20 02:49:57.519894: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations. 2017-06-20 02:49:57.519898: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations. 2017-06-20 02:49:57.798192: I tensorflow/core/common_runtime/gpu/gpu_device.cc:887] Found device 0 with properties: name: GeForce GTX 1080 major: 6 minor: 1 memoryClockRate (GHz) 1.8095 pciBusID 0000:01:00.0 Total memory: 7.92GiB Free memory: 7.64GiB 2017-06-20 02:49:57.798225: I tensorflow/core/common_runtime/gpu/gpu_device.cc:908] DMA: 0 2017-06-20 02:49:57.798232: I tensorflow/core/common_runtime/gpu/gpu_device.cc:918] 0: Y 2017-06-20 02:49:57.798241: I tensorflow/core/common_runtime/gpu/gpu_device.cc:977] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080, pci bus id: 0000:01:00.0) DEBUG 2017-06-20 02:49:57.000835: model.py: 314 images: Tensor("img_data:0", shape=(32, 150, 600, 3), dtype=float32) DEBUG 2017-06-20 02:49:57.000837: model.py: 319 Views=4 single view: Tensor("AttentionOcr_v1/split:0", shape=(32, 150, 150, 3), dtype=float32) DEBUG 2017-06-20 02:49:57.000837: model.py: 186 Using final_endpoint=Mixed_5d DEBUG 2017-06-20 02:49:58.000554: model.py: 186 Using final_endpoint=Mixed_5d DEBUG 2017-06-20 02:49:58.000940: model.py: 186 Using final_endpoint=Mixed_5d DEBUG 2017-06-20 02:49:59.000301: model.py: 186 Using final_endpoint=Mixed_5d DEBUG 2017-06-20 02:49:59.000722: model.py: 325 Conv tower: Tensor("AttentionOcr_v1/conv_tower_fn/INCE/InceptionV3/Mixed_5d/concat:0", shape=(32, 16, 16, 288), dtype=float32) DEBUG 2017-06-20 02:49:59.000724: model.py: 328 Pooled views: Tensor("AttentionOcr_v1/pool_views_fn/STCK/Reshape:0", shape=(32, 1024, 288), dtype=float32) DEBUG 2017-06-20 02:49:59.000724: sequence_layers.py: 421 Use AttentionWithAutoregression as a layer class DEBUG 2017-06-20 02:50:00.000818: model.py: 331 chars_logit: Tensor("AttentionOcr_v1/sequence_logit_fn/SQLR/concat:0", shape=(32, 37, 134), dtype=float32) WARNING:tensorflow:From /home/sudheer/Flipkart/Research/maneesh/tensorflow_1.1/models/attention_ocr/python/model.py:358: get_total_loss (from tensorflow.contrib.losses.python.losses.loss_ops) is deprecated and will be removed after 2016-12-30. Instructions for updating: Use tf.losses.get_total_loss instead. WARNING 2017-06-20 02:50:01.000253: deprecation.py: 117 From /home/sudheer/Flipkart/Research/maneesh/tensorflow_1.1/models/attention_ocr/python/model.py:358: get_total_loss (from tensorflow.contrib.losses.python.losses.loss_ops) is deprecated and will be removed after 2016-12-30. Instructions for updating: Use tf.losses.get_total_loss instead. WARNING:tensorflow:From /home/sudheer/Flipkart/Research/maneesh/tensorflow_1.1/local/lib/python2.7/site-packages/tensorflow/contrib/losses/python/losses/loss_ops.py:261: get_losses (from tensorflow.contrib.losses.python.losses.loss_ops) is deprecated and will be removed after 2016-12-30. Instructions for updating: Use tf.losses.get_losses instead. WARNING 2017-06-20 02:50:01.000253: deprecation.py: 117 From /home/sudheer/Flipkart/Research/maneesh/tensorflow_1.1/local/lib/python2.7/site-packages/tensorflow/contrib/losses/python/losses/loss_ops.py:261: get_losses (from tensorflow.contrib.losses.python.losses.loss_ops) is deprecated and will be removed after 2016-12-30. Instructions for updating: Use tf.losses.get_losses instead. WARNING:tensorflow:From /home/sudheer/Flipkart/Research/maneesh/tensorflow_1.1/local/lib/python2.7/site-packages/tensorflow/contrib/losses/python/losses/loss_ops.py:263: get_regularization_losses (from tensorflow.contrib.losses.python.losses.loss_ops) is deprecated and will be removed after 2016-12-30. Instructions for updating: Use tf.losses.get_regularization_losses instead. WARNING 2017-06-20 02:50:01.000253: deprecation.py: 117 From /home/sudheer/Flipkart/Research/maneesh/tensorflow_1.1/local/lib/python2.7/site-packages/tensorflow/contrib/losses/python/losses/loss_ops.py:263: get_regularization_losses (from tensorflow.contrib.losses.python.losses.loss_ops) is deprecated and will be removed after 2016-12-30. Instructions for updating: Use tf.losses.get_regularization_losses instead. INFO 2017-06-20 02:50:01.000279: model.py: 511 Request to re-store 116 weights from model.ckpt-399731 INFO 2017-06-20 02:50:01.000462: model.py: 511 Request to re-store 104 weights from /home/sudheer/Flipkart/Research/maneesh/tensor_flow/models/models/attention_ocr/python/pretrained_models/inception_v3.ckpt Traceback (most recent call last): File "test.py", line 60, in <module> app.run() File "/home/sudheer/Flipkart/Research/maneesh/tensorflow_1.1/local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 48, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File "test.py", line 54, in main predictions = sess.run(endpoints.predicted_chars, feed_dict={img_data:data.images}) File "/home/sudheer/Flipkart/Research/maneesh/tensorflow_1.1/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 778, in run run_metadata_ptr) File "/home/sudheer/Flipkart/Research/maneesh/tensorflow_1.1/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 936, in _run raise TypeError('The value of a feed cannot be a tf.Tensor object. ' TypeError: The value of a feed cannot be a tf.Tensor object. Acceptable feed values include Python scalars, strings, lists, numpy ndarrays, or TensorHandles.
Please let me know if I'm doing something wrong and how should I fix my code. If anyone has successfully used pretrained attention_ocr model to test on their images, I really appreciate if you can provide me the python script you used or series of steps I need to follow to do the same.