AttnGAN icon indicating copy to clipboard operation
AttnGAN copied to clipboard

Transition from Python 2.7 to 3.0+

Open rchavezj opened this issue 6 years ago • 4 comments

After invoking "python main.py --cfg cfg/bird_attn2.yml --gpu 2" for bird dataset, I get the following error:

Total filenames: 11788 001.Black_footed_Albatross/Black_Footed_Albatross_0046_18.jpg Load filenames from: ../data/birds/train/filenames.pickle (8855) Load filenames from: ../data/birds/test/filenames.pickle (2933) Load from: ../data/birds/captions.pickle Traceback (most recent call last): File "main.py", line 129, in transform=image_transform) File "/Users/user/Desktop/AttnGAN-master/code/datasets.py", line 118, in init self.class_id = self.load_class_id(split_dir, len(self.filenames)) File "/Users/user/Desktop/AttnGAN-master/code/datasets.py", line 254, in load_class_id class_id = pickle.load(f) UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 0: ordinal not in range(128)

I couldn't find an answer through Google so I posted back to the community.

rchavezj avatar May 30 '18 21:05 rchavezj

I meet the same problem. Have you solved it?

Sadden avatar Oct 17 '18 01:10 Sadden

I have successfully solved,You should modify (AttnGAN-master/code/datasets.py", line 254, in load_class_id)“class_id = pickle.load(f)” to “class_id = pickle.load(f,encoding="bytes")”.I hope that you can successful.

HaijunMa avatar Nov 16 '18 08:11 HaijunMa

For a python 3.6 and pytorch 1.0 version, see my Pull request.

davidstap avatar Mar 07 '19 16:03 davidstap

@davidstap ### when i run yours python3.6 in colab, the follow error appear

""" /content/drive/My Drive/AttnGAN/code Using config: {'B_VALIDATION': False, 'CONFIG_NAME': 'attn2', 'CUDA': True, 'DATASET_NAME': 'birds', 'DATA_DIR': '../data/birds', 'GAN': {'B_ATTENTION': True, 'B_DCGAN': False, 'CONDITION_DIM': 100, 'DF_DIM': 64, 'GF_DIM': 32, 'R_NUM': 2, 'Z_DIM': 100}, 'GPU_ID': 0, 'RNN_TYPE': 'LSTM', 'TEXT': {'CAPTIONS_PER_IMAGE': 10, 'EMBEDDING_DIM': 256, 'WORDS_NUM': 25}, 'TRAIN': {'BATCH_SIZE': 100, 'B_NET_D': False, 'DISCRIMINATOR_LR': 0.0002, 'ENCODER_LR': 0.0002, 'FLAG': False, 'GENERATOR_LR': 0.0002, 'MAX_EPOCH': 600, 'NET_E': '../DAMSMencoders/bird/text_encoder200.pth', 'NET_G': '../models/bird_AttnGAN2.pth', 'RNN_GRAD_CLIP': 0.25, 'SMOOTH': {'GAMMA1': 5.0, 'GAMMA2': 5.0, 'GAMMA3': 10.0, 'LAMBDA': 1.0}, 'SNAPSHOT_INTERVAL': 2000}, 'TREE': {'BASE_SIZE': 64, 'BRANCH_NUM': 3}, 'WORKERS': 1} Total filenames: 11788 001.Black_footed_Albatross/Black_Footed_Albatross_0046_18.jpg Load filenames from: ../data/birds/train/filenames.pickle (8855) Load filenames from: ../data/birds/test/filenames.pickle (2933) Load from: ../data/birds/captions.pickle THCudaCheck FAIL file=/pytorch/aten/src/THC/THCGeneral.cpp line=47 error=100 : no CUDA-capable device is detected Traceback (most recent call last): File "main.py", line 136, in algo = trainer(output_dir, dataloader, dataset.n_words, dataset.ixtoword) File "/content/drive/My Drive/AttnGAN/code/trainer.py", line 36, in init torch.cuda.set_device(cfg.GPU_ID) File "/usr/local/lib/python3.6/dist-packages/torch/cuda/init.py", line 281, in set_device torch._C._cuda_setDevice(device) File "/usr/local/lib/python3.6/dist-packages/torch/cuda/init.py", line 190, in _lazy_init torch._C._cuda_init() RuntimeError: cuda runtime error (100) : no CUDA-capable device is detected at /pytorch/aten/src/THC/THCGeneral.cpp:47 """

then i change the vision to torch==1.2.0; torchvision==0.4.0; it will appear the follow error

""" /content/drive/My Drive/AttnGAN/code Traceback (most recent call last): File "main.py", line 4, in from datasets import TextDataset File "/content/drive/My Drive/AttnGAN/code/datasets.py", line 14, in import torchvision.transforms as transforms File "/usr/local/lib/python3.6/dist-packages/torchvision/init.py", line 2, in from torchvision import datasets File "/usr/local/lib/python3.6/dist-packages/torchvision/datasets/init.py", line 9, in from .fakedata import FakeData File "/usr/local/lib/python3.6/dist-packages/torchvision/datasets/fakedata.py", line 3, in from .. import transforms File "/usr/local/lib/python3.6/dist-packages/torchvision/transforms/init.py", line 1, in from .transforms import * File "/usr/local/lib/python3.6/dist-packages/torchvision/transforms/transforms.py", line 17, in from . import functional as F File "/usr/local/lib/python3.6/dist-packages/torchvision/transforms/functional.py", line 5, in from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION ImportError: cannot import name 'PILLOW_VERSION' """

can you tell me what should i do .

cainiaoshiwo avatar Aug 18 '20 08:08 cainiaoshiwo