fruit_project.utils.logging¶
Functions¶
|
Initializes a wandb run. |
|
Generates a run name based on the configuration. |
|
Logs a grid of images with their bounding boxes to wandb. |
|
Logs a grid of transformed images with their bounding boxes to wandb. |
|
Logs the elapsed training time. |
|
Logs the total and trainable parameters of a model. |
|
Logs the class distribution of a dataset. |
|
Logs a model checkpoint as a wandb artifact. |
|
Logs a detection confusion matrix plot to wandb. |
Module Contents¶
- fruit_project.utils.logging.initwandb(cfg: omegaconf.DictConfig) wandb.sdk.wandb_run.Run [source]¶
Initializes a wandb run.
- Parameters:
cfg (DictConfig) – Configuration object.
- Returns:
The wandb run object.
- Return type:
Run
- fruit_project.utils.logging.get_run_name(cfg: omegaconf.DictConfig) str [source]¶
Generates a run name based on the configuration.
- Parameters:
cfg (DictConfig) – Configuration object.
- Returns:
The generated run name.
- Return type:
str
- fruit_project.utils.logging.log_images(run: wandb.sdk.wandb_run.Run, batch: Tuple[Dict, List], id2lbl: Dict, grid_size: Tuple[int, int] = (3, 3), mean: torch.Tensor | None = None, std: torch.Tensor | None = None) None [source]¶
Logs a grid of images with their bounding boxes to wandb.
- Parameters:
run (Run) – The wandb run object.
batch (Tuple[Dict, List]) – A single batch of data (processed_batch, targets).
id2lbl (Dict) – A dictionary mapping class IDs to labels.
grid_size (Tuple[int, int], optional) – The grid size for displaying images. Defaults to (3, 3).
mean (Optional[torch.Tensor], optional) – The mean used for normalization. Defaults to None.
std (Optional[torch.Tensor], optional) – The standard deviation used for normalization. Defaults to None.
- fruit_project.utils.logging.log_transforms(run: wandb.sdk.wandb_run.Run, batch: Tuple[Dict, List], grid_size: Tuple[int, int] = (3, 3), id2lbl: Dict | None = None, transforms: Dict | None = None, mean: torch.Tensor | None = None, std: torch.Tensor | None = None) None [source]¶
Logs a grid of transformed images with their bounding boxes to wandb.
- Parameters:
run (Run) – The wandb run object.
batch (Tuple[Dict, List]) – A single batch of data (processed_batch, targets).
grid_size (Tuple[int, int], optional) – The grid size for displaying images. Defaults to (3, 3).
id2lbl (Optional[Dict], optional) – A dictionary mapping class IDs to labels. Defaults to None.
transforms (Optional[Dict], optional) – The transforms applied. Defaults to None.
mean (Optional[torch.Tensor], optional) – The mean used for normalization. Defaults to None.
std (Optional[torch.Tensor], optional) – The standard deviation used for normalization. Defaults to None.
- fruit_project.utils.logging.log_training_time(run: wandb.sdk.wandb_run.Run, start_time: float) None [source]¶
Logs the elapsed training time.
- Parameters:
run (Run) – The wandb run object.
start_time (float) – The start time of training.
- fruit_project.utils.logging.log_model_params(run: wandb.sdk.wandb_run.Run, model: torch.nn.Module) None [source]¶
Logs the total and trainable parameters of a model.
- Parameters:
run (Run) – The wandb run object.
model (nn.Module) – The model.
- fruit_project.utils.logging.log_class_value_counts(run: wandb.sdk.wandb_run.Run, samples: List[Tuple[str, str]], stage: str = 'Train') None [source]¶
Logs the class distribution of a dataset.
- Parameters:
run (Run) – The wandb run object.
samples (List[Tuple[Any, Any]]) – A list of samples (e.g., [(image, label), …]).
stage (str, optional) – The dataset stage (e.g., ‘Train’, ‘Test’). Defaults to “Train”.
- fruit_project.utils.logging.log_checkpoint_artifact(run: wandb.sdk.wandb_run.Run, path: str, name: str, epoch: int, wait: bool = False) None [source]¶
Logs a model checkpoint as a wandb artifact.
- Parameters:
run (Run) – The wandb run object.
path (str) – The path to the checkpoint file.
name (str) – The name of the artifact.
epoch (int) – The epoch number.
wait (bool, optional) – Whether to wait for the artifact to be uploaded. Defaults to False.
- fruit_project.utils.logging.log_detection_confusion_matrix(run: wandb.sdk.wandb_run.Run, cm_object: fruit_project.utils.metrics.ConfusionMatrix, class_names: List[str]) None [source]¶
Logs a detection confusion matrix plot to wandb.
- Parameters:
run (Run) – The wandb run object.
cm_object (ConfusionMatrix) – The confusion matrix object.
class_names (List[str]) – The list of class names.