Shortcuts

torchtraining.metrics.classification.multiclass

class torchtraining.metrics.classification.multiclass.Accuracy(reduction=<built-in method mean of type object>)[source]

Calculate accuracy score between output and target.

Works for both logits and probabilities of output out of the box.

Parameters

reduction (Callable(torch.Tensor) -> Any, optional) – One argument callable getting torch.Tensor and returning argument after specified reduction. Default: torch.mean (mean across batch, user can use torchtraining.savers.Mean to get mean across iterations/epochs).

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,,C1)(N, *, C-1) , where CC is the number of classes. Should contain logits (unnormalized probabilities) or probabilities after softmax activation or similar. targets should be of shape (N,)(N, *) and contain integers in the range [0,C1][0, C-1]

Returns

If reduction is left as default mean is taken and single value returned. Otherwise whatever reduction returns.

Return type

torch.Tensor

class torchtraining.metrics.classification.multiclass.BalancedAccuracy[source]

Critical success index between output and target.

Works for both logits and probabilities of output out of the box.

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,,C1)(N, *, C-1) , where CC is the number of classes. Should contain logits (unnormalized probabilities) or probabilities after softmax activation or similar. targets should be of shape (N,)(N, *) and contain integers in the range [0,C1][0, C-1]

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.classification.multiclass.ConfusionMatrix[source]

Confusion matrix between output and target.

Works for both logits and probabilities of output out of the box.

Parameters

reduction (Callable, optional) – One argument callable getting torch.Tensor and returning torch.Tensor. Default: torch.sum (sum of all elements, user can use torchtraining.savers.Sum to get sum across iterations/epochs).

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,,C1)(N, *, C-1) , where CC is the number of classes. Should contain logits (unnormalized probabilities) or probabilities after softmax activation or similar. targets should be of shape (N,)(N, *) and contain integers in the range [0,C1][0, C-1]

Returns

If reduction is left as default sum is taken and single value returned. Otherwise whatever reduction returns.

Return type

torch.Tensor

class torchtraining.metrics.classification.multiclass.CriticalSuccessIndex[source]

Critical success index between output and target.

Works for both logits and probabilities of output out of the box.

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,,C1)(N, *, C-1) , where CC is the number of classes. Should contain logits (unnormalized probabilities) or probabilities after softmax activation or similar. targets should be of shape (N,)(N, *) and contain integers in the range [0,C1][0, C-1]

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.classification.multiclass.F1[source]

F1 score between output and target.

Works for both logits and probabilities of output out of the box.

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,,C1)(N, *, C-1) , where CC is the number of classes. Should contain logits (unnormalized probabilities) or probabilities after softmax activation or similar. targets should be of shape (N,)(N, *) and contain integers in the range [0,C1][0, C-1]

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.classification.multiclass.FBeta(beta: float)[source]

Get f-beta score between outputs and targets.

Works for both logits and probabilities of output out of the box.

Parameters
  • beta (float) – Beta coefficient of f-beta score.

  • data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,,C1)(N, *, C-1) , where CC is the number of classes. Should contain logits (unnormalized probabilities) or probabilities after softmax activation or similar. targets should be of shape (N,)(N, *) and contain integers in the range [0,C1][0, C-1]

Returns

Scalar tensor

Return type

torch.Tensor

forward(data)[source]
class torchtraining.metrics.classification.multiclass.FalseDiscoveryRate[source]

False discovery rate between output and target.

Works for both logits and probabilities of output out of the box.

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,,C1)(N, *, C-1) , where CC is the number of classes. Should contain logits (unnormalized probabilities) or probabilities after softmax activation or similar. targets should be of shape (N,)(N, *) and contain integers in the range [0,C1][0, C-1]

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.classification.multiclass.FalseNegative(reduction=<built-in method sum of type object>)[source]

Number of false negatives between output and target.

Works for both logits and probabilities of output out of the box.

Parameters

reduction (Callable, optional) – One argument callable getting torch.Tensor and returning torch.Tensor. Default: torch.sum (sum of all elements, user can use torchtraining.savers.Sum to get sum across iterations/epochs).

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,,C1)(N, *, C-1) , where CC is the number of classes. Should contain logits (unnormalized probabilities) or probabilities after softmax activation or similar. targets should be of shape (N,)(N, *) and contain integers in the range [0,C1][0, C-1]

Returns

If reduction is left as default sum is taken and single value returned. Otherwise whatever reduction returns.

Return type

torch.Tensor

class torchtraining.metrics.classification.multiclass.FalseNegativeRate[source]

False negative rate between output and target.

Works for both logits and probabilities of output out of the box.

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,,C1)(N, *, C-1) , where CC is the number of classes. Should contain logits (unnormalized probabilities) or probabilities after softmax activation or similar. targets should be of shape (N,)(N, *) and contain integers in the range [0,C1][0, C-1]

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.classification.multiclass.FalseOmissionRate[source]

False omission rate between output and target.

Works for both logits and probabilities of output out of the box.

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,,C1)(N, *, C-1) , where CC is the number of classes. Should contain logits (unnormalized probabilities) or probabilities after softmax activation or similar. targets should be of shape (N,)(N, *) and contain integers in the range [0,C1][0, C-1]

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.classification.multiclass.FalsePositive(reduction=<built-in method sum of type object>)[source]

Number of false positives between output and target.

Works for both logits and probabilities of output out of the box.

Parameters

reduction (Callable, optional) – One argument callable getting torch.Tensor and returning torch.Tensor. Default: torch.sum (sum of all elements, user can use torchtraining.savers.Sum to get sum across iterations/epochs).

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,,C1)(N, *, C-1) , where CC is the number of classes. Should contain logits (unnormalized probabilities) or probabilities after softmax activation or similar. targets should be of shape (N,)(N, *) and contain integers in the range [0,C1][0, C-1]

Returns

If reduction is left as default sum is taken and single value returned. Otherwise whatever reduction returns.

Return type

torch.Tensor

class torchtraining.metrics.classification.multiclass.FalsePositiveRate[source]

False positive rate between output and target.

Works for both logits and probabilities of output out of the box.

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,,C1)(N, *, C-1) , where CC is the number of classes. Should contain logits (unnormalized probabilities) or probabilities after softmax activation or similar. targets should be of shape (N,)(N, *) and contain integers in the range [0,C1][0, C-1]

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.classification.multiclass.Jaccard(reduction=<built-in method mean of type object>)[source]

Calculate Jaccard score between output and target.

Works for both logits and probabilities of output out of the box.

Parameters

reduction (Callable(torch.Tensor) -> Any, optional) – One argument callable getting torch.Tensor and returning argument after specified reduction. Default: torch.mean (mean across batch, user can use torchtraining.savers.Mean to get mean across iterations/epochs).

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,,C1)(N, *, C-1) , where CC is the number of classes. Should contain logits (unnormalized probabilities) or probabilities after softmax activation or similar. targets should be of shape (N,)(N, *) and contain integers in the range [0,C1][0, C-1]

Returns

If reduction is left as default mean is taken and single value returned. Otherwise whatever reduction returns.

Return type

torch.Tensor

class torchtraining.metrics.classification.multiclass.MatthewsCorrelationCoefficient[source]

Matthews correlation coefficient between output and target.

Works for both logits and probabilities of output out of the box.

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,,C1)(N, *, C-1) , where CC is the number of classes. Should contain logits (unnormalized probabilities) or probabilities after softmax activation or similar. targets should be of shape (N,)(N, *) and contain integers in the range [0,C1][0, C-1]

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.classification.multiclass.NegativePredictiveValue[source]

Negative predictive value between output and target.

Works for both logits and probabilities of output out of the box.

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,,C1)(N, *, C-1) , where CC is the number of classes. Should contain logits (unnormalized probabilities) or probabilities after softmax activation or similar. targets should be of shape (N,)(N, *) and contain integers in the range [0,C1][0, C-1]

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.classification.multiclass.Precision[source]

Precision between output and target.

Works for both logits and probabilities of output out of the box.

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,,C1)(N, *, C-1) , where CC is the number of classes. Should contain logits (unnormalized probabilities) or probabilities after softmax activation or similar. targets should be of shape (N,)(N, *) and contain integers in the range [0,C1][0, C-1]

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.classification.multiclass.Recall[source]

Recall between output and target.

Works for both logits and probabilities of output out of the box.

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,,C1)(N, *, C-1) , where CC is the number of classes. Should contain logits (unnormalized probabilities) or probabilities after softmax activation or similar. targets should be of shape (N,)(N, *) and contain integers in the range [0,C1][0, C-1]

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.classification.multiclass.Specificity[source]

Specificity between output and target.

Works for both logits and probabilities of output out of the box.

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,,C1)(N, *, C-1) , where CC is the number of classes. Should contain logits (unnormalized probabilities) or probabilities after softmax activation or similar. targets should be of shape (N,)(N, *) and contain integers in the range [0,C1][0, C-1]

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.classification.multiclass.TopK(k: int, reduction=<built-in method mean of type object>)[source]

Get top-k accuracy score between outputs and targets.

Works for both logits and probabilities of output out of the box.

Parameters
  • k (int) – How many top results should be chosen.

  • reduction (Callable, optional) – One argument callable getting torch.Tensor and returning torch.Tensor. Default: torch.sum (sum of all elements, user can use torchtraining.savers.Sum to get sum across iterations/epochs).

  • data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,,C1)(N, *, C-1) , where CC is the number of classes. Should contain logits (unnormalized probabilities) or probabilities after softmax activation or similar. targets should be of shape (N,)(N, *) and contain integers in the range [0,C1][0, C-1]

Returns

If reduction is left as default mean is taken and single value returned. Otherwise whatever reduction returns.

Return type

torch.Tensor

forward(data)[source]
class torchtraining.metrics.classification.multiclass.TrueNegative(reduction=<built-in method sum of type object>)[source]

Number of true negatives between output and target.

Works for both logits and probabilities of output out of the box.

Parameters

reduction (Callable, optional) – One argument callable getting torch.Tensor and returning torch.Tensor. Default: torch.sum (sum of all elements, user can use torchtraining.savers.Sum to get sum across iterations/epochs).

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,,C1)(N, *, C-1) , where CC is the number of classes. Should contain logits (unnormalized probabilities) or probabilities after softmax activation or similar. targets should be of shape (N,)(N, *) and contain integers in the range [0,C1][0, C-1]

Returns

If reduction is left as default sum is taken and single value returned. Otherwise whatever reduction returns.

Return type

torch.Tensor

class torchtraining.metrics.classification.multiclass.TruePositive(reduction=<built-in method sum of type object>)[source]

Number of false positives between output and target.

Works for both logits and probabilities of output out of the box.

Parameters

reduction (Callable, optional) – One argument callable getting torch.Tensor and returning torch.Tensor. Default: torch.sum (sum of all elements, user can use torchtraining.savers.Sum to get sum across iterations/epochs).

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and targets (ground truths). outputs should be of shape (N,,C1)(N, *, C-1) , where CC is the number of classes. Should contain logits (unnormalized probabilities) or probabilities after softmax activation or similar. targets should be of shape (N,)(N, *) and contain integers in the range [0,C1][0, C-1]

Returns

If reduction is left as default sum is taken and single value returned. Otherwise whatever reduction returns.

Return type

torch.Tensor