无法使用 Tensorflow 的对象检测评估测试数据 API

Trouble evaluating test data with Tensorflow's Object Detection API

概述

我正在使用 Tensorflow's Object Detection API 使用自定义训练数据开发对象检测器。到目前为止,我的理解是我可以将我的训练数据输入模型,然后使用经过训练的模型 [0] 来评估测试数据,并且在评估之后,我将能够看到一组图像,如下所示弄清楚经过训练的模型能够在我的测试数据中的每个图像中检测到什么。

到目前为止我做了什么

根据这个假设,我已经能够创建一个 .tfrecord 格式的训练数据集,并且我已经能够使用以下命令将其输入到我的模型训练器中:

PIPELINE_CONFIG_PATH="nbl-tf-test.config"
MODEL_DIR="./object_detection/modeldir"
NUM_TRAIN_STEPS=50000
SAMPLE_1_OF_N_EVAL_EXAMPLES=1

python3 object_detection/model_main.py \
    --pipeline_config_path=${PIPELINE_CONFIG_PATH} \
    --model_dir=${MODEL_DIR} \
    --num_train_steps=${NUM_TRAIN_STEPS} \
    --sample_1_of_n_eval_examples=$SAMPLE_1_OF_N_EVAL_EXAMPLES \
    --alsologtostderr

这给了我看起来像这样的输出(重复了很多次——这只是一个代表性样本):

2019-01-08 00:47:31.007154: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1511] Adding visible gpu devices: 0
2019-01-08 00:47:31.007931: I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-01-08 00:47:31.007957: I tensorflow/core/common_runtime/gpu/gpu_device.cc:988]      0
2019-01-08 00:47:31.007964: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 0:   N
2019-01-08 00:47:31.008119: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 5278 MB memory) -> physical GPU (device: 0, na
me: Tesla K20Xm, pci bus id: 0000:02:00.0, compute capability: 3.5)
creating index...
index created!
creating index...
index created!
Running per image evaluation...
Evaluate annotation type *bbox*
DONE (t=17.90s).
Accumulating evaluation results...
DONE (t=2.83s).
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.007
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.020
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.003
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.000
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.006
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.008
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.018
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.089
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.485
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.015
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.367
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.573
creating index...
index created!
creating index...
index created!
Running per image evaluation...
Evaluate annotation type *bbox*
DONE (t=17.94s).
Accumulating evaluation results...
DONE (t=2.86s).

本次培训结束后,我在object_detection/modeldir目录下找到了一组文件:

$ ls modeldir
checkpoint                              model.ckpt-308.meta
eval_0                                  model.ckpt-485.data-00000-of-00001
events.out.tfevents.1546897788.moose55  model.ckpt-485.index
export                                  model.ckpt-485.meta
graph.pbtxt                             model.ckpt-664.data-00000-of-00001
model.ckpt-1000.data-00000-of-00001     model.ckpt-664.index
model.ckpt-1000.index                   model.ckpt-664.meta
model.ckpt-1000.meta                    model.ckpt-844.data-00000-of-00001
model.ckpt-308.data-00000-of-00001      model.ckpt-844.index
model.ckpt-308.index                    model.ckpt-844.meta

我的问题

我应该如何处理这个目录的内容来测试我的测试数据?我假设我必须为所有测试数据创建一个 .tfrecord 文件(类似于我之前为训练数据创建的文件)。基于 the model's documentation,我一直在尝试 运行 以下命令:

python3 object_detection/inference/infer_detections.py \
  --input_tfrecord_paths=output.tfrecord \
  --output_tfrecord_path=detections.tfrecord \
  --inference_graph=object_detection/modeldir-8steps/graph.pbtxt \
  --discard_image_pixels

但是当我这样做时,我 运行 出现以下错误(运行 Python 2 和 Python 3):

INFO:tensorflow:Reading graph and building model...
Traceback (most recent call last):
  File "object_detection/inference/infer_detections.py", line 96, in <module>
    tf.app.run()
  File "/usr/lib/python3.4/site-packages/tensorflow/python/platform/app.py", line 125, in run
    _sys.exit(main(argv))
  File "object_detection/inference/infer_detections.py", line 74, in main
    image_tensor, FLAGS.inference_graph)
  File "/home/jlittle/honors/5-tf-nbl-clean-setup/object_detection/inference/detection_inference.py", line 71, in build_inference_graph
    graph_def.MergeFromString(graph_content)
TypeError: 'str' does not support the buffer interface

有谁知道:

  1. 我上面的概述是否正确?如果是这样,
  2. 如果这是正确的评价python脚本我应该运行宁?如果是,
  3. 如果我提供给脚本的数据有任何问题,会出现上面的错误吗?最后,
  4. 如果这是进行该项目的最佳方式,或者我是否偏离了基本点并且应该考虑其他事情?

谢谢。


[0]:这是正确的词汇表,以两种不同的方式使用 model 吗?

我理解错了。 model_main.py 程序是独立的;它执行训练和评估步骤,之后我不需要对该目录做任何事情。要查看测试输出,只需将 TensorBoard 实例附加到模型目录即可。