我想知道对象检测api中边界框的大小

时间:2017-09-12 05:22:00

标签: tensorflow object-detection

我使用了API

https://github.com/tensorflow/models/tree/master/object_detection

然后,

我怎么知道边界框的长度?

我已经在github上实时使用了Tutorial IPython笔记本。

但我不知道用哪个命令来计算盒子的长度。

5 个答案:

答案 0 :(得分:7)

只是为了扩展Beta的答案:

您可以从检测图中获取预测的边界框。 Tutorial IPython notebook on github给出了一个例子。这是Beta的代码剪辑来自的地方。访问SWS_FULL_CHR_H_INT | SWS_ACCURATE_RND并从张量中提取预测边界框的坐标:

通过调用detection_graph,您可以将它们重新整形为(m,4),其中m表示预测框的数量。您现在可以访问这些框并计算长度,面积或您想要的任何内容。

但请记住预测的盒子坐标是标准化的!它们按以下顺序排列:

np.squeeze(boxes)

因此,以像素计算长度将类似于:

[ymin, xmin, ymax, xmax]

答案 1 :(得分:3)

我写了一个关于如何找到边界框坐标here的完整答案,并认为它对这个线程上的某个人也有用。

Google Object Detection API以[ymin,xmin,ymax,xmax]格式和标准化格式(完整说明here)返回边界框。要找到(x,y)像素坐标,我们需要将结果乘以图像的宽度和高度。首先得到图像的宽度和高度:

width, height = image.size

然后,从boxes对象中提取ymin,xmin,ymax,xmax并乘以得到(x,y)坐标:

ymin = boxes[0][i][0]*height
xmin = boxes[0][i][1]*width
ymax = boxes[0][i][2]*height
xmax = boxes[0][i][3]*width

最后打印方框角的坐标:

print 'Top left'
print (xmin,ymin,)
print 'Bottom right'
print (xmax,ymax)

答案 2 :(得分:2)

您可以拨打电话,如下所示:

boxes = detection_graph.get_tensor_by_name('detection_boxes:0')

类似于分数和课程。

然后在会话运行中调用它们。

(boxes, scores, classes) = sess.run(
              [boxes, scores, classes],
              feed_dict={image_tensor: imageFile})

答案 3 :(得分:1)

基本上,您可以从图表中获取所有这些

image_tensor = graph.get_tensor_by_name('image_tensor:0')
boxes = graph.get_tensor_by_name('detection_boxes:0')
scores = graph.get_tensor_by_name('detection_scores:0')
classes = graph.get_tensor_by_name('detection_classes:0')
num_detections = graph.get_tensor_by_name('num_detections:0')

和boxes [0]包含所有预测的边界框坐标,格式为[top_left_x,top_left_y,bottom_right_x,bottom_right_y],这正是您要查找的内容。

查看此回购,您可能会找到更多详细信息: https://github.com/KleinYuan/tf-object-detection

答案 4 :(得分:0)

下面的识别对象并返回位置和置信度信息的代码是:

Select date, sum( ("Time TO Abandon" is null)::int ) as TotalCalls,
       sum( ("Time TO Abandon" > 0)::int ) as AbandonCalls
From five9_data.calllog
Where Campaign IN ('FYF', 'SF') and "Campaign Type" IN ('Inbound') and
Group By date
Order By date Desc;

要遍历各个框

(boxes, scores, classes, num_detections) = sess.run(
          [boxes, scores, classes, num_detections],
          feed_dict={image_tensor: image_np_expanded})

获取宽度和高度:

 for i,b in enumerate(boxes[0]):

您可以找到更多详细信息:[https://pythonprogramming.net/detecting-distances-self-driving-car/]