训练后使用 TensorFlow 模型进行物体检测

Use TensorFlow model for object detection after training

我按照这个 tutorial 来训练自定义对象检测器。我已经按照教程成功完成并导出了训练好的推理图。此步骤说明:

Once your training job is complete, you need to extract the newly trained inference graph, which will be later used to perform the object detection.

我现在训练demo下有一个目录结构:

training_demo
  \ trained-inference-graphs
    \ output_inference_Graph_v1.pb
       \ saved_model
          \ variables
          - saved_model.pb
       - checkpoint
       - frozen_inference_graph.pb
       - model.ckpt.data-00000-of-00001
       - model.ckpt.index
       - model.ckpt.meta
       - pipeline.config

问题是我找不到任何关于如何将其用于新图像以检测其中的对象的说明?

我想加载这个新训练的模型并传递一些图像来检测物体。

了解这一点的最简单方法是阅读 Tensorflow 中包含的 Jupyter Notebook 教程。

您可以在 Tensorflow -> 模型 -> 研究 -> 对象检测 -> object_detection_tutorial.ipynb 中找到它,或者通过 link here.

那你需要稍微修改一下Notebook。在这里您需要更改:

  • 删除 "Download Model" 部分。

  • 从重新训练的模型更改到冻结推理图的路径。

  • 将 label_map.pbtxt 更改为您重新训练的标签。

  • 标记测试图像的路径并根据它们的文件扩展名进行调整。默认情况下,它们遵循 "image1.jpg"、"image2.jpg" 等模式

瞧,大功告成。如果需要,您可以先在 Tensorflow Detection Zoo 的预训练模型上使用默认脚本对其进行测试。