首页 > 解决方案 > 如何在tensorflow对象检测api中为不同检测类可视化具有不同min_thres值的框和标签?

问题描述

我有一个训练有素的模型,有 3 个不同的类。在运行推理时,我想通过以下方法可视化我的检测:

def visualize_boxes_and_labels_on_image_array(
image,
boxes,
classes,
scores,
category_index,
instance_masks=None,
instance_boundaries=None,
keypoints=None,
keypoint_scores=None,
keypoint_edges=None,
track_ids=None,
use_normalized_coordinates=False,
max_boxes_to_draw=20,
min_score_thresh=.5,
agnostic_mode=False,
line_thickness=4,
mask_alpha=.4,
groundtruth_box_visualization_color='black',
skip_boxes=False,
skip_scores=False,
skip_labels=False,
skip_track_ids=False):

但是,每个检测类都以相同的 min_score_thresh 显示,但我想显示具有 min_score_thresh=0.9 的 1 类对象、具有 min_score_thresh=0.6 的 class2-objects 和具有 mimin_score_thresh=0.2 的 class3-objects。你有什么想法吗?

太感谢了。

标签: tensorflowtensorflow2.0object-detectionobject-detection-api

解决方案


使用示例代码可视化边界框。

plt.rcParams['figure.figsize'] = [42, 21]
  label_id_offset = 1
  image_np_with_detections = image_np.copy()
  viz_utils.visualize_boxes_and_labels_on_image_array(
        image_np_with_detections,
        detections['detection_boxes'][0].numpy(),
        detections['detection_classes'][0].numpy().astype(np.int32),
        detections['detection_scores'][0].numpy(),
        category_index,
        use_normalized_coordinates=True,
        max_boxes_to_draw=200,
        min_score_thresh=.40,
        agnostic_mode=False)
  plt.subplot(2, 1, i+1)
  plt.imshow(image_np_with_detections)

在此处查看 Tensorflow 对象检测 API 演示


推荐阅读