-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Is it possible to change class weight? #2703
Comments
👋 Hello @KazuhideMimura, thank you for your interest in YOLOv8 🚀! We recommend a visit to the YOLOv8 Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered. If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it. If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results. InstallPip install the pip install ultralytics EnvironmentsYOLOv8 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 Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit. |
@KazuhideMimura hello! |
@glenn-jocher Hi, thank you for your reply! |
@KazuhideMimura You're welcome! Yes, that's exactly right. By modifying the |
Thanks, I'll try! |
@KazuhideMimura of course, KazuhideMimura! You understood it correctly. By modifying the |
👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help. For additional resources and information, please see the links below:
Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed! Thank you for your contributions to YOLO 🚀 and Vision AI ⭐ |
Hi, |
@NikhilM97 hello, I apologize for the confusion, but in the current YOLOv8 implementation, As for the train.py file, it might have been moved or refactored. The current YOLOv8 implementation could be different from the previous one when that guidance was provided. Please ensure you're working with the most recent version of YOLOv8 and consult the most recent documentation for the most up-to-date information. I hope this helps. Let me know if you have more questions. |
Thanks for the reply @glenn-jocher ,Is there any way i can change the class weights in yolov8?Because i am dealing with the imbalanced dataset.I did go through the documentation.But i couldn't find any parameters,where i can change change weights of classes.Can i change class weights here?https://github.com/ultralytics/ultralytics/blob/main/ultralytics/utils/loss.py#L115 |
Hello @NikhilM97, Apologies for the confusion earlier. Under the current YOLOv8 architecture, we do not have a direct While deep learning models like YOLOv8 can generally handle class imbalance to some extent, one common approach to deal with severe class imbalance in the object detection tasks is to oversample the minority class or undersample the majority class. You can also try data augmentation techniques geared towards the minority class to artificially balance your dataset. However, I would advise caution and careful fine-tuning, as too much augmentation could make the model overfit to the minority class. While adjusting class weights might seem the norm in problems like multi-class classification, it doesn't directly extend to object detection tasks due to the complexity of considerations including the object scales, ratios, and spatial locations. Hope this clarifies your issue. Please let me know if you have further questions. |
Hi @glenn-jocher , |
Hello @NikhilM97, You're welcome! I'm glad I could help. If you have any more questions or run into any more issues, don't hesitate to ask. YOLOv8 is a constantly evolving project, and I'm here to make sure you're able to get the most out of it. Happy coding! |
@glenn-jocher I have created a PR for this feature. Please check that! |
Search before asking
Question
Hi, I'd like to train on a dataset with imbalanced number of classes.
I trained a detection model with on a dataset with 2 classes, and class1:class2 is ~1:4.
The trained model seems to be more fitted to detect class2, and cannot detect class1 as I expected. Therefore, I'd like to increase the weight for class1 and decrease class2's weight, which is typically conducted in image classification tasks.
Is that possible?
Additional
No response
The text was updated successfully, but these errors were encountered: