Reputation: 371
I'm trying to perform inference using a SavedModel from the detection model zoo. I was able to get a working example using the Object Detection Tutorial. However, it runs far to slowly and I suspect it could be quicker if I use tfrecords as inputs. Additionally, unfortunately I'm stuck using Tensorflow 1.14.
feature_description = {'image_raw': tf.io.FixedLenFeature([], tf.string, default_value='')}
def _parse_function(example_proto):
# Parse the input `tf.Example` proto using the dictionary above.
return tf.io.parse_single_example(example_proto, feature_description)
sm_dir = '/faster_rcnn_inception_resnet_v2_atrous_coco_2018_01_28/saved_model'
sm = tf.saved_model.load_v2(sm_dir)
f = sm.signatures['serving_default']
tfr_loc = 'inputs.tfr'
raw_dataset = tf.data.TFRecordDataset(tfr_loc)
parsed_dataset = raw_dataset.map(_parse_function)
with tf.Session() as sess:
for tfr_i in parsed_dataset:
imgs_raw = tf.decode_raw(tfr_i['image_raw'], tf.float32)
imgs_raw = tf.reshape(imgs_raw, [-1, 1028, 768, 3])
inference = f(imgs_raw)
sess.run(inference)
This gives me the following error:
tensorflow.python.framework.errors_impl.NotFoundError: Resource AnonymousIterator/AnonymousIterator0/N10tensorflow4data16IteratorResourceE does not exist.
Upvotes: 0
Views: 346
Reputation: 51
I know this is an old question, but this came up for me recently, and I found that most of the answers surrounding this issue were unhelpful. I figured I would post what worked for me to potentially help any future troubleshooters.
Via the TF GitHub: https://github.com/tensorflow/tensorflow/issues/33258
A dev suggested passing experimental_run_tf_function=False
to model.compile()
, and this solved my issue. The output looks odd, but the code runs and my model trains successfully.
Upvotes: 1
Reputation: 994
You need to use Eager Execution at the beginning of your script.
tf.enable_eager_execution()
Reference: https://www.tensorflow.org/api_docs/python/tf/data/Dataset#iter
Upvotes: 0