RuntimeError: stack expects each tensor to be equal size, but got [3, 530, 500] at entry 0 and [3, 500, 530] at entry 3

I get this error:
RuntimeError: stack expects each tensor to be equal size, but got [3, 530, 500] at entry 0 and [3, 500, 530] at entry 3
image(32bit) and label (4bit) , the same size(500*530), is there anything wrong with my transpose process?

class Resize(object):
“”“Resize image and/or masks.”""
def init(self, imageresize, maskresize):
self.imageresize = imageresize
self.maskresize = maskresize

def call(self, sample):
image, mask = sample[‘image’], sample[‘mask’]
if len(image.shape) == 3:
image = image.transpose(1, 2, 0)
if len(mask.shape) == 3:
mask = mask.transpose(1, 2, 0)
mask = cv2.resize(mask, self.maskresize, cv2.INTER_AREA)
image = cv2.resize(image, self.imageresize, cv2.INTER_AREA)
if len(image.shape) == 3:
image = image.transpose(2, 0, 1)
if len(mask.shape) == 3:
mask = mask.transpose(2, 0, 1)

return {'image': image,
        'mask': mask}

If the image as well as the mask have the same initial shape and you are applying the same transpose operations on these numpy arrays, the error might be raised by trying to stack different samples.
Could you check the shape of both arrays and make sure the height and width is equal for all samples?

PS: you can post code snippets by wrapping them into three backticks ```, which makes debugging easier. :wink: