[PyTorch]Seed 고정
실험을 위한 Randomness 제어 방법
- Pytorch
import torch
torch.manula_seed(random_seed)
- CuDNN
: 딥러닝에 특화된 CUDA library. 딥러닝 프레임워크에서 필수적으로 사용되는 라이브러리
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
*주의사항 : 연산 속도가 느려짐 (연구 실험 초기단계보다는 후반 단계에서 사용하는 것을 권장)
- Numpy
: numpy로 데이터를 받아오고, metric 계산
import numpy as np
np.random.seed(random_seed)
- Random
: torchvision trasnforms는 python random 라이브러리로 randomness가 제어됨
import random
random.seed(random_seed)
- 동일한 조건에서 학습시 weight가 변화하지 않게 하는 옵션
torch.cuda.manual_seed(random_seed)
torch.cuda.manual_seed_all(random_seed) # if use multi-GPU
- 결론
torch.manual_seed(random_seed) # torch
torch.cuda.manual_seed(random_seed)
torch.cuda.manual_seed_all(random_seed) # if use multi-GPU
torch.backends.cudnn.deterministic = True # cudnn
torch.backends.cudnn.benchmark = False # cudnn
np.random.seed(random_seed) # numpy
random.seed(random_seed) # random
Author And Source
이 문제에 관하여([PyTorch]Seed 고정), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@ohado/Seed-고정저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)