예제 #1
0
파일: common.py 프로젝트: BebDong/MXNetSeg
def misclassified_prop(mis_pixels: np.ndarray, prob: nd.NDArray) -> np.ndarray:
    """
    get the probability distribution of misclassified pixels.
    :param mis_pixels: misclassified pixels of shape HW where 0 indicates misclassified pixels
    :param prob: the predicted probability with shape CHW
    :return: numpy array of shape NC where N is the total number of misclassified pixels
    """
    prob = prob.as_in_context(mx.cpu())
    prob = nd.transpose(nd.reshape(prob, shape=(0, -1)), axes=(1, 0))
    flag_bit = np.reshape(mis_pixels, newshape=(-1))
    mis_index = nd.array(np.where(flag_bit == 0)).squeeze()
    return prob[mis_index, :].asnumpy()
예제 #2
0
파일: common.py 프로젝트: BebDong/MXNetSeg
def misclassified_pixels(prob: nd.NDArray,
                         label: nd.NDArray,
                         ignore_label: int = -1) -> np.ndarray:
    """
    return misclassified pixels.
    :param prob: the predicted probability with shape CHW
    :param label: the ground truth label with shape HW
    :param ignore_label: ignored label
    :return: numpy array of shape HW where 0 indicates misclassified pixels
    """
    # needs to process on cpu
    prob = prob.as_in_context(mx.cpu())
    label = label.as_in_context(mx.cpu())

    # determine equal or not to get misclassified pixels
    pred = nd.squeeze(nd.argmax(prob, axis=0)).astype('int32')
    mis_classify = (pred == label).asnumpy()

    # deal with ignored label via numpy
    label = label.asnumpy()
    mis_classify[label == ignore_label] = 1

    return mis_classify