Deep Learning Project Template
1.0.0
シンプルで適切に設計された構造は、あらゆるディープラーニングプロジェクトに不可欠であるため、Pytorchプロジェクトで多くの練習と貢献の後、シンプルさ、フォルダー構造のベストプラクティス、優れたOOPデザインを組み合わせたPytorchプロジェクトテンプレートがあります。主なアイデアは、Pytorchプロジェクトを開始するときに毎回行うこととほぼ同じことがあるということです。そのため、この共有されたものすべてをラップすると、新しいPytorchプロジェクトを開始するたびにコアアイデアだけを変えるのに役立ちます。
したがって、メインプロジェクトに早くメインプロジェクトに入り、コアに集中するのに役立つシンプルなPytorchテンプレートがあります(モデルアーキテクチャ、トレーニングフローなど)
繰り返しのものを減らすために、高レベルのライブラリを使用することをお勧めします。独自のハイレベルライブラリを書くことも、Ignite、Fastai、MMCVなどの3部構成のライブラリを使用することもできます。これは、コンパクトでフル機能のトレーニングループを数行のコードで作成するのに役立ちます。ここでは、Igniteを使用して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を作成します。このファイルでは、次のオブジェクト「モデル」、「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
あらゆる種類の強化または貢献が歓迎されます。