2018年4月25号,PyTorch 官方发布 0.4.0 版本,该版本的 PyTorch 有多项重大更新,其中最重要的改进是官方支持 Windows (详细改动见Pytorch官方GitHub):
#使用conda安装,不支持python2.7,cudanone就是CPU版本的
'conda,cuda8,python3.5': conda install pytorch -c pytorch
'conda,cuda9.0,python3.5': conda install pytorch cuda90 -c pytorch
'conda,cuda9.1,python3.5': conda install pytorch cuda91
'conda,cudanone,python3.5': conda install pytorch-cpu -c pytorch
'conda,cuda8,python3.6': conda install pytorch -c pytorch
'conda,cuda9.0,python3.6': conda install pytorch cuda90 -c pytorch
'conda,cuda9.1,python3.6': conda install pytorch cuda91 -c pytorch
'conda,cudanone,python3.6': conda install pytorch-cpu -c pytorch
#使用pip安装,不支持python2.7,cudanone就是CPU版本的
'pip,cudanone,python3.5': pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.0-cp35-cp35m-win_amd64.whl
'pip,cuda8,python3.5': pip3 install http://download.pytorch.org/whl/cu80/torch-0.4.0-cp35-cp35m-win_amd64.whl
'pip,cuda9.0,python3.5': pip3 install http://download.pytorch.org/whl/cu90/torch-0.4.0-cp35-cp35m-win_amd64.whl
'pip,cuda9.1,python3.5': pip3 install http://download.pytorch.org/whl/cu91/torch-0.4.0-cp35-cp35m-win_amd64.whl
'pip,cudanone,python3.6': pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.0-cp36-cp36m-win_amd64.whl
'pip,cuda8,python3.6': pip3 install http://download.pytorch.org/whl/cu80/torch-0.4.0-cp36-cp36m-win_amd64.whl
'pip,cuda9.0,python3.6': pip3 install http://download.pytorch.org/whl/cu90/torch-0.4.0-cp36-cp36m-win_amd64.whl
'pip,cuda9.1,python3.6': pip3 install http://download.pytorch.org/whl/cu91/torch-0.4.0-cp36-cp36m-win_amd64.whl
#源码编译
需要安装VS2017,我电脑没有,所以略过。
pip install http://download.pytorch.org/whl/cu80/torch-0.4.0-cp36-cp36m-win_amd64.whl
pip install http://download.pytorch.org/whl/cpu/torch-0.4.0-cp36-cp36m-win_amd64.whl
pip install torchvision-0.2.1-py2.py3-none-any.whl
>>>import torch
>>>torch.__version__
>>>torch.cuda.is_available()
#import torch时出现以下错误:
from torch._C import *
ImportError: DLL load failed: The specified module could not be found.
#解决方案:缺少了必要的一些动态链接库,或者没英伟达显卡而误装了GPU版本的
在cmd中输入:conda install -c peterjc123 vc vs2017_runtime
#使用pytorch时出现的多进程错误,如下描述:
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom
in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.
#解决方案如下:
import torch
def main()
for i, data in enumerate(dataloader):
# do something here
if __name__ == '__main__':
main()