报错的代码
File "C:\Users\****\anaconda3\envs\Pytorch\lib\site-packages\torch\cuda\__init__.py", line 47, in _check_driver
raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled
查看原错误的代码
device = torch.device("cuda" if args.gpu_no >= 0 else "cpu")
修改方法
把原代码注释掉,换为下面这个
#device = torch.device("cuda" if args.gpu_no >= 0 else "cpu")
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
分析原因
此错误是由于下载的torch没有cuda,在运行时就会出错。
代码其余地方出现.cuda()的地方改成.to(device)就可以在无gpu的环境中运行了。
https://blog.csdn.net/m0_37690102/article/details/108364458