方法一:

pip install --upgrade --force-reinstall http://download.pytorch.org/whl/cu80/torch-0.2.0.post3-cp27-cp27mu-manylinux1_x86_64.whl

后面这个可以自己到官网上找自己对应的python和cuda版本的安装包,官网为链接:

方法二:

conda install pytorch torchvision cuda80 -c soumith

这里可以根据自己cuda版本确定。查看cuda版本,在python命令行里面输入:

import torch
torch.version.cuda

即可。

补充:关于win10环境下在使用torch调用cuda()失败的原因

看了无数篇博客都是牛头不对马嘴,忙活了半天才搞清楚

如果大家在用torch的过程中看见这样的错误。。。。淡定,不是你的问题,也不是代码问题。。。是破win10的原因

只需要在代码前面加上

torch.cuda.current_device()
torch.cuda._initialized = true

就可以正常训练了。。。心累啊