pytorch-CycleGAN-and-pix2pix icon indicating copy to clipboard operation
pytorch-CycleGAN-and-pix2pix copied to clipboard

Unet generator for large images

Open myfrannie opened this issue 4 years ago • 6 comments

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?

myfrannie avatar Apr 03 '20 06:04 myfrannie

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.

junyanz avatar Apr 03 '20 18:04 junyanz

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

zhangdan8962 avatar Apr 16 '20 19:04 zhangdan8962

Sure. It might be worth trying.

junyanz avatar Apr 16 '20 19:04 junyanz

@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.

Mayurji avatar Sep 04 '20 08:09 Mayurji

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.

junyanz avatar Sep 06 '20 20:09 junyanz

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

atFinland2023 avatar Dec 04 '23 12:12 atFinland2023