Pytorch-cyclegan-and-pix2pix: AttributeError: 'Sequential' object has no attribute 'model'

Created on 29 Aug 2018  Â·  15Comments  Â·  Source: junyanz/pytorch-CycleGAN-and-pix2pix

I have some satellite(aerial) images, all are 256x256, and I put them in * ~/temp/*, I want to translate them into map, so I downloaded the pretrained model and use the following command to test:

CUDA_VISIBLE_DEVICES=1 python test.py --dataroot ~/temp/ --dataset_mode single --resize_or_crop none --which_direction AtoB --model test --name sat2map_pretrained

But I have got an AttributeError from python , here is the output:

----------------- Options ---------------
aspect_ratio: 1.0
batchSize: 1
checkpoints_dir: ./checkpoints
dataroot: /home/niu/temp/ [default: None]
dataset_mode: single
display_env: main
display_id: 1
display_port: 8097
display_server: http://localhost
display_winsize: 256
fineSize: 256
gpu_ids: 0
how_many: 50
init_gain: 0.02
init_type: normal
input_nc: 3
isTrain: False [default: None]
loadSize: 256
max_dataset_size: inf
model: test

â–½
model_suffix:
nThreads: 4
n_layers_D: 3
name: sat2map_pretrained [default: experiment_name]
ndf: 64
ngf: 64
no_dropout: True
no_flip: False
norm: instance
ntest: inf
output_nc: 3
phase: test
resize_or_crop: none [default: resize_and_crop]
results_dir: ./results/
serial_batches: False
suffix:
verbose: False
which_direction: AtoB
which_epoch: latest
which_model_netD: basic
which_model_netG: resnet_9blocks
----------------- End -------------------
dataset [SingleImageDataset] was created
initialize network with normal
model [TestModel] was created
loading the model from ./checkpoints/sat2map_pretrained/latest_net_G.pth
Traceback (most recent call last):
File "test.py", line 19, in
model.setup(opt)
File "/home/niu/src/github/pytorch-CycleGAN-and-pix2pix/models/base_model.py", line 43, in setup
self.load_networks(opt.which_epoch)
File "/home/niu/src/github/pytorch-CycleGAN-and-pix2pix/models/base_model.py", line 135, in load_networks
self.__patch_instance_norm_state_dict(state_dict, net, key.split('.'))
File "/home/niu/src/github/pytorch-CycleGAN-and-pix2pix/models/base_model.py", line 115, in __patch_instance_norm_state_dict
self.__patch_instance_norm_state_dict(state_dict, getattr(module, key), keys, i + 1)
File "/home/niu/src/github/pytorch-CycleGAN-and-pix2pix/models/base_model.py", line 115, in __patch_instance_norm_state_dict
self.__patch_instance_norm_state_dict(state_dict, getattr(module, key), keys, i + 1)
File "/home/niu/anaconda3/envs/pix2pix/lib/python3.7/site-packages/torch/nn/modules/module.py", line 518, in __getattr__
type(self).__name__, name))
AttributeError: 'Sequential' object has no attribute 'model'

I have looked into similat issues and googled for an hour but got nothing.
Could someone help me with this? Thank you!

Most helpful comment

edit to
parser.set_defaults(model='pix2pix')
in
test_options.py

All 15 comments

hmmmm..... are you using the latest code and the model? Could you git pull the latest code, and also download the latest pretrained model, and try it again? I think I vaguely remember our code had this kind of bug a while ago...

I wonder if you've solved this issue.
I met the same problem when testing a cyclegan model, but it didn't happen in my test of pix2pix model before.

Are you using the latest code? Which PyTorch version are you using?

yeah. I'm using the latest code with PyTorch 0.4.0

you need to set --netG option if you are not using the default netG

i found the problem was caused by the incorrect input of --model. thank you for your reply

Hi, I have encountered the same error. I found this error occurred due to running a pix2pix model uisng --model test . I have changed line 14 in models/test_model.py from parser = CycleGANModel.modify_commandline_options(parser, is_train=False) to parser = Pix2PixModel.modify_commandline_options(parser, is_train = False) . Also I added from .pix2pix_model import Pix2PixModel at the beginning of the file. Then it runs well. Hope this helps.

For pix2pix, you just need to use --model pix2pix for testing. See the instruction. --model test is useful when you want to apply cyclegan in one direction.

Actually I want to use --dataset_mode single then it seems I must use --model test to go with it

I see. You can also specify --netG unet --norm batch for --model test.

please tell me , i am beginner,i meet same question , i just change the netG, what can i do? thank you every much.

@ taozhuang123 hi ,I got the trick, IN 'test_option.py' Line20 ,the model should set as: model='pix2pix'.....hhha~~~~

edit to
parser.set_defaults(model='pix2pix')
in
test_options.py

you need to set --netG option if you are not using the default netG

This works for me. Keep --netG the same as training

@ taozhuang123 hi ,I got the trick, IN 'test_option.py' Line20 ,the model should set as: model='pix2pix'.....hhha~~~~

you are right! thanks!

Was this page helpful?
0 / 5 - 0 ratings