由于训练好的权重会记录原来数据的位置,当我们将别人训练好的权重拿来测试时会出现路径不对的情况,又或者想测试数据集的test部分,只需要指定数据集的配置文件位置即可:
from ultralytics import YOLO
import os
os.environ["WANDB_MODE"] = "offline"
# Load a model
model = YOLO('yolov8n.pt') # load an official model
model.overrides['data'] = 'C:/ultralytics/cfg/datasets/coco.yaml' # 自己数据集的配置文件
if __name__ == '__main__':
# Validate the model18
metrics = model.val() # no arguments needed, dataset and settings remembered
metrics.box.map # map50-95
metrics.box.map50 # map50
metrics.box.map75 # map75
metrics.box.maps # a list contains map50-95 of each category