Deep Learning Project Template
1.0.0
간단하고 잘 설계된 구조는 모든 딥 러닝 프로젝트에 필수적이므로 Pytorch 프로젝트에 많은 연습과 기여를 한 후에는 폴더 구조 및 우수한 OOP 디자인을 위한 단순성, 모범 사례를 결합한 Pytorch 프로젝트 템플릿이 있습니다. 주요 아이디어는 Pytorch 프로젝트를 시작할 때마다하는 것과 거의 같은 일이 있다는 것입니다. 따라서이 공유 물건을 모두 마무리하면 새로운 Pytorch 프로젝트를 시작할 때마다 핵심 아이디어 만 변경하는 데 도움이됩니다.
따라서 다음은 기본 프로젝트에 더 빠르게 들어가서 핵심 (모델 아키텍처, 교육 흐름 등)에 중점을 두는 데 도움이되는 간단한 Pytorch 템플릿입니다.
반복적 인 물건을 줄이려면 높은 수준의 라이브러리를 사용하는 것이 좋습니다. 고유 한 수준의 라이브러리를 작성하거나 Ignite, Fastai, MMCV 등과 같은 세 번째 부동 라이브러리를 사용할 수 있습니다. 이는 몇 줄의 코드로 컴팩트하지만 완전한 기능을 갖춘 교육 루프를 작성하는 데 도움이 될 수 있습니다. 여기서 우리는 Ignite를 사용하여 MNIST를 예로 들어 훈련합니다.
간단히 말해서이 템플릿을 사용하는 방법은 예를 들어 MNIST를 훈련시키기 위해 RESNET-18을 구현한다고 가정하므로 다음을 수행해야합니다.
modeling 폴더에서 원하는대로 이름이라는 이름의 Python 파일을 만듭니다. 여기서 우리는 example_model.py 라고 불렀습니다. modeling/__init__.py 파일에서 build_model 이라는 기능을 작성하여 모델을 호출 할 수 있습니다. from . example_model import ResNet18
def build_model ( cfg ):
model = ResNet18 ( cfg . MODEL . NUM_CLASSES )
return modelengine 폴더에서 모델 트레이너 기능 및 추론 기능을 만듭니다. 트레이너 기능에서는 훈련 과정의 논리를 작성해야합니다. 일부 타사 라이브러리를 사용하여 반복 된 물건을 줄일 수 있습니다. # trainer
def do_train ( cfg , model , train_loader , val_loader , optimizer , scheduler , loss_fn ):
"""
implement the logic of epoch:
-loop on the number of iterations in the config and call the train step
-add any summaries you want using the summary
"""
pass
# inference
def inference ( cfg , model , val_loader ):
"""
implement the logic of the train step
- run the tensorflow session
- return any metrics you need to summarize
"""
passtools 폴더에서 train.py 만듭니다. 이 파일에서는 다음 객체 "Model", "Dataloader", "Optimizer"및 Config의 인스턴스를 가져와야합니다. # create instance of the model you want
model = build_model ( cfg )
# create your data generator
train_loader = make_data_loader ( cfg , is_train = True )
val_loader = make_data_loader ( cfg , is_train = False )
# create your model optimizer
optimizer = make_optimizer ( cfg , model )do_train 에 전달하고 훈련을 시작하십시오. # here you train your model
do_train ( cfg , model , train_loader , val_loader , optimizer , None , F . cross_entropy )모델 및 트레이너 폴더에 템플릿 파일과 간단한 예제를 찾아 첫 번째 모델을 간단히 시도하는 방법을 보여줍니다.
├── config
│ └── defaults.py - here's the default config file.
│
│
├── configs
│ └── train_mnist_softmax.yml - here's the specific config file for specific model or dataset.
│
│
├── data
│ └── datasets - here's the datasets folder that is responsible for all data handling.
│ └── transforms - here's the data preprocess folder that is responsible for all data augmentation.
│ └── build.py - here's the file to make dataloader.
│ └── collate_batch.py - here's the file that is responsible for merges a list of samples to form a mini-batch.
│
│
├── engine
│ ├── trainer.py - this file contains the train loops.
│ └── inference.py - this file contains the inference process.
│
│
├── layers - this folder contains any customed layers of your project.
│ └── conv_layer.py
│
│
├── modeling - this folder contains any model of your project.
│ └── example_model.py
│
│
├── solver - this folder contains optimizer of your project.
│ └── build.py
│ └── lr_scheduler.py
│
│
├── tools - here's the train/test model of your project.
│ └── train_net.py - here's an example of train model that is responsible for the whole pipeline.
│
│
└── utils
│ ├── logger.py
│ └── any_other_utils_you_need
│
│
└── tests - this foler contains unit test of your project.
├── test_data_sampler.py
모든 종류의 향상 또는 기여도를 환영합니다.