def calculate_confusion_matrix_from_arrays()

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


def calculate_confusion_matrix_from_arrays(prediction, ground_truth, nr_labels):
    """
    calculate the confusion matrix for one image pair.
    prediction and ground_truth have to have the same shape.
    """

    # a long 2xn array with each column being a pixel pair
    replace_indices = np.vstack((
        ground_truth.flatten(),
        prediction.flatten())
    ).T

    # add up confusion matrix
    confusion_matrix, _ = np.histogramdd(
        replace_indices,
        bins=(nr_labels, nr_labels),
        range=[(0, nr_labels), (0, nr_labels)]
    )
    confusion_matrix = confusion_matrix.astype(np.uint64)
    return confusion_matrix