Tensorflow 测试自己的目标检测与识别模型 (六)
在该文件下新建一个名为test.py的文件,其代码如下:
import numpy as np
import os
import sys
import tensorflow as tf
from matplotlib import pyplot as plt
from PIL import Image
from object_detection.utils import label_map_util
from object_detection.utils import visualization_utils as vis_util
PATH_TO_CKPT = './data_set/ssd_inception_v2_coco/frozen_inference_graph.pb'
PATH_TO_LABELS = './label_map.pbtxt' # 添加pbtxt文件的路径
NUM_CLASSES = 6 # 我的类别数为1, 这里根据自己的类别数修改
detection_graph = tf.Graph()
with detection_graph.as_default():
od_graph_def = tf.GraphDef()
with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:
serialized_graph = fid.read()
od_graph_def.ParseFromString(serialized_graph)
tf.import_graph_def(od_graph_def, name='')
#Loading label map
label_map = label_map_util.load_labelmap(PATH_TO_LABELS