hanzhanggit / StackGAN-v2

MIT License
843 stars 190 forks source link

How do I fix this?AttributeError: 'module' object has no attribute '_cuda_setDevice' #35

Open XinChengit opened 4 years ago

XinChengit commented 4 years ago

I am running this on a MacBook Pro (Retina, 13-inch, Early 2015) macOS Catalina 10.15.3 GPU Intel Iris Graphics 6100 1536 MB I am at this step in the instructions: python main.py --cfg cfg/birds_3stages.yml --gpu 0

And I get this as a result: /Users/f00l/Desktop/GitHubProject/StackGAN-v2/code/miscc/config.py:103: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details. yaml_cfg = edict(yaml.load(f)) Using config: {'CONFIG_NAME': '3stages', 'CUDA': False, 'DATASET_NAME': 'birds', 'DATA_DIR': '../data/birds', 'EMBEDDING_TYPE': 'cnn-rnn', 'GAN': {'B_CONDITION': True, 'DF_DIM': 64, 'EMBEDDING_DIM': 128, 'GF_DIM': 64, 'NETWORK_TYPE': 'default', 'R_NUM': 2, 'Z_DIM': 100}, 'GPU_ID': '0', 'TEST': {'B_EXAMPLE': True, 'SAMPLE_NUM': 30000}, 'TEXT': {'DIMENSION': 1024}, 'TRAIN': {'BATCH_SIZE': 24, 'COEFF': {'COLOR_LOSS': 0.0, 'KL': 2.0, 'UNCOND_LOSS': 1.0}, 'DISCRIMINATOR_LR': 0.0002, 'FLAG': True, 'GENERATOR_LR': 0.0002, 'MAX_EPOCH': 600, 'NET_D': '', 'NET_G': '', 'SNAPSHOT_INTERVAL': 2000, 'VIS_COUNT': 64}, 'TREE': {'BASE_SIZE': 64, 'BRANCH_NUM': 3}, 'WORKERS': 4} /Users/f00l/Desktop/GitHubProject/StackGAN-v2/venv/lib/python2.7/site-packages/torchvision/transforms/transforms.py:156: UserWarning: The use of the transforms.Scale transform is deprecated, please use transforms.Resize instead. "please use transforms.Resize instead.") Total filenames: 11788 001.Black_footed_Albatross/Black_Footed_Albatross_0046_18.jpg Load filenames from: ../data/birds/train/filenames.pickle (8855) embeddings: (8855, 10, 1024) Traceback (most recent call last): File "main.py", line 140, in algo = trainer(output_dir, dataloader, imsize) File "/Users/f00l/Desktop/GitHubProject/StackGAN-v2/code/trainer.py", line 537, in init torch.cuda.set_device(self.gpus[0]) File "/Users/f00l/Desktop/GitHubProject/StackGAN-v2/venv/lib/python2.7/site-packages/torch/cuda/init.py", line 262, in set_device torch._C._cuda_setDevice(device) AttributeError: 'module' object has no attribute '_cuda_setDevice'

How do I fix this?

mansijoshii commented 3 years ago

Before torch.cuda.setDevice in the trainer.py code, try adding an if condition. Do it only if cfg.CUDA is true.