-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
AssertionError: Label class 2 exceeds nc=2 in data/zhongmei.yaml. Possible class labels are 0-1 #1601
Comments
@Stephenfang51 can you please help me in resolving this, I too have same issue, I have only one class images , showing the error.. |
@joshnarani9 @Stephenfang51 this is very simple. If your data.yaml shows nc=2, then valid class labels are 0-1. You have labels beyond 0-1. |
@glenn-jocher I got it but already I do have class label as 1 and which is only 1 class, as I don't have label as 0 in all text files...which is why it is throwing error and my concern is without changing label to 0 in all files, I want to resolve it... I can able to resolve only if in train.py file by commenting out assert statements and it worked fine |
@joshnarani9 I see your point. While commenting out the assert statement might temporarily resolve the issue, it's important to have the correct label values in your dataset for accurate training and inference. You can consider adding a background class with label 0 in your data.yaml and updating your label files accordingly. This would help in maintaining the integrity of your dataset. Let me know if you need further assistance with this approach. |
@joshnarani9 Hi!I had to deal with the same thing.Your experience may be of great help to me. I don't want to add a background class with label 0 in my data.yaml, what assert statements should i comment out. I comment out the "assert mlc < nc, f'Label class {mlc} exceeds nc={nc} in {data}" in train_dual.py, but it still doesn't work. |
@glenn-jocher can you please help me?My dataset is labeled from 1 to 21, with a total of 21 classes. If I add a background class with label 0 in my data.yaml, I worry that it will affect the training accuracy. if I don't want to add the label 0, but want to train the 21 classes with the label which from 1 to 21,what can i do? |
Hi @54HaoHao-hue, Thank you for reaching out! If your dataset is labeled from 1 to 21 and you prefer not to add a background class with label 0, you can modify the code to accommodate your labeling scheme. However, it's generally recommended to start class labels from 0 for compatibility and consistency. Here's a potential solution to modify the code:
While these steps can help you bypass the immediate issue, it's important to note that adhering to standard practices (starting labels from 0) can prevent potential issues and ensure compatibility with other tools and libraries. If you encounter any further issues or need additional assistance, feel free to ask. The YOLO community and the Ultralytics team are here to help! 😊 |
@glenn-jocher Thank you very much for your patient reply, which helped me a lot |
Hi @54HaoHao-hue, You're very welcome! I'm glad to hear that the information was helpful to you. 😊 If you encounter any more issues or have further questions, please don't hesitate to ask. The YOLO community and the Ultralytics team are always here to support you. Also, if you believe you've found a bug, please ensure you're using the latest versions of the packages and provide any relevant details to help us reproduce and address the issue. Happy training and best of luck with your project! |
I have two classes
why the error occurs ?
The text was updated successfully, but these errors were encountered: