如何在cyclegan源码中修改cyclegan生成图像的大小,也就是如何在cyclegan源码中去掉输入图像裁剪和resize操作,使得生成的输出图像和输入的图像大小一致,不发生变化
1条回答 默认 最新
关注在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 256python test.py --dataroot ./datasets/maps --name maps_cyclegan --model cycle_gan --no_dropout --crop_size 256这样就可以生成和输入图像大小一致的输出图像了。
解决 无用评论 打赏 举报