-
-
Notifications
You must be signed in to change notification settings - Fork 15.9k
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
updated pos_weight to be per class #8788
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π Hello @seermer, thank you for submitting a YOLOv5 π PR! To allow your work to be integrated as seamlessly as possible, we advise you to:
- β Verify your PR is up-to-date with upstream/master. If your PR is behind upstream/master an automatic GitHub Actions merge may be attempted by writing /rebase in a new comment, or by running the following code, replacing 'feature' with the name of your local branch:
git remote add upstream https://github.com/ultralytics/yolov5.git
git fetch upstream
# git checkout feature # <--- replace 'feature' with local branch name
git merge upstream/master
git push -u origin -f
- β Verify all Continuous Integration (CI) checks are passing.
- β Reduce changes to the absolute minimum required for your bug fix or feature addition. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." -Bruce Lee
@seermer thanks for the PR! I reviewed it and your new function seems to do the same as our existing function here: Lines 654 to 671 in 08c8c3e
Would it be better to modify or use the existing function instead of creating a similar one? |
Hello sir, I think they do similar things but have different results. from what I understand, the existing one returns the normalized inverse frequency. for example, if we have 800 class A, and 200 class B, then it returns [0.2, 0.8]. Although it is true that mine is just a multiple of the existing one, it would still perform differently as weights. |
for more information, see https://pre-commit.ci
@glenn-jocher Hello sir, I have just refactored the code so that the computation for counting samples will only perform once. However, the functions calculating pos_weight and class_weight are still separate since they do different things. Another possibility to refactor is to simply put the pos_weight and class_weight outside the function, directly in train.py, but it looks messy if I do so. Do you think my current change works? |
@seermer looks better now! Have you tried training to see how this affects the results? |
sorry, I don't have sufficient resources to train on any decent dataset right now, I have tried a small number of epochs on a private dataset, and see very little difference (~0.3 map0.5). |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions YOLOv5 π and Vision AI β. |
π Hello there! We wanted to let you know that we've decided to close this pull request due to inactivity. We appreciate the effort you put into contributing to our project, but unfortunately, not all contributions are suitable or aligned with our product roadmap. We hope you understand our decision, and please don't let it discourage you from contributing to open source projects in the future. We value all of our community members and their contributions, and we encourage you to keep exploring new projects and ways to get involved. For additional resources and information, please see the links below:
Thank you for your contributions to YOLO π and Vision AI β |
No worries, @seermer. Thanks for the update and for your efforts. Small datasets might not show the full potential of these changes. If you can, please monitor the issue for feedback from others who might be able to train on larger datasets. Your contribution is valuable, and we'll review it further. Keep up the good work! π |
changed pos_weight as described to fix #8749
π οΈ PR Summary
Made with β€οΈ by Ultralytics Actions
π Summary
Improvements in class weight calculation for better loss computation in YOLOv5 training.
π Key Changes
labels_to_class_weights()
withcounts_to_class_weights()
andcounts_to_pos_weights()
, offering a more granular approach.count_samples()
to count the number of samples for each class in the dataset.train.py
, changing how hyperparameters such asbox
,cls
, andobj
are scaled based on the dataset.ComputeLoss
inutils/loss.py
to use the new positional class weights directly.π― Purpose & Impact
These updates could lead to more accurate object detection models π, particularly when users are working with imbalanced datasets.