PyTorch 安装

PyTorch 安装相当简便。先去官网上配置环境,生成安装命令,然后执行即可。

1. 去官网配置环境,生成安装命令

打开官网网址,配置环境,生成安装命令,如下图所示:

图

2. 执行安装命令

执行安装命令:

Kevin@QIKEGU C:\Users\Kevin
> pip3 install torch==1.2.0+cpu torchvision==0.4.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
Looking in links: https://download.pytorch.org/whl/torch_stable.html
Collecting torch==1.2.0+cpu
  Downloading https://download.pytorch.org/whl/cpu/torch-1.2.0%2Bcpu-cp37-cp37m-win_amd64.whl (89.4MB)
     |████████████████████████████████| 89.4MB 16kB/s
Collecting torchvision==0.4.0+cpu
  Downloading https://download.pytorch.org/whl/cpu/torchvision-0.4.0%2Bcpu-cp37-cp37m-win_amd64.whl (684kB)
     |████████████████████████████████| 686kB 13kB/s
Requirement already satisfied: numpy in d:\program files\python\lib\site-packages (from torch==1.2.0+cpu) (1.16.4)
Requirement already satisfied: six in c:\users\kevin\appdata\roaming\python\python37\site-packages (from torchvision==0.4.0+cpu) (1.12.0)
Collecting pillow>=4.1.1 (from torchvision==0.4.0+cpu)
  Using cached https://files.pythonhosted.org/packages/ae/96/6f83deebfcd20a5d4ad35e4e989814a16559d8715741457e670aae1a5a09/Pillow-6.1.0-cp37-cp37m-win_amd64.whl
Installing collected packages: torch, pillow, torchvision
Successfully installed pillow-6.1.0 torch-1.2.0+cpu torchvision-0.4.0+cpu

3. 验证安装

进入Python:

> python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

执行如下语句:

from __future__ import print_function
import torch
x = torch.rand(5, 3)
print(x)

如果安装正确,将输出以下内容:

tensor([[0.0799, 0.8004, 0.3068],
        [0.9890, 0.6794, 0.4926],
        [0.2001, 0.2437, 0.3993],
        [0.9377, 0.5443, 0.6676],
        [0.7629, 0.2589, 0.6175]])


浙ICP备17015664号联系我们网站地图  
@2019 qikegu.com 版权所有,禁止转载