코딩하는 애옹😸

[PyTorch] Basics 본문

부스트캠프 AI Tech 3기/Study

[PyTorch] Basics

DevYe 2022. 1. 25. 00:08
728x90
반응형

PyTorch

  • 딥러닝 프레임워크
  • Numpy 구조를 가지는 Tensor 객체로 array 표현
  • 자동 미분(AutoGrad) 지원 $\rightarrow$ DL 연산 지원

장점

  • Define by Run : 즉시 확인 가능 $\rightarrow$ pythonic code
  • GPU 지원, Good API and community

Basics

  • numpy의 ndarray와 pytorch의 tensor가 유사
## numpy
import numpy as np
n_array = np.arange(10).reshape(2, 5)
print(n_array)
print("ndim: ", n_array.ndim, "shape: ", n_array.shape)
​
## pytorch
import torch
t_array = torch.FloatTensor(n_array)
print(t_array)
print("ndim: ", t_array.ndim, "shape: ", t_array.shape)

기본적으로 numpy의 대부분의 사용법이 그대로 적용

  • Slicing, flatten, ones_like, shape, dtype 등

device : GPU에 올릴 것이냐, CPU에 올릴 것이냐를 확인

view : reshape과 동일하게 tensor의 shape 변환, copy할 때 메모리 주소 그대로 copy

mm : 행렬곱셈 연산(내적)

matmul : broadcasting 지원

반응형

'부스트캠프 AI Tech 3기 > Study' 카테고리의 다른 글

[PyTorch] 모델 불러오기  (0) 2022.01.26
[PyTorch] AutoGrad  (0) 2022.01.25
[예제] BackPropagation  (0) 2022.01.23
(AI Math 10강) RNN  (0) 2022.01.21
(AI Math 9강) CNN  (0) 2022.01.21
Comments