【问题标题】:Print probabilities and class label tensor flow object detetcion API打印概率和类标签 tensorflow 对象检测 API
【发布时间】:2018-04-20 09:58:42
【问题描述】:

我正在关注 tensorflow 教程并对每张图像进行预测,我想要的是获得类和预测概率

https://github.com/tensorflow/models

我正在使用这段代码按照上面的教程进行操作,我在图像中得到了检测框、标签和概率

代码:

   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.
  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)
  plt.figure(figsize=IMAGE_SIZE)

  plt.imshow(image_np)

想要像

这样的输出
{class: p, prediction:99% , boundigbox: filename,width,height,class,xmin,ymin,xmax,ymax}

【问题讨论】:

    标签: python tensorflow object-detection-api


    【解决方案1】:

    这段代码应该可以正常工作:

    from tensorflow.models.research.object_detection.utils import label_map_util
    
    
    width = image_np.shape[1]  # Number of columns
    height = image_np.shape[0]  # number of rows
    category_index = label_map_util.create_category_index(categories)
    for i in range(len(output_dict['detection_boxes'])):
        class_name = category_index[output_dict['detection_classes'][i]]['name']
        print("{class: %s, prediction: %s, boundingbox: %s,%i,%i,%i,%i,%i,%i,%i}"
              % (class_name,
                 output_dict['detection_scores'][i],
                 image_path,
                 width,
                 height,
                 output_dict['detection_classes'][i],
                 int(width * output_dict['detection_boxes'][i][1]),  # The boxes are given normalized and in row/col order
                 int(height * output_dict['detection_boxes'][i][0]),
                 int(width * output_dict['detection_boxes'][i][3]),
                 int(height * output_dict['detection_boxes'][i][2])
                 ))
    

    【讨论】:

      猜你喜欢
      • 2019-04-21
      • 2021-06-30
      • 2021-12-05
      • 2022-10-08
      • 2018-05-17
      • 1970-01-01
      • 2018-08-01
      • 1970-01-01
      • 2022-07-15
      相关资源
      最近更新 更多