【发布时间】:2017-08-26 14:35:13
【问题描述】:
我已经使用object_detection_tutorial.ipynb来显示目标检测器的预测值百分比,但是变量num_detections是TensorVariable,例如Tensor("num_detections:0", dtype=float32),那么如何打印预测值的百分比?
【问题讨论】:
标签: tensorflow object-detection
我已经使用object_detection_tutorial.ipynb来显示目标检测器的预测值百分比,但是变量num_detections是TensorVariable,例如Tensor("num_detections:0", dtype=float32),那么如何打印预测值的百分比?
【问题讨论】:
标签: tensorflow object-detection
num_detections 是 TensorVariable 是什么意思?从他们的代码中可以看出,他们返回了这个张量,num_detections = detection_graph.get_tensor_by_name('num_detections:0')。在这种情况下,num_detections 默认为 100,因为他们以这种方式训练了他们的模型。要获得预测值的百分比,您需要scores。假设您的阈值为 0.5,您可以这样计算预测值的百分比:
import numpy as np
threshold = 0.5 # in order to get higher percentages you need to lower this number; usually at 0.01 you get 100% predicted objects
print(len(np.where(scores[0] > threshold)[0]) / num_detections[0])
【讨论】:
np.where() 的输出是一个数组,因此长度始终为 1,因此它始终为 0.1。请参阅我的更新答案。它现在应该可以工作了!