pix2pix测试报错

错误信息如下:

Traceback (most recent call last):
  File "/workspace/imageregistration/test.py", line 113, in
    model.setup(opt)               # regular setup: load and print networks; create schedulers(调整学习率)
  File "/workspace/imageregistration/models/base_model.py", line 88, in setup
    self.load_networks(load_suffix)
  File "/workspace/imageregistration/models/base_model.py", line 210, in load_networks
    self.__patch_instance_norm_state_dict(state_dict, net, key.split('.'))
  File "/workspace/imageregistration/models/base_model.py", line 187, in __patch_instance_norm_state_dict
    self.__patch_instance_norm_state_dict(state_dict, getattr(module, key), keys, i + 1)
  File "/workspace/imageregistration/models/base_model.py", line 187, in __patch_instance_norm_state_dict
    self.__patch_instance_norm_state_dict(state_dict, getattr(module, key), keys, i + 1)
  File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 535, in __getattr__
    type(self).__name__, name))
AttributeError: 'Sequential' object has no attribute 'model'

解决方案:https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix/blob/master/docs/qa.md#runtimeerror-errors-in-loading-state_dict-812-671461-296

If you get the above errors when loading the generator during test time, you probably have used different network configurations for training and test. There are a few things to check: (1) the network architecture --netG: you will get an error if you use --netG unet256 during training, and use --netG resnet_6blocks during test. Make sure that the flag is the same. (2) the normalization parameters --norm: we use different default --norm parameters for --model cycle_gan, --model pix2pix, and --model test. They might be different from the one you used in your training time. Make sure that you add the --norm flag in your test code. (3) If you use dropout during training time, make sure that you use the same Dropout setting in your test. Check the flag --no_dropout.

Note that we use different default generators, normalization, and dropout options for different models. The model file can overwrite the default arguments and add new arguments. For example, this line adds and changes default arguments for pix2pix. For CycleGAN, the default is --netG resnet_9blocks --no_dropout --norm instance --dataset_mode unaligned. For pix2pix, the default is --netG unet_256 --norm batch --dataset_mode aligned. For model testing with single direction (--model test), the default is --netG resnet_9blocks --norm instance --dataset_mode single. To make sure that your training and test follow the same setting, you are encouraged to plicitly specify the --netG, --norm, --dataset_mode, and --no_dropout (or not) in your script.

你可能感兴趣的:(神经网络,机器学习,pytorch)