使用TensorFlow Object Detection API進行影象物體檢測
阿新 • • 發佈:2019-02-13
匯出模型
訓練完成後得到一些checkpoint檔案在
ssd_mobilenet_train_logs
中,如:- graph.pbtxt
- model.ckpt-200000.data-00000-of-00001
- model.ckpt-200000.info
- model.ckpt-200000.meta
其中meta儲存了graph和metadata,ckpt儲存了網路的weights。
而進行預測時只需模型和權重,不需要metadata,故可使用官方提供的指令碼生成推導圖。
python object_detection/export_inference_graph.py \ --input_type image_tensor \ --pipeline_config_path object_detection/VOC2012/ssd_mobilenet_v1_voc2012.config \ --trained_checkpoint_prefix object_detection/VOC2012/ssd_mobilenet_train_logs/model.ckpt-200000
測試圖片
執行
object_detection_tutorial.ipynb
並修改其中的各種路徑即可。或自寫編譯inference指令碼,如
tensorflow/models/object_detection/infer.py
import sys sys.path.append('..') import os import time import tensorflow as tf import numpy as np from PIL import Image from matplotlib import
執行
infer.py test_images/image1.jpg
即可