many small improvements

This commit is contained in:
hobogalaxy committed 2020-11-29 16:04:00 +01:00
1 parent 8d55f151bd
commit ad0344d0a1
11 files changed
+90 -76

No files matched your search

+74 -64
View File
@@ -4,17 +4,17 @@ A convenient starting template for most deep learning projects. Built with <b>Py
## Setup
Read [SETUP.md](SETUP.md) for more info or just do this quick setup:
Read [SETUP.md](SETUP.md) for more info and explanations or just do this quick setup:
```
git clone https://github.com/kinoai/hackathon-template
cd hackathon-template
conda update conda
conda env create -f conda_env.yml -n hack_env
conda activate hack_env
pip install -r requirements.txt
wandb login
cd project
python train.py
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>
@@ -58,88 +58,98 @@ The directory structure of new project looks like this:
├── LICENSE
├── README.md
├── SETUP.md
├── conda_env.yaml
└── requirements.txt
```
## Project config parameters ([project_config.yaml](project/project_config.yml))
## Project config parameters ([project_config.yaml](project/project_config.yaml))
```yaml
num_of_gpus: -1
num_of_gpus: -1 <- '-1' to use all gpus available, '0' to train on cpu
resume_training:
lightning_ckpt:
resume_from_ckpt: False
ckpt_path: "logs/checkpoints/epoch=2.ckpt"
lightning_ckpt:
resume_from_ckpt: False <- set True if you want to resume
ckpt_path: "epoch=7.ckpt" <- path to your checkpoint
wandb:
resume_wandb_run: False
wandb_run_id: "8uuomodb"
resume_wandb_run: False <- set True if you want to resume Weight&Biases run
wandb_run_id: "8uuomodb" <- id of Weight&Biases run you want to resume
loggers:
wandb:
project: "hackathon_template_test"
team: "kino"
group: None
job_type: "train"
tags: []
log_model: True
offline: False
project: "project_name" <- wandb project name
team: "kino" <- wandb entity name
group: None <- wandb group name
job_type: "train" <- wandb job_type name
tags: [] <- wandb tags name
log_model: True <- set True if you want to upload ckpts to wandb automatically
offline: False <- set True if you want to store all data locally
callbacks:
checkpoint:
monitor: "val_acc"
save_top_k: 1
save_last: True
mode: "max"
monitor: "val_acc" <- name of the logged metric that determines when model is improving
save_top_k: 1 <- save k best models (determined by above metric)
save_last: True <- additionaly always save model from last epoch
mode: "max" <- can be "max" or "min"
early_stop:
monitor: "val_acc"
patience: 100
mode: "max"
monitor: "val_acc" <- name of the logged metric that determines when model is improving
patience: 100 <- how many epochs of not improving until training stops
mode: "max" <- can be "max" or "min"
printing:
progress_bar_refresh_rate: 5
weights_summary: "top" # "full"
profiler: False
progress_bar_refresh_rate: 5 <- refresh rate of training bar in terminal
weights_summary: "top" <- print summary of model (alternatively "full")
profiler: False <- set True if you want to see execution time profiling
```
## Run config parameters ([run_configs.yaml](project/run_configs.yml))
## Run config parameters ([run_configs.yaml](project/run_configs.yaml))
You can store many run configurations in this file.<br>
Example run configuration:
```yaml
MNIST_CLASSIFIER_V1:
trainer:
min_epochs: 1
max_epochs: 5
gradient_clip_val: 0.5
accumulate_grad_batches: 1
limit_train_batches: 1.0
model:
model_folder: "simple_mnist_classifier"
lr: 0.001
weight_decay: 0.000001
input_size: 784 # img size is 1*28*28
trainer: <- lightning 'Trainer' parameters (all except 'max_epochs' are optional)
max_epochs: 5 <- number of training epochs
gradient_clip_val: 0.5 <- gradient clipping value (helps with exploding gradient issues)
accumulate_grad_batches: 3 <- optimise after accumulating gradient from 3 batches
limit_train_batches: 1.0 <- 0.6 would mean to train only on 60% of training data
model: <- all of the parameters here will be passed to 'LitModel' in 'hparams' dictionary
model_folder: "simple_mnist_classifier" <- name of folder from which 'lightning_module.py' (with 'LitMdodel' class) will be loaded
lr: 0.001 <- learning rate
weight_decay: 0.000001 <- L2 normalization set in optimizer
input_size: 784 # img size for mnist digits is 1*28*28
output_size: 10 # there are 10 digit classes
lin1_size: 256
lin2_size: 256
lin3_size: 128
dataset:
datamodule_folder: "mnist_digits_datamodule"
batch_size: 256
train_val_split_ratio: 0.9
num_workers: 4
pin_memory: True
```
To run training pass run config name as an argument:
dataset: <- all of the parameters here will be passed to 'DataModule' in 'hparams' dictionary
datamodule_folder: "mnist_digits_datamodule" <- name of folder from which 'datamodule.py' (with 'DataModule' class) will be loaded
batch_size: 256 <- batch size
train_val_split_ratio: 0.9 <- split ratio between training and validation set
num_workers: 1 <- how many subprocesses to use for data loading
pin_memory: False <- if True, the data loader will copy Tensors into CUDA pinned memory before returning them.
```
## 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
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("-c", "--conf_name", type=str, default="MNIST_CLASSIFIER_V1")
args = parser.parse_args()
main(run_config_name=args.conf_name)
```
```
Or modify default run config name in [train.py](project/train.py):
```python
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("-c", "--conf_name", type=str, default="MNIST_CLASSIFIER_V1")
args = parser.parse_args()
main(run_config_name=args.conf_name)
```