Reference for ultralytics/utils/callbacks/dvc.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/utils/callbacks/dvc.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.utils.callbacks.dvc._log_images
Log images at specified path with an optional prefix using DVCLive.
This function logs images found at the given path to DVCLive, organizing them by batch to enable slider functionality in the UI. It processes image filenames to extract batch information and restructures the path accordingly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
Path to the image file to be logged. |
required |
prefix
|
str
|
Optional prefix to add to the image name when logging. |
''
|
Examples:
>>> from pathlib import Path
>>> _log_images(Path("runs/train/exp/val_batch0_pred.jpg"), prefix="validation")
Source code in ultralytics/utils/callbacks/dvc.py
ultralytics.utils.callbacks.dvc._log_plots
Log plot images for training progress if they have not been previously processed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
plots
|
dict
|
Dictionary containing plot information with timestamps. |
required |
prefix
|
str
|
Optional prefix to add to the logged image paths. |
''
|
Source code in ultralytics/utils/callbacks/dvc.py
ultralytics.utils.callbacks.dvc._log_confusion_matrix
Log confusion matrix for a validator using DVCLive.
This function processes the confusion matrix from a validator object and logs it to DVCLive by converting the matrix into lists of target and prediction labels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
validator
|
BaseValidator
|
The validator object containing the confusion matrix and class names. Must have attributes: confusion_matrix.matrix, confusion_matrix.task, and names. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in ultralytics/utils/callbacks/dvc.py
ultralytics.utils.callbacks.dvc.on_pretrain_routine_start
Initializes DVCLive logger for training metadata during pre-training routine.
Source code in ultralytics/utils/callbacks/dvc.py
ultralytics.utils.callbacks.dvc.on_pretrain_routine_end
Logs plots related to the training process at the end of the pretraining routine.
ultralytics.utils.callbacks.dvc.on_train_start
ultralytics.utils.callbacks.dvc.on_train_epoch_start
Sets the global variable _training_epoch value to True at the start of training each epoch.
ultralytics.utils.callbacks.dvc.on_fit_epoch_end
Log training metrics, model info, and advance to next step at the end of each fit epoch.
This function is called at the end of each fit epoch during training. It logs various metrics including training loss items, validation metrics, and learning rates. On the first epoch, it also logs model information. Additionally, it logs training and validation plots and advances the DVCLive step counter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trainer
|
BaseTrainer
|
The trainer object containing training state, metrics, and plots. |
required |
Notes
This function only performs logging operations when DVCLive logging is active and during a training epoch. The global variable _training_epoch is used to track whether the current epoch is a training epoch.
Source code in ultralytics/utils/callbacks/dvc.py
ultralytics.utils.callbacks.dvc.on_train_end
Log best metrics, plots, and confusion matrix at the end of training.
This function is called at the conclusion of the training process to log final metrics, visualizations, and model artifacts if DVCLive logging is active. It captures the best model performance metrics, training plots, validation plots, and confusion matrix for later analysis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trainer
|
BaseTrainer
|
The trainer object containing training state, metrics, and validation results. |
required |
Examples:
>>> # Inside a custom training loop
>>> from ultralytics.utils.callbacks.dvc import on_train_end
>>> on_train_end(trainer) # Log final metrics and artifacts