如何在张量流对象检测 API 中获取预测值的百分比?



我已经使用object_detection_tutorial.ipynb显示带有预测值百分比的对象检测器,但是变量num_detectionsTensor("num_detections:0", dtype=float32)之类的TensorVariable,那么如何打印预测值的百分比呢?

你说num_detections是张量变量是什么意思?正如你从他们的代码中看到的那样,他们返回这个张量,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])

最新更新