概要
Mac OS X 10.14.4にPyTorchをインストールして動作確認する
環境
- Mac OS X 10.14.4 Mojave
- oh-my-zsh使用
- Homebrew 2.1.6 (git revision 0d363)
- Python 3.7.2
- anaconda3-5.3.1
- pip 19.1.1
PyTorchのインストール方法
$ pip3 install torch torchvision
Collecting torch
Downloading https://files.pythonhosted.org/packages/95/80/0851d6088bb054be3ddf47bfde1aedb4e1cbd170cf8e1c60cad321b97162/torch-1.1.0.post2-cp37-none-macosx_10_7_x86_64.whl (88.1MB)
|████████████████████████████████| 88.1MB 604kB/s
Collecting torchvision
Downloading https://files.pythonhosted.org/packages/af/7c/247d46a1f76dee688636d4d5394e440bb32c4e251ea8afe4442c91296830/torchvision-0.3.0-cp37-cp37m-macosx_10_7_x86_64.whl (231kB)
|████████████████████████████████| 235kB 894kB/s
Requirement already satisfied: numpy in /Users/hoge/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages (from torch) (1.15.1)
Requirement already satisfied: pillow>=4.1.1 in /Users/hoge/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages (from torchvision) (5.2.0)
Requirement already satisfied: six in /Users/hoge/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages (from torchvision) (1.11.0)
Installing collected packages: torch, torchvision
Successfully installed torch-1.1.0.post2 torchvision-0.3.0
- PyTorch公式に沿って、以下のpythonコードを作成してpytorchの動作確認
from __future__ import print_function
import torch
x = torch.rand(5, 3)
print(x)
- 実行結果
tensor([[0.7747, 0.9627, 0.1806],
[0.9219, 0.1319, 0.9026],
[0.6719, 0.6495, 0.5341],
[0.6629, 0.4546, 0.7309],
[0.3577, 0.8918, 0.8544]])
- GPUが使えるか確認
import torch
print(torch.cuda.is_available())
- GPUが使えない場合
False