Def _sync_transform(self, img, mask):

Hello
np.unpackbits get 24 bits for Cityscapes we reverse the order (total 19 classes) for SBD datasets we reverse the order (total 20 classes)

For ADE20K that has 150 classes what i do for getting 150 bits.

def _sync_transform(self, img, mask):
#hy modified this function
# random crop crop_size
crop_size = self.crop_size
w, h = img.size
x1 = random.randint(0, w - crop_size)
y1 = random.randint(0, h - crop_size)
img = img.crop((x1, y1, x1+crop_size, y1+crop_size))
mask = mask.crop((x1, y1, x1+crop_size, y1+crop_size))
#np.unpackbits get 24 bits, we extract [:,:5:] and reverse the order (total 19 classes), i.e. [:,:,-1:-20:-1]
mask = np.unpackbits(np.array(mask), axis=2)[:,:,-1:-20:-1]
mask = torch.from_numpy(np.array(mask)).float()
mask = mask.transpose(0, 1).transpose(0, 2) #channel first
# return img, self._mask_transform(mask)
return img, mask

Thank you

As far as I see it in the docs, only np.uint8 is supported by np.unpackbits, so you might need to use byte swapping to get the underlying representation.

What is your use case that you need to hack around the bits?

1 Like

Hi
Thank you for your response.

DFF algorithm estimate for each pixel at the boundry the probabilities belongs to each class.
I’ve understood each bit if equal 1 then this pixel correspond to Class_i
but until now it is complicate to modify mask = np.unpackbits(np.array(mask), axis=2) to extract more than 24 bits.