【问题标题】:ObjectDetection inference with a SavedModel on TFRecords在 TFRecords 上使用 SavedModel 进行 ObjectDetection 推理
【发布时间】:2019-11-19 20:47:01
【问题描述】:

我正在尝试使用SavedModel from the detection model zoo 执行推理。我能够使用Object Detection Tutorial 获得一个工作示例。但是,它运行得非常缓慢,我怀疑如果我使用 tfrecords 作为输入它可能会更快。此外,不幸的是我被困在使用 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)

这给了我以下错误:

tensorflow.python.framework.errors_impl.NotFoundError: Resource AnonymousIterator/AnonymousIterator0/N10tensorflow4data16IteratorResourceE does not exist.

【问题讨论】:

    标签: tensorflow tensorflow-datasets


    【解决方案1】:

    我知道这是一个老问题,但最近我遇到了这个问题,我发现围绕这个问题的大多数答案都没有帮助。我想我会发布对我有用的内容,以帮助未来的疑难解答者。

    通过 TF GitHub:https://github.com/tensorflow/tensorflow/issues/33258

    开发人员建议将experimental_run_tf_function=False 传递给model.compile(),这解决了我的问题。输出看起来很奇怪,但代码运行并且我的模型训练成功。

    【讨论】:

      【解决方案2】:

      您需要在脚本开头使用 Eager Execution。

      tf.enable_eager_execution()
      

      参考:https://www.tensorflow.org/api_docs/python/tf/data/Dataset#iter

      【讨论】:

        猜你喜欢
        • 2021-10-27
        • 2020-10-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-04
        • 2020-10-25
        • 2020-10-11
        • 1970-01-01
        相关资源
        最近更新 更多