Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Tensorflow对象检测API-如何在推断后读取TFRecord?_Python 3.x_Tensorflow_Object Detection Api - Fatal编程技术网

Python 3.x Tensorflow对象检测API-如何在推断后读取TFRecord?

Python 3.x Tensorflow对象检测API-如何在推断后读取TFRecord?,python-3.x,tensorflow,object-detection-api,Python 3.x,Tensorflow,Object Detection Api,我已使用以下方法运行对象检测推断: PYTHONPATH=$PYTHONPATH:$(readlink -f ..) \ python -m object_detection/inference/infer_detections \ --input_tfrecord_paths=$TF_RECORD_FILES \ --output_tfrecord_path=${SPLIT}_detections.tfrecord-00000-of-00001 \ --inference_grap

我已使用以下方法运行对象检测推断:

PYTHONPATH=$PYTHONPATH:$(readlink -f ..) \
python -m object_detection/inference/infer_detections \
  --input_tfrecord_paths=$TF_RECORD_FILES \
  --output_tfrecord_path=${SPLIT}_detections.tfrecord-00000-of-00001 \
  --inference_graph=faster_rcnn_inception_resnet_v2_atrous_oid/frozen_inference_graph.pb \
  --discard_image_pixels
如何读取生成的TFRecord文件以查看检测到的对象

我有以下代码

    def read_decode(fname_queue):
    reader = tf.TFRecordReader()
    key, serialized_example = reader.read(fname_queue)
    features = tf.parse_single_example(serialized_example,
                                  features = {
                                    'image/encoded': tf.FixedLenFeature([], tf.string),
                                    'image/height': tf.FixedLenFeature([],tf.int64),
                                    'image/width': tf.FixedLenFeature([], tf.int64),
                                    'image/detection/bbox/xmin': tf.FixedLenFeature([], tf.float32),
                                    'image/detection/bbox/xmax': tf.FixedLenFeature([], tf.float32),
                                    'image/detection/bbox/ymin': tf.FixedLenFeature([], tf.float32),
                                    'image/detection/bbox/ymax': tf.FixedLenFeature([], tf.float32),
                                    'image/detection/label': tf.FixedLenFeature([], tf.int64),
                                    'image/detection/score': tf.FixedLenFeature([], tf.float32,)
                                              }
                                      )
    image_encoded = features["image/encoded"]
    image_raw = tf.image.decode_png(image_encoded, channels=3)
    height = features['image/height']
    width = features['image/width']
    xmin = features['image/detection/bbox/xmin']
    ymin = features['image/detection/bbox/ymin']
    xmax = features['image/detection/bbox/xmax']
    ymax = features['image/detection/bbox/ymax']
    label = features['image/detection/label']
    score = features['image/detection/score']
    bbox = [ymin,xmin,ymax,xmax]
    return [image_raw,bbox,score,label]

current_image = read_decode(fname_queue)
with tf.Session() as sess:
    sess.run(tf.initialize_all_variables())
    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(coord=coord)
    for i in range(1):
        image_data = sess.run([current_image])
        img = Image.fromarray(image_data[0], "RGB")
        plt.imshow(img)
    coord.request_stop()
    coord.join(threads)
    sess.close()
但我得到了一个错误:

InvalidArgumentError:Key:image/detection/bbox/xmin。无法分析序列化的示例。 [{node ParseSingleExample_17/ParseSingleExample}}=ParseSingleExample[Tdense=[DT_FLOAT,DT_FLOAT,DT_FLOAT,DT_INT64,DT_FLOAT,DT_STRING,DT_INT64,DT_INT64],密集_键=[“image/detection/bbox/xmax”,“image/detection/bbox/xmin”,“image/detection/bbox/ymax”,“image/detection/label”,“image/detection/index/score”,“图像/编码”、“图像/高度”、“图像/宽度”]、密集形状=[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、[]、(ReaderReadV2_17:1,ParseSingleExample_17/Const,ParseSingleExample_17/Const,ParseSingleExample_17/Const,ParseSingleExample_17/Const,ParseSingleExample_17/Const 6,ParseSingleExample_17/Const_4,ParseSingleExample_17/Const_4)]

只是一个建议(与错误无关),如果Tensorflow版本>=1.4,您可以尝试tf.data模块,而不是使用线程、队列和协调器。这将有助于从代码中删除for循环、线程和协调器行

以下是Tensorflow文档中的注释:

注意:在TensorFlow 1.2之前的版本中,我们建议使用基于队列->的多线程输入管道来提高性能。但是,从TensorFlow 1.4开始,我们>建议改用tf.data模块。(有关详细信息,请参阅数据集。在TensorFlow 1.2>和1.3中,该模块称为tf.contrib.data。)tf.data模块提供了一个更易于->使用的接口,用于构建高效的输入管道。此外,我们已停止>开发旧的多线程、基于队列的输入管道。我们在该文件中保留了>文档,以帮助仍在维护旧代码的开发人员

有关详细信息,请查看此页:

这与批量中有两个大小不同的元素有关,即使在1.6版本中也会失败