logger.py
Implement a callback to log images.
- class ptlflow.utils.callbacks.logger.LoggerCallback(num_images: int = 5, image_size: Tuple[int, int] = (200, 400), log_keys: Sequence[str] = ('images', 'flows', 'occs', 'mbs', 'confs'), epe_clip: float = 5.0)[source]
Callback to collect and log images during training and validation.
For each dataloader, num_images samples will be collected. The samples are collected by trying to retrieve from both inputs and outputs tensors whose keys match the values provided in log_keys.
num_images samples are uniformly sampled from the whole dataloader.
- __init__(num_images: int = 5, image_size: Tuple[int, int] = (200, 400), log_keys: Sequence[str] = ('images', 'flows', 'occs', 'mbs', 'confs'), epe_clip: float = 5.0) None [source]
Initialize LoggerCallback.
- Parameters:
- num_imagesint, default 5
Number of images to log during one epoch.
- image_sizeTuple[int, int], default (200, 400)
The size of the stored images.
- log_keysSequence[str], default (‘images’, ‘flows’, ‘occs’, ‘mbs’, ‘confs’)
The keys to use to collect the images from the inputs and outputs of the model. If a key is not found, it is ignored.
- epe_clipfloat, default 5.0
The maximum EPE value that is shown on EPE image. All EPE values above this will be clipped.
- log_image(title: str, image: Tensor, pl_module: BaseModel) None [source]
Log the image in all of the pl_module loggers.
Note, however, that not all loggers may be able to log images.
- Parameters:
- titlestr
A title for the image.
- imagetorch.Tensor
The image to log. It must be a 3D tensor CHW (typically C=3).
- pl_moduleBaseModel
An instance of the optical flow model to get the logger from.
- on_train_batch_end(trainer: Trainer, pl_module: BaseModel, outputs: Dict[str, Tensor], batch: Dict[str, Tensor], batch_idx: int, **kwargs) None [source]
Store one image to be logged, if the current batch_idx is in the log selection group.
- Parameters:
- trainerTrainer
An instance of the PyTorch Lightning trainer.
- pl_moduleBaseModel
An instance of the optical flow model.
- outputsDict[str, torch.Tensor]
The outputs of the current training batch.
- batchDict[str, torch.Tensor]
The inputs of the current training batch.
- batch_idxint
The counter value of the current batch.
- on_train_epoch_end(trainer: Trainer, pl_module: BaseModel, **kwargs) None [source]
Log the images accumulated during the training.
- Parameters:
- trainerTrainer
An instance of the PyTorch Lightning trainer.
- pl_moduleBaseModel
An instance of the optical flow model.
- outputsAny
Outputs of the training epoch.
- on_train_epoch_start(trainer: Trainer, pl_module: BaseModel) None [source]
Reset the training log params and accumulators.
- Parameters:
- trainerTrainer
An instance of the PyTorch Lightning trainer.
- pl_moduleBaseModel
An instance of the optical flow model.
- on_validation_batch_end(trainer: Trainer, pl_module: BaseModel, outputs: Dict[str, Tensor], batch: Dict[str, Tensor], batch_idx: int, dataloader_idx: int) None [source]
Store one image to be logged, if the current batch_idx is in the log selection group.
- Parameters:
- trainerTrainer
An instance of the PyTorch Lightning trainer.
- pl_moduleBaseModel
An instance of the optical flow model.
- outputsDict[str, torch.Tensor]
The outputs of the current validation batch.
- batchDict[str, torch.Tensor]
The inputs of the current validation batch.
- batch_idxint
The counter value of the current batch.
- dataloader_idxint
The index number of the current dataloader.