我使用了Tensorflow对象检测API来检测自定义对象。模型运行得很完美,但现在我想知道这些框的坐标。有没有办法知道每个检测到的对象的框坐标?
回答:
请查看教程的IPython笔记本,里面有他们用于检测的代码(链接到GitHub):
with detection_graph.as_default(): with tf.Session(graph=detection_graph) as sess: # 定义检测图的输入和输出张量 image_tensor = detection_graph.get_tensor_by_name('image_tensor:0') # 每个框代表图像中检测到特定对象的部分。 detection_boxes = detection_graph.get_tensor_by_name('detection_boxes:0') # 每个分数表示对每个对象的置信度。 # 分数显示在结果图像上,并与类别标签一起显示。 detection_scores = detection_graph.get_tensor_by_name('detection_scores:0') detection_classes = detection_graph.get_tensor_by_name('detection_classes:0') num_detections = detection_graph.get_tensor_by_name('num_detections:0') for image_path in TEST_IMAGE_PATHS: image = Image.open(image_path) # 图像的数组表示将在后面用于准备带有框和标签的结果图像。 image_np = load_image_into_numpy_array(image) # 扩展维度,因为模型期望图像的形状为:[1, None, None, 3] image_np_expanded = np.expand_dims(image_np, axis=0) # 实际检测。 (boxes, scores, classes, num) = sess.run( [detection_boxes, detection_scores, detection_classes, num_detections], feed_dict={image_tensor: image_np_expanded})
他们将坐标存储在boxes变量中。