[英]How to predict Precision, Recall and F1 score after training SSD
I am new to deep learning and I want to be able to evaluate the model which underwent training for certain epochs using F1 score.我是深度学习的新手,我希望能够使用 F1 分数评估经过特定时期训练的模型。 I believe it requires the calculation of precision and recall first.
我相信它首先需要计算精度和召回率。
The model trained is SSD-300-Tensorflow.训练的模型是 SSD-300-Tensorflow。 Is there a code or something that can produce these results?
是否有代码或可以产生这些结果的东西? I am not using sci-kit or anything as I am not sure if that is required to calculate the score but any guidance is appreciated.
我没有使用 sci-kit 或任何东西,因为我不确定计算分数是否需要这样做,但感谢任何指导。
You should first calculate False positive, False negatives, True positive and True negatives.您应该首先计算假阳性、假阴性、真阳性和真阴性。 To obtain these values you must evaluate your model with test dataset.
要获得这些值,您必须使用测试数据集评估您的模型。 This link might help
此链接可能会有所帮助
with these formulas you can calculate precision and recall and here is some example code:使用这些公式,您可以计算精度和召回率,以下是一些示例代码:
y_hat = []
y = []
threshold = 0.5
for data, label in test_dataset:
y_hat.extend(model.predict(data))
y.extend(label.numpy()[:, 1])
y_hat = np.asarray(y_hat)
y = np.asarray(y)
m = len(y)
y_hat = np.asarray([1 if i > threshold else 0 for i in y_hat[:, 1]])
true_positive = np.logical_and(y, y_hat).sum()
true_negative = np.logical_and(np.logical_not(y_hat), np.logical_not(y)).sum()
false_positive = np.logical_and(np.logical_not(y), y_hat).sum()
false_negative = np.logical_and(np.logical_not(y_hat), y).sum()
total = true_positive + true_negative + false_negative + false_positive
assert total == m
precision = true_positive / (true_positive + false_positive)
recall = true_positive / (true_positive + false_negative)
accuracy = (true_positive + true_negative) / total
f1score = 2 * precision * recall / (precision + recall)
If you are using the Tensorflow Object Detection API, it provides a way for running model evaluation that can be configured for different metrics.如果您使用的是 Tensorflow 对象检测 API,它提供了一种运行模型评估的方法,可以针对不同的指标进行配置。 A tutorial on how to do this is here .
有关如何执行此操作的教程在这里。
The COCO evaluation metrics includes analogous measures of precision and recall for object detection use cases. COCO 评估指标包括对对象检测用例的精确度和召回率的类似测量。 A good overview of these metrics is here .
这些指标的一个很好的概述是here 。 The concepts of precision and recall need to be adapted somewhat for object detection scenarios because you have to define "how closely" a predicted bounding box needs to match the ground truth bounding box to be considered a true positive.
精确率和召回率的概念需要针对对象检测场景进行一些调整,因为您必须定义预测边界框与地面实况边界框匹配的“接近程度”才能被视为真正的正例。
I am not certain what the analog for F1 score would be for object detection scenarios.我不确定对象检测场景中 F1 分数的模拟是什么。 Typically, I have seen models compared using mAP as the single evaluation metric.
通常,我已经看到使用 mAP 作为单一评估指标来比较模型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.