ClassificationOutput

class torch_ecg.components.ClassificationOutput(*args: Any, **kwargs: Any)[source]

Bases: BaseOutput

Class that maintains the output of a (typically single-label) classification task.

Parameters:
  • classes (Sequence[str]) – Class names.

  • prob (numpy.ndarray) – Probabilities of each class, of shape (batch_size, num_classes).

  • pred (numpy.ndarray) – Predicted class indices of shape (batch_size,), or binary predictions of shape (batch_size, num_classes).

Note

Known issues:

  • fields of type dict are not well supported due to the limitations of the base class CFG, for example

>>> output = ClassificationOutput(classes=["AF", "N", "SPB"], pred=np.ones((1,3)), prob=np.ones((1,3)), d={"d":1})
>>> output
{'classes': ['AF', 'N', 'SPB'],
    'prob': array([[1., 1., 1.]]),
    'pred': array([[1., 1., 1.]]),
    'd': {'d': 1}}
>>> output.d  # has to access via `output["d"]`
AttributeError: 'ClassificationOutput' object has no attribute 'd'
compute_metrics() ClassificationMetrics[source]

Compute metrics from the output.

Returns:

metrics – Metrics computed from the output.

Return type:

ClassificationMetrics

required_fields() Set[str][source]

The required fields of the output class.