-
-
Notifications
You must be signed in to change notification settings - Fork 16.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to save :AssertionError: Label class 16 exceeds nc=1 in ../data.yaml. Possible class labels are 0-0 #1538
Comments
Hello @yaober, thank you for your interest in 🚀 YOLOv5! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution. If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you. If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available. For business inquiries or professional support requests please visit https://www.ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com. RequirementsPython 3.8 or later with all requirements.txt dependencies installed, including $ pip install -r requirements.txt EnvironmentsYOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
StatusIf this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit. |
@yaober your dataset can only contain a class 0, as you specified in your data.yaml. You've provided labels that have up to class 16. |
but i just have one label class,in my dataset just have one too
…------------------ 原始邮件 ------------------
发件人: "ultralytics/yolov5" <notifications@github.com>;
发送时间: 2020年11月27日(星期五) 下午5:15
收件人: "ultralytics/yolov5"<yolov5@noreply.github.com>;
抄送: "北方"<2576094621@qq.com>;"Mention"<mention@noreply.github.com>;
主题: Re: [ultralytics/yolov5] how to save :AssertionError: Label class 16 exceeds nc=1 in ../data.yaml. Possible class labels are 0-0 (#1538)
@yaober your dataset can only contain a class 0, as you specified in your data.yaml. You've provided labels that have up to class 16.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
but i just have one label class,in my dataset just have one too |
@glenn-jocher your dataset has classes labelled as 16. You need to fix your dataset. |
how to fix
…------------------ 原始邮件 ------------------
发件人: "ultralytics/yolov5" <notifications@github.com>;
发送时间: 2020年11月27日(星期五) 下午5:23
收件人: "ultralytics/yolov5"<yolov5@noreply.github.com>;
抄送: "北方"<2576094621@qq.com>;"Mention"<mention@noreply.github.com>;
主题: Re: [ultralytics/yolov5] how to save :AssertionError: Label class 16 exceeds nc=1 in ../data.yaml. Possible class labels are 0-0 (#1538)
@glenn-jocher your dataset has classes labelled as 16. You need to fix your dataset.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
i follow this tips,but error to.
…------------------ 原始邮件 ------------------
发件人: "ultralytics/yolov5" <notifications@github.com>;
发送时间: 2020年11月27日(星期五) 下午5:25
收件人: "ultralytics/yolov5"<yolov5@noreply.github.com>;
抄送: "北方"<2576094621@qq.com>;"Mention"<mention@noreply.github.com>;
主题: Re: [ultralytics/yolov5] how to save :AssertionError: Label class 16 exceeds nc=1 in ../data.yaml. Possible class labels are 0-0 (#1538)
See https://docs.ultralytics.com/yolov5/tutorials/train_custom_data
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
i fthis is my dataset ,please help me, i sincerly thank for you
i use it to check it
…------------------ 原始邮件 ------------------
发件人: "ultralytics/yolov5" <notifications@github.com>;
发送时间: 2020年11月27日(星期五) 下午5:25
收件人: "ultralytics/yolov5"<yolov5@noreply.github.com>;
抄送: "北方"<2576094621@qq.com>;"Mention"<mention@noreply.github.com>;
主题: Re: [ultralytics/yolov5] how to save :AssertionError: Label class 16 exceeds nc=1 in ../data.yaml. Possible class labels are 0-0 (#1538)
See https://docs.ultralytics.com/yolov5/tutorials/train_custom_data
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
That probably because your current execution has reloaded the labels from the .cache file in your label folder, which hasn't been updated when you modify the actual label in the .txt file. Maybe try to delete the .cache and rerun it. |
When training with data I got annotated in Roboflow, I saw this error when I overwrote my train, valid, and test folder with the newly downloaded dataset using |
@mayukhberkeley this error is generated by an unsupported 3rd party notebook. Please see the official YOLOv5 Colab Notebook below, and visit the Train Custom Data Tutorial to get started with YOLOv5. Tutorials
RequirementsPython 3.8 or later with all requirements.txt dependencies installed, including $ pip install -r requirements.txt EnvironmentsYOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
StatusIf this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are passing. These tests evaluate proper operation of basic YOLOv5 functionality, including training (train.py), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu. |
Your label file may be something like this The first part is label where I have 15 labels in default in my annotation software which are dog, bike, car etc.. which I don't require. Change it to 1 if you are working on single class. if you are working on multiclass then, change the class number to the first part of label instead of 15. I have changed it to 1 because I am working on single class |
@triyam python is zero indexed so single class datasets should be labelled as class 0. See Train Custom Data tutorial for details on correctly formatting your dataset: YOLOv5 Tutorials
Good luck 🍀 and let us know if you have any other questions! |
Hello, have you solved your problem? I have the same problem. |
This is because your 1.txt 2.txt information has import os
import sys
files = os.listdir(".")
for file in files:
if ".txt" in file:
with open(file, "r") as f:
lines = f.readlines()
for line in lines:
if line[0] == "1":
line = line.replace("1", "0")
with open(file, "w") as f:
f.write(line)
print(line)
else:
print(line)
continue
else:
continue
|
@ kranercc |
Isnt class: 0 reserved to be a background images in COCO? I.e. in the COCO format, the first label starts with "1", not "0". |
This also works on Yolov8 |
@valentin-fngr thank you for sharing your experience and solution. That is correct! When dealing with custom datasets, it may be necessary to manually refresh the cache file in order to reflect the latest changes made in the label files. Your solution of deleting the cache and rerunning the code can be an effective way to do this. Note that, depending on the specific details of your workflow, there may be different ways to handle label files and caching. In some situations, it may be more appropriate to manually refresh the cache file using certain flags or command line arguments. Thank you for sharing your insight and contributing to the community's knowledge base! |
Go for the Label files (.txt). Open it, and check for the class id. that is, the first number for each file. If you have one class, change the class ID to 0. That's it. Make a program to do this if you have so many files. |
@khoshg to modify the class ID in the label files, you can follow these steps:
If you have a large number of files, you can consider writing a program to automate this process. The program can iterate through each file, open it, and update the class ID as necessary. Remember to save the modified label files after making the changes. Please let me know if you have any further questions or need any additional assistance. |
❔Question
Additional context
The text was updated successfully, but these errors were encountered: