【问题标题】:Tensorflow object detection API: output boxes for probability less than 50%Tensorflow 对象检测 API:概率小于 50% 的输出框
【发布时间】:2018-08-01 17:09:48
【问题描述】:

我指的是 Tensorflow 对象检测 API (https://github.com/tensorflow/models/tree/master/research/object_detection):这是我正在使用的检测代码的 IPython 笔记本 (https://github.com/tensorflow/models/blob/master/research/object_detection/object_detection_tutorial.ipynb)。在此文件中,输出值设置为绘制概率大于 50% 的框 检测代码:

with detection_graph.as_default():
  with tf.Session(graph=detection_graph) as sess:
    # Definite input and output Tensors for detection_graph
    image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
    # Each box represents a part of the image where a particular object was detected.
    detection_boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
    # Each score represent how level of confidence for each of the objects.
    # Score is shown on the result image, together with the class label.
    detection_scores = detection_graph.get_tensor_by_name('detection_scores:0')
    detection_classes = detection_graph.get_tensor_by_name('detection_classes:0')
    num_detections = detection_graph.get_tensor_by_name('num_detections:0')

    #myFile = open('example2.csv', 'w')
    i=0
    #boxeslist=[]
    new_boxes = []
    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.
      (boxes, scores, classes, num) = sess.run(
          [detection_boxes, detection_scores, detection_classes, num_detections],
          feed_dict={image_tensor: image_np_expanded})
      # Visualization of the results of a detection.
      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)

      plt.figure(figsize=IMAGE_SIZE)
      plt.imshow(image_np)

如何更改代码,使其以 > 10% 的概率输出对象周围的框

【问题讨论】:

    标签: python tensorflow machine-learning deep-learning object-detection


    【解决方案1】:

    应该很容易。

    如您所见,本教程调用函数“vis_util.visualize_boxes_and_labels_on_image_array”,其参数为:

    image
    boxes
    classes
    scores
    category_index
    use_normalized_coordinates
    line_thickness
    

    如果在文件中搜索:'research/object_detection/utilis/visualization_utils.py',您可以找到该函数并查看您可以设置的其他参数。

    您可以在其中找到:min_score_tresh 设置为 .5

    如果你设置:

    min_score_tresh=.1
    

    应该会得到想要的结果。

    小心,因为会被吓到

    【讨论】:

    【解决方案2】:

    简单的方法是在“vis_util.visualize_boxes_and_labels_on_image_array”中添加“min_score_thresh”来设置检测阈值:

          # Visualization of the results of a detection.
          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,
              min_score_thresh=.1) # <<======== Add this line for threshold
    
              
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-21
      • 1970-01-01
      • 2022-07-15
      • 2021-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-09
      相关资源
      最近更新 更多