【发布时间】: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