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. |
|
|
|
Performs final validation, logs metrics, and logs it to wandb |
|
Constructs and logs a dictionary of metrics for logging at the end of an epoch. |
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: Dict, 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: Dict, grid_size: Tuple[int, int], id2lbl: Dict[int, str], transforms: Dict | None = None, mean: torch.Tensor | None = None, std: torch.Tensor | None = None, do_normalize: bool = False) 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.
- fruit_project.utils.logging.log_per_class_metric(class_names: List, metric_per_class: torch.Tensor, ds_type: str, metric_name: str, log_data: Dict) None [source]¶
- fruit_project.utils.logging.log_test_data(epoch: int, best_val_map: float, trainer) None [source]¶
Performs final validation, logs metrics, and logs it to wandb
- Parameters:
epoch (int) – The final epoch number.
best_test_map (float) – The best test mAP@.50 achieved during training.
- Returns:
None
- fruit_project.utils.logging.log_epoch_data(epoch: int, train_loss: Dict[str, float], val_loss: Dict[str, float], val_metrics: Dict, trainer) None [source]¶
Constructs and logs a dictionary of metrics for logging at the end of an epoch.
- Parameters:
epoch (int) – The current epoch number.
train_loss (Dict) – Dict containing total, classification, bbox and giou training loss for epoch.
test_map (float) – The test mAP@.5-.95.
test_map50 (float) – The test mAP@.50.
test_loss (Dict) – Dict containing total, classification, bbox and giou test loss for epoch.
test_map_per_class (torch.Tensor) – The test mAP@.50 for each class.
trainer (Trainer) – instance of Trainer class
- Returns:
None