mingyuliutw / UNIT

Unsupervised Image-to-Image Translation
Other
1.98k stars 360 forks source link

NameError: name 'trainer' is not defined #69

Closed ConnectionistSystems closed 6 years ago

ConnectionistSystems commented 6 years ago

Traceback (most recent call last): File "cocogan_translate_one_image.py", line 81, in main(sys.argv) File "cocogan_translate_one_image.py", line 44, in main trainer.gen.load_state_dict(torch.load(opts.weights)) NameError: name 'trainer' is not defined

I get this error when I run

python cocogan_translate_one_image.py --config ../exps/unit/cat2tiger.yaml --a2b 1 --weights ../outputs/unit/cat2tiger/cat2tiger_gen_00500000.pkl --image_name ../images/cat001.jpg --output_image_name ../results/cat2tiger_cat001.jpg self.snapshot_save_iterations=5000 self.image_save_iterations=2500 self.image_display_iterations=100 self.display=1 self.snapshot_prefix='../outputs/unit/cat2tiger/cat2tiger' self.hyperparameters={'trainer': 'COCOGANTrainer', 'lr': 0.0001, 'll_direct_link_w': 100, 'kl_direct_link_w': 0.1, 'll_cycle_link_w': 100, 'kl_cycle_link_w': 0.1, 'gan_w': 10, 'batch_size': 1, 'max_iterations': 500000, 'gen': {'name': 'COCOResGen', 'ch': 64, 'input_dim_a': 3, 'input_dim_b': 3, 'n_enc_front_blk': 3, 'n_enc_res_blk': 3, 'n_enc_shared_blk': 1, 'n_gen_shared_blk': 1, 'n_gen_res_blk': 3, 'n_gen_front_blk': 3}, 'dis': {'name': 'COCODis', 'ch': 64, 'input_dim_a': 3, 'input_dim_b': 3, 'n_layer': 6}} self.datasets={'train_a': {'channels': 3, 'scale': 1.2, 'crop_image_height': 216, 'crop_image_width': 216, 'class_name': 'dataset_imagenet_image', 'root': '../images', 'folder': './', 'list_name': 'image_list.txt'}, 'train_b': {'channels': 3, 'scale': 1.2, 'crop_image_height': 216, 'crop_image_width': 216, 'class_name': 'dataset_imagenet_image', 'root': '../images', 'folder': './', 'list_name': 'image_list.txt'}} Traceback (most recent call last): File "cocogan_translate_one_image.py", line 81, in main(sys.argv) File "cocogan_translate_one_image.py", line 44, in main trainer.gen.load_state_dict(torch.load(opts.weights)) NameError: name 'trainer' is not defined

Any ideas? I'm using python 3.6

Thanks!

klnt19 commented 6 years ago

Hello,

I also had the same problem. Surely not the greatest approach but I managed to run "cocogan_translate_one_image.py" with no errors by downgrading PyTorch to 0.1.12. Since I use PyTorch on cpu the command was:

conda install -c jjh_pytorch pytorch-cpu torchvision-cpu

The link I followed is https://anaconda.org/jjh_pytorch/pytorch-cpu.

Hope that helps!

mingyuliutw commented 6 years ago

Sorry for the inconvenience. Have been working on combining all of my image-to-image translation works into a single interface and reduce the library dependency. The new version is now committed.