Ultralytics YOLO27: 加入候补名单。
Get Started

使用 Ultralytics YOLO 验证模型#

Ultralytics YOLO ecosystem and integrations

简介#

验证是机器学习流程中的关键步骤,可帮助你评估训练模型的质量。Ultralytics YOLO26 的 Val 模式提供了评估对象检测模型及所有其他受支持任务的工具和指标。本指南将说明如何使用 Val 模式确认模型的准确性和可靠性。

查看尚未发布的 YOLO27 预览版,了解初步验证结果。



观看: Ultralytics 模式教程:验证

为什么使用 Ultralytics YOLO 进行验证?#

使用 YOLO26 Val 模式的理由:

  • 精确度:获取 mAP50、mAP75 和 mAP50-95 等准确指标,全面评估模型。
  • 便捷性:使用内置功能记住训练设置,简化验证流程。
  • 灵活性: 使用相同或不同的数据集和图像尺寸验证模型。
  • 超参数调优: 使用验证指标微调模型,以获得更佳性能。

Val 模式的主要功能#

YOLO26 Val 模式的主要功能:

  • 自动设置: 模型会记住训练配置,让验证变得简单直接。
  • 支持多种指标:使用一系列准确性指标评估模型。
  • CLI 和 Python API:可通过命令行界面或 Python API 验证,任你选择。
  • 数据兼容性:既支持训练时使用的数据集,也支持自定义数据集。
提示
  • YOLO26 模型会自动记住训练设置,因此 yolo val model=path/to/best.pt 或 YOLO("path/to/best.pt").val() 会在训练时使用的图像尺寸和原始数据集上进行验证。官方权重会回退到任务默认数据集;传入 data 可覆盖此设置。

使用示例#

验证训练好的 YOLO26n 模型的准确性。无需提供任何参数,因为 model 会将训练时的 data 和参数保留为模型属性:path/to/best.pt 会在模型训练所用的数据集上进行验证。官方权重记录的训练数据集路径在你的机器上可能不存在,因此系统会发出警告,并改用任务默认值 coco8.yaml。传入 data 可在其他数据集上验证。

Windows 多进程错误

在 Windows 上,如果以脚本方式启动验证,你可能会收到 RuntimeError。在验证代码前添加 if __name__ == "__main__": 块即可解决此问题。

示例
from ultralytics import YOLO

# 加载模型
model = YOLO("yolo26n.pt")  # 加载官方模型
model = YOLO("path/to/best.pt")  # 加载自定义模型

# 验证模型
metrics = model.val()  # 无需参数,数据集和设置会自动记住
metrics.box.map  # map50-95
metrics.box.map50  # map50
metrics.box.map75  # map75
metrics.box.maps  # 每个类别的 mAP50-95;未出现在验证集中的类别采用整体 mAP 值
metrics.box.ap_class_index  # 实际参与评估的类别索引
metrics.box.image_metrics  # 包含精确率、召回率、F1、TP、FP 和 FN 的逐图像指标字典

YOLO 模型验证参数#

验证 YOLO 模型时,可以调整多个参数以定制评估流程。这些参数控制输入图像尺寸、批处理和性能阈值等方面。下文将逐一介绍各参数。

参数类型默认值说明
datastrNone指定数据集 YAML 文件的路径(例如 coco8.yaml),其中应包含验证数据的路径。分类任务则使用数据集目录或内置数据集名称(例如 imagenet10)。
imgszint640定义输入图像的尺寸。处理前会将所有图像调整为此尺寸。较大的尺寸可能提高小对象的检测准确率,但会增加计算时间。
batchint16设置每个批次的图像数量。较大的值能更高效地利用 GPU 内存,但需要更多 VRAM。请根据可用硬件资源进行调整。
save_jsonboolFalse如果 True,则将结果保存到 JSON 文件,以便进一步分析、与其他工具集成,或提交到 COCO 等评估服务器。在检测数据集上,它还会使用 faster-coco-eval 评估预测结果,并报告小、中、大目标的 mAP;训练期间,这些指标会记录为 results.csv 中的 metrics/mAP_small(B)、metrics/mAP_medium(B) 和 metrics/mAP_large(B)。对于语义分割,则会将 PNG 类别掩码保存到 results/ 下,并保留图像子目录结构。
conffloat0.001设置检测结果的最低置信度阈值。较低的值会提高召回率,但可能引入更多假阳性。精确率-召回率曲线、mAP 和检测混淆矩阵均使用此值;较高的 conf(例如 0.25)会使矩阵更接近预测输出,但可能降低 mAP。汇总精确率和召回率使用最大 F1 值对应的置信度,因此可能与根据 confusion_matrix.png 得出的值不同。OBB 验证的默认值为 0.01,以降低内存使用量。
ioufloat0.7设置用于非极大值抑制的交并比阈值。控制重复检测的消除。
max_detint300限制每张图像的最大检测数量。对于 detect、segment、pose 和 OBB,如果保持 300,当图像中的标注对象数量超出此值时,该上限会提高到验证集划分中最大的标注对象数量,并发出警告;使用其他值时则保持不变,并会在图像中的对象数量超出上限时警告召回率可能受限。
quantizeint 或 strNone验证精度:16/"fp16" 和 32/"fp32"/unset 用于为 PyTorch 和 TorchScript 模型选择 FP16 或 FP32 计算(CPU 上为 FP32);其他格式使用其模型文件和运行时所选的精度。在 16 中,OpenVINO 仍会在客户端将输入舍入为 FP16,再扩展回 FP32,但不会更改运行时精度。INT8/PTQ 量化在导出期间配置,然后通过验证导出的模型来使用。此参数替代已弃用的 half 标志。
devicestrNone指定验证设备(cpu、cuda:0、npu、npu:0 等)。如果为 None,则自动选择最佳可用设备。可以用逗号分隔来指定多个 CUDA 设备。
dnnboolFalse如果 True,则使用 OpenCV DNN 模块执行 ONNX 模型推理,作为 PyTorch 推理方法的替代方案。
plotsboolTrue设为 True 时,会生成并保存预测结果与真实标注的对比图、混淆矩阵和 PR 曲线,以便直观评估模型性能。
classeslist[int]None指定要评估的类别 ID 列表。适用于在评估期间筛选并只关注某些类别。
rectboolTrue如果 True,则会按宽高比将相似图像分组成矩形形状。每个维度向上取整到步幅的倍数之前,会先增加半个步幅(semantic 不会额外增加半个步幅)。步幅为 32 时,imgsz=640 下的 640×640 图像会变为 672×672,并产生 16 px 的偏移;而 predict 使用 640×640,因此指标可能不同。对于正方形图像,rect=False 与 predict 一致。对 depth 和 RT-DETR 会忽略此设置,这些模型会将图像拉伸为 imgsz 的正方形。
splitstr'val'决定验证时使用的数据集划分(val、test 或 train),便于灵活选择用于性能评估的数据部分。
fractionfloat、int 或 list1.0已验证数据划分的子集。使用 [train, val, test] 列表时,应用与 split 对应的条目(1 = 完整数据划分,大于 1 的整数 = 图像数量;省略的条目表示完整数据划分)。标量仅适用于 split=train;val 和 test 随后会使用完整数据划分。
projectstrNone保存验证输出的项目目录名称。相对路径会置于 runs_dir/<task> 下,绝对路径则按原样使用。
namestrNone验证运行的名称。用于在项目文件夹中创建子目录,以存储验证日志和输出。
verboseboolTrue如果 True,则在验证过程中显示详细信息,包括每个类别的指标、批次进度和其他调试信息。
save_txtboolFalse如果 True,则将检测结果保存到文本文件中,每张图像对应一个文件,便于进一步分析、自定义后处理或与其他系统集成。
save_confboolFalse如果 True,且启用了 save_txt,则在保存的文本文件中包含置信度值,为分析和筛选提供更详细的输出。
workersint8用于加载数据的工作线程数。较大的值可以加快数据预处理,但可能增加 CPU 使用率。设置为 0 时使用主线程,在某些环境中会更稳定。
augmentboolFalse在验证期间启用测试时增强(TTA),通过对输入的变换版本运行推理,可能提高检测准确率,但会降低推理速度。仅适用于 Ultralytics PyTorch 模型。
agnostic_nmsboolFalse启用类别无关的非极大值抑制,无论预测类别为何,都会抑制得分较低且相互重叠的框。适用于以实例为核心的应用。对于无 NMS 推理(在 YOLO26 或 YOLOv10 上使用 nms=False),此功能仅用于防止同一检测结果带有多个类别标签(IoU=1.0 的重复项),不会根据 IoU 阈值抑制不同的框。
single_clsboolFalse在验证期间将所有类别视为单个类别。适用于评估模型在二元检测任务上的性能,或类别区分不重要的情况。
visualizeboolFalse可视化每张图像的真实标注、真正例、假正例和假负例。适用于调试和模型解读。
show_labelsboolTrue当 visualize=True 时,在验证可视化中显示类别标签。设置为 False 可更清晰地查看匹配项和错误。
show_confboolTrue当 visualize=True 时,在验证可视化中显示置信度分数。设置为 False 可更清晰地查看匹配项和错误。
compilebool 或 strFalse使用backend='inductor'启用 PyTorch 2.x torch.compile图编译。接受True → "default"、False → 禁用,或"default"、"reduce-overhead"、"max-autotune-no-cudagraphs"等字符串模式。如果不受支持,则会发出警告并回退到即时执行模式。
channels_lastboolNone对原生 PyTorch 验证使用 channels_last(NHWC)内存格式。对于启用了 oneDNN 的 Linux 和 Windows x86 CPU,且 PyTorch 版本为 1.13 或更高版本时,None 会自动启用该格式;False 会禁用该格式;True 会在受支持的 x86 CPU 或 CUDA 设备上请求使用该格式。ARM64、MPS、较旧的 PyTorch 版本、未启用 oneDNN 的 CPU,以及导出格式均不受影响;训练期间的验证会保持训练模型的布局。
nmsbool,可选None默认使用 NMS 执行一对多推理(None 或 True)。设置 False 可在可用时使用无 NMS 的一对一检测头。详情请参阅端到端检测指南。

根据你的具体需求和资源调整这些设置,有助于在评估准确性与速度之间取得合适的平衡。

矩形验证几何形状(rect)#

静态导出会使用其记录的 (height, width) 输入形状(包括非正方形导出)进行验证。例如,如果模型导出时使用了 imgsz=(384, 640),YOLO("yolo26n.onnx").val(data="coco8.yaml") 就会使用 384×640 输入。

对于检测、实例分割、姿态估计和 OBB,矩形验证(rect=True)会使用 ceil(shape * imgsz / stride + 0.5) * stride 将每个批次维度向上取整,其中 shape 是该批次归一化后的高度或宽度。生成的填充会分配到相对的两侧。例如,边长为 640×640 的正方形图像在 imgsz=640 下进行验证时,使用步幅为 32 的输入会变为 672×672,每侧填充 16 px;而 predict() 则使用 640×640 的输入,不进行填充。

这种差异会影响验证指标。对于边长为正方形且与步幅对齐的输入,model.val(rect=False) 的几何形状与 predict() 以及正方形固定形状导出模型一致。在训练期间,无论训练的 rect 设置如何,这些 YOLO 任务都会使用矩形验证批次,因此 model.train(rect=False) 仍会通过矩形验证选择 best.pt。其他任务则有所不同:语义分割不会添加额外的验证填充,深度估计会禁用矩形验证,分类会忽略 rect,而 RT-DETR 使用自己的数据集构建器,并采用 rect=False。

使用参数进行验证的示例#



观看: 如何将模型验证结果导出为 CSV、JSON、SQL、Polars DataFrame 等格式

Explore model validation and different export methods in Google Colab

以下示例展示了如何在 Python 和 CLI 中使用自定义参数运行 YOLO 模型验证。

示例
from ultralytics import YOLO

# 加载模型
model = YOLO("yolo26n.pt")

# 自定义验证设置
metrics = model.val(data="coco8.yaml", imgsz=640, batch=16, conf=0.25, iou=0.7, device="0")
导出 ConfusionMatrix

你也可以将混淆矩阵结果导出为不同格式,例如 DataFrame:

from ultralytics import YOLO

model = YOLO("yolo26n.pt")

results = model.val(data="coco8.yaml", plots=True)
print(results.confusion_matrix.to_df())
逐图像精确率、召回率和 F1

除分类任务外,验证过程会为所有任务存储每张图像的精确率、召回率、F1、TP、FP 和 FN 指标(IoU 阈值为 0.5)。验证完成后,可通过 results.box.image_metrics 访问检测和 OBB 的指标,通过 results.seg.image_metrics 访问分割指标,并通过 results.pose.image_metrics 访问姿态指标。

from ultralytics import YOLO

# 加载模型
model = YOLO("yolo26n.pt")

# 验证并访问逐图像指标
results = model.val(data="coco8.yaml")

# image_metrics 是一个字典,以图像文件名作为键
print(results.box.image_metrics)
# 输出:{'image1.jpg': {'precision': 0.85, 'recall': 0.92, 'f1': 0.88, 'tp': 17, 'fp': 3, 'fn': 1}, ...}

# 访问特定图像的指标
results.box.image_metrics["image1.jpg"]  # {'precision': 0.85, 'recall': 0.92, 'f1': 0.88, 'tp': 17, 'fp': 3, 'fn': 1}

image_metrics 中的每个条目都包含以下键:

键说明
precision图像的精确率得分(tp / (tp + fp))。
recall图像的召回率得分(tp / (tp + fn))。
f1精确率和召回率的调和平均值。
tp图像的真正例数量。
fp图像的假正例数量。
fn图像的假负例数量。

此功能适用于检测、分割、姿态估计和 OBB 任务。

返回的指标对象还提供来自 DataExportMixin 的导出辅助方法,便于后续分析:

方法返回类型说明
summary()List[Dict[str, Any]]将验证结果转换为汇总字典。
to_df()DataFrame以结构化 Polars DataFrame 的形式返回验证结果。
to_csv()str以 CSV 格式导出验证结果并返回 CSV 字符串。
to_json()str以 JSON 格式导出验证结果并返回 JSON 字符串。

接下来做什么#

对指标结果满意吗?导出模型,以转换为部署格式。如果准确率不理想,可以返回并重新训练,调整超参数或增加训练数据。

常见问题#

  • 要验证 YOLO26 模型,可以使用 Ultralytics 提供的 Val 模式。例如,使用 Python API 加载模型并运行验证:

    from ultralytics import YOLO
    
    # 加载模型
    model = YOLO("yolo26n.pt")
    
    # 验证模型
    metrics = model.val()
    print(metrics.box.map)  # map50-95

    或者,你也可以使用命令行界面 (CLI):

    yolo detect val model=yolo26n.pt data=coco8.yaml

    如需进一步自定义,你可以在 Python 和 CLI 模式下调整各种参数,例如 imgsz、batch 和 conf。如需查看完整参数列表,请参阅YOLO 模型验证参数部分。

  • YOLO26 模型验证会提供多个关键指标,用于评估模型性能,包括:

    • mAP50(平均精度均值,IoU 阈值为 0.5)
    • mAP75(IoU 阈值为 0.75 时的平均精度均值)
    • mAP50-95(IoU 阈值从 0.5 到 0.95 的多个阈值下的平均精度均值)

    使用 Python API 时,你可以按如下方式访问这些指标:

    metrics = model.val()  # 假设已加载 `model`
    print(metrics.box.map)  # mAP50-95
    print(metrics.box.map50)  # mAP50
    print(metrics.box.map75)  # mAP75
    print(metrics.box.maps)  # 每个类别的 mAP50-95;未出现在验证集中的类别采用整体 mAP 值
    print(metrics.box.ap_class_index)  # 实际参与评估的类别索引
    print(metrics.box.image_metrics)  # 包含精确率、召回率、F1、TP、FP 和 FN 的逐图像指标字典

    查看所有这些指标,全面评估模型性能。

  • 使用 Ultralytics YOLO 进行验证有以下几项优势:

    • 精确度:YOLO26 提供 mAP50、mAP75 和 mAP50-95 等准确的性能指标。
    • 便捷性: 模型会记住训练设置,让验证变得简单直接。
    • 灵活性: 你可以使用相同或不同的数据集和图像尺寸进行验证。
    • 超参数调优: 验证指标有助于微调模型,从而提升性能。

    这些优势能帮助你全面评估模型并对模型进行优化。

  • 可以,你可以使用自定义数据集验证 YOLO26 模型。将 data 参数设为数据集 YAML 文件的路径,该文件应包含验证数据的路径。对于分类任务,参数应为数据集目录或内置数据集名称(例如 imagenet10)。

    注意

    验证使用模型自身的类别名称,你可以通过 model.names 查看这些名称;它们可能与数据集定义的名称不同。

    Python 示例:

    from ultralytics import YOLO
    
    # 加载模型
    model = YOLO("yolo26n.pt")
    
    # 使用自定义数据集进行验证
    metrics = model.val(data="path/to/your/custom_dataset.yaml")
    print(metrics.box.map)  # map50-95

    CLI 示例:

    yolo val model=yolo26n.pt data=path/to/your/custom_dataset.yaml

    如需在验证过程中进行更多自定义设置,请参阅使用参数进行验证的示例部分。

  • 要将验证结果保存到 JSON 文件,请在运行验证时将 save_json 参数设为 True。Python API 和 CLI 均支持此操作。

    Python 示例:

    from ultralytics import YOLO
    
    # 加载模型
    model = YOLO("yolo26n.pt")
    
    # 将验证结果保存为 JSON
    metrics = model.val(save_json=True)

    CLI 示例:

    yolo val model=yolo26n.pt save_json=True

    对于检测数据集,save_json=True 还会通过 faster-coco-eval 报告小型、中型和大型目标的 mAP。如需了解更多详情,请参阅YOLO 模型验证参数。

评论279

  1. BedoHatemGitHub

    I have a couple of models (a mix of object detection and segmentation), so I want to run them on the same validation dataset to compare them properly. The exact tasks for the seg and obj-det models are the same at a certain level, so I'm aware that seg models give a B-Box and Mask, while obj-det gives just a B-Box.

    With that said, will a segmentation dataset work on both seg and obj-det models ? Or should i make a seg and a obj-det version of the same dataset, so i can use it to equally validate the models ?

    Thanks in Advance

    1
    1. BedoHatemGitHub

      I tested it. It seems you can use a segmentation dataset to validate an obj-det model, as the seg datasets include B-Boxes and Masks of the classes.

      1
    2. Glenn JocherUltralytics(已编辑)

      @BedoHatem yes, you're correct! Segmentation datasets can be used to validate object detection models because they contain the bounding box annotations needed for detection evaluation. The segmentation masks are simply ignored when the dataset is used with a detection model.

      This flexibility is an advantage of the YOLO annotation format - the additional segmentation data doesn't interfere with detection evaluation. For the most accurate comparison between models, using the same validation dataset ensures you're evaluating performance on exactly the same ground truth data.

      @417dq the recall reported by val() is taken at the confidence value that maximizes F1, while the confusion matrix is built at the validation conf (0.001 by default) with an IoU matching threshold of 0.45, so the two can differ. The metrics output from val() is the reference for your model's performance.

  2. CyedenGitHub

    请问如果验针集是已经被多尺度分割了,那么再进行验证的时候imgsz应该设置为不同尺度验证的逻辑吗?例如: if name == 'main': model = YOLO(r'C:\Users\Lazy\Desktop\yolo_detect\weights\best.pt')

    multi_scale_sizes = [640, 800, 1024, 1280] 
    
    for size in multi_scale_sizes:
        model.val(
            data='ultralytics/cfg/datasets/DOTAv1.yaml',
            split='val',
            imgsz=size,
            batch=16,
            project='runs/val',
            name=f'v8n-obb-LSKNet_prev8x-obbpt_{size}',
        )
    1
    1. Glenn JocherUltralytics

      @Cyeden for multi-scale validation, you can indeed set imgsz to different scales within a loop. This approach allows you to evaluate the model's performance across various image sizes. Your implementation looks correct. Ensure you are using the latest version of the Ultralytics package to avoid any potential issues. For more details, you can refer to the validation documentation.

  3. YunYeTangGitHub

    hi, when I use yolov8-obb to validate DOTAv1, I found that confusion matrix is empty. Does it mean that confusion matrix is not supported in OBB validation?

    1
    1. Glenn JocherUltralytics(已编辑)

      Hi there! 👋

      The confusion matrix is supported for OBB validation in current Ultralytics versions. If yours is empty, update with pip install -U ultralytics and re-run validation with plots=True. If it is still empty, please share your yolo checks output and the validation command so we can look into it.

      In the meantime, you can still rely on the other validation metrics such as mAP, precision, and recall.

    2. Glenn JocherUltralytics(已编辑)

      Hey there! 🚀

      Thank you for reaching out! The confusion matrix is supported for OBB validation in current Ultralytics versions. If yours is empty, update with pip install -U ultralytics and re-run validation with plots=True; if it is still empty, share your yolo checks output and validation command so we can look into it.

      For a comprehensive evaluation you can also rely on the other metrics provided during validation, such as mAP, precision, and recall. Cheers! 🌟

    1. Glenn JocherUltralytics

      It looks like you’re on the Chinese locale (the URL contains "/zh/"). Remove "/zh/" to view the English version, or use the top‑right language selector (GB English) and hard‑refresh; also ensure your browser’s auto‑translate is disabled.

    2. Glenn JocherUltralytics

      Thanks for the detailed description—that behavior sounds like a docs locale‑routing bug on our side rather than anything you can fix locally; we’ll get it forwarded to the web/docs team, and in the meantime could you confirm whether going directly to the English URL Model Validation with Ultralytics YOLO (English) still forces you back to Chinese and share your OS + browser version so we can reproduce it?

    3. Glenn JocherUltralytics

      Thanks for the extra details—that confirms this is an issue on the docs side, likely tied to your system/browser language being Chinese and our locale detection forcing /zh/ even when you pick English. I’ve passed this to the web/docs team to investigate; as a temporary workaround you can try using a browser whose interface language is set to English (or move English to the top of Chrome’s language preferences) so the site stops auto‑redirecting to the Chinese locale.

  4. AA278-HUBGitHub

    I have a model trained on a dataset containing four classes (car, bus, motorbike, and trunk). Now, I have a new dataset with only one class (vehicle). How can I validate this model using the new dataset, given that I only care about whether the model can identify the vehicle and its position, without concern for the specific type of vehicle?

    1. AA278-HUBGitHub

      f I want to change the validation rules in this specific situation, which .py files need to be modified

    2. Glenn JocherUltralytics

      @liujixingit save_txt writes normalized YOLO xywh (center x/y, width, height) relative to the original image size; recover pixel xyxy via the original W,H then center→corner conversion, e.g.:

      # line format: class x y w h [conf]
      cls, x, y, w, h, *rest = map(float, line.split())
      x1 = (x - w/2) * W; y1 = (y - h/2) * H
      x2 = (x + w/2) * W; y2 = (y + h/2) * H

      Function details are in the save_one_txt reference and the save_txt format is noted under Validation settings.

      @carlos-cell To get APs/APm/APl, run COCO-style evaluation with JSON saving and check the printed COCO summary:

      yolo detect val model=yolo11n.pt data=coco.yaml save_json=True

      This triggers COCO eval inside validation; see COCO evaluation in val and the size-specific metrics overview in the Performance metrics deep dive.

      @AA278-HUB For “any vehicle” validation, use single-class evaluation so all types collapse to one:

      metrics = model.val(data='vehicle.yaml', single_cls=True, agnostic_nms=True)

      Argument behavior is documented in the Val mode arguments.

      @AA278-HUB You don’t need code changes for the above, but if you must customize matching/metrics, start from DetectionValidator and the val() entry point: see the DetectionValidator reference and the val() method in engine/model.py; if proposing a PR, please keep scope minimal and include tests.

  5. liujixingitGitHub

    YOLOv8 调用验证功能开启save_txt后保存的坐标如何还原到原图,我尝试了直接×原图宽高,还原的坐标是错误的。save_txt保存的结果是相对什么计算得出的归一化坐标?

  6. CherishzyhGitHub

    hello, I read some dialog about the IOU threshold and confidence threshold and have some questions.

    1. CherishzyhGitHub
      1. the document shows that 'iou' is the threshold for NMS.Is it also a threshold for calculate the confusion matrix? eg. I hope that if the IoU between the prediction and the ground truth is greater than 0.2, it will be considered a true positive (TP). At the same time, does the NMS threshold also have to be 0.2?
    2. CherishzyhGitHub
      1. For confidence threshold, if I set it to 0.1, that mean all bboxes with a score lower than 0.1 will be removed when calculate the PR-curve?. If so, does it will also be remove in result json or txt ?
    3. Glenn JocherUltralytics

      @Cherishzyh great questions:

      1. The iou argument in val() controls NMS overlap removal only; it does not change the IoU used to determine TP/FP or mAP. Metrics are computed over fixed IoU thresholds 0.50–0.95. If you need evaluation at IoU=0.2, export predictions and compute custom metrics offline. See the Performance Metrics deep dive.

      2. The conf argument is a minimum score filter. Setting conf=0.1 removes all predictions with score < 0.1 prior to evaluation and from saved outputs (save_json/save_txt). You can still access PR data from the results object:

      from ultralytics import YOLO
      model = YOLO("yolo11n.pt")
      res = model.val(conf=0.1, iou=0.7, save_json=True, save_txt=True, plots=True)
      print(res.box.p_curve)  # precision curve vs score thresholds
      print(res.box.r_curve)  # recall curve vs score thresholds

      Argument details are in the Val mode arguments.

  7. lauravchrobakGitHub

    When I run validate without setting plots=True I still get the f1, PR curve plots in the val folder. Potentially the default for this flag is actually true despite it being false in the table above?

  8. sea190GitHub

    The question about val of yoloworld, and I used my custom dataset, and I make sure the format of ma dataset is corret. While when I run the val.py the code still validate the categories of COCO Dataset instead of my dataset? How can I solve this problem?

    1. ihciabGitHub

      You can try specifying the path of the validation set. When calling the val function, specify model.val(data=‘your_data’)

    2. Glenn JocherUltralytics

      @sea190 for YOLO-World validation with custom datasets, ensure your dataset YAML file correctly defines the class names and paths. YOLO-World may default to COCO categories if the dataset configuration isn't properly specified. Try:

      model.val(data='path/to/your/custom_dataset.yaml')

      Make sure your YAML file includes the correct names field with your custom class names and verify the val path points to your validation images and labels. If issues persist, check that your dataset follows the expected format for YOLO-World validation.