yolov8模型训练遇到的问题

训练时有一种报错:no labels found in xxx.cache

步骤1

首先要确定我们的图像,标签文件夹内容无误。检查完后如果还不行,就看看训练用到的东西,比如dataset.py,部分代码如下:

def get_labels(self):
        """Returns dictionary of labels for YOLO training."""
        self.label_files = img2label_paths(self.im_files)
        cache_path = Path(self.label_files[0]).parent.with_suffix('.cache')
        try:
            cache, exists = load_dataset_cache_file(cache_path), True  # attempt to load a *.cache file
            assert cache['version'] == DATASET_CACHE_VERSION  # matches current version
            assert cache['hash'] == get_hash(self.label_files + self.im_files)  # identical hash
        except (FileNotFoundError, AssertionError, AttributeError):
            cache, exists = self.cache_labels(cache_path), False  # run cache ops

        # Display cache
        nf, nm, ne, nc, n = cache.pop('results')  # found, missing, empty, corrupt, total
        if exists and LOCAL_RANK in (-1, 0):
            d = f'Scanning {cache_path}... {nf} images, {nm + ne} backgrounds, {nc} corrupt'
            tqdm(None, desc=self.prefix + d, total=n, initial=n, bar_format=TQDM_BAR_FORMAT)  # display results
            if cache['msgs']:
                LOGGER.info('\n'.join(cache['msgs']))  # display warnings
        if nf == 0:  # number of labels found
            raise FileNotFoundError(f'{self.prefix}No labels found in {cache_path}, can not start training. {HELP_URL}')

img2label_paths(self.im_files)这个函数大概率有猫腻,跳进去看看。
以下是其中部分代码,发现人家用的名字叫images和labels

def img2label_paths(img_paths):
    """Define label paths as a function of image paths."""
    sa, sb = f'{os.sep}images{os.sep}', f'{os.sep}labels{os.sep}'  # /images/, /labels/ substrings
    return [sb.join(x.rsplit(sa, 1)).rsplit('.', 1)[0] + '.txt' for x in img_paths]

但我的文件夹名字对不上,所以把函数里的名字改过来就可以了(数据集小的话也可以直接改数据集名字)
在这里插入图片描述
在这里插入图片描述

步骤2

最关键的一步,是调整我们的数据摆放位置,以及yaml文件的编写。
如果像我一样,数据集里有多个小数据集,那就要把数据按以下标准排列,比如1.1是个小数据集,test文件夹里是图片
在这里插入图片描述
labels文件夹也是同理
在这里插入图片描述
最后就是调整yaml文件
在这里插入图片描述
我按这样去操作,最后是可以跑的,记录一下

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值