Skip to content

Register now for

# Reference for `ultralytics/utils/callbacks/platform.py`

Note

This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/utils/callbacks/platform.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!

## `` ultralytics.utils.callbacks.platform.on_pretrain_routine_start

    on_pretrain_routine_start(trainer)

Initialize and start console logging immediately at the very beginning.

Source code in `ultralytics/utils/callbacks/platform.py`

     6
     7
     8
     9
    10
    11
    12
    13
    def on_pretrain_routine_start(trainer):
        """Initialize and start console logging immediately at the very beginning."""
        if RANK in {-1, 0}:
            from ultralytics.utils.logger import DEFAULT_LOG_PATH, ConsoleLogger, SystemLogger

            trainer.system_logger = SystemLogger()
            trainer.console_logger = ConsoleLogger(DEFAULT_LOG_PATH)
            trainer.console_logger.start_capture()

## `` ultralytics.utils.callbacks.platform.on_pretrain_routine_end

    on_pretrain_routine_end(trainer)

Handle pre-training routine completion event.

Source code in `ultralytics/utils/callbacks/platform.py`

    16
    17
    18
    def on_pretrain_routine_end(trainer):
        """Handle pre-training routine completion event."""
        pass

## `` ultralytics.utils.callbacks.platform.on_fit_epoch_end

    on_fit_epoch_end(trainer)

Handle end of training epoch event and collect system metrics.

Source code in `ultralytics/utils/callbacks/platform.py`

    21
    22
    23
    24
    25
    def on_fit_epoch_end(trainer):
        """Handle end of training epoch event and collect system metrics."""
        if RANK in {-1, 0} and hasattr(trainer, "system_logger"):
            system_metrics = trainer.system_logger.get_metrics()
            print(system_metrics)  # for debug

## `` ultralytics.utils.callbacks.platform.on_model_save

    on_model_save(trainer)

Handle model checkpoint save event.

Source code in `ultralytics/utils/callbacks/platform.py`

    28
    29
    30
    def on_model_save(trainer):
        """Handle model checkpoint save event."""
        pass

## `` ultralytics.utils.callbacks.platform.on_train_end

    on_train_end(trainer)

Stop console capture and finalize logs.

Source code in `ultralytics/utils/callbacks/platform.py`

    33
    34
    35
    36
    def on_train_end(trainer):
        """Stop console capture and finalize logs."""
        if logger := getattr(trainer, "console_logger", None):
            logger.stop_capture()

## `` ultralytics.utils.callbacks.platform.on_train_start

    on_train_start(trainer)

Handle training start event.

Source code in `ultralytics/utils/callbacks/platform.py`

    39
    40
    41
    def on_train_start(trainer):
        """Handle training start event."""
        pass

## `` ultralytics.utils.callbacks.platform.on_val_start

    on_val_start(validator)

Handle validation start event.

Source code in `ultralytics/utils/callbacks/platform.py`

    44
    45
    46
    def on_val_start(validator):
        """Handle validation start event."""
        pass

## `` ultralytics.utils.callbacks.platform.on_predict_start

    on_predict_start(predictor)

Handle prediction start event.

Source code in `ultralytics/utils/callbacks/platform.py`

    49
    50
    51
    def on_predict_start(predictor):
        """Handle prediction start event."""
        pass

## `` ultralytics.utils.callbacks.platform.on_export_start

    on_export_start(exporter)

Handle model export start event.

Source code in `ultralytics/utils/callbacks/platform.py`

    54
    55
    56
    def on_export_start(exporter):
        """Handle model export start event."""
        pass

📅 Created 28 days ago ✏️ Updated 28 days ago