如何在 Tensorflow 对象检测 API 中获得预测值的百分比?
how to get percentage of predicted value in Tensorflow Object Detection API?
我已经用object_detection_tutorial.ipynb来显示预测值百分比的对象检测器,但是变量num_detections
是一个TensorVariable
,比如Tensor("num_detections:0", dtype=float32)
,那怎么能我打印预测值的百分比?
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])
我已经用object_detection_tutorial.ipynb来显示预测值百分比的对象检测器,但是变量num_detections
是一个TensorVariable
,比如Tensor("num_detections:0", dtype=float32)
,那怎么能我打印预测值的百分比?
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])