BIG clean up and refactoring

This commit is contained in:
hobogalaxy committed 2020-11-27 20:23:05 +01:00
1 parent a905c0b094
commit e7a579d720
24 files changed
+369 -597

No files matched your search

+37 -47
View File
@@ -14,47 +14,43 @@ The directory structure of new project looks like this:
├── project
│ ├── data <- Data from third party sources
│ │
│ ├── data_modules <- Data related modules
│ │ ├── datamodules.py <- "LightningDataModule" modules
│ │ ├── datasets.py <- "Dataset" modules
│ │ └── transforms.py <- Data transformations
│ │
│ ├── logs <- Logs generated by Weights&Biases and PyTorch Lightning
│ │
│ ├── utils <- Any extra scripts not belonging to training pipeline
│ │
│ ├── notebooks <- Jupyter notebooks
│ │
│ ├── lightning_modules <- PyTorch Lightning related modules
│ │ ├── callbacks.py <- Training callbacks
│ │ └── init_utils.py <- Some useful initializers
│ ├── utils <- Different utilities
│ │ ├── callbacks.py <- Useful training callbacks
│ │ ├── execute_sweep.py <- Special file for executing Weights&Biases sweeps
│ │ ├── init_utils.py <- Useful initializers
│ │ └── predict_example.py <- Example of inference with trained model
│ │
│ ├── data_modules <- All your data modules should be located here
│ │ ├── example_datamodule <- Each datamodule should be located in separate folder!
│ │ │ ├── datamodule.py <- Contains 'DataModule' class
│ │ │ ├── datasets.py <- Contains pytorch 'Dataset' classes
│ │ │ └── transforms.py <- Contains data transformations
│ │ ├── ...
│ │ └── ...
│ │
│ ├── models <- All your models should be located here
│ │ ├── simple_mnist_classifier <- Example model
│ │ │ ├── lightning_module.py <- Contains train/val/test step methods
│ │ │ └── models.py <- Model declarations used in lightning_module.py
│ │ │
│ │ ├── simple_cifar10_classifier <- Example model
│ │ │ ├── lightning_module.py <- Contains train/val/test step methods
│ │ │ └── models.py <- Model declarations used in lightning_module.py
│ │ │
│ │ ├── example_model <- Each model should be located in separate folder!
│ │ │ ├── lightning_module.py <- Contains 'LitModel' class with train/val/test step methods
│ │ │ └── models.py <- Model architectures used by lightning_module.py
│ │ ├── ...
│ │ └── ...
│ │
│ ├── project_config.yaml <- Project configuration
│ ├── run_configs.yaml <- Run configurations
│ ├── execute_sweep.py <- Special file for executing wandb sweeps (hyperparameter search)
│ └── train.py <- Train model
│ ├── run_configs.yaml <- Configurations of different runs/experiments
│ └── train.py <- Train model with chosen run configuration
│
├── .gitignore
├── LICENSE
├── README.md
├── SETUP.md
├── TIPS.md
└── requirements.txt
```
## Project config parameters
#### [project_config.yaml](project/project_config.yaml)
## Project config parameters ([project_config.yaml](project/project_config.yaml))
```yaml
num_of_gpus: -1
@@ -93,43 +89,37 @@ printing:
profiler: False
```
## 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>
Example run configuration:
```yaml
CIFAR10_CLASSIFIER_V2:
MNIST_CLASSIFIER_V1:
trainer:
max_epochs: 10
min_epochs: 1
max_epochs: 5
gradient_clip_val: 0.5
accumulate_grad_batches: 1
limit_train_batches: 1.0
model:
name: "simple_cifar10_classifier"
lr: 0.002
weight_decay: 0.00001
output_size: 10
lin1_size: 512
model_folder: "simple_mnist_classifier"
lr: 0.001
weight_decay: 0.000001
input_size: 784 # img size is 1*28*28
output_size: 10 # there are 10 digit classes
lin1_size: 256
lin2_size: 256
lin3_size: 128
dataset:
name: "CIFAR10DataModule"
datamodule_folder: "mnist_digits_datamodule"
batch_size: 256
train_val_split_ratio: 0.9
num_workers: 1
pin_memory: False
num_workers: 4
pin_memory: True
```
The run configuration that you want to train with needs to be chose in [train.py](project/train.py):
The run configuration that you want to train with needs to be chosen in [train.py](project/train.py):
```python
if __name__ == "__main__":
RUN_CONFIG = "MNIST_CLASSIFIER_V1" # choose your run config here
RUN_CONFIG_NAME = "MNIST_CLASSIFIER_V1"
main(run_config_name=RUN_CONFIG_NAME)
project_conf = load_config("project_config.yaml")
run_conf = load_config("run_configs.yaml")[RUN_CONFIG]
train(project_config=project_conf, run_config=run_conf) # train with chosen run config
```
## Tips
For training tips read [TIPS.md](TIPS.md)