【问题标题】:Count number of objects detected using tensorflow object detection api计算使用 tensorflow 对象检测 api 检测到的对象数量
【发布时间】:2017-08-02 23:01:00
【问题描述】:

我是张量流的新手。我对如何计算使用 TensorFlow 对象检测 API 检测到的对象数量感到困惑?

# Score is shown on the result image, together with the class label.

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')

if image_np_expanded is not None:
    # Actual detection.
    (boxes, scores, classes, num_detections) = sess.run(
        [boxes, scores, classes, num_detections],
        feed_dict={image_tensor: image_np_expanded}
    )

由于 num_detections 是一个 numpy.ndarray,我已尝试检索它的长度但不起作用。

num_detections.size
>> 1

不使用张量长度:

tf.size(num_detections, out_type=tf.int32)
>> 1

在我的情况下,检测到的对象数量不止一个。

【问题讨论】:

  • 你能说说你写num_detections.size时遇到了什么错误吗?
  • 它返回1,但检测到的对象不止一个。
  • 试试 num_detections[0]?
  • num_detections 总是返回 1 作为大小。为了获得检测到的对象数量,我使用了 box.shape[0] 并带有关于分数精度的条件。感谢您的帮助
  • 看来您实际上需要在通过非最大抑制函数后计算边界框的数量。我不知道num_detections 应该代表什么。

标签: python numpy tensorflow object-detection


【解决方案1】:

我一直在做类似的过程,但工作流程不同。我在 object_detection 笔记本中重写了教程代码,如下所示。它捕获检测框、类别和概率的输出,并忽略推理后的任何图像处理。对于我的情况,我将结果转储到 JSON 文件中,然后将它们导入另一个程序以完成我的分析(确定检测次数),但如果你喜欢 python,我认为你可以处理“myResults”来得到你的答案。

myResults = collections.defaultdict(list)
for image_path in TEST_IMAGE_PATHS:
  if os.path.exists(image_path):  
    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.
    op=get_scores(
      output_dict['detection_boxes'],
      output_dict['detection_classes'],
      output_dict['detection_scores'],
      category_index,
      min_score_thresh=.2)
    myResults[image_path].append(op)  

【讨论】:

  • get_scores 方法在哪里?
猜你喜欢
  • 1970-01-01
  • 2021-02-01
  • 2018-01-17
  • 2017-12-02
  • 1970-01-01
  • 1970-01-01
  • 2019-03-12
  • 1970-01-01
  • 2018-01-14
相关资源
最近更新 更多