我想要张量流模型中预测边界框的坐标。我正在使用here中的对象检测脚本。在关于stackoverflow的一些答案之后,我将检测的最后一块修改为
for image_path in TEST_IMAGE_PATHS:
image = Image.open(image_path)
# the array based representation of the image will be used later in order to prepare the
# result image with boxes and labels on it.
image_np = load_image_into_numpy_array(image)
# Expand dimensions since the model expects images to have shape: [1, None, None, 3]
image_np_expanded = np.expand_dims(image_np, axis=0)
# Actual detection.
output_dict = run_inference_for_single_image(image_np, detection_graph)
# Visualization of the results of a detection.
width, height = image.size
print(width,height)
ymin = output_dict['detection_boxes'][5][0]*height
xmin = output_dict['detection_boxes'][5][1]*width
ymax = output_dict['detection_boxes'][5][2]*height
xmax = output_dict['detection_boxes'][5][3]*width
#print(output_dict['detection_boxes'][0])
print (xmin,ymin)
print (xmax,ymax)
但是output_dict ['detection_boxes']中有100个元组。即使对于无法预测的图像,也存在100个元组。
我想要的是单个图像所有边界框的坐标。
我想要张量流模型中预测边界框的坐标。我正在从这里使用对象检测脚本。在对stackoverflow做出一些回答之后,我修改了...
expand_dims行之后,您可以添加这些代码。 filtered_boxes变量将给出其预测值大于0.5的边界框。
如果检查正在使用的模型的pipeline.config文件,则可以看到在某些地方最大框数设置为100。例如,在演示笔记本中的型号config file of ssd_mobilenet_v1中,您可以在[]下看到它
post_processing {
batch_non_max_suppression {
...
max_detections_per_class: 100
max_total_detections: 100
}
}
for image_path in TEST_IMAGE_PATHS:
image_np = cv2.imread(image_path)
# Expand dimensions since the model expects images to have shape: [1, None, None, 3]
image_np_expanded = np.expand_dims(image_np, axis=0)
# Actual detection.
output_dict = run_inference_for_single_image(image_np, detection_graph)
# Visualization of the results of a detection.
vis_util.visualize_boxes_and_labels_on_image_array(
image_np,
output_dict['detection_boxes'],
output_dict['detection_classes'],
output_dict['detection_scores'],
category_index,
instance_masks=output_dict.get('detection_masks'),
use_normalized_coordinates=True,
line_thickness=8)
#if using cv2 to load image
(im_width, im_height) = image_np.shape[:2]
ymin = output_dict['detection_boxes'][0][0]*im_height
xmin = output_dict['detection_boxes'][0][1]*im_width
ymax = output_dict['detection_boxes'][0][2]*im_height
xmax = output_dict['detection_boxes'][0][3]*im_width