Dataloader: Invalid Argument Error: Invalid Shape

visualize works only on my images, but on masks it gives Invalid shape () for image data , all masks have the same size 512x512 , what could be the reason ?

Could you post a code snippet showing this behavior?
In case you are using matplotlib, it should allow you to visualize images containing only the spatial size as seen here:

mask = torch.randint(0, 2, (244, 244))

I am using the code from

when i reach:


it gives:

all my images and masks have same shape(512x512) but here it gives:

  print(dataset[0][0].shape) gives (512, 512, 3)
  print(dataset[0][1].shape) gives (1,)

Your mask seems to have a single dimension, which is not a valid image format, so you would have to check the Dataset and make sure mask is created properly.

 def __getitem__(self, i):
    image = cv2.imread(self.images_fps[i])
    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    mask = cv2.imread(self.masks_fps[i], 0)

i think here are images and masks created, it works for images but not for masks -.- , they all have same size (512x512)

The posted code looks alright, but doesn’t match

print(dataset[0][1].shape) gives (1,)

so could you check what exactly is returned in the __getitem__ method, as the second return value doesn’t seem to be the mask.

Assuming the first image represents the image while the second one the mask, the data loading looks correct, so I’m still unsure why the previous shape is returned.
Could you iterate the Dataset for an entire epoch and check all mask shapes?