yolov8/ultralytics-main/validation.py
2025-03-26 11:26:55 +08:00

21 lines
918 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 导入ultralytics的YOLO库
from ultralytics import YOLO
# 加载模型
model = YOLO(r'D:\ultralytics-main\ultralytics-main\runs\detect\train5\weights\best.pt') # 加载自定义的训练模型
if __name__ == '__main__':
# 对模型进行验证
metrics = model.val() # 调用val方法进行模型验证不需要传入参数数据集和设置已被模型记住
# 输出不同的性能指标
print("AP (mAP@0.5:0.95):", metrics.box.map) # 输出平均精度均值APAverage Precision在IoU阈值从0.5到0.95的范围内的结果
print("AP@0.5 (mAP@0.5):", metrics.box.map50) # 输出在IoU=0.5时的平均精度AP50
print("AP@0.75 (mAP@0.75):", metrics.box.map75) # 输出在IoU=0.75时的平均精度AP75
print("APs per category (mAP@0.5:0.95 per category):", metrics.box.maps) # 输出每个类别在IoU阈值从0.5到0.95的平均精度的列表