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

训练Darknet YOLOv3模型时遭遇文件加载问题求助

YOLOv3训练报错:无法加载图片及标签文件

问题场景

训练单类目标检测模型,执行命令:

sudo ./darknet detector train cfg/coco.data cfg/yolov3_test.cfg darknet53.conv.74

coco.data配置:

classes= 1
train  = /home/philip/Downloads/YOLO/images/train.txt
valid  = /home/philip/Downloads/YOLO/images/train.txt
names = /home/philip/darknet/AlexeyAB/darknet/data/coco.names
backup = /home/philip/darknet/AlexeyAB/darknet/backup
eval=coco

(注:训练集与验证集暂时设为同一文件,仅用于验证训练流程)

coco.names内容:

plasticwaste

报错信息

..... Cannot load image "/home/philip/Downloads/YOLO/images/plastic_bags.png 115,74,178,108,0 223,87,298,114,0 254,47,279,58,0 286,64,298,74,0"
STB Reason: can't fopen
Failed to infer label file name (check image extension is supported): /home/philip/Downloads/YOLO/images/plastic_bags.png 115,74,178,108,0 223,87,298,114,0 254,47,279,58,0 286,64,298,74,0 
Can't open label file. (This can be normal only if you use MSCOCO): /home/philip/Downloads/YOLO/images/plastic_bags.png 115,74,178,108,0 223,87,298,114,0 254,47,279,58,0 286,64,298,74,0 
......

核心问题

train.txt格式错误:将图片路径和标注信息写在同一行,YOLO会把整行内容当作图片路径读取,导致找不到对应文件。

YOLO的标准格式要求:

  • train.txt每行仅存放单独的图片绝对路径
  • 标注信息需单独存入对应图片的.txt文件,命名规则为「图片文件名(不含扩展名)+.txt」,与图片同目录(或通过配置指定路径)

修复步骤

  • 修改train.txt内容,每行仅保留图片路径:

    /home/philip/Downloads/YOLO/images/plastic_bags.png
    
  • 创建对应标注文件/home/philip/Downloads/YOLO/images/plastic_bags.txt,转换为YOLO格式标注:
    YOLO标注格式为每行类别索引 x_center y_center width height(所有坐标需归一化至0-1范围)。
    你的原始标注是x1,y1,x2,y2,类别索引(类别索引为0,对应coco.names中第一个类别),转换公式如下(W为图片宽度,H为图片高度):

    • x_center = (x1 + x2)/(2*W)
    • y_center = (y1 + y2)/(2*H)
    • width = (x2 - x1)/W
    • height = (y2 - y1)/H
      转换后示例(替换为实际图片尺寸计算值):
    0 0.xxx 0.xxx 0.xxx 0.xxx
    0 0.xxx 0.xxx 0.xxx 0.xxx
    0 0.xxx 0.xxx 0.xxx 0.xxx
    0 0.xxx 0.xxx 0.xxx 0.xxx
    
  • 调整coco.data中的eval字段为voc(自定义数据集不适用COCO评估标准):

    eval=voc
    
  • 重新执行训练命令即可。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 11:05:06