def calculate_iiou()

in mapillary_vistas/evaluation/confusion_matrix.py [0:0]


def calculate_iiou(labels, confusion_matrix, instance_information):
    """
    Calculates the iIoU (instance specific intersecion over union) and IoU.
    The true positives and false negatives are scaled by the average
    instance size of the category. Scaling factors are applied outside
    of this function.
    """

    ious = calculate_iou(confusion_matrix)
    iious = []
    for index, (label, iou) in enumerate(zip(labels, ious)):
        if not label['instances']:
            iious.append((iou, None, None))
            continue

        true_positives = confusion_matrix[index, index]
        false_positives = confusion_matrix[:, index].sum() - true_positives

        weighted_true_positives = instance_information[label['name']]['weighted_true_positives']
        weighted_false_negatives = instance_information[label['name']]['weighted_false_negatives']

        denom = weighted_true_positives + weighted_false_negatives + false_positives

        if denom == 0:
            weighted_iiou = float('nan')
        else:
            weighted_iiou = weighted_true_positives / denom

        iious.append((iou, weighted_iiou))

    return iious