junyanz / pytorch-CycleGAN-and-pix2pix

Image-to-Image Translation in PyTorch
Other
22.88k stars 6.3k forks source link

Unet generator for large images #977

Open myfrannie opened 4 years ago

myfrannie commented 4 years ago

Hello, thanks for providing your code. I applied cycleGAN to my own dataset whose size is 900x900. First, I used the code with default setting and it worked well. (of course train with option --preprocess scale_width_and_crop --load_size 900 --crop_size 256 and test with --preprocess scale_width --load_size 900) After then, I tried to train and test the dataset with unet generator with same options. However, it didn't work, and I think because the images size should be 256x256 for unet. Is there any way to use large images with unet generator except cropping the dataset?

junyanz commented 4 years ago

When you mentioned "it didn't work", does it mean a) the program crashes or 2) the results look worse?

  1. For CycleGAN, Resnet-based generators often work much better than UNet.
  2. UNet does support images whose width and height are divisable by 256. For example, 512x512.
zhangdan8962 commented 4 years ago

@junyanz I am wondering if combining Resnet-based with UNet makes sense? Specifically, adding the connection between down/up sampling layers.

junyanz commented 4 years ago

Sure. It might be worth trying.

Mayurji commented 4 years ago

@junyanz, As you mentioned , "For CycleGAN, Resnet-based generators often work much better than UNet.", is there any specific reason because i tried with UNet and burnt my gpu for 200 epochs to find no good result.

junyanz commented 4 years ago

I hypothesize that the ResNet has fewer parameters and fewer downsampling, which are both good for color and style transfer, while U-Net has many more parameters (hard to learn these parameters without paired data) and has lots of downsampling layers. But this is just my speculation.

atFinland2023 commented 10 months ago

I trained with: ## Traing Model with Generator_unet256 and Discriminator PatchGaN train_SPSCDvsALSHD_random_Gunet_256_DPatchGAN: nohup $(PYTHON_INTERPRETER) ../train.py --dataroot ../datasets/SPSCDvsALSHD_random --name SPSCDvsALSHD_random_Gunet_256_DPatchGAN --model cycle_gan --gpu_ids 2 --netG unet_256 --gan_mode vanilla --pool_size 50 --batch_size 1 --checkpoints_dir ../checkpoints --display_id -1 --preprocess scale_width_and_crop --load_size 1920 --crop_size 512 --save_epoch_freq 20> ./checkpoints/SPSCDvsALSHD_random_Gunet_256_DPatchGAN/SPSCDvsALSHD_random_Gunet_256_DPatchGAN.log 2>&1 &

And I test with: ## Testinng Model with Generator_resnet9B and Discriminator PatchGaN test_SPSCDvsALSHD_random_Gunet_256_DPatchGAN: $(PYTHON_INTERPRETER) ../test.py --dataroot ../datasets/SPSCDvsALSHD_random/testB --name SPSCDvsALSHD_random_Gunet_256_DPatchGAN --model test --no_dropout --checkpoints_dir ../checkpoints --preprocess none --load_size 1920 --gpu_ids 3

I got the following error. Sorry I'm new to this area and I could not figure out what kind parameters I missed for testing, could you please let me know?

Traceback (most recent call last): File "../test.py", line 52, in model.setup(opt) # regular setup: load and print networks; create schedulers File "/ediss_data/ediss6/ali/pytorch-CycleGAN-and-pix2pix/models/base_model.py", line 88, in setup self.load_networks(load_suffix) File "/ediss_data/ediss6/ali/pytorch-CycleGAN-and-pix2pix/models/base_model.py", line 198, in load_networks self.patch_instance_norm_state_dict(state_dict, net, key.split('.')) File "/ediss_data/ediss6/ali/pytorch-CycleGAN-and-pix2pix/models/base_model.py", line 174, in patch_instance_norm_state_dict self.patch_instance_norm_state_dict(state_dict, getattr(module, key), keys, i + 1) File "/ediss_data/ediss6/ali/pytorch-CycleGAN-and-pix2pix/models/base_model.py", line 174, in patch_instance_norm_state_dict self.patch_instance_norm_state_dict(state_dict, getattr(module, key), keys, i + 1) File "/ediss_data/ediss6/ali/miniconda3/envs/pytorch-CycleGAN-and-pix2pix/lib/python3.8/site-packages/torch/nn/modules/module.py", line 947, in getattr__ raise AttributeError("'{}' object has no attribute '{}'".format( AttributeError: 'Sequential' object has no attribute 'model' make: *** [Makefile:63: test_SPSCDvsALSHD_random_Gunet_256_DPatchGAN] Error 1