如何设置绘制框的最低阈值?

时间:2019-02-17 10:21:39

标签: tensorflow object-detection object-detection-api

我有一个与Opencv一起使用的对象检测模型来检测我的自定义类。

我只想在模型的置信度为95%或更高时输出这些框。

有没有办法配置它?

(奖励问题:我可以设置为仅显示置信度最高的对象吗?示例:凸轮分别检测到两个置信度为98%和91%的对象。我希望它仅输出98的框%one。)

如果您需要它,这是我使用opencv的推理代码。

with detection_graph.as_default():
  with tf.Session(graph=detection_graph) as sess:
    while True:
      ret, image_np = cap.read()
      image_np_expanded = np.expand_dims(image_np, axis=0)
      image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
      boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
      scores = detection_graph.get_tensor_by_name('detection_scores:0')
      classes = detection_graph.get_tensor_by_name('detection_classes:0')
      num_detections = detection_graph.get_tensor_by_name('num_detections:0')

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

      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=6)

      cv2.imshow('object detection', cv2.resize(image_np, (800, 600)))
      if cv2.waitKey(25) & 0xFF == ord('q'):
        cv2.destroyAllWindows()
        break

1 个答案:

答案 0 :(得分:0)

好的,回答我自己的问题。我只花了1分钟就自己找到了。

这是使方框可视化的功能。其输入参数在源代码中有很好的解释。

  

object_detection / utils / visualization_utils.visualize_boxes_and_labels_on_image_array(...)

对于我来说,我只需要设置

min_score_thresh=.95max_boxes_to_draw=1,当调用此函数时。