@ptrblck why we need to do a transpose here img = Image.fromarray(np.transpose(img, (1, 2, 0))) ?
I need to convert images to the grayscale, and I did the same but I’ve got this error File "C:\Users\Neda\Anaconda3\lib\site-packages\PIL\Image.py", line 2463, in fromarray raise TypeError("Cannot handle this data type") TypeError: Cannot handle this data type
I am doing like this, am I doing a mistake?
      
class CustomDataset(Dataset):
    def __init__(self, image_paths, target_paths):   # initial logic happens like transform

        self.image_paths = image_paths
        self.target_paths = target_paths
        #self.convert_gray = transforms.Grayscale(1)
        self.transforms = transforms.ToTensor()
        self.mapping = {
            0: 0,
            255: 1
#            85: 0,
#            170: 1,
#            255: 2               
        }
    def mask_to_class(self, mask):
        for k in self.mapping:
            mask[mask==k] = self.mapping[k]
        return mask
    
    def __getitem__(self, index):

        image = Image.open(self.image_paths[index])
        mask = Image.open(self.target_paths[index])
        #t_image = self.convert_gray(image)
        img = Image.fromarray(np.transpose(image, (1, 2, 0)))
        t_image = img.convert('LA')
        t_image = self.transforms(t_image)
        #mask = torch.from_numpy(np.array(mask))    #this is for BMCC dataset
        mask = torch.from_numpy(np.array(mask, dtype=np.uint8)) # this is for my dataset(lv)
        mask = self.mask_to_class(mask)
        mask = mask.long()
        return t_image, mask

    def __len__(self):  # return count of sample we have

        return len(self.image_paths)