tasklog

These loggers are designed to handle the logging and analysis for a whole task.

class MinervaTaskLogger(task_name: str, n_batches: int, batch_size: int, input_size: tuple[int, int, int], output_size: tuple[int, ...], step_logger_params: dict[str, Any] | None = None, record_int: bool = True, record_float: bool = False, writer: None | Run = None, **params)

Abstract class for metric logging within the minerva framework.

n_batches

Dictionary of the number of batches in each mode of fitting.

Type:

dict[str, int]

batch_size

Batch size.

Type:

int

output_size

Shape of the output data in H x W.

Type:

tuple[int, int]

metrics

Dictionary to hold the metrics to assess the model with for each mode of fitting.

Type:

dict[str, Any]

model_type

Type of the model.

Type:

str

Parameters:
  • n_batches (dict[str, int]) – Dictionary of the number of batches in each mode of fitting.

  • batch_size (int) – Batch size.

  • data_size (tuple[int, int, int]) – Shape of the input data in C x H x W.

  • logger_params (dict[str, Any]) – Optional; Parameters for a logger other than the default for these metrics.

Added in version 0.27.

calc_metrics(epoch_no: int) None

Updates metrics with epoch results.

Parameters:

epoch_no (int) – Epoch number to log.

property get_logs: dict[str, Any]

Get the logs of each step from the latest epoch of the task.

Returns:

Logs per step of last epoch.

Return type:

dict[str, Any]

Added in version 0.27.

property get_metrics: dict[str, Any]

Get the metrics dictionary.

Returns:

Metrics dictionary.

Return type:

dict[str, Any]

property get_results: dict[str, Any]

Get the results of each step from the latest epoch of the task.

Returns:

Logs per step of last epoch.

Return type:

dict[str, Any]

Added in version 0.27.

get_sub_metrics(pattern: tuple[str, ...] = ('train', 'val')) dict[str, Any]

Gets a subset of the metrics dictionary with keys containing strings in the pattern.

Useful for getting the train and validation metrics for plotting for example.

Parameters:

pattern (tuple[str, ...]) – Optional; Strings to pattern match the metric keys to be returned. Defaults to ("train", "val").

Returns:

Subset of metrics with keys that contained strings in pattern.

Return type:

dict[str, Any]

log_epoch_number(epoch_no: int) None

Logs the epoch number to metrics.

Parameters:

epoch_no (int) – Epoch number to log.

log_null() None

Log numpy.NAN for this epoch.

Useful for logging null when a validation epoch was skipped so that the length of the logs remains the same as the training logs.

abstract print_epoch_results(epoch_no: int) None

Prints the results from an epoch to stdout.

Parameters:

epoch_no (int) – Epoch number to print results from.

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

Abstract method to log a step, using the logger. Must be overwritten.

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 SSLTaskLogger(task_name: str, n_batches: int, batch_size: int, input_size: tuple[int, int, int], output_size: tuple[int, ...], step_logger_params: dict[str, Any] | None = None, record_int: bool = True, record_float: bool = False, writer: None | Run = None, model_type: str = 'segmentation', sample_pairs: bool = False, **params)

Metric logging for self-supervised models.

n_batches

Dictionary of the number of batches in each mode of fitting.

Type:

dict[str, int]

batch_size

Batch size.

Type:

int

data_size

Shape of the input data in C x H x W.

Type:

tuple[int, int, int]

metrics

Dictionary to hold the metrics to assess the model with for each mode of fitting.

Type:

dict[str, Any]

model_type

Type of the model.

Type:

str

Parameters:
  • n_batches (dict[str, int]) – Dictionary of the number of batches in each mode of fitting.

  • batch_size (int) – Batch size.

  • data_size (tuple[int, int, int]) – Shape of the input data in C x H x W.

  • model_type (str) – Optional; Type of the model.

Added in version 0.27.

print_epoch_results(epoch_no: int) None

Prints the results from an epoch to stdout.

Parameters:

epoch_no (int) – Epoch number to print results from.

class SupervisedTaskLogger(task_name: str, n_batches: int, batch_size: int, input_size: tuple[int, int, int], output_size: tuple[int, ...], step_logger_params: dict[str, Any] | None = None, record_int: bool = True, record_float: bool = False, writer: None | Run = None, model_type: str = 'segmentation', **params)

Metric logging for supervised models.

n_batches

Dictionary of the number of batches in each mode of fitting.

Type:

dict[str, int]

batch_size

Batch size.

Type:

int

data_size

Shape of the input data in C x H x W.

Type:

tuple[int, int, int]

metrics

Dictionary to hold the metrics to assess the model with for each mode of fitting.

Type:

dict[str, Any]

model_type

Type of the model.

Type:

str

Parameters:
  • n_batches (dict[str, int]) – Dictionary of the number of batches in each mode of fitting.

  • batch_size (int) – Batch size.

  • data_size (tuple[int, int, int]) – Shape of the input data in C x H x W.

  • model_type (str) – Optional; Type of the model.

Added in version 0.27.

print_epoch_results(epoch_no: int) None

Prints the results from an epoch to stdout.

Parameters:

epoch_no (int) – Epoch number to print results from.