I'm trying to run the code from this repository and I need to use Pytorch 1.4.0. I've installed the CPU only version of pytorch with pip install torch==1.4.0+cpu torchvision==0.5.0+cpu -f https://download.pytorch.org/whl/torch_stable.html.
I ran the program by doing py -m train_Kfold_CV --device 0 --fold_id 10 --np_data_dir "C:\Users\username\OneDrive\Desktop\emadeldeen\AttnSleep\prepare_datasets\edf_20_npz" but I'm getting this error:
File "C:\Users\username\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\username\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\username\OneDrive\Desktop\emadeldeen\AttnSleep\train_Kfold_CV.py", line 94, in <module>
main(config, fold_id)
File "C:\Users\username\OneDrive\Desktop\emadeldeen\AttnSleep\train_Kfold_CV.py", line 65, in main
trainer.train()
File "C:\Users\username\OneDrive\Desktop\emadeldeen\AttnSleep\base\base_trainer.py", line 66, in train
result, epoch_outs, epoch_trgs = self._train_epoch(epoch, self.epochs)
File "C:\Users\username\OneDrive\Desktop\emadeldeen\AttnSleep\trainer\trainer.py", line 49, in _train_epoch
loss = self.criterion(output, target, self.class_weights)
File "C:\Users\username\OneDrive\Desktop\emadeldeen\AttnSleep\model\loss.py", line 6, in weighted_CrossEntropyLoss
cr = nn.CrossEntropyLoss(weight=torch.tensor(classes_weights).cuda())
File "C:\Users\username\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\cuda\__init__.py", line 196, in _lazy_init
_check_driver()
File "C:\Users\username\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\cuda\__init__.py", line 94, in _check_driver
raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled
I've changed the number of GPU in the config to 0 and tried adding device = torch.device('cpu') at the begining of the program, but it's not doing anything. How can I fix this error? I'm using windows 10 with python 3.7.9 if it helps
Thanks
You are using CPU only pytorch, but your code has statement like cr = nn.CrossEntropyLoss(weight=torch.tensor(classes_weights).cuda()) which is trying to move the tensor to GPU.
To fix it,
remove all the .cuda() operations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With