关于#cyclegan#的问题,如何解决?(语言-python)

如何在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.pytrain.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

这样就可以生成和输入图像大小一致的输出图像了。