alibi.models.pytorch.metrics
This module contains a loss wrapper and a definition of various monitoring metrics used during training. The model to be trained inherits form :py:class:alibi.explainers.models.pytorch.model.Model and represents a simplified version of the tensorflow.keras API for training and monitoring the model. Currently it is used internally to test the functionalities for the Pytorch backend. To be discussed if the module will be exposed to the user in future versions.
AccuracyMetric
AccuracyMetricInherits from: Metric, ABC
Accuracy monitoring metric.
Constructor
AccuracyMetric(self, name: str = 'accuracy')name
str
'accuracy'
Name of the metric.
reduction
Metric's reduction type. Possible values mean
Methods
compute_metric
compute_metriccompute_metric(y_pred: Union[torch.Tensor, numpy.ndarray], y_true: Union[torch.Tensor, numpy.ndarray]) -> Noney_pred
Union[torch.Tensor, numpy.ndarray]
Predicted label.
y_true
Union[torch.Tensor, numpy.ndarray]
True label.
Returns
Type:
None
LossContainer
LossContainerLoss wrapped to monitor the average loss throughout training.
Constructor
LossContainer(self, loss: Callable[[torch.Tensor, torch.Tensor], torch.Tensor], name: str)loss
Callable[[.[<class 'torch.Tensor'>, <class 'torch.Tensor'>]], torch.Tensor]
Loss function.
name
str
Name of the loss function
Methods
reset
resetreset()Resets the loss.
result
resultresult() -> Dict[str, float]Computes the average loss obtain by dividing the cumulated loss by the number of steps
Returns
Type:
Dict[str, float]
Metric
MetricInherits from: ABC
Monitoring metric object. Supports two types of reduction: mean and sum.
Constructor
Metric(self, reduction: alibi.models.pytorch.metrics.Reduction = <Reduction.MEAN: 'mean'>, name: str = 'unknown')reduction
alibi.models.pytorch.metrics.Reduction
<Reduction.MEAN: 'mean'>
Metric's reduction type. Possible values mean
name
str
'unknown'
Name of the metric.
Methods
compute_metric
compute_metriccompute_metric(y_pred: Union[torch.Tensor, numpy.ndarray], y_true: Union[torch.Tensor, numpy.ndarray])y_pred
Union[torch.Tensor, numpy.ndarray]
y_true
Union[torch.Tensor, numpy.ndarray]
reset
resetreset()Resets the monitoring metric.
result
resultresult() -> Dict[str, float]Computes the result according to the reduction procedure.
Returns
Type:
Dict[str, float]
update_state
update_stateupdate_state(values: numpy.ndarray)Update the state of the metric by summing up the metric values and updating the counts by adding the number of instances for which the metric was computed (first dimension).
values
numpy.ndarray
Reduction
ReductionInherits from: Enum
Reduction operation supported by the monitoring metrics.
Last updated
Was this helpful?

