bug记录yolov7 AssertionError: train: No labels in ...train_list.cache. Can not train without
Posted 少吃蛋糕的倒霉蛋
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bug记录yolov7 AssertionError: train: No labels in ...train_list.cache. Can not train without相关的知识,希望对你有一定的参考价值。
问题描述
我在用yolov7跑自己的visdrone数据集时,遇到了如下报错:
train: WARNING: No labels found in datasets/VisDrone/train_list.cache. See https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data
train: New cache created: datasets/VisDrone/train_list.cache
Traceback (most recent call last):
File "train.py", line 616, in <module>
train(hyp, opt, device, tb_writer)
File "train.py", line 245, in train
dataloader, dataset = create_dataloader(train_path, imgsz, batch_size, gs, opt,
File "/disk2/lxs/yolov7/utils/datasets.py", line 69, in create_dataloader
dataset = LoadImagesAndLabels(path, imgsz, batch_size,
File "/disk2/lxs/yolov7/utils/datasets.py", line 403, in __init__
assert nf > 0 or not augment, f'prefixNo labels in cache_path. Can not train without labels. See help_url'
AssertionError: train: No labels in datasets/VisDrone/train_list.cache. Can not train without labels. See https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data
解决方案:
提示:如果train_list.txt中使用的是相对路径,建议全部改为绝对路径。生成train_list.txt代码如下
# -*-coding:utf-8-*-
# 生成文件夹中所有文件的路径到txt
import os
def listdir(path, list_name): # 传入存储的list
for file in os.listdir(path):
file_path = os.path.join(path, file)
if os.path.isdir(file_path):
listdir(file_path, list_name)
else:
list_name.append(file_path)
list_name = []
path = '/disk2/lxs/yolov7/datasets/VisDrone/images/test/' # 文件夹路径
listdir(path, list_name)
print(list_name)
with open('./datasets/VisDrone/test_list.txt', 'w') as f: # 要存入的txt
write = ''
for i in list_name:
write = write + str(i) + '\\n'
f.write(write)
以上是关于bug记录yolov7 AssertionError: train: No labels in ...train_list.cache. Can not train without的主要内容,如果未能解决你的问题,请参考以下文章