Skip to content
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

Optimised Callback Class to Reduce Code and Fix Errors #4688

Merged
merged 9 commits into from
Sep 7, 2021
Merged

Optimised Callback Class to Reduce Code and Fix Errors #4688

merged 9 commits into from
Sep 7, 2021

Conversation

kalenmike
Copy link
Member

@kalenmike kalenmike commented Sep 6, 2021

Removed methods for each callback and implemented checks for available callbacks based on the dictionary defined in the class. Modified train.py to pass the name of the callback hook it is requesting. Initially, this was to fix the callbacks class because some of the methods were not accepting self and this was crashing certain callbacks. To prevent similar mistakes in the future I thought it would be better to combine all the methods into one as they were all using the same code.

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Improved callback system for greater flexibility in YOLOv5 training and validation flow.

📊 Key Changes

  • 📝 train.py and val.py scripts now use callbacks.run instead of individual callback methods like on_pretrain_routine_end().
  • 🚀 The Callbacks class in utils/callbacks.py is refactored to remove individual methods tied to specific events and add a universal run method.
  • 🧹 Cleanup of the Callbacks class constructor and other methods that were previously used to run callbacks.

🎯 Purpose & Impact

  • 🔨 Purpose: The main purpose is to streamline how callbacks are handled in the code, providing a more scalable and manageable system.
  • Impact: The impact on users includes a cleaner and more maintainable codebase with potentially easier customization of training behaviour through callbacks and improved code readability. This change is mainly under-the-hood and shouldn't affect the user experience or training results directly.

@kalenmike kalenmike marked this pull request as draft September 6, 2021 12:56
@kalenmike
Copy link
Member Author

Made required changes to prevent crash when running from console.

@kalenmike kalenmike marked this pull request as ready for review September 6, 2021 13:31
@glenn-jocher glenn-jocher merged commit 2317f86 into ultralytics:master Sep 7, 2021
@glenn-jocher
Copy link
Member

@kalenmike PR is merged. Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐

jveitchmichaelis added a commit to jveitchmichaelis/yolov5 that referenced this pull request Sep 10, 2021
Fix following ultralytics#4688 which modified the function signature to `train`
glenn-jocher added a commit that referenced this pull request Sep 10, 2021
* add callbacks to train function in wandb sweep

Fix following #4688 which modified the function signature to `train`

* Cleanup

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
@kalenmike kalenmike deleted the feature/optimise-callbacks branch September 10, 2021 17:20
CesarBazanAV pushed a commit to CesarBazanAV/yolov5 that referenced this pull request Sep 29, 2021
)

* added callbacks

* added back callback to main

* added save_dir to callback output

* reduced code count

* updated callbacks

* added default callback class to main, added missing parameters to on_model_save

* Glenn updates

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
CesarBazanAV pushed a commit to CesarBazanAV/yolov5 that referenced this pull request Sep 29, 2021
* add callbacks to train function in wandb sweep

Fix following ultralytics#4688 which modified the function signature to `train`

* Cleanup

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
BjarneKuehl pushed a commit to fhkiel-mlaip/yolov5 that referenced this pull request Aug 26, 2022
)

* added callbacks

* added back callback to main

* added save_dir to callback output

* reduced code count

* updated callbacks

* added default callback class to main, added missing parameters to on_model_save

* Glenn updates

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
BjarneKuehl pushed a commit to fhkiel-mlaip/yolov5 that referenced this pull request Aug 26, 2022
* add callbacks to train function in wandb sweep

Fix following ultralytics#4688 which modified the function signature to `train`

* Cleanup

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
SecretStar112 added a commit to SecretStar112/yolov5 that referenced this pull request May 24, 2023
* add callbacks to train function in wandb sweep

Fix following ultralytics/yolov5#4688 which modified the function signature to `train`

* Cleanup

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants