yolo问题记录:AssertionError: train: No labels in ...\ds1\Images\train.cache.

博客提到修改文件夹名字后,记得更改路径,完成这些操作后就可以开始训练,涉及深度学习相关训练准备工作。

在这里插入图片描述原因就是下面这个,修改文件夹名字后记得改路径啊家人们

在这里插入图片描述
改后就正常了
在这里插入图片描述
可以开始训练了

在这里插入图片描述

(yolo11) D:\2026\ultralytics-yolo11-main>D:/anaconda3/envs/yolo11/python.exe d:/2026/ultralytics-yolo11-main/train.py Ultralytics 8.3.9 🚀 Python-3.9.23 torch-2.0.1+cu117 CUDA:0 (NVIDIA GeForce RTX 3050 Laptop GPU, 4096MiB) engine\trainer: task=detect, mode=train, model=D:/2026/ultralytics-yolo11-main/ultralytics/cfg/models/11/yolo11n.yaml, data=D:/2026/YOLOv11/datasets/potholes/d.yaml, epochs=100, time=None, patience=100, batch=4, imgsz=640, save=True, save_period=-1, cache=False, device=None, workers=0, project=D:/2026/ultralytics-yolo11-main/runs/train, name=232, exist_ok=False, pretrained=True, optimizer=SGD, verbose=True, seed=0, deterministic=True, single_cls=False, rect=False, cos_lr=False, close_mosaic=0, resume=None, amp=True, fraction=1.0, profile=False, freeze=None, multi_scale=False, overlap_mask=True, mask_ratio=4, dropout=0.0, val=True, split=val, save_json=False, save_hybrid=False, conf=None, iou=0.7, max_det=300, half=False, dnn=False, plots=True, source=None, vid_stride=1, stream_buffer=False, visualize=False, augment=False, agnostic_nms=False, classes=None, retina_masks=False, embed=None, show=False, save_frames=False, save_txt=False, save_conf=False, save_crop=False, show_labels=True, show_conf=True, show_boxes=True, line_width=None, format=torchscript, keras=False, optimize=False, int8=False, dynamic=False, simplify=True, opset=None, workspace=4, nms=False, lr0=0.005, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=7.5, cls=0.5, dfl=1.5, pose=12.0, kobj=1.0, label_smoothing=0.0, nbs=64, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, bgr=0.0, mosaic=1.0, mixup=0.0, copy_paste=0.0, copy_paste_mode=flip, auto_augment=randaugment, erasing=0.4, crop_fraction=1.0, cfg=None, tracker=botsort.yaml, save_dir=D:\2026\ultralytics-yolo11-main\runs\train\exp+2025\7\232 from n params module arguments 0 -1 1 464 ultralytics.nn.modules.conv.Conv [3, 16, 3, 2] 1 -1 1 4672 ultralytics.nn.modules.conv.Conv [16, 32, 3, 2] 2 -1 1 6640 ultralytics.nn.modules.block.C3k2 [32, 64, 1, False, 0.25] 3 -1 1 36992 ultralytics.nn.modules.conv.Conv [64, 64, 3, 2] 4 -1 1 26080 ultralytics.nn.modules.block.C3k2 [64, 128, 1, False, 0.25] 5 -1 1 147712 ultralytics.nn.modules.conv.Conv [128, 128, 3, 2] 6 -1 1 87040 ultralytics.nn.modules.block.C3k2 [128, 128, 1, True] 7 -1 1 295424 ultralytics.nn.modules.conv.Conv [128, 256, 3, 2] 8 -1 1 346112 ultralytics.nn.modules.block.C3k2 [256, 256, 1, True] 9 -1 1 164608 ultralytics.nn.modules.block.SPPF [256, 256, 5] 10 -1 1 249728 ultralytics.nn.modules.block.C2PSA [256, 256, 1] 11 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] 12 [-1, 6] 1 0 ultralytics.nn.modules.conv.Concat [1] 13 -1 1 111296 ultralytics.nn.modules.block.C3k2 [384, 128, 1, False] 14 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] 15 [-1, 4] 1 0 ultralytics.nn.modules.conv.Concat [1] 16 -1 1 32096 ultralytics.nn.modules.block.C3k2 [256, 64, 1, False] 17 -1 1 36992 ultralytics.nn.modules.conv.Conv [64, 64, 3, 2] 18 [-1, 13] 1 0 ultralytics.nn.modules.conv.Concat [1] 19 -1 1 86720 ultralytics.nn.modules.block.C3k2 [192, 128, 1, False] 20 -1 1 147712 ultralytics.nn.modules.conv.Conv [128, 128, 3, 2] 21 [-1, 10] 1 0 ultralytics.nn.modules.conv.Concat [1] 22 -1 1 378880 ultralytics.nn.modules.block.C3k2 [384, 256, 1, True] 23 [16, 19, 22] 1 430867 ultralytics.nn.modules.head.Detect [1, [64, 128, 256]] YOLO11n summary: 319 layers, 2,590,035 parameters, 2,590,019 gradients, 6.4 GFLOPs Freezing layer 'model.23.dfl.conv.weight' AMP: running Automatic Mixed Precision (AMP) checks with YOLO11n... AMP: checks passed ✅ train: Scanning D:\2026\YOLOv11\datasets\potholes\train\labels... 263 images, 2709 backgrounds, 1 corrupt: 100%|██████████| 2973/2973 [00:01<00:00, 2478.82 train: WARNING ⚠️ D:\2026\YOLOv11\datasets\potholes\train\images\01883.jpg: ignoring corrupt image/label: invalid image format GIF. Supported formats are: images: {'webp', 'jpeg', 'pfm', 'bmp', 'mpo', 'tif', 'tiff', 'png', 'jpg', 'dng'} videos: {'mp4', 'mpeg', 'mov', 'asf', 'wmv', 'avi', 'mpg', 'gif', 'webm', 'ts', 'mkv', 'm4v'} train: New cache created: D:\2026\YOLOv11\datasets\potholes\train\labels.cache Traceback (most recent call last): File "d:\2026\ultralytics-yolo11-main\ultralytics\data\base.py", line 121, in get_img_files assert im_files, f"{self.prefix}No images found in {img_path}. {FORMATS_HELP_MSG}" AssertionError: val: No images found in D:\2026\YOLOv11\datasets\potholes\val. Supported formats are: images: {'webp', 'jpeg', 'pfm', 'bmp', 'mpo', 'tif', 'tiff', 'png', 'jpg', 'dng'} videos: {'mp4', 'mpeg', 'mov', 'asf', 'wmv', 'avi', 'mpg', 'gif', 'webm', 'ts', 'mkv', 'm4v'} The above exception was the direct cause of the following exception: Traceback (most recent call last): File "d:\2026\ultralytics-yolo11-main\train.py", line 32, in <module> model.train(data='D:/2026/YOLOv11/datasets/potholes/d.yaml', # 选择数据集配置路径 File "d:\2026\ultralytics-yolo11-main\ultralytics\engine\model.py", line 802, in train self.trainer.train() File "d:\2026\ultralytics-yolo11-main\ultralytics\engine\trainer.py", line 208, in train self._do_train(world_size) File "d:\2026\ultralytics-yolo11-main\ultralytics\engine\trainer.py", line 328, in _do_train self._setup_train(world_size) File "d:\2026\ultralytics-yolo11-main\ultralytics\engine\trainer.py", line 295, in _setup_train self.test_loader = self.get_dataloader( File "d:\2026\ultralytics-yolo11-main\ultralytics\models\yolo\detect\train.py", line 50, in get_dataloader dataset = self.build_dataset(dataset_path, mode, batch_size) File "d:\2026\ultralytics-yolo11-main\ultralytics\models\yolo\detect\train.py", line 43, in build_dataset return build_yolo_dataset(self.args, img_path, batch, self.data, mode=mode, rect=mode == "val", stride=gs) File "d:\2026\ultralytics-yolo11-main\ultralytics\data\build.py", line 87, in build_yolo_dataset return dataset( File "d:\2026\ultralytics-yolo11-main\ultralytics\data\dataset.py", line 64, in __init__ super().__init__(*args, **kwargs) File "d:\2026\ultralytics-yolo11-main\ultralytics\data\base.py", line 73, in __init__ self.im_files = self.get_img_files(self.img_path) File "d:\2026\ultralytics-yolo11-main\ultralytics\data\base.py", line 123, in get_img_files raise FileNotFoundError(f"{self.prefix}Error loading data from {img_path}\n{HELP_URL}") from e FileNotFoundError: val: Error loading data from D:\2026\YOLOv11\datasets\potholes\val See https://docs.ultralytics.com/datasets for dataset formatting guidance.
最新发布
07-24
### 问题分析 在运行YOLOv7时遇到的 `AssertionError: train: No labels in data\coco\train.cache. Can not train without labels.` 错误表明训练数据集中缺少标签文件(labels),这导致模型无法正常进行训练。此错误通常与数据集格式不正确或路径配置错误有关。 --- ### 解决方案 #### 1. 检查数据集格式 确保训练数据集严格遵循YOLOv7所要求的数据集格式。根据引用[^2],如果文件夹名称不符合规范(例如使用了大写字母 "Images" 而非 "images"),可能会导致标签文件未被正确加载。以下是正确的数据集目录结构: ``` dataset/ ├── images/ │ ├── train/ │ │ ├── image1.jpg │ │ ├── image2.jpg │ │ └── ... │ └── val/ │ ├── image1.jpg │ ├── image2.jpg │ └── ... └── labels/ ├── train/ │ ├── image1.txt │ ├── image2.txt │ └── ... └── val/ ├── image1.txt ├── image2.txt └── ... ``` - **images** 文件夹包含所有图像文件。 - **labels** 文件夹包含对应的标签文件(`.txt` 格式)。每个标签文件的内容应符合YOLO格式,即每行表示一个目标框: ``` <class_id> <x_center> <y_center> <width> <height> ``` --- #### 2. 验证 `train.cache` 文件 `train.cache` 是YOLOv7生成的一个缓存文件,用于加速数据加载。如果标签文件缺失或路径配置错误,可能导致该文件无法正确生成。以下步骤可验证并修复此问题: - **删除旧缓存文件**:在数据集目录中查找 `train.cache` 和 `val.cache` 文件,并将其删除。重新运行训练脚本时,YOLOv7会重新生成这些文件。 ```bash rm -f data/coco/train.cache rm -f data/coco/val.cache ``` - **检查数据集配置文件**:确保 `data.yaml` 文件中的路径配置正确。例如: ```yaml train: ../dataset/images/train val: ../dataset/images/val nc: 80 # 类别数量 names: ['class1', 'class2', ..., 'class80'] # 类别名称 ``` --- #### 3. 修改源码(不推荐) 如果确实需要自定义文件夹名称(如 "Images" 或其他),可以修改 YOLOv7 的源代码。根据引用[^2],进入 `utils/dataset.py` 文件,搜索相关代码片段(如 `define label` 或类似关键词),将默认的 `'images'` 替换为自定义名称。例如: ```python # 原始代码 image_dir = os.path.join(dataset_dir, 'images', phase) # 修改后的代码 image_dir = os.path.join(dataset_dir, 'Images', phase) ``` **注意**:这种方法可能会影响后续更新或与其他功能的兼容性,因此不建议使用。 --- #### 4. 检查标签文件内容 确保每个 `.txt` 标签文件的内容符合 YOLO 格式。例如,假设类别 ID 为 0 的目标框位于图像中心,宽度和高度分别为 0.5 和 0.3,则标签文件内容应为: ``` 0 0.5 0.5 0.5 0.3 ``` 如果标签文件为空或格式错误,也可能导致 `AssertionError`。 --- ### 示例代码 以下是一个简单的 Python 脚本,用于验证标签文件是否完整且格式正确: ```python import os def validate_labels(data_dir): label_dir = os.path.join(data_dir, 'labels', 'train') if not os.path.exists(label_dir): print(f"Error: Label directory '{label_dir}' does not exist.") return for label_file in os.listdir(label_dir): if not label_file.endswith('.txt'): continue file_path = os.path.join(label_dir, label_file) with open(file_path, 'r') as f: lines = f.readlines() if not lines: print(f"Warning: Empty label file: {file_path}") continue for line in lines: parts = line.strip().split() if len(parts) != 5: print(f"Error: Invalid format in {file_path}: {line.strip()}") break validate_labels('path/to/dataset') ``` --- ### 总结 通过检查数据集格式、验证 `train.cache` 文件、修改源码(若必要)以及确保标签文件内容正确,可以有效解决 `AssertionError: train: No labels in data\coco\train.cache` 错误。 ---
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值