[英]How to use Tensorflows object detection model zoo with pretrained models but missing label files (.pbtxt)
我正在嘗試運行Tensorflow對象檢測。 不幸的是,我發現Tensorflow的預訓練模型都沒有標簽文件。 如何獲得這些文件? 我要做的就是測試目標檢測中的幾張圖片並顯示標簽。 到目前為止,以下代碼是我所擁有的。 不幸的是,幾乎所有教程都使用我沒有的標簽文件(.pbtxt)。 在Tensorflow的適當下載頁面上,Tensorflow 檢測模型Zoo據說下載中包含標簽文件,但沒有。 我已經下載了不同的模型。 這些模型都沒有標簽文件。 如果有人可以幫助我,我將不勝感激。
到目前為止,我的代碼:
import tensorflow as tf
import cv2
import os
def get_frozen_graph(graph_file):
"""Read Frozen Graph file from disk."""
with tf.gfile.FastGFile(graph_file, "rb") as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
return graph_def
# The TensorRT inference graph file downloaded from Colab or your local machine.
pb_fname = os.path.join(os.getcwd(), "faster_rcnn_inception_resnet_v2_atrous_coco_2018_01_28", "frozen_inference_graph.pb")
trt_graph = get_frozen_graph(pb_fname)
input_names = ['image_tensor']
# Create session and load graph
tf_config = tf.ConfigProto()
tf_config.gpu_options.allow_growth = True
tf_sess = tf.Session(config=tf_config)
tf.import_graph_def(trt_graph, name='')
tf_input = tf_sess.graph.get_tensor_by_name(input_names[0] + ':0')
tf_scores = tf_sess.graph.get_tensor_by_name('detection_scores:0')
tf_boxes = tf_sess.graph.get_tensor_by_name('detection_boxes:0')
tf_classes = tf_sess.graph.get_tensor_by_name('detection_classes:0')
tf_num_detections = tf_sess.graph.get_tensor_by_name('num_detections:0')
IMAGE_PATH = os.path.join(os.getcwd(), "testimages", "000002_491724089556.png")
image = cv2.imread(IMAGE_PATH)
image = cv2.resize(image, (300, 300))
scores, boxes, classes, num_detections = tf_sess.run([tf_scores, tf_boxes, tf_classes, tf_num_detections], feed_dict={
tf_input: image[None, ...]
})
boxes = boxes[0] # index by 0 to remove batch dimension
scores = scores[0]
classes = classes[0]
num_detections = int(num_detections[0])
最終我可以自己解決問題。 Tensorflow文檔當場有故障。 標簽文件(.pbtxt)隨Tensorflow一起提供,並且位於文件夾/ models / research / object_detection / data /
。 當您僅獲得Model Zoo模型時,它們不在您下載的文件夾中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.