What is PyTorch?
It’s a Python based scientific computing package targeted at two sets of audiences:
- A replacement for NumPy to use the power of GPUs
- a deep learning research platform that provides maximum flexibility and speed
- GPU들의 계산을 사용하기 위해서 NumPy 교체 합니다.
- 최대 유연성과 속도를 제공하는 Deep Learning 연구 플랫폼입니다.
0. 설치 환경
Windows 10CUDA 지원 안함
1. 아나콘다 설치
요즘 아나콘다가 대세네요https://www.anaconda.com/download/
3.6 버전 설치
64bit 용 설치 바랍니다. PyTorch용이 64bit만 존재합니다.(2019.1.13일 기준)
2. PyTorch 설치
https://pytorch.org/ 접속운영체제와 python 버전 선택
anaconda shell에서 실행
conda install pytorch-cpu -c pytorch
pip3 install torchvision
=> pip3는 동작안합니다.
pip install torchvision 을 실행하도록 합니다.
(base) E:\>pip install torchvision
Collecting torchvision
Using cached https://files.pythonhosted.org/packages/ca/0d/f00b2885711e08bd71242ebe7b96561e6f6d01fdb4b9dcf4d37e2e13c5e1/torchvision-0.2.1-py2.py3-none-any.whl
Requirement already satisfied: pillow>=4.1.1 in e:\programdata\anaconda3\lib\site-packages (from torchvision) (5.1.0)
Requirement already satisfied: numpy in e:\programdata\anaconda3\lib\site-packages (from torchvision) (1.14.3)
Requirement already satisfied: torch in e:\programdata\anaconda3\lib\site-packages (from torchvision) (0.4.0)
Requirement already satisfied: six in e:\programdata\anaconda3\lib\site-packages (from torchvision) (1.11.0)
distributed 1.21.8 requires msgpack, which is not installed.
Installing collected packages: torchvision
Successfully installed torchvision-0.2.1
빨간색으로 msgpack이 없다고 에러가 난다면 아래와 같이 msgpack를 설치해줍니다.
(base) E:\>pip install msgpack
Collecting msgpack
Downloading https://files.pythonhosted.org/packages/04/81/c6363198f24ec1c56e5c48ce685cb532e175125adade0cdb181c8c5fea6e/msgpack-0.5.6-cp36-cp36m-win_amd64.whl (85kB)
100% |████████████████████████████████| 92kB 303kB/s
Installing collected packages: msgpack
Successfully installed msgpack-0.5.6
다시 설치해보면 에러 문구는 나타나지 않습니다.
(base) E:\>pip install torchvision
Requirement already satisfied: torchvision in e:\programdata\anaconda3\lib\site-packages (0.2.1)
Requirement already satisfied: pillow>=4.1.1 in e:\programdata\anaconda3\lib\site-packages (from torchvision) (5.1.0)
Requirement already satisfied: numpy in e:\programdata\anaconda3\lib\site-packages (from torchvision) (1.14.3)
Requirement already satisfied: torch in e:\programdata\anaconda3\lib\site-packages (from torchvision) (0.4.0)
Requirement already satisfied: six in e:\programdata\anaconda3\lib\site-packages (from torchvision) (1.11.0)
3. 예제 실행해보기
아직 뭐가 뭔지는 모르겠지만 제대로 설치되었는지 샘플을 실행해보면 됩니다.
아래에서 제일아래 tensor_tutorial.py 예제를 다운로드 받을 수 있습니다.
https://pytorch.org/tutorials/beginner/blitz/tensor_tutorial.html#getting-started
실행은 아래와 같이 합니다.
(base) E:\pytorch>python tensor_tutorial.py
결과
tensor(1.00000e-43 * [[ 0.0000, 0.0000, 0.0000], [ 0.0000, 0.0000, 0.0000], [ 0.0000, 0.0000, 0.0000], [ 0.0000, 1.6816, 0.0000], [ 0.0000, 0.0000, 0.0000]]) tensor([[ 0.9836, 0.3660, 0.1008], [ 0.9361, 0.0545, 0.4045], [ 0.7703, 0.6550, 0.0720], [ 0.5599, 0.6790, 0.6733], [ 0.8420, 0.5594, 0.4168]]) tensor([[ 0, 0, 0], [ 0, 0, 0], [ 0, 0, 0], [ 0, 0, 0], [ 0, 0, 0]]) tensor([ 5.5000, 3.0000]) tensor([[ 1., 1., 1.], [ 1., 1., 1.], [ 1., 1., 1.], [ 1., 1., 1.], [ 1., 1., 1.]], dtype=torch.float64) tensor([[ 0.1702, -0.5912, 0.8690], [-0.0291, 0.5152, 1.1440], [-0.2709, -0.3549, 0.0495], [ 1.6595, 0.5233, -0.2273], [ 0.9720, 0.5231, 0.8539]]) torch.Size([5, 3]) tensor([[ 1.0499, 0.2793, 1.6822], [ 0.4391, 0.9968, 1.4158], [ 0.4017, 0.1225, 0.2590], [ 2.1562, 1.3099, -0.0821], [ 1.7752, 1.0990, 0.9617]]) tensor([[ 1.0499, 0.2793, 1.6822], [ 0.4391, 0.9968, 1.4158], [ 0.4017, 0.1225, 0.2590], [ 2.1562, 1.3099, -0.0821], [ 1.7752, 1.0990, 0.9617]]) tensor([[ 1.0499, 0.2793, 1.6822], [ 0.4391, 0.9968, 1.4158], [ 0.4017, 0.1225, 0.2590], [ 2.1562, 1.3099, -0.0821], [ 1.7752, 1.0990, 0.9617]]) tensor([[ 1.0499, 0.2793, 1.6822], [ 0.4391, 0.9968, 1.4158], [ 0.4017, 0.1225, 0.2590], [ 2.1562, 1.3099, -0.0821], [ 1.7752, 1.0990, 0.9617]]) tensor([-0.5912, 0.5152, -0.3549, 0.5233, 0.5231]) torch.Size([4, 4]) torch.Size([16]) torch.Size([2, 8]) tensor([ 0.3910]) 0.39095234870910645
결과가 뭘 뜻하는지는 getting-started 페이지를 천천히 읽어봐야 할것 같습니다만, 에러가 없다는것에 만족하며 여기에서 끝내야 할 것 같습니다.
댓글 없음:
댓글 쓰기