PyTorch 프로젝트 구조

박정재·2022년 3월 16일
0

PyTorch

목록 보기
1/2

PyTorch Project Template Overview

  • jupyter notebook 같은 대화식 개발 과정이 초기 단계에서 유리할 수 있다.
    - 학습과정과 디버깅 등 지속적인 확인이 가능하다.
  • 배포 및 공유 단계에서는 notebook 공유는 좋지 않을 수 있다.
    - 쉬운 재현의 어려움, 실행순서가 꼬일 수 있다.
  • 개발 용이성 확보와 유지보수 향상을 위한 방법이 필요하다.

OOP + 모듈 -> 프로젝트

실행, 데이터, 모델, 설정, 로깅, 지표, 유틸리티 등 다양한 모듈들을 분리하여 프로젝트 템플릿화 할 수 있다.

PyTorch Template 추천
https://github.com/victoresque/pytorch-template

  • base - abstract module
    - base_data_loader : 데이터 불러오기
    • base_model : model architecture 설정
    • base_trainer : 실행을 시켜주는 가장 기본적인 단계의 트리거
  • trainer : 학습을 수행하기 위한 트리거. 여러가지 설정, 모델, 데이터 저장소, 로깅하는 방법들을 다 넣고 실행. 각각의 '레고 블록'을 연결

터미널 실행 예시

conda activate torch
python new_project.py MyProject
cd MyProject
code .
python train.py -c config.json

train.py

if __name__ == '__main__':
	# 실행 창에서 argument 지정해줄 때,
    args = argparse.ArgumentParser(description='PyTorch Template')
    # 실행할 때 설정 파일 불러오기. 예시: python train.py -c config.json
    args.add_argument('-c', '--config', default=None, type=str,
                      help='config file path (default: None)')
    # 예전에 실행했던 것을 연속해서 실행할 것인지
    args.add_argument('-r', '--resume', default=None, type=str,
                      help='path to latest checkpoint (default: None)')
    # cpu or gpu
    args.add_argument('-d', '--device', default=None, type=str,
                      help='indices of GPUs to enable (default: all)')

등등...

다음주 프로젝트부터 다시 실전에서 부딪혀보자... ㅎㅎ...

profile
Keep on dreaming and dreaming

0개의 댓글