Reference for ultralytics/utils/callbacks/raytune.py
Improvements
This page is sourced from https://github.com/ultralytics/ultralytics/blob/main/ultralytics/utils/callbacks/raytune.py. Have an improvement or example to add? Open a Pull Request — thank you! 🙏
Summary
function ultralytics.utils.callbacks.raytune.on_fit_epoch_end
def on_fit_epoch_end(trainer)
Report training metrics to Ray Tune at epoch end when a Ray session is active.
Captures metrics from the trainer object and sends them to Ray Tune with the current epoch number, enabling hyperparameter tuning optimization. Only executes when within an active Ray Tune session.
Args
| Name | Type | Description | Default |
|---|---|---|---|
trainer | ultralytics.engine.trainer.BaseTrainer | The Ultralytics trainer object containing metrics and epochs. | required |
Examples
>>> # Called automatically by the Ultralytics training loop
>>> on_fit_epoch_end(trainer)
References:
Ray Tune docs: https://docs.ray.io/en/latest/tune/index.html
Source code in ultralytics/utils/callbacks/raytune.py
View on GitHubdef on_fit_epoch_end(trainer):
"""Report training metrics to Ray Tune at epoch end when a Ray session is active.
Captures metrics from the trainer object and sends them to Ray Tune with the current epoch number, enabling
hyperparameter tuning optimization. Only executes when within an active Ray Tune session.
Args:
trainer (ultralytics.engine.trainer.BaseTrainer): The Ultralytics trainer object containing metrics and epochs.
Examples:
>>> # Called automatically by the Ultralytics training loop
>>> on_fit_epoch_end(trainer)
References:
Ray Tune docs: https://docs.ray.io/en/latest/tune/index.html
"""
if ray.train._internal.session.get_session(): # check if Ray Tune session is active
metrics = trainer.metrics
session.report({**metrics, **{"epoch": trainer.epoch + 1}})
📅 Created 2 years ago ✏️ Updated 2 days ago