(predict, target, nclass)
return area_inter, area_union
Batch Intersection of Union
    Args:
        predict: input 4D tensor
        target: label 3D tensor
        nclass: number of categories (int)
Batch Intersection of Union
    Args:
        predict: input 4D tensor
        target: label 3D tensor
        nclass: number of categories (int)
Batch Intersection of Union Args : predict : input 4D tensor target : label 3D tensor nclass : number of categories ( int )
def batch_intersection_union(predict, target, nclass):
    """Batch Intersection of Union
    Args:
        predict: input 4D tensor
        target: label 3D tensor
        nclass: number of categories (int)
    """
    _, predict = torch.max(predict, 1)
    mini = 1
    maxi = nclass
    nbins = nclass
    predict = predict.cpu().numpy() + 1
    target = target.cpu().numpy() + 1

    k = (target >= 1) & (target <= nclass)
    # predict = predict * (target > 0).astype(predict.dtype)
    predict = predict * k.astype(predict.dtype)
    intersection = predict * (predict == target)
    # areas of intersection and union
    area_inter, _ = np.histogram(intersection, bins=nbins, range=(mini, maxi))
    area_pred, _ = np.histogram(predict, bins=nbins, range=(mini, maxi))
    area_lab, _ = np.histogram(target, bins=nbins, range=(mini, maxi))
    area_union = area_pred + area_lab - area_inter
    assert (area_inter <= area_union).all(), \
        "Intersection area should be smaller than Union area"
    return area_inter, area_union
def batch_intersection_union ( predict , target , nclass ) : _ , predict = torch . max ( predict , 1 ) mini = 1 maxi = nclass nbins = nclass predict = predict . cpu ( ) . numpy ( ) + 1 target = target . cpu ( ) . numpy ( ) + 1 k = ( target >= 1 ) & ( target <= nclass ) # predict = predict * (target > 0).astype(predict.dtype) predict = predict * k . astype ( predict . dtype ) intersection = predict * ( predict == target ) # areas of intersection and union area_inter , _ = np . histogram ( intersection , bins = nbins , range = ( mini , maxi ) ) area_pred , _ = np . histogram ( predict , bins = nbins , range = ( mini , maxi ) ) area_lab , _ = np . histogram ( target , bins = nbins , range = ( mini , maxi ) ) area_union = area_pred + area_lab - area_inter assert ( area_inter <= area_union ) . all ( ) , "Intersection area should be smaller than Union area" return area_inter , area_union