如何删除检测分数(百分比)?
How to remove Detection score(percentage)?
我正在尝试使用 faster_rcnn_inception_v2
模型检测自定义对象,我正在使用 Tensorflow Object-Detection API.
在测试模型时,它会将对象检测为带有分数的对象名称,例如 *Person: 99%*
。
如何删除分数
这是我的可视化函数
vis_util.visualize_boxes_and_labels_on_image_array(
image_np,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
use_normalized_coordinates=True,
line_thickness=8)
我已将分数更改为 none
vis_util.visualize_boxes_and_labels_on_image_array(
image_np,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
None,
category_index,
use_normalized_coordinates=True,
line_thickness=8)
改完之后,我得到了这个结果
我假设您使用的是官方 Object Detection Demo notebook 提供的代码,或者它的某些变体?如果是这样,这里的这部分代码就是负责渲染边界框的部分:
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)
要从渲染的边界框中删除检测分数,只需将 output_dict['detection_scores']
替换为 scores=None
:
vis_util.visualize_boxes_and_labels_on_image_array(
image_np,
output_dict['detection_boxes'],
output_dict['detection_classes'],
scores=None, # replace here
category_index,
instance_masks=output_dict.get('detection_masks'),
use_normalized_coordinates=True,
line_thickness=8)
您可以在tensorflow/models/research/object_detection/utils/visualization_utils.py
中查看此函数的源代码。这是其中一条评论中所说的:
scores: a numpy array of shape [N] or None. If scores=None, then this function assumes that the boxes to be plotted are groundtruth boxes and plot all boxes as black with no classes or scores.
要回答您的原始问题,您应该将 visualize_boxes_and_labels_on_image_array
的 skip_scores
和 skip_labels
输入参数设置为 True。
您得到了多余的框,因为当您将 None 作为分数传递时,可视化功能不再能够为预测分数设置阈值。
查看 visualize_boxes_and_labels_on_image_array
的定义,您会注意到默认设置为 0.5 的 min_score_thresh
输入参数。默认情况下,检测到的分数小于 0.5 的框不会可视化,除非您不将 scores
传递给此函数,在这种情况下所有框都会可视化。
我正在尝试使用 faster_rcnn_inception_v2
模型检测自定义对象,我正在使用 Tensorflow Object-Detection API.
在测试模型时,它会将对象检测为带有分数的对象名称,例如 *Person: 99%*
。
如何删除分数
这是我的可视化函数
vis_util.visualize_boxes_and_labels_on_image_array(
image_np,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
use_normalized_coordinates=True,
line_thickness=8)
我已将分数更改为 none
vis_util.visualize_boxes_and_labels_on_image_array(
image_np,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
None,
category_index,
use_normalized_coordinates=True,
line_thickness=8)
改完之后,我得到了这个结果
我假设您使用的是官方 Object Detection Demo notebook 提供的代码,或者它的某些变体?如果是这样,这里的这部分代码就是负责渲染边界框的部分:
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)
要从渲染的边界框中删除检测分数,只需将 output_dict['detection_scores']
替换为 scores=None
:
vis_util.visualize_boxes_and_labels_on_image_array(
image_np,
output_dict['detection_boxes'],
output_dict['detection_classes'],
scores=None, # replace here
category_index,
instance_masks=output_dict.get('detection_masks'),
use_normalized_coordinates=True,
line_thickness=8)
您可以在tensorflow/models/research/object_detection/utils/visualization_utils.py
中查看此函数的源代码。这是其中一条评论中所说的:
scores: a numpy array of shape [N] or None. If scores=None, then this function assumes that the boxes to be plotted are groundtruth boxes and plot all boxes as black with no classes or scores.
要回答您的原始问题,您应该将 visualize_boxes_and_labels_on_image_array
的 skip_scores
和 skip_labels
输入参数设置为 True。
您得到了多余的框,因为当您将 None 作为分数传递时,可视化功能不再能够为预测分数设置阈值。
查看 visualize_boxes_and_labels_on_image_array
的定义,您会注意到默认设置为 0.5 的 min_score_thresh
输入参数。默认情况下,检测到的分数小于 0.5 的框不会可视化,除非您不将 scores
传递给此函数,在这种情况下所有框都会可视化。