如何在cyclegan源码中修改cyclegan生成图像的大小,也就是如何在cyclegan源码中去掉输入图像裁剪和resize操作,使得生成的输出图像和输入的图像大小一致,不发生变化
在CycleGAN源码中,输入图像的裁剪和resize操作是在data_loader.py
文件中的__getitem__
函数中进行的。如果要去掉这些操作,可以将__getitem__
函数中的以下代码注释掉:
# # Random crop
# if self.opt.preprocess == 'resize_and_crop':
# osize = [self.opt.load_size, self.opt.load_size]
# w, h = img.size
# if w == h:
# crop_size = w
# else:
# crop_size = self.opt.crop_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))
# else:
# osize = [self.opt.load_size, self.opt.load_size]
# img = img.resize(osize, Image.BICUBIC)
然后,在test.py
和train.py
文件中,将--crop_size
参数的值设置为输入图像的大小即可。例如,如果输入图像的大小为256x256,则可以将--crop_size
参数的值设置为256:
python train.py --dataroot ./datasets/maps --name maps_cyclegan --model cycle_gan --pool_size 50 --no_dropout --crop_size 256
python test.py --dataroot ./datasets/maps --name maps_cyclegan --model cycle_gan --no_dropout --crop_size 256
这样就可以生成和输入图像大小一致的输出图像了。