lucasb-eyer / pydensecrf

Python wrapper to Philipp Krähenbühl's dense (fully connected) CRFs with gaussian edge potentials.
MIT License
1.93k stars 411 forks source link

Bad shape for unary energy (Need (2, 1053979828), got (39677, 26564)) #100

Open pratik-segmind opened 4 years ago

pratik-segmind commented 4 years ago

My Code:

def mask_smoothen(img, mask, nclasses):

    mask = mask.astype(np.float32) #mask.astype(np.uint8)
    image = img
    height, width, channels = image.shape

    d = dcrf.DenseCRF2D(height, width, nclasses)

    labels = mask.T

    U = unary_from_softmax(labels)
    U = np.ascontiguousarray(U) 
    print(U.dtype, U.shape)

    d.setUnaryEnergy(U)

    d.addPairwiseBilateral(sxy=80, srgb=13, rgbim=image, compat=10)

    Q = d.inference(5)

    fine_mask = np.argmax(Q, axis=0).reshape(height, width)

    return fine_mask

I get the error "Bad shape for unary energy (Need (2, 1053979828), got (39677, 26564))"

My image and masks are large: 39677 x 26564

Can some one help me understand what is happening here.

andres-fr commented 4 years ago

The readme says that you need to flatten it to the shape (NUM_CLASSES, H*W). Hope that helps!

huixiancheng commented 3 years ago

resize you pic maybe