报错:AssertionError: Torch not compiled with CUDA enabled

环境:win0+torch(cpu)
详细报错信息
报错:AssertionError: Torch not compiled with CUDA enabled_第1张图片
解决
查阅资料发现此错误是由于下载的torch没有cuda,所以在运行时会报错,在程序最开始的地方加上:
device = torch.device(“cuda” if torch.cuda.is_available() else “cpu”)
代码其余地方出现.cuda()的地方改成.to(device)就可以在无gpu的环境中运行了。
在这里插入图片描述
参考博客:https://blog.csdn.net/m0_37690102/article/details/108364458

你可能感兴趣的:(报错:AssertionError: Torch not compiled with CUDA enabled)