fl4health.metrics.base_metrics module

class Metric(name)[source]

Bases: ABC

__init__(name)[source]

Base abstract Metric class to extend for metric accumulation and computation.

Parameters:

name (str) – Name of the metric.

abstract clear()[source]

Resets metric.

Raises:

NotImplementedError – To be defined in the classes expending this class.

Return type:

None

abstract compute(name=None)[source]

Compute metric on state accumulated over updates.

Parameters:

name (str | None) – Optional name used in conjunction with class attribute name to define key in metrics dictionary.

Raises:

NotImplementedError – To be defined in the classes extending this class.

Returns:

A dictionary of string and Scalar representing the computed metric and its associated key.

Return type:

Metrics

abstract update(input, target)[source]

This method updates the state of the metric by appending the passed input and target pairing to their respective list.

Parameters:
  • input (torch.Tensor) – The predictions of the model to be evaluated.

  • target (torch.Tensor) – The ground truth target to evaluate predictions against.

Raises:

NotImplementedError – To be defined in the classes extending this class.

Return type:

None

class MetricPrefix(value)[source]

Bases: Enum

An enumeration.

TEST_PREFIX = 'test -'
VAL_PREFIX = 'val -'