1

首先,我的英语不是很好。因此,以下问题由谷歌翻译并转发。我真的很抱歉。

其实这几天我一直在搭建yolov5环境并尝试运行它。我使用以下代码测试我的设置是否成功。

python train.py --img 640 --data data/coco128.yaml --cfg models/yolov5s.yaml --weights weights/yolov5s.pt --batch-size 16 --epochs 100

然后它给了我以下错误,我试图在谷歌上找到答案,但我没有看到任何有用的东西。我现在很沮丧。有人可以帮帮我吗?对此,我真的非常感激。

Transferred 362/370 items from weights/yolov5s.pt
Optimizer groups: 62 .bias, 70 conv.weight, 59 other
Scanning labels data\coco128\labels\train2017.cache (32 found, 0 missing, 0 empty, 0 duplicate, for 32 images): 32it [00:00, 3270.57it/s]
Traceback (most recent call last):
  File "train.py", line 456, in <module>
    train(hyp, opt, device, tb_writer)
  File "train.py", line 172, in train
    assert mlc < nc, 'Label class %g exceeds nc=%g in %s. Possible class labels are 0-%g' % (mlc, nc, opt.data, nc - 1)
AssertionError: Label class 15 exceeds nc=1 in data/coco128.yaml. Possible class labels are 0-0

我真的不使用这个网站。对不起。

附加图片

4

2 回答 2

1

I found this exact error too.

In your .txt files you've created for the annotations, there will be an integer number followed by four floats (ie, 13 0.3434 0.251 0.4364 0.34353) - something like that.

This error essentially articulates that your number of classes (ie, the number of different objects you're trying to train into the model) is too low for the ID number of the classes you're using. In my example above, the ID is 13 (the 14th class since 0 is included). If I set nc=1, then I can only have on class (0). I would need to set nc=14 and ensure that 0-12 existed.

To fix this, simply change the classes so that the IDs sit inside your chose number of classes. For nc=1, you'll only need class/ID = 0.

As a note (and I fell foul of this), delete train.cache before you re-run the training. That caused me a bit of a nuisance since it still was certain I had classes of >0, when I didn't.

Thanks, Jamie

于 2021-01-14T00:00:47.210 回答
0

该错误是由于您有一个或多个编号为 15 的标签作为一个类别。您必须将类更改为允许的类值(在您的情况下似乎只有 0),您可以手动或使用脚本来完成。我在我的数据集中手动更改了类的值,为了查找包含不允许的类的文件,我运行了一个 python 脚本,我已经针对您的情况进行了调整:

path = 'C:/foo/bar' #path of labels
labels = os.listdir('path')
for x in labels:
    with open('path'+x) as f:
    lines = f.read().splitlines()
    for y in lines:
        if y[:1]!='0':
            print(x)

此代码段将打印所有包含不同于 0 的类的文件。

对于任何找到这个并且拥有多个类的人,您必须将值 0 替换为高于您声明的类数的一个或多个类的值(您可以遍历可能值的列表)前。

于 2020-11-17T10:34:26.870 回答