steplog

Loggers to handle the logging from each step of a task.

class KNNStepLogger(task_name: str, n_batches: int, batch_size: int, record_int: bool = True, record_float: bool = False, writer: None | Run = None, model_type: str = '', **kwargs)

Logger specifically designed for use with the KNN validation in trainer.Trainer.weighted_knn_validation().

logs

The main logs from the KNN with these metrics:

  • batch_num

  • total_loss

  • total_correct

  • total_top5

Type:

dict[str, Any]

results

Hold these additional, full results from the KNN:

  • y

  • z

  • probs

  • ids

  • index

Type:

dict[str, Any]

Parameters:
  • n_batches (int) – Number of batches in the epoch.

  • batch_size (int) – Size of the batch.

  • n_samples (int) – Total number of samples in the epoch.

  • record_int (bool) – Optional; Whether to record the integer values from an epoch of model fitting. Defaults to True.

  • record_float (bool) – Optional; Whether to record the floating point values from an epoch of model fitting. Defaults to False.

  • writer (SummaryWriter | Run) – Optional; Writer object from tensorboard, a wandb Run object or None.

Added in version 0.27.

log(global_step_num: int, local_step_num: int, loss: Tensor, x: Tensor | None = None, y: Tensor | None = None, z: Tensor | None = None, index: int | BoundingBox | None = None, *args, **kwargs) None

Logs the outputs and results from a step of model fitting. Overwrites abstract method.

Parameters:
  • global_step_num (int) – The global step number of the model fitting.

  • local_step_num (int) – The local step number for this logger.

  • loss (Tensor) – Loss from this step of model fitting.

  • x (Tensor) – Optional; Images supplied to the model.

  • y (Tensor) – Optional; Labels to assess model output against.

  • z (Tensor) – Optional; Output tensor from the model.

  • index (int | BoundingBox) – Optional; Bounding boxes or index of the input samples.

Returns:

None

class MinervaStepLogger(task_name: str, n_batches: int, batch_size: int, input_size: tuple[int, int, int], output_size: tuple[int, ...], record_int: bool = True, record_float: bool = False, writer: None | Run = None, model_type: str = '', **kwargs)

Base abstract class for all minerva step logger classes to ensure intercompatibility with Trainer.

record_int

Whether to record the integer values from an epoch of model fitting.

Type:

bool

record_float

Whether to record the floating point values from an epoch of model fitting.

Type:

bool

n_batches

Number of batches in the epoch.

Type:

int

batch_size

Size of the batch.

Type:

int

n_samples

Total number of samples in the epoch.

Type:

int

logs

Dictionary to hold the logs from the epoch. Logs should be more lightweight than results.

Type:

dict[str, Any]

results

Dictionary to hold the results from the epoch.

Type:

dict[str, Any]

Parameters:
  • n_batches (int) – Number of batches in the epoch.

  • batch_size (int) – Size of the batch.

  • n_samples (int) – Total number of samples in the epoch.

  • record_int (bool) – Optional; Whether to record the integer values from an epoch of model fitting. Defaults to True.

  • record_float (bool) – Optional; Whether to record the floating point values from an epoch of model fitting. Defaults to False.

  • writer (SummaryWriter | Run) – Optional; Writer object from tensorboard, a wandb Run object or None.

Added in version 0.27.

property get_logs: dict[str, Any]

Gets the logs dictionary.

Returns:

Log dictionary of the logger.

Return type:

dict[str, Any]

property get_results: dict[str, Any]

Gets the results dictionary.

Returns:

Results dictionary of the logger.

Return type:

dict[str, Any]

abstract log(global_step_num: int, local_step_num: int, loss: Tensor, x: Tensor | None = None, y: Tensor | None = None, z: Tensor | None = None, index: int | BoundingBox | None = None, *args, **kwargs) None

Abstract logging method, the core functionality of a logger. Must be overwritten.

Parameters:
  • global_step_num (int) – The global step number of for the mode of model fitting.

  • local_step_num (int) – The local step number of for the mode of model fitting.

  • loss (Tensor) – Loss from this step of model fitting.

  • x (Tensor) – Optional; Images supplied to the model.

  • y (Tensor) – Optional; Labels to assess model output against.

  • z (Tensor) – Optional; Output tensor from the model.

  • index (int | BoundingBox) – Optional; Bounding boxes or index of the input samples.

Returns:

None

write_metric(key: str, value: SupportsFloat, step_num: int | None = None)

Write metric values to logging backends after calculation.

Parameters:
  • key (str) – Key for the metric that value belongs to.

  • value (SupportsFloat) – Metric to write to logger.

  • step_num (int) – Optional; Global step number for this mode of fitting.

class SSLStepLogger(task_name: str, n_batches: int, batch_size: int, input_size: tuple[int, int, int], output_size: tuple[int, int], record_int: bool = True, record_float: bool = False, writer: None | Run = None, model_type: str = '', **kwargs)

Logger designed for self-supervised learning.

logs

Dictionary to hold these logged metrics:

  • batch_num

  • total_loss

  • total_correct

  • total_top5

  • avg_loss

  • avg_output_std

Type:

dict[str, Any]

collapse_level

Adds calculation and logging of the collapse level to the metrics. Only to be used with Siamese type models.

Type:

bool

euclidean

Adds calculation and logging of the euclidean distance to the metrics. Only to be used with Siamese type models.

Type:

bool

Parameters:
  • n_batches (int) – Number of batches in the epoch.

  • batch_size (int) – Size of the batch.

  • n_samples (int) – Total number of samples in the epoch.

  • out_shape (tuple[int, ...]) – Shape of the model output.

  • n_classes (int) – Number of classes in dataset.

  • record_int (bool) – Optional; Whether to record the integer values from an epoch of model fitting. Defaults to True.

  • record_float (bool) – Optional; Whether to record the floating point values from an epoch of model fitting. Defaults to False.

  • writer (SummaryWriter | Run) – Optional; Writer object from tensorboard, a wandb Run object or None.

Added in version 0.27.

log(global_step_num: int, local_step_num: int, loss: Tensor, x: Tensor | None = None, y: Tensor | None = None, z: Tensor | None = None, index: int | BoundingBox | None = None, *args, **kwargs) None

Logs the outputs and results from a step of model fitting. Overwrites abstract method.

Parameters:
  • global_step_num (int) – The global step number of the model fitting.

  • local_step_num (int) – The local step number for this logger.

  • loss (Tensor) – Loss from this step of model fitting.

  • x (Tensor) – Optional; Images supplied to the model.

  • y (Tensor) – Optional; Labels to assess model output against.

  • z (Tensor) – Optional; Output tensor from the model.

  • index (int | BoundingBox) – Optional; Bounding boxes or index of the input samples.

Returns:

None

class SupervisedStepLogger(task_name: str, n_batches: int, batch_size: int, input_size: tuple[int, int, int], output_size: tuple[int, int], record_int: bool = True, record_float: bool = False, writer: None | Run = None, model_type: str = '', n_classes: int | None = None, **kwargs)

Logger designed for supervised learning using torchgeo datasets.

logs

The main logs with these metrics:

  • batch_num

  • total_loss

  • total_correct

  • total_top5

Type:

dict[str, Any]

results

Hold these additional, full results from the KNN:

  • y

  • z

  • probs

  • ids

  • index

  • images

Type:

dict[str, Any]

calc_miou

Activates the calculating and logging of MIoU for segmentation models. Places the metric in the total_miou key of logs.

Type:

bool

Parameters:
  • n_batches (int) – Number of batches in the epoch.

  • batch_size (int) – Size of the batch.

  • n_samples (int) – Total number of samples in the epoch.

  • out_shape (int | tuple[int, ...]) – Shape of the model output.

  • n_classes (int) – Number of classes in dataset.

  • record_int (bool) – Optional; Whether to record the integer values from an epoch of model fitting. Defaults to True.

  • record_float (bool) – Optional; Whether to record the floating point values from an epoch of model fitting. Defaults to False.

  • writer (SummaryWriter | Run) – Optional; Writer object from tensorboard, a wandb Run object or None.

Raises:
  • MemoryError – If trying to allocate memory to hold the probabilites of predictions from the model exceeds capacity.

  • MemoryError – If trying to allocate memory to hold the bounding boxes of samples would exceed capacity.

Added in version 0.27.

log(global_step_num: int, local_step_num: int, loss: Tensor, x: Tensor | None = None, y: Tensor | None = None, z: Tensor | None = None, index: int | BoundingBox | None = None, *args, **kwargs) None

Logs the outputs and results from a step of model fitting. Overwrites abstract method.

Parameters:
  • global_step_num (int) – The global step number of the model fitting.

  • local_step_num (int) – The local step number for this logger.

  • loss (Tensor) – Loss from this step of model fitting.

  • x (Tensor) – Optional; Images supplied to the model.

  • y (Tensor) – Optional; Labels to assess model output against.

  • z (Tensor) – Optional; Output tensor from the model.

  • index (int | BoundingBox) – Optional; Bounding boxes or index of the input samples.

Returns:

None