TransUNet
TransUNet copied to clipboard
Question about how to train with image size with different length and width
Very impressive works. I trying to use the transUnet in my dataset. But my dataset shape is (672,448) which length and width not equal. I find this will lead bugs. because the patch needs the same w and h. How to deal with this problem, do you have some advise ? Thanks!
Look at https://github.com/Beckschen/TransUNet/issues/35
I think you could crop or rescale your image according to the mentioned factor
The errors may happen when data argumentation, an easy way to solve this is that zoom first and argumentation later. Change the code like this:
class RandomGenerator(object):
def __init__(self, output_size):
self.output_size = output_size
def __call__(self, sample):
image, label = sample['image'], sample['label']
x, y = label.shape
if x != self.output_size[0] or y != self.output_size[1]:
image = zoom(image, (1, self.output_size[0] / x, self.output_size[1] / y), order=3)
label = zoom(label, (self.output_size[0] / x, self.output_size[1] / y), order=0)
if random.random() > 0.5:
image, label = random_rot_flip(image, label)
elif random.random() > 0.5:
image, label = random_rotate(image, label)
image = torch.from_numpy(image.astype(np.float32))
label = torch.from_numpy(label.astype(np.float32))
sample = {'image': image, 'label': label.long()}
return sample