Skip to content

mlvbench.metrics

Evaluation metrics.

intersection_over_union(prediction, target)

Compute the intersection over union (IoU) of two binary masks.

\[ \mathrm{IoU} = \frac{|P \cap T|}{|P \cup T|} \]

If both the prediction and target are empty (\(|P \cup T| = 0\)), this returns 1.0 since the prediction is correct.

Parameters:

Name Type Description Default
prediction Tensor

The predicted mask, a bool tensor of arbitrary shape.

required
target Tensor

The target mask, a bool tensor of the same shape as prediction.

required

Returns:

Type Description
float

The IoU computed over all elements. Returns 1.0 if both masks are empty.