10 files changed
+126
-81
No files matched your search
@@ -229,5 +229,3 @@ project/data/
|
|||||||
project/lightning_logs/
|
project/lightning_logs/
|
||||||
project/wandb/
|
project/wandb/
|
||||||
project/logs/
|
project/logs/
|
||||||
|
|
||||||
project/project_config.yaml
|
|
||||||
@@ -4,8 +4,19 @@ A convenient starting template for most deep learning projects. Built with <b>Py
|
|||||||
|
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
Read [SETUP.md](SETUP.md)
|
Read [SETUP.md](SETUP.md) for more info and explanations or just do this quick setup:
|
||||||
<br><br>
|
```
|
||||||
|
git clone https://github.com/kinoai/hackathon-template
|
||||||
|
cd hackathon-template
|
||||||
|
conda update conda
|
||||||
|
conda env create -f conda_env.yaml -n hack_env
|
||||||
|
conda activate hack_env
|
||||||
|
pip install -r requirements.txt
|
||||||
|
wandb login
|
||||||
|
cd project
|
||||||
|
python train.py
|
||||||
|
```
|
||||||
|
<br>
|
||||||
|
|
||||||
|
|
||||||
## Project structure
|
## Project structure
|
||||||
@@ -47,79 +58,98 @@ The directory structure of new project looks like this:
|
|||||||
├── LICENSE
|
├── LICENSE
|
||||||
├── README.md
|
├── README.md
|
||||||
├── SETUP.md
|
├── SETUP.md
|
||||||
|
├── conda_env.yaml
|
||||||
└── requirements.txt
|
└── requirements.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Project config parameters ([project_config.yaml](project/project_config.yaml))
|
## Project config parameters ([project_config.yaml](project/project_config.yaml))
|
||||||
```yaml
|
```yaml
|
||||||
num_of_gpus: -1
|
num_of_gpus: -1 <- '-1' to use all gpus available, '0' to train on cpu
|
||||||
|
|
||||||
resume_training:
|
resume_training:
|
||||||
lightning_ckpt:
|
lightning_ckpt:
|
||||||
resume_from_ckpt: False
|
resume_from_ckpt: False <- set True if you want to resume
|
||||||
ckpt_path: "logs/checkpoints/epoch=2.ckpt"
|
ckpt_path: "epoch=7.ckpt" <- path to your checkpoint
|
||||||
wandb:
|
wandb:
|
||||||
resume_wandb_run: False
|
resume_wandb_run: False <- set True if you want to resume Weight&Biases run
|
||||||
wandb_run_id: "8uuomodb"
|
wandb_run_id: "8uuomodb" <- id of Weight&Biases run you want to resume
|
||||||
|
|
||||||
loggers:
|
loggers:
|
||||||
wandb:
|
wandb:
|
||||||
project: "hackathon_template_test"
|
project: "project_name" <- wandb project name
|
||||||
team: "kino"
|
team: "kino" <- wandb entity name
|
||||||
group: None
|
group: None <- wandb group name
|
||||||
job_type: "train"
|
job_type: "train" <- wandb job_type name
|
||||||
tags: []
|
tags: [] <- wandb tags name
|
||||||
log_model: True
|
log_model: True <- set True if you want to upload ckpts to wandb automatically
|
||||||
offline: False
|
offline: False <- set True if you want to store all data locally
|
||||||
|
|
||||||
callbacks:
|
callbacks:
|
||||||
checkpoint:
|
checkpoint:
|
||||||
monitor: "val_acc"
|
monitor: "val_acc" <- name of the logged metric that determines when model is improving
|
||||||
save_top_k: 1
|
save_top_k: 1 <- save k best models (determined by above metric)
|
||||||
save_last: True
|
save_last: True <- additionaly always save model from last epoch
|
||||||
mode: "max"
|
mode: "max" <- can be "max" or "min"
|
||||||
early_stop:
|
early_stop:
|
||||||
monitor: "val_acc"
|
monitor: "val_acc" <- name of the logged metric that determines when model is improving
|
||||||
patience: 100
|
patience: 100 <- how many epochs of not improving until training stops
|
||||||
mode: "max"
|
mode: "max" <- can be "max" or "min"
|
||||||
|
|
||||||
printing:
|
printing:
|
||||||
progress_bar_refresh_rate: 5
|
progress_bar_refresh_rate: 5 <- refresh rate of training bar in terminal
|
||||||
weights_summary: "top" # "full"
|
weights_summary: "top" <- print summary of model (alternatively "full")
|
||||||
profiler: False
|
profiler: False <- set True if you want to see execution time profiling
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Run config parameters ([run_configs.yaml](project/run_configs.yaml))
|
## Run config parameters ([run_configs.yaml](project/run_configs.yaml))
|
||||||
You can store many run configurations in this file.<br>
|
You can store many run configurations in this file.<br>
|
||||||
Example run configuration:
|
Example run configuration:
|
||||||
```yaml
|
```yaml
|
||||||
MNIST_CLASSIFIER_V1:
|
MNIST_CLASSIFIER_V1:
|
||||||
trainer:
|
trainer: <- lightning 'Trainer' parameters (all except 'max_epochs' are optional)
|
||||||
min_epochs: 1
|
|
||||||
max_epochs: 5
|
max_epochs: 5
|
||||||
gradient_clip_val: 0.5
|
gradient_clip_val: 0.5
|
||||||
accumulate_grad_batches: 1
|
accumulate_grad_batches: 3
|
||||||
limit_train_batches: 1.0
|
limit_train_batches: 1.0
|
||||||
model:
|
model: <- all of the parameters here will be passed to 'LitModel' in 'hparams' dictionary
|
||||||
model_folder: "simple_mnist_classifier"
|
model_folder: "simple_mnist_classifier" <- name of folder from which 'lightning_module.py' (with 'LitMdodel' class) will be loaded
|
||||||
lr: 0.001
|
lr: 0.001
|
||||||
weight_decay: 0.000001
|
weight_decay: 0.000001
|
||||||
input_size: 784 # img size is 1*28*28
|
input_size: 784
|
||||||
output_size: 10 # there are 10 digit classes
|
output_size: 10
|
||||||
lin1_size: 256
|
lin1_size: 256
|
||||||
lin2_size: 256
|
lin2_size: 256
|
||||||
lin3_size: 128
|
lin3_size: 128
|
||||||
dataset:
|
dataset: <- all of the parameters here will be passed to 'DataModule' in 'hparams' dictionary
|
||||||
datamodule_folder: "mnist_digits_datamodule"
|
datamodule_folder: "mnist_digits_datamodule" <- name of folder from which 'datamodule.py' (with 'DataModule' class) will be loaded
|
||||||
batch_size: 256
|
batch_size: 256
|
||||||
train_val_split_ratio: 0.9
|
train_val_split_ratio: 0.9
|
||||||
num_workers: 4
|
num_workers: 1
|
||||||
pin_memory: True
|
pin_memory: False
|
||||||
```
|
```
|
||||||
The run configuration that you want to train with needs to be chosen in [train.py](project/train.py):
|
|
||||||
|
|
||||||
|
## Workflow
|
||||||
|
1. Add your model to `project/models` folder<br>
|
||||||
|
(you need to create folder with `lightning_module.py` file containing `LitModel` class)
|
||||||
|
2. Add your datamodule to `project/data_modules` folder<br>
|
||||||
|
(you need to create folder with `datamodule.py` file containig `DataModule` class)
|
||||||
|
3. Add your run config to [run_configs.yaml](project/run_configs.yaml) (specify there folders containing your model and datamodule)
|
||||||
|
3. Configure [project_config.yaml](project/project_config.yaml)
|
||||||
|
4. Run training:<br>
|
||||||
|
Either pass run config name as an argument:
|
||||||
|
```
|
||||||
|
python train.py -c MNIST_CLASSIFIER_V1
|
||||||
|
python train.py --conf_name MNIST_CLASSIFIER_V1
|
||||||
|
```
|
||||||
|
Or modify default run config name in [train.py](project/train.py):
|
||||||
```python
|
```python
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
RUN_CONFIG_NAME = "MNIST_CLASSIFIER_V1"
|
parser = ArgumentParser()
|
||||||
main(run_config_name=RUN_CONFIG_NAME)
|
parser.add_argument("-c", "--conf_name", type=str, default="MNIST_CLASSIFIER_V1")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
main(run_config_name=args.conf_name)
|
||||||
```
|
```
|
||||||
@@ -1,48 +1,55 @@
|
|||||||
## Setup
|
## Setup
|
||||||
|
1. Install anaconda if you don't already have it
|
||||||
|
|
||||||
#### 1. Install anaconda
|
|
||||||
https://docs.conda.io/projects/conda/en/latest/user-guide/install/download.html
|
https://docs.conda.io/projects/conda/en/latest/user-guide/install/download.html
|
||||||
|
|
||||||
#### 2. Create anaconda env
|
2. Clone repo
|
||||||
```
|
```
|
||||||
conda create --name hack_env
|
git clone https://github.com/kinoai/hackathon-template
|
||||||
|
cd hackathon-template
|
||||||
|
```
|
||||||
|
3. Create conda environment (change 'hack_env' to any name you want)
|
||||||
|
```
|
||||||
|
conda update conda
|
||||||
|
conda env create -f conda_env.yaml -n hack_env
|
||||||
conda activate hack_env
|
conda activate hack_env
|
||||||
```
|
```
|
||||||
|
4. Make sure proper python PATH is loaded<br>
|
||||||
#### 3. Make sure proper python PATH is loaded
|
- Unix
|
||||||
Unix
|
|
||||||
```
|
```
|
||||||
which python
|
which python
|
||||||
```
|
```
|
||||||
Windows
|
- Windows
|
||||||
```
|
```
|
||||||
for %i in (python.exe) do @echo. %~$PATH:i
|
for %i in (python.exe) do @echo. %~$PATH:i
|
||||||
```
|
```
|
||||||
Expected result: `PATH_TO_CONDA/envs/ENV_NAME/bin/python`
|
Expected result: `PATH_TO_CONDA/envs/ENV_NAME/bin/python`
|
||||||
|
5. Install requirements
|
||||||
#### 4. Install pytorch with conda
|
|
||||||
Installation command generator: https://pytorch.org/get-started/locally/
|
|
||||||
```
|
```
|
||||||
conda install pytorch torchvision torchaudio cudatoolkit=11.0 -c pytorch
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 5. Clone repo
|
|
||||||
```
|
|
||||||
git clone https://github.com/kinoai/hackathon-template
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 6. Install requirements with pip
|
|
||||||
```
|
|
||||||
cd hackathon-template
|
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
```
|
```
|
||||||
|
6. Log to your Weights&Biases account
|
||||||
#### 7. Log into your wandb account
|
|
||||||
```
|
```
|
||||||
wandb login
|
wandb login
|
||||||
```
|
```
|
||||||
|
7. Run training
|
||||||
|
```
|
||||||
|
cd project
|
||||||
|
python train.py
|
||||||
|
```
|
||||||
|
<br>
|
||||||
|
|
||||||
#### 8. PyCharm setup
|
|
||||||
|
#### Important notes!
|
||||||
|
- If you're using CUDA compatible GPU make sure your drivers are updated!
|
||||||
|
- If you are not using GPU (CUDA incompatible GPU) you may need to specify the number of GPUs manually instead of leaving the default `-1` in `project_config.yaml`:
|
||||||
|
```
|
||||||
|
num_of_gpus: 0
|
||||||
|
```
|
||||||
|
<br>
|
||||||
|
|
||||||
|
|
||||||
|
## PyCharm setup
|
||||||
- open this repository as PyCharm project
|
- open this repository as PyCharm project
|
||||||
- set "hack_env" as project interpreter:<br>
|
- set "hack_env" as project interpreter:<br>
|
||||||
`Ctrl + Shift + A -> type "Project Interpreter"`
|
`Ctrl + Shift + A -> type "Project Interpreter"`
|
||||||
@@ -52,11 +59,3 @@ Installation command generator: https://pytorch.org/get-started/locally/
|
|||||||
`Ctrl + Shift + A -> type "Edit Configurations..." -> select "Emulate terminal in output console"`
|
`Ctrl + Shift + A -> type "Edit Configurations..." -> select "Emulate terminal in output console"`
|
||||||
- run training:<br>
|
- run training:<br>
|
||||||
`right click on train.py file -> "Run 'train'"`
|
`right click on train.py file -> "Run 'train'"`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#### Important notes!
|
|
||||||
- If you are not using GPU (CUDA incompatible GPU) you may need to specify the number of GPUs manually instead of leaving the default `-1` in `config.yaml`:
|
|
||||||
```
|
|
||||||
num_of_gpus: 0
|
|
||||||
```
|
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#name: hack_env
|
||||||
|
channels:
|
||||||
|
- pytorch
|
||||||
|
- conda-forge
|
||||||
|
- defaults
|
||||||
|
dependencies:
|
||||||
|
- python=3.8
|
||||||
|
- pip
|
||||||
|
- cudatoolkit
|
||||||
|
- pytorch
|
||||||
|
- torchvision
|
||||||
|
- torchaudio
|
||||||
|
#prefix: C:\Users\UserX\Anaconda3\envs\hack_env
|
||||||
Whitespace-only changes.
@@ -9,12 +9,13 @@ from models.example_model.models import *
|
|||||||
class LitModel(pl.LightningModule):
|
class LitModel(pl.LightningModule):
|
||||||
"""
|
"""
|
||||||
This is example of lightning model.
|
This is example of lightning model.
|
||||||
The folder name of LitModel used during trainig should be specified in run config and all parameters from
|
It should always be located in file named 'lightninig_module.py' and always be named 'LitModel'!
|
||||||
|
|
||||||
|
The folder name of 'LitModel' used during training should be specified in run config and all parameters from
|
||||||
'model' section will be passed in 'hparams' dictionary.
|
'model' section will be passed in 'hparams' dictionary.
|
||||||
|
|
||||||
It enables you to specify what happens during training, validation and test step.
|
It enables you to specify what happens during training, validation and test step.
|
||||||
You can just remove validatin_step() or test_step() if you don't want to use them during trainig and model
|
You can just remove 'validation_step()' or 'test_step()' methods if you don't want to have them during training.
|
||||||
should still train correctly.
|
|
||||||
|
|
||||||
See 'simple_mnist_classifier' for more proper example.
|
See 'simple_mnist_classifier' for more proper example.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
num_of_gpus: -1
|
num_of_gpus: 0
|
||||||
|
|
||||||
resume_training:
|
resume_training:
|
||||||
lightning_ckpt:
|
lightning_ckpt:
|
||||||
|
|||||||
+6
-3
@@ -1,4 +1,5 @@
|
|||||||
from pytorch_lightning.profiler import SimpleProfiler
|
from pytorch_lightning.profiler import SimpleProfiler
|
||||||
|
from argparse import ArgumentParser
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
# utils
|
# utils
|
||||||
@@ -7,7 +8,6 @@ from utils.callbacks import *
|
|||||||
|
|
||||||
|
|
||||||
def train(project_config, run_config):
|
def train(project_config, run_config):
|
||||||
|
|
||||||
# Init PyTorch Lightning model ⚡
|
# Init PyTorch Lightning model ⚡
|
||||||
lit_model = init_lit_model(hparams=run_config["model"])
|
lit_model = init_lit_model(hparams=run_config["model"])
|
||||||
|
|
||||||
@@ -91,5 +91,8 @@ def main(run_config_name):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
RUN_CONFIG_NAME = "MNIST_CLASSIFIER_V2"
|
parser = ArgumentParser()
|
||||||
main(run_config_name=RUN_CONFIG_NAME)
|
parser.add_argument("-c", "--conf_name", type=str, default="MNIST_CLASSIFIER_V1")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
main(run_config_name=args.conf_name)
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
from models.simple_mnist_classifier.lightning_module import LitModel
|
|
||||||
from data_modules.mnist_digits_datamodule import transforms
|
from data_modules.mnist_digits_datamodule import transforms
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
# the LitModel you import should be the same as the one you used for training!
|
||||||
|
from models.simple_mnist_classifier.lightning_module import LitModel
|
||||||
|
|
||||||
|
|
||||||
def predict():
|
def predict():
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -4,4 +4,3 @@ pytorch-lightning-bolts>=0.2.5
|
|||||||
wandb>=0.10.11
|
wandb>=0.10.11
|
||||||
PyYAML>=5.3.1
|
PyYAML>=5.3.1
|
||||||
scikit-learn>=0.23.2
|
scikit-learn>=0.23.2
|
||||||
efficientnet-pytorch>=0.7.0
|
|
||||||
Reference in new issue
Block a user