我想知道对象检测中边界框的大小 api
I want to know the size of bounding box in object-detection api
我用过 API
(https://github.com/tensorflow/models/tree/master/object_detection)
然后,
我怎么知道边界框的长度?
我在 github 上实时使用了教程 IPython 笔记本。
但是我不知道用哪个命令来计算盒子的长度
您可以像下面这样调用盒子:
boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
得分类似,类。
然后在会话中调用它们 运行。
(boxes, scores, classes) = sess.run(
[boxes, scores, classes],
feed_dict={image_tensor: imageFile})
只是为了扩展 Beta 的答案:
您可以从检测图中得到预测的边界框。 Tutorial IPython notebook on github 中给出了一个例子。这就是 Beta 的代码片段的来源。访问 detection_graph
并从张量中提取预测边界框的坐标:
通过调用 np.squeeze(boxes)
,您将它们重塑为 (m, 4),其中 m 表示预测框的数量。您现在可以访问这些框并计算长度、面积或任何您想要的东西。
但请记住,预测的框坐标是标准化的!它们的顺序如下:
[ymin, xmin, ymax, xmax]
因此计算像素长度类似于:
def length_of_bounding_box(bbox):
return bbox[3]*IMG_WIDTH - bbox[1]*IMG_WIDTH
基本上,你可以从图中得到所有这些
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')
and boxes[0] 包含格式为 [top_left_x、top_left_y、bottom_right_x、bottom_right_y] 的所有预测边界框坐标寻找。
查看此存储库,您可能会找到更多详细信息:
https://github.com/KleinYuan/tf-object-detection
我写了一个关于如何找到边界框坐标的完整答案 并且认为它也可能对这个线程上的某些人有用。
Google 对象检测 API returns 边界框 [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)
以下识别对象和returns位置和置信度信息的代码是:
(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]):
获取宽度和高度:
width = boxes[0][i][1]+boxes[0][i][3]
height = boxes[0][i][0]+boxes[0][i][2]
您可以找到更多详细信息:[https://pythonprogramming.net/detecting-distances-self-driving-car/]
我用过 API
(https://github.com/tensorflow/models/tree/master/object_detection)
然后,
我怎么知道边界框的长度?
我在 github 上实时使用了教程 IPython 笔记本。
但是我不知道用哪个命令来计算盒子的长度
您可以像下面这样调用盒子:
boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
得分类似,类。
然后在会话中调用它们 运行。
(boxes, scores, classes) = sess.run(
[boxes, scores, classes],
feed_dict={image_tensor: imageFile})
只是为了扩展 Beta 的答案:
您可以从检测图中得到预测的边界框。 Tutorial IPython notebook on github 中给出了一个例子。这就是 Beta 的代码片段的来源。访问 detection_graph
并从张量中提取预测边界框的坐标:
通过调用 np.squeeze(boxes)
,您将它们重塑为 (m, 4),其中 m 表示预测框的数量。您现在可以访问这些框并计算长度、面积或任何您想要的东西。
但请记住,预测的框坐标是标准化的!它们的顺序如下:
[ymin, xmin, ymax, xmax]
因此计算像素长度类似于:
def length_of_bounding_box(bbox):
return bbox[3]*IMG_WIDTH - bbox[1]*IMG_WIDTH
基本上,你可以从图中得到所有这些
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')
and boxes[0] 包含格式为 [top_left_x、top_left_y、bottom_right_x、bottom_right_y] 的所有预测边界框坐标寻找。
查看此存储库,您可能会找到更多详细信息: https://github.com/KleinYuan/tf-object-detection
我写了一个关于如何找到边界框坐标的完整答案
Google 对象检测 API returns 边界框 [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)
以下识别对象和returns位置和置信度信息的代码是:
(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]):
获取宽度和高度:
width = boxes[0][i][1]+boxes[0][i][3]
height = boxes[0][i][0]+boxes[0][i][2]
您可以找到更多详细信息:[https://pythonprogramming.net/detecting-distances-self-driving-car/]