yolov7评价指标P,R
时间: 2025-03-05 10:42:55 浏览: 71
### YOLOv7 模型评估中的精确率(Precision) 和召回率(Recall)
对于YOLOv7模型而言,在目标检测任务中,精确率和召回率是非常重要的两个评价指标。
#### 精确率 (Precision)
精确率定义为被正确识别为目标的实例数占所有被预测为目标实例的比例。其计算公式如下:
\[ \text{Precision} = \frac{\text{TP}}{\text{TP} + \text{FP}} \]
其中 TP 表示真正类(True Positive),即实际存在且被正确分类的目标;FP 则表示假正类(False Positive),指的是实际上不存在却被错误地标记为目标的情况[^1]。
#### 召回率 (Recall)
召回率衡量的是在所有的实际阳性样本中,有多少比例被成功检出。具体表达式为:
\[ \text{Recall} = \frac{\text{TP}}{\text{TP} + \text{FN}} \]
这里 FN 是指假负类(False Negative),意味着确实存在的物体却没有被检测到的情形。
为了更直观地理解这两个概念及其相互关系,通常会绘制 Precision-Recall 曲线来展示随着阈值变化时两者之间的权衡情况。此外,还可以通过 F1-score 来综合考虑 precision 和 recall 的平衡程度,它等于两者的调和平均值:
\[ F_1\ score = 2 * (\frac{\text{precision}*\text{recall}}{\text{precision}+\text{recall}})\ ]
当评估像YOLOv7这样的多类别对象检测器的整体性能时,除了单独查看每个类别的 P-R 值外,还经常采用 mAP(mean Average Precision)作为总体度量标准之一[^2]。
```python
def calculate_precision_recall(tp, fp, fn):
"""
计算给定tp(真阳)、fp(假阳)和fn(假阴)下的精度和召回率
参数:
tp -- 正确预测的数量
fp -- 错误标记为正类的数量
fn -- 应该被发现但实际上未找到的对象数量
返回:
precision -- 精确率
recall -- 召回率
"""
try:
precision = tp / (tp + fp)
except ZeroDivisionError:
precision = 0
try:
recall = tp / (tp + fn)
except ZeroDivisionError:
recall = 0
return round(precision, 4), round(recall, 4)
# 示例数据点
true_positives = 95
false_positives = 5
false_negatives = 10
precision_value, recall_value = calculate_precision_recall(true_positives, false_positives, false_negatives)
print(f"Precision: {precision_value}, Recall: {recall_value}")
```
阅读全文
相关推荐


















