在我的另一篇博客中[tensorflow 物体检测(检测限速标志)](https://blog.csdn.net/WK785456510/article/details/86149398)中已经训练好了模型,接下来我们进行测试模型。
- 导出模型文件
训练完以后,如何对单张图片进行目标检测呢?Object Detection API提供了一个export_inference_graph.py脚本用于导出训练好的模型,我们先将训练好的checkpoint导出成“,pb”文件,再用上一讲的代码,对图片进行目标检测。导出模型命令如下:python export_inference_graph.py --pipeline_config_path=object_detection/my_images/VOCdevkit/VOC2012/ssd_mobilenet_v1.config --trained_checkpoint_prefix=object_detection/my_images/train/model.ckpt-xxxxx --output_directory=object_detection/my_images/train,最后的文件名存在train中的frozen_inference_graph.pb 。
- 批量测试代码
训练过程中会输出精确度,但是我们需要测试自己的图像,查看验证集和训练集效果的时候就需要批量测试。在object_detection建立python文件。代码如下:根据自己图像数量和路径进行必要的修改:
import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import zipfile
import matplotlib
# Matplotl