Reference for ultralytics/utils/callbacks/wb.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/utils/callbacks/wb.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.utils.callbacks.wb._custom_table
_custom_table(
x,
y,
classes,
title="Precision Recall Curve",
x_title="Recall",
y_title="Precision",
)
Create and log a custom metric visualization to wandb.plot.pr_curve.
This function crafts a custom metric visualization that mimics the behavior of the default wandb precision-recall curve while allowing for enhanced customization. The visual metric is useful for monitoring model performance across different classes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
list
|
Values for the x-axis; expected to have length N. |
required |
y
|
list
|
Corresponding values for the y-axis; also expected to have length N. |
required |
classes
|
list
|
Labels identifying the class of each point; length N. |
required |
title
|
str
|
Title for the plot; defaults to 'Precision Recall Curve'. |
'Precision Recall Curve'
|
x_title
|
str
|
Label for the x-axis; defaults to 'Recall'. |
'Recall'
|
y_title
|
str
|
Label for the y-axis; defaults to 'Precision'. |
'Precision'
|
Returns:
Type | Description |
---|---|
Object
|
A wandb object suitable for logging, showcasing the crafted metric visualization. |
Source code in ultralytics/utils/callbacks/wb.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
ultralytics.utils.callbacks.wb._plot_curve
_plot_curve(
x,
y,
names=None,
id="precision-recall",
title="Precision Recall Curve",
x_title="Recall",
y_title="Precision",
num_x=100,
only_mean=False,
)
Log a metric curve visualization.
This function generates a metric curve based on input data and logs the visualization to wandb. The curve can represent aggregated data (mean) or individual class data, depending on the 'only_mean' flag.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
ndarray
|
Data points for the x-axis with length N. |
required |
y
|
ndarray
|
Corresponding data points for the y-axis with shape (C, N), where C is the number of classes. |
required |
names
|
list
|
Names of the classes corresponding to the y-axis data; length C. |
None
|
id
|
str
|
Unique identifier for the logged data in wandb. |
'precision-recall'
|
title
|
str
|
Title for the visualization plot. |
'Precision Recall Curve'
|
x_title
|
str
|
Label for the x-axis. |
'Recall'
|
y_title
|
str
|
Label for the y-axis. |
'Precision'
|
num_x
|
int
|
Number of interpolated data points for visualization. |
100
|
only_mean
|
bool
|
Flag to indicate if only the mean curve should be plotted. |
False
|
Notes
The function leverages the '_custom_table' function to generate the actual visualization.
Source code in ultralytics/utils/callbacks/wb.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
ultralytics.utils.callbacks.wb._log_plots
_log_plots(plots, step)
Log plots to WandB at a specific step if they haven't been logged already.
This function checks each plot in the input dictionary against previously processed plots and logs new or updated plots to WandB at the specified step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
plots
|
dict
|
Dictionary of plots to log, where keys are plot names and values are dictionaries containing plot metadata including timestamps. |
required |
step
|
int
|
The step/epoch at which to log the plots in the WandB run. |
required |
Notes
- The function uses a shallow copy of the plots dictionary to prevent modification during iteration
- Plots are identified by their stem name (filename without extension)
- Each plot is logged as a WandB Image object
Source code in ultralytics/utils/callbacks/wb.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
ultralytics.utils.callbacks.wb.on_pretrain_routine_start
on_pretrain_routine_start(trainer)
Initiate and start wandb project if module is present.
Source code in ultralytics/utils/callbacks/wb.py
125 126 127 128 129 130 131 132 |
|
ultralytics.utils.callbacks.wb.on_fit_epoch_end
on_fit_epoch_end(trainer)
Log training metrics and model information at the end of an epoch.
Source code in ultralytics/utils/callbacks/wb.py
135 136 137 138 139 140 141 |
|
ultralytics.utils.callbacks.wb.on_train_epoch_end
on_train_epoch_end(trainer)
Log metrics and save images at the end of each training epoch.
Source code in ultralytics/utils/callbacks/wb.py
144 145 146 147 148 149 |
|
ultralytics.utils.callbacks.wb.on_train_end
on_train_end(trainer)
Save the best model as an artifact and log final plots at the end of training.
Source code in ultralytics/utils/callbacks/wb.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|