使用Tensorflow的对象检测API评估测试数据很困难

时间:2019-01-08 19:14:42

标签: python tensorflow object-detection object-detection-api

概述

我正在使用Tensorflow's Object Detection API和自定义训练数据来开发物体检测器。到目前为止,我的理解是,我可以将训练数据输入模型,然后使用训练好的模型[0]评估测试数据,并且在评估之后,我将能够看到类似于以下内容的一组图像找出训练后的模型能够在我的测试数据中的每张图像中检测到什么。

Image of example output

到目前为止我做了什么

基于此假设,我已经能够创建.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 这样的语言?

1 个答案:

答案 0 :(得分:0)

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