如何在Tensorflow Object Detection API中获得预测值的百分比?

时间:2017-08-26 14:35:14

标签: tensorflow object-detection

我已经使用object_detection_tutorial.ipynb来显示具有预测值百分比的对象检测器,但变量num_detectionsTensorVariable,例如Tensor("num_detections:0", dtype=float32),那么如何打印预测值的百分比?

1 个答案:

答案 0 :(得分:0)

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