more comments and explanations
This commit is contained in:
1 parent
757f0fc25a
commit
23e9c4fecf
5 files changed
+26
-18
No files matched your search
@@ -3,13 +3,14 @@ A convenient starting template for most deep learning projects. Built with <b>Py
|
|||||||
Click on <b>"Use this template"</b> button above to initialize new repository.<br>
|
Click on <b>"Use this template"</b> button above to initialize new repository.<br>
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
- All advantages of PyTorch Lightning
|
|
||||||
- Predefined folder structure
|
- Predefined folder structure
|
||||||
- Storing project configuration in a convenient way ([project_config.yaml](project/project_config.yaml))
|
- Storing project configuration in a convenient way ([project_config.yaml](project/project_config.yaml))
|
||||||
- Storing many run configurations in a convenient way ([run_configs.yaml](project/run_configs.yaml))
|
- Storing many run configurations in a convenient way ([run_configs.yaml](project/run_configs.yaml))
|
||||||
- Automates the whole training process and initialization, you only need to create `model` and `datamodule` and specify them in [run_configs.yaml](project/run_configs.yaml)
|
- All advantages of PyTorch Lightning
|
||||||
|
- Weights&Biases integration:
|
||||||
- Automatically stores all relevant code, configs and model checkpoints in Weights&Biases cloud
|
- Automatically stores all relevant code, configs and model checkpoints in Weights&Biases cloud
|
||||||
- Hyperparameter search with Weights&Biases sweeps ([execute_sweep.py](project/template_utils/execute_sweep.py))
|
- Hyperparameter search with Weights&Biases sweeps ([execute_sweep.py](project/template_utils/execute_sweep.py))
|
||||||
|
- Automates the whole training process and initialization, you only need to create `model` and `datamodule` and specify them in [run_configs.yaml](project/run_configs.yaml)
|
||||||
- Scheduling execution of many experiments ([execute_all_runs.py](project/template_utils/execute_all_runs.py))
|
- Scheduling execution of many experiments ([execute_all_runs.py](project/template_utils/execute_all_runs.py))
|
||||||
- Built in requirements ([requirements.txt](requirements.txt))
|
- Built in requirements ([requirements.txt](requirements.txt))
|
||||||
- Built in conda environment initialization ([conda_env.yaml](conda_env.yaml))
|
- Built in conda environment initialization ([conda_env.yaml](conda_env.yaml))
|
||||||
@@ -36,16 +37,16 @@ The directory structure of new project looks like this:
|
|||||||
│ │ ├── init_utils.py <- Useful initializers
|
│ │ ├── init_utils.py <- Useful initializers
|
||||||
│ │ └── predict_example.py <- Example of inference with trained model
|
│ │ └── predict_example.py <- Example of inference with trained model
|
||||||
│ │
|
│ │
|
||||||
│ ├── data_modules <- All your data modules should be located here!
|
│ ├── datamodules <- All your datamodules should be located here!
|
||||||
│ │ ├── example_datamodule <- Each datamodule should be located in separate folder!
|
│ │ ├── example_datamodule <- It's best to locate each datamodule in separate folder!
|
||||||
│ │ │ ├── datamodule.py <- Contains class of type 'LightningDataModule'
|
│ │ │ ├── datamodule.py <- Contains class of type 'LightningDataModule'
|
||||||
│ │ │ ├── datasets.py <- Optional file
|
│ │ │ ├── transforms.py <- Some optional file
|
||||||
│ │ │ └── transforms.py <- Optional file
|
│ │ │ └── ...
|
||||||
│ │ ├── ...
|
│ │ ├── ...
|
||||||
│ │ └── ...
|
│ │ └── ...
|
||||||
│ │
|
│ │
|
||||||
│ ├── models <- All your models should be located here!
|
│ ├── models <- All your models should be located here!
|
||||||
│ │ ├── example_model <- Each model should be located in separate folder!
|
│ │ ├── example_model <- It's best to locate each model in separate folder!
|
||||||
│ │ │ ├── lightning_module.py <- Contains class of type 'LightningModule'
|
│ │ │ ├── lightning_module.py <- Contains class of type 'LightningModule'
|
||||||
│ │ │ └── models.py <- Model architectures used by 'LightningModule'
|
│ │ │ └── models.py <- Model architectures used by 'LightningModule'
|
||||||
│ │ ├── ...
|
│ │ ├── ...
|
||||||
@@ -93,6 +94,9 @@ printing:
|
|||||||
progress_bar_refresh_rate: 5 <- refresh rate of training bar in terminal
|
progress_bar_refresh_rate: 5 <- refresh rate of training bar in terminal
|
||||||
weights_summary: "top" <- print summary of model (alternatively "full")
|
weights_summary: "top" <- print summary of model (alternatively "full")
|
||||||
profiler: False <- set True if you want to see execution time profiling
|
profiler: False <- set True if you want to see execution time profiling
|
||||||
|
|
||||||
|
data_dir: "data/" <- path to data folder
|
||||||
|
logs_dir: "logs/" <- path to logs folder
|
||||||
```
|
```
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
@@ -129,20 +133,20 @@ SIMPLE_CONFIG_EXAMPLE_MNIST:
|
|||||||
To start training with this configuration run: `python train.py --run_config_name SIMPLE_CONFIG_EXAMPLE_MNIST`
|
To start training with this configuration run: `python train.py --run_config_name SIMPLE_CONFIG_EXAMPLE_MNIST`
|
||||||
|
|
||||||
Each run configuration needs to contain sections `trainer`, `model` and `datamodule`. <br>
|
Each run configuration needs to contain sections `trainer`, `model` and `datamodule`. <br>
|
||||||
Sections `callbacks`, `wandb` and `resume_training` are optional and can be removed.<br>
|
Sections `seed`, `callbacks`, `wandb` and `resume_training` are optional and can be removed (see advanced config example in [run_configs.yaml](project/run_configs.yaml)).<br>
|
||||||
|
|
||||||
Every parameter specified in model hparams section will be passed to your model class and can be retrieved through `hparams` dictionary (see example with [simple_mnist_classifier](project/models/simple_mnist_classifier/lightning_module.py)).<br>
|
Every parameter specified in model hparams section will be passed to your model class and can be retrieved through `hparams` dictionary (see example with [simple_mnist_classifier](project/models/simple_mnist_classifier/lightning_module.py)).<br>
|
||||||
Every parameter specified in datamodule hparams section will be passed to your datamodule class and can be retrieved through `hparams` dictionary (see example with [mnist_digits_datamodule](project/datamodules/mnist_datamodule/datamodule.py)).<br>
|
Every parameter specified in datamodule hparams section will be passed to your datamodule class and can be retrieved through `hparams` dictionary (see example with [mnist_datamodule](project/datamodules/mnist_datamodule/datamodule.py)).<br>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
|
||||||
## Workflow
|
## Workflow
|
||||||
1. Create model in PyTorch Lightning
|
1. Create PyTorch Lightning model
|
||||||
2. Create datamodule in PyTorch Lightning
|
2. Create PyTorch Lightning datamodule
|
||||||
3. Create new run config in [run_configs.yaml](project/run_configs.yaml)
|
3. Create new run config in [run_configs.yaml](project/run_configs.yaml)
|
||||||
- specify path to your model class
|
- specify path to your model class
|
||||||
- specify path to your datamodule class
|
- specify path to your datamodule class
|
||||||
- you can add there and hyperparametrs you want!
|
- you can add there and hyperparameters you want!
|
||||||
3. Configure your project in [project_config.yaml](project/project_config.yaml)
|
3. Configure your project in [project_config.yaml](project/project_config.yaml)
|
||||||
4. Run training with chosen run config<br>
|
4. Run training with chosen run config<br>
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ class MNISTDataModule(LightningDataModule):
|
|||||||
This is example of datamodule for MNIST dataset.
|
This is example of datamodule for MNIST dataset.
|
||||||
|
|
||||||
The path to datamodule should be specified in your run config. (run_configs.yaml)
|
The path to datamodule should be specified in your run config. (run_configs.yaml)
|
||||||
The 'hparams' dict contains your hparams specified in run config! (run_configs.yaml)
|
The 'hparams' dict contains your hparams specified in run config. (run_configs.yaml)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, data_dir: str, hparams: dict):
|
def __init__(self, data_dir: str, hparams: dict):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ import os
|
|||||||
|
|
||||||
class TestDataset(Dataset):
|
class TestDataset(Dataset):
|
||||||
"""
|
"""
|
||||||
Example dataset class for loading images from folder.
|
Example dataset class for loading images from folder and converting them to monochromatic.
|
||||||
'Dataset' classes can be used by 'DataModule' class.
|
Can be used to perform inference with trained MNIST model.
|
||||||
|
'Dataset' type classes can also be used to create 'DataLoader' type classes which are used by datamodules.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, img_dir, transform):
|
def __init__(self, img_dir, transform):
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
"""
|
||||||
|
Example file containing data transformations which can be used by datamodule.
|
||||||
|
"""
|
||||||
from torchvision import transforms
|
from torchvision import transforms
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import pytorch_lightning as pl
|
|||||||
import torch.nn.functional as F
|
import torch.nn.functional as F
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
# custom models
|
# import custom models
|
||||||
from models.simple_mnist_classifier.models import *
|
from models.simple_mnist_classifier.models import *
|
||||||
|
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ class LitModel(pl.LightningModule):
|
|||||||
This is example of lightning model for MNIST digits classification.
|
This is example of lightning model for MNIST digits classification.
|
||||||
|
|
||||||
The path to model should be specified in your run config. (run_configs.yaml)
|
The path to model should be specified in your run config. (run_configs.yaml)
|
||||||
The 'hparams' dict contains your hparams specified in run config! (run_configs.yaml)
|
The 'hparams' dict contains your hparams specified in run config. (run_configs.yaml)
|
||||||
|
|
||||||
This class enables you to specify what happens during training, validation and test step.
|
This class enables you to specify what happens during training, validation and test step.
|
||||||
You can just remove 'validation_step()' or 'test_step()' methods if you don't want to have them during training.
|
You can just remove 'validation_step()' or 'test_step()' methods if you don't want to have them during training.
|
||||||
|
|||||||
Reference in new issue
Block a user