junyanz / pytorch-CycleGAN-and-pix2pix

Image-to-Image Translation in PyTorch
Other
23.17k stars 6.33k forks source link

loading model error -- AttributeError: 'UnetSkipConnectionBlock' #687

Closed leemengwei closed 5 years ago

leemengwei commented 5 years ago

Great work。 command python test.py --dataroot ./datasets/MYsummer2winter/ --direction BtoA --model pix2pix --name summer2winter_yosemite_pretrained gives loading the model from ./checkpoints/summer2winter_yosemite_pretrained/latest_net_G.pth Traceback (most recent call last): File "test.py", line 47, in <module> model.setup(opt) # regular setup: load and print networks; create schedulers File "/mfs/home/limengwei/pytorch-CycleGAN-and-pix2pix/models/base_model.py", line 88, in setup self.load_networks(load_suffix) File "/mfs/home/limengwei/pytorch-CycleGAN-and-pix2pix/models/base_model.py", line 197, in load_networks self.__patch_instance_norm_state_dict(state_dict, net, key.split('.')) File "/mfs/home/limengwei/pytorch-CycleGAN-and-pix2pix/models/base_model.py", line 173, in __patch_instance_norm_state_dict self.__patch_instance_norm_state_dict(state_dict, getattr(module, key), keys, i + 1) File "/mfs/home/limengwei/pytorch-CycleGAN-and-pix2pix/models/base_model.py", line 173, in __patch_instance_norm_state_dict self.__patch_instance_norm_state_dict(state_dict, getattr(module, key), keys, i + 1) File "/home/user/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 518, in __getattr__ type(self).__name__, name)) AttributeError: 'UnetSkipConnectionBlock' object has no attribute '1'

YvonneTsang16 commented 5 years ago

Hey there, I have come across the same question when rendering a single picture. I wonder whether you have solved it since the issue is closed, and it would be great help to me if you want to share the solution

leemengwei commented 5 years ago

nop @YvonneTsang16 I think not

DanielXu123 commented 2 years ago

Hey, @leemengwei . I met the same question. May I ask did you also occur this error when using resnet9blks as the generator network. I can successfully run the test.py when using unet_256 as the generator .

@junyanz Will this related to the version of Pytorch or torchvision version, I found that it can be trained when setting the generator network as resnet9blks but can't be tested for all different tasks.

I'm using Pytorch '1.5.0' and torchvision '0.6.0 a0+82fd1c8'

junyanz commented 2 years ago

The default pix2pix network is U-Net. To test pix2pix model with resnet9blks, you need to explicitly set the flag --netG resnet_9blocks during test time.

lprintf commented 2 years ago

This may be due to incomplete model parameters.

I trained several models with pix2pix unet 256 and note that those generators can't be loaded which file size is little then 208M.

lprintf commented 2 years ago

OOOOh! I note that I used resne_9blocks as backbone in some training and got some parameter files with the size of 44M.

lprintf commented 2 years ago

OOOOh! I note that I used resne_9blocks as backbone in some training and got some parameter files with the size of 44M.

Maybe...OK...It is also not the parameter file of resnet_9blocks or unet_128 or resnet_6block.

It is the mater about gan_mode='lsgan'.

RohitDhankar commented 1 year ago

The default pix2pix network is U-Net. To test pix2pix model with resnet9blks, you need to explicitly set the flag --netG resnet_9blocks during test time.

@junyanz -- thanks for the excellent code and documentation , am facing the same issue with the default params .

 netD: basic                         
netG: unet_256

Kindly refer here for detailed stackt-race -- thanks https://github.com/RohitDhankar/Machine-Learning-with-Python_ML_Py/issues/112

lengqianqi commented 6 months ago

I solute this problem. See what netG and norm you use when training. Use the same when testing. Note that pix2pix will automatically change the generator to unet256, so set netG to unet256 and norm to batch when testing pix2pix