首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在TFRecords上使用SavedModel进行ObjectDetection推理

在TFRecords上使用SavedModel进行ObjectDetection推理
EN

Stack Overflow用户
提问于 2019-11-20 04:47:01
回答 2查看 177关注 0票数 0

我正在尝试使用SavedModel from the detection model zoo执行推理。我能够使用Object Detection Tutorial获得一个工作示例。然而,它的运行速度太慢了,我怀疑如果我使用tfrecords作为输入,它可能会更快。此外,不幸的是,我不得不使用Tensorflow 1.14。

代码语言:javascript
复制
    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)

这会给我以下错误:

代码语言:javascript
复制
tensorflow.python.framework.errors_impl.NotFoundError: Resource AnonymousIterator/AnonymousIterator0/N10tensorflow4data16IteratorResourceE does not exist.
EN

回答 2

Stack Overflow用户

发布于 2021-11-08 14:12:51

我知道这是一个老问题,但我最近想到了这个问题,我发现围绕这个问题的大多数答案都没有帮助。我想我会发布对我有用的东西,以潜在地帮助任何未来的疑难解答。

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

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

票数 1
EN

Stack Overflow用户

发布于 2020-06-10 14:18:40

您需要在脚本的开头使用急切执行。

代码语言:javascript
复制
tf.enable_eager_execution()

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58942535

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档