kornia.utils.metrics

confusion_matrix(input: torch.Tensor, target: torch.Tensor, num_classes: int, normalized: Optional[bool] = False) → torch.Tensor[source]

Compute confusion matrix to evaluate the accuracy of a classification.

Parameters
  • input (torch.Tensor) – tensor with estimated targets returned by a classifier. The shape can be \((B, *)\) and must contain integer values between 0 and K-1.

  • target (torch.Tensor) – tensor with ground truth (correct) target values. The shape can be \((B, *)\) and must contain integer values between 0 and K-1, whete targets are assumed to be provided as one-hot vectors.

  • num_classes (int) – total possible number of classes in target.

  • normalized – (Optional[bool]): wether to return the confusion matrix normalized. Default: False.

Returns

a tensor containing the confusion matrix with shape \((B, K, K)\) where K is the number of classes.

Return type

torch.Tensor

mean_iou(input: torch.Tensor, target: torch.Tensor, num_classes: int, eps: Optional[float] = 1e-06) → torch.Tensor[source]

Calculate mean Intersection-Over-Union (mIOU).

The function internally computes the confusion matrix.

Parameters
  • input (torch.Tensor) – tensor with estimated targets returned by a classifier. The shape can be \((B, *)\) and must contain integer values between 0 and K-1.

  • target (torch.Tensor) – tensor with ground truth (correct) target values. The shape can be \((B, *)\) and must contain integer values between 0 and K-1, whete targets are assumed to be provided as one-hot vectors.

  • num_classes (int) – total possible number of classes in target.

Returns

a tensor representing the mean intersection-over union with shape \((B, K)\) where K is the number of classes.

Return type

torch.Tensor