728x90

Pytorch Code를 보다보면 다음과 같이 Variable로 Tensor를 감싸는 경우를 볼 수 있다.

 

    for input, _ in tr:
        input = Variable(input.cuda(async=True))

이는 해당 Tensor의 gradient의 변화를 추적하고 싶을 때 사용하는 것이다.

 

위와 같이 하고 'required_grad=True' 옵션을 주면  gradient 변화량을 확인할 수 있다.

 

이때 명령어를 다음과 같이 하면 된다.

 

print(input.grad)

 

그러나 현재는 모든 tensor에서 required_grad 옵션을 통해 gradient를 추적할 수 있기 때문에

따로 위와 같이 Variable로 감싸줄 필요가 없다.

(현재는 쓸 필요 없음)

 

https://aigong.tistory.com/179

 

torch.autograd.Variable 알아보기

torch.autograd.Variable 알아보기 목차 PyTorch Autograd Variable 한글 튜토리얼 9bow.github.io/PyTorch-tutorials-kr-0.3.1/beginner/blitz/autograd_tutorial.html Autograd: 자동 미분 — PyTorch Tutorial..

aigong.tistory.com

 

728x90

'Pytorch' 카테고리의 다른 글

Pytorch : Dataloader num_workers  (0) 2021.06.01
Deep learning model code basic structure  (0) 2021.04.28
THOP: PyTorch-OpCounter  (0) 2021.04.01
visualization  (0) 2020.08.05
torch.utils.data.DataLoader  (0) 2020.06.20
728x90

Pytorch data_loader에서 num_worker를 세팅하는 부분이 있다.

 

num_worker를 공식문서에서 설명하는 것은 다음과 같다.

 

num_workers (int, optional) – how many subprocesses to use for data loading. 
      0 means that the data will be loaded in the main process. (default: 0)

 

( default 값은 0 이며, 이는 main process만 사용하는 것을 의미한다. 이때, 다른 값을 입력하는 경우 sub process를 추가적으로 얼마나 사용할지를 정하는 것이다.)

 

먼저 우리가 GPU를 사용하는 이유는 딥러닝에서 많이 사용되는 행렬 연산을 병렬처리하여 빠르게 연산하기 위함이다.

그러기 위해서는 CPU에 loading되어 있는 data를 GPU로 넘겨주는 작업의 속도도 중요하다. 이때, 넘겨주는 속도가 느리게 되면 전체적인 작업속도가 느려지는 것이고, 이를 빠르게 하기 위해서 멀티프로세싱 방법을 사용할 수 있다.

이에 대한 그림은 아래와 같이 표현된다.

(빨간색은 넘겨주는 속도가 느린경우, 보라색은 이 속도가 최적화되어 빨라진 경우이다.)

 

가장 좋은 예시는 아래와 같이 GPU 사용률을 100%로 만드는 것이다. ( GPU-Util ) 

 

그러면 이러한 의문이 생길 수 있다.

 

"무조건 많은 CPU코어를 data proceccing에 할당해 주면 좋은거 아닌가?"

 

이 질문에 대한 대답은 

 

"꼭 그렇지는 않다" 이다.

 

CPU 코어의 수는 한정되어 있으므로 적당한 수를 지정해주는 것이 좋고, 

(CPU 코어는 데이터 로딩 이외에도 다른 일을 해야 되므로..) 

 

코어의 절반 정도를 사용하면 적당하다고 이야기 하고 있다.

 

자세한 내용은 아래 링크 참고.

 

https://jybaek.tistory.com/799

 

DataLoader num_workers에 대한 고찰

Pytorch에서 학습 데이터를 읽어오는 용도로 사용되는 DataLoader는 torch 라이브러리를 import만 하면 쉽게 사용할 수 있어서 흔히 공식처럼 잘 쓰고 있습니다. 다음과 같이 같이 사용할 수 있겠네요. fr

jybaek.tistory.com

 

 

 

728x90

'Pytorch' 카테고리의 다른 글

Pytorch : Variable() 클래스 사용용도 및 의미 (현재는 필요없음)  (0) 2021.09.09
Deep learning model code basic structure  (0) 2021.04.28
THOP: PyTorch-OpCounter  (0) 2021.04.01
visualization  (0) 2020.08.05
torch.utils.data.DataLoader  (0) 2020.06.20
728x90

if __name__=='__main__':

 

# args 선언

(dataset)

-dataset

-dataroot

 

(model)

-model 종류

 

(optimization)

-batch_size

-learning_rate

-step_size

 

(loss)

-loss_function

 

(options)

-seed

-the number of gpu

-use gpu

-eval mode

 

#main

(seed 선언)

(gpu 사용)

(dataset)

(model 선언)

- model

- criterion

 

 

(train)

-train

() load_network

-val

-save_network

 

result save & printing

tensorboard

git

 

 

 

 

 

 

 

 

 

 

 

 

 

728x90

'Pytorch' 카테고리의 다른 글

Pytorch : Variable() 클래스 사용용도 및 의미 (현재는 필요없음)  (0) 2021.09.09
Pytorch : Dataloader num_workers  (0) 2021.06.01
THOP: PyTorch-OpCounter  (0) 2021.04.01
visualization  (0) 2020.08.05
torch.utils.data.DataLoader  (0) 2020.06.20
728x90

pypi.org/project/thop/

 

thop

A tool to count the FLOPs of PyTorch model.

pypi.org

 

728x90

'Pytorch' 카테고리의 다른 글

Pytorch : Dataloader num_workers  (0) 2021.06.01
Deep learning model code basic structure  (0) 2021.04.28
visualization  (0) 2020.08.05
torch.utils.data.DataLoader  (0) 2020.06.20
Data Nomalization  (0) 2019.10.08
728x90

http://www.gisdeveloper.co.kr/?p=8498

 

이미지 분류 모델의 구성 레이어에 대한 결과값 시각화 – GIS Developer

이미지에 대한 Classification 및 Detection, Segmentation에 대한 신경망 모델을 구성하는 레이어 중 Convolution 관련 레이어의 결과값에 대한 시각화에 대한 내용입니다. 딥러닝 라이브러리 중 PyTorch로 예제

www.gisdeveloper.co.kr

 

728x90

'Pytorch' 카테고리의 다른 글

Deep learning model code basic structure  (0) 2021.04.28
THOP: PyTorch-OpCounter  (0) 2021.04.01
torch.utils.data.DataLoader  (0) 2020.06.20
Data Nomalization  (0) 2019.10.08
PyTorch Autograd  (0) 2019.10.03
728x90

https://wikidocs.net/57165

 

위키독스

온라인 책을 제작 공유하는 플랫폼 서비스

wikidocs.net

 

728x90

'Pytorch' 카테고리의 다른 글

Deep learning model code basic structure  (0) 2021.04.28
THOP: PyTorch-OpCounter  (0) 2021.04.01
visualization  (0) 2020.08.05
Data Nomalization  (0) 2019.10.08
PyTorch Autograd  (0) 2019.10.03
728x90

https://discuss.pytorch.org/t/about-normalization-using-pre-trained-vgg16-networks/23560/2

 

About Normalization using pre-trained vgg16 networks

Usually if your use case stays in the same data domain, the mean and std won’t be that different and you can try to use the ImageNet statistics. I would recommend to use your own data statistics if you are dealing with another domain, e.g. medical images.

discuss.pytorch.org

 

728x90

'Pytorch' 카테고리의 다른 글

Deep learning model code basic structure  (0) 2021.04.28
THOP: PyTorch-OpCounter  (0) 2021.04.01
visualization  (0) 2020.08.05
torch.utils.data.DataLoader  (0) 2020.06.20
PyTorch Autograd  (0) 2019.10.03
728x90

https://towardsdatascience.com/pytorch-autograd-understanding-the-heart-of-pytorchs-magic-2686cd94ec95

 

PyTorch Autograd

Understanding the heart of PyTorch’s magic

towardsdatascience.com

 

728x90

'Pytorch' 카테고리의 다른 글

Deep learning model code basic structure  (0) 2021.04.28
THOP: PyTorch-OpCounter  (0) 2021.04.01
visualization  (0) 2020.08.05
torch.utils.data.DataLoader  (0) 2020.06.20
Data Nomalization  (0) 2019.10.08

+ Recent posts