You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

YOLOv5自定义类yaml文件配置及类别名称不显示问题求助

解决YOLOv5单类别检测不显示类别名称及配置报错问题

正确的data.yaml配置格式

YOLOv5要求配置文件必须同时包含nc(类别总数)和规范的names字段,以下两种格式均有效:

格式一(键值对映射,推荐)

train: /content/yolov5/DataSet/ForYolov5/images/train  # 训练集路径
val: /content/yolov5/DataSet/ForYolov5/images/test  # 验证集路径
test:  # 测试集(可选)

# 类别配置
nc: 1  # 必须明确指定类别数量
names:
  0: vehicle  # 类别编号对应名称

格式二(列表形式)

train: /content/yolov5/DataSet/ForYolov5/images/train
val: /content/yolov5/DataSet/ForYolov5/images/test
test:

nc: 1
names: ['vehicle']  # 列表索引对应类别编号(0对应第一个元素)

问题原因及修复步骤

  1. 第一个配置不显示类别名称:

    • 缺失nc: 1字段,YOLOv5无法正确识别类别总数,导致可视化时无法完成编号到名称的映射。补上nc字段即可解决。
  2. 第二个配置报错:

    • 你的配置缺少训练/验证集路径定义,且YAML语法要求names列表的缩进需和nc字段对齐。补充完整路径并规范缩进即可。
  3. 额外检查项:

    • 训练时需指定正确的data.yaml路径,示例命令:
      python train.py --data /content/yolov5/DataSet/ForYolov5/data.yaml --weights yolov5s.pt --epochs 50
      
    • 推理检测时也要加载对应配置文件,确保读取类别名称,示例命令:
      python detect.py --weights runs/train/exp/weights/best.pt --source test_images/ --data /content/yolov5/DataSet/ForYolov5/data.yaml
      

内容的提问来源于stack exchange,提问作者Rashmi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 13:20:28