Table of Contents [Disable]
Pytorch を Windows10 にインストールした
Pytorch とは、Facebook が開発した Python 用の機械学習ライブラリ。
Pytorch を pip でインストールしたので、その手順を公開する。
インストール前の確認
動作環境
Pytorch をインストールする環境は以下のとおり。
- Windows 10 home 1909
- Python 3.7.7
- Pycharm 2020.1.4 (Community Edition)
Pytorch のサイトにアクセス
https://pytorch.org/ にアクセスし、インストールオプションを選択する。
インストールオプションの選択
インストールオプションを選択すると項目が赤色になる。
今回選択したのは以下のとおり。
- PyTorch Build : Stable (1.5.1)
安定版を選択した。 - Your OS : Windows
- Package : pip
pip でインストールするため。 - CUDA : None
CUDA を使用していないため。
インストール
Run this Command: の右側にあるコマンドをコピーし、Pycharm の Terminal に貼り付けて実行。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(venv) C:\Development\Python\Project001>pip install torch==1.5.1+cpu torchvision==0.6.1+cpu -f https://download.pytorch.org/whl/torch_stable.html | |
Looking in links: https://download.pytorch.org/whl/torch_stable.html | |
Collecting torch==1.5.1+cpu | |
Downloading https://download.pytorch.org/whl/cpu/torch-1.5.1%2Bcpu-cp37-cp37m-win_amd64.whl (109.2 MB) | |
|████████████████████████████████| 109.2 MB 55 kB/s | |
Collecting torchvision==0.6.1+cpu | |
Downloading https://download.pytorch.org/whl/cpu/torchvision-0.6.1%2Bcpu-cp37-cp37m-win_amd64.whl (456 kB) | |
|████████████████████████████████| 456 kB 6.8 MB/s | |
Requirement already satisfied: future in c:\development\python\project001\venv\lib\site-packages (from torch==1.5.1+cpu) (0.18.2) | |
Requirement already satisfied: numpy in c:\development\python\project001\venv\lib\site-packages (from torch==1.5.1+cpu) (1.18.4) | |
Requirement already satisfied: pillow>=4.1.1 in c:\development\python\project001\venv\lib\site-packages (from torchvision==0.6.1+cpu) (7.1.2) | |
Installing collected packages: torch, torchvision | |
Attempting uninstall: torch | |
Found existing installation: torch 1.0.0 | |
Uninstalling torch-1.0.0: | |
Successfully uninstalled torch-1.0.0 | |
Attempting uninstall: torchvision | |
Found existing installation: torchvision 0.6.1 | |
Uninstalling torchvision-0.6.1: | |
Successfully uninstalled torchvision-0.6.1 | |
Successfully installed torch-1.5.1+cpu torchvision-0.6.1+cpu |
動作確認
PyTorch のバージョンをチェックし、検証用プログラムで動作確認を行う。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Terminal で PyTorch のバージョンをチェック | |
(venv) C:\Development\Python\Project001>py -c "import torch; print( torch.__version__ )" | |
1.5.1+cpu | |
Python Console で検証用プログラムを実行して動作確認 | |
from __future__ import print_function | |
import torch | |
x = torch.rand(5, 3) | |
print(x) | |
tensor([[0.2918, 0.1548, 0.4478], | |
[0.5609, 0.6826, 0.4353], | |
[0.4960, 0.2695, 0.6763], | |
[0.9208, 0.2819, 0.9709], | |
[0.5085, 0.6319, 0.6999]]) |
謝辞
今回の記事を書くに当たり、PyTorch のインストール(Windows 上) を参考にさせていただいた。
ありがとうございました。
Python 3 入門 + 応用 +アメリカのシリコンバレー流コードスタイルを学ぶオンライン講座
未経験からエンジニアを目指すTechAcademy Pro