Skip to content

Conversation

glenn-jocher
Copy link
Member

@glenn-jocher glenn-jocher commented Apr 6, 2022

Add all callbacks even if currently unused to allow user flexibility. @kalenmike

def __init__(self):
# Define the available callbacks
self._callbacks = {
'on_pretrain_routine_start': [],
'on_pretrain_routine_end': [],
'on_train_start': [],
'on_train_epoch_start': [],
'on_train_batch_start': [],
'optimizer_step': [],
'on_before_zero_grad': [],
'on_train_batch_end': [],
'on_train_epoch_end': [],
'on_val_start': [],
'on_val_batch_start': [],
'on_val_image_end': [],
'on_val_batch_end': [],
'on_val_end': [],
'on_fit_epoch_end': [], # fit = train + val
'on_model_save': [],
'on_train_end': [],
'on_params_update': [],
'teardown': [],}
self.stop_training = False # set True to interrupt training

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Improved callback integration in training and validation workflows.

📊 Key Changes

  • Added on_pretrain_routine_start callback invocation before training starts.
  • Inserted on_train_start and on_train_epoch_start callbacks in the training routine.
  • Introduced on_train_batch_start callback at the beginning of each training batch.
  • Included on_val_start and on_val_batch_start callbacks when validation begins and at the start of each validation batch, respectively.
  • Added a on_val_batch_end callback at the end of each validation batch.

🎯 Purpose & Impact

  • 🚀 Purpose: The purpose of these changes is to provide better hook points for custom callbacks within the training and validation loops of the model, which can be useful for logging, custom metrics, or other user-defined operations.
  • 🌐 Impact: Users can now incorporate advanced callback functions into their training and validation pipelines, enabling more dynamic and flexible model customization. This can improve monitoring and management of the training process, leading to potentially better model performance and experiment tracking.

@glenn-jocher glenn-jocher self-assigned this Apr 6, 2022
@glenn-jocher glenn-jocher changed the title Add callbacks to train.py Add callbacks Apr 6, 2022
@glenn-jocher glenn-jocher merged commit 245d645 into master Apr 6, 2022
@glenn-jocher glenn-jocher deleted the update/on_train_start_callback branch April 6, 2022 15:23
BjarneKuehl pushed a commit to fhkiel-mlaip/yolov5 that referenced this pull request Aug 26, 2022
* Add `on_train_start()` callback

* Update

* Update
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.

1 participant