# mean_iou¶

paddle.fluid.layers.mean_iou(input, label, num_classes)[source]

Mean Intersection-Over-Union is a common evaluation metric for semantic image segmentation, which first computes the IOU for each semantic class and then computes the average over classes. IOU is defined as follows:

$IOU = \frac{true\_positive}{(true\_positive + false\_positive + false\_negative)}.$

The predictions are accumulated in a confusion matrix and mean-IOU is then calculated from it.

Parameters
• input (Variable) – A n-D Tensor of prediction results for semantic labels with type int32 or int64.

• label (Variable) – A Tensor of ground truth labels with type int32 or int64. Its shape should be the same as input.

• num_classes (int32) – The possible number of labels.

Returns

Three Variables.

• mean_iou(Variable) : A 1-D Tensor representing the mean intersection-over-union with shape [1]. Data type is float32.

• out_wrong(Variable) : A 1-D Tensor with shape [num_classes]. Data type is int32. The wrong numbers of each class.

• out_correct(Variable): A 1-D Tensor with shape [num_classes]. Data type is int32. The correct numbers of each class.

Examples

import paddle.fluid as fluid
iou_shape = [None, 32, 32]
num_classes = 5
predict = fluid.data(name='predict', shape=iou_shape, dtype='int64')
label = fluid.data(name='label', shape=iou_shape, dtype='int64')
mean_iou, out_wrong, out_correct = fluid.layers.mean_iou(predict, label,
num_classes)