MeanIntersectionOverUnion#
- class torch_uncertainty.metrics.segmentation.MeanIntersectionOverUnion(num_classes, top_k=1, ignore_index=None, validate_args=True, **kwargs)[source]#
Computes the Mean Intersection over Union (mIoU) score.
For a multi-class segmentation task with \(C\) classes, the per-class Intersection over Union is
\[\text{IoU}_c = \frac{\text{TP}_c}{\text{TP}_c + \text{FP}_c + \text{FN}_c},\]where \(\text{TP}_c\), \(\text{FP}_c\), \(\text{FN}_c\) are the numbers of true-positive, false-positive and false-negative pixels for class \(c\) (aggregated over all images). The mean IoU is the unweighted average
\[\text{mIoU} = \frac{1}{C} \sum_{c=1}^{C} \text{IoU}_c.\]Classes that never appear in the targets are excluded from the average (
nanmean).- Parameters:
num_classes (
int) – Integer specifying the number of classes.top_k (
int) – Number of highest probability or logit score predictions considered to find the correct label. Only works whenpredscontain probabilities/logits. Defaults to1.ignore_index (
int|None) – Specifies a target value that is ignored and does not contribute to the metric calculation. Defaults toNone.validate_args (
bool) – Bool indicating if input arguments and tensors should be validated for correctness. Set toFalsefor faster computations. Defaults toTrue.**kwargs – kwargs: Additional keyword arguments, see Advanced metric settings for more info.
- Shape:
As input to
forwardandupdatethe metric accepts the following input:preds (
Tensor): An int tensor of shape(B, *)or float tensor of shape(B, C, *). If preds is a floating point we applytorch.argmaxalong theCdimension to automatically convert probabilities/logits into an int tensor.target (
Tensor): An int tensor of shape(B, *).
As output to
forwardandcomputethe metric returns the following output:mean_iou (
Tensor): The computed Mean Intersection over Union (IoU) score. A tensor containing a single float value.