add setup.py
This commit is contained in:
1 parent
249992ee0a
commit
ec7cb25364
2 files changed
+55
-38
No files matched your search
@@ -3,15 +3,16 @@ 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
|
- 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` classes and specify them in [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)
|
||||||
- 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/utils/execute_sweep.py))
|
- Hyperparameter search with Weights&Biases sweeps ([execute_sweep.py](project/utils/execute_sweep.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))
|
||||||
|
- Built in package setup ([setup.py](setup.py))
|
||||||
- Example with MNIST digits classification
|
- Example with MNIST digits classification
|
||||||
- Useful example callbacks ([callbacks.py](project/utils/callbacks.py))
|
- Useful example callbacks ([callbacks.py](project/utils/callbacks.py))
|
||||||
<br>
|
<br>
|
||||||
@@ -55,7 +56,7 @@ The directory structure of new project looks like this:
|
|||||||
├── .gitignore
|
├── .gitignore
|
||||||
├── LICENSE
|
├── LICENSE
|
||||||
├── README.md
|
├── README.md
|
||||||
├── SETUP.md
|
├── setup.py
|
||||||
├── conda_env.yaml
|
├── conda_env.yaml
|
||||||
└── requirements.txt
|
└── requirements.txt
|
||||||
```
|
```
|
||||||
@@ -63,6 +64,7 @@ The directory structure of new project looks like this:
|
|||||||
|
|
||||||
|
|
||||||
## Project config parameters ([project_config.yaml](project/project_config.yaml))
|
## Project config parameters ([project_config.yaml](project/project_config.yaml))
|
||||||
|
Example project configuration:
|
||||||
```yaml
|
```yaml
|
||||||
num_of_gpus: -1 <- '-1' to use all gpus available, '0' to train on cpu
|
num_of_gpus: -1 <- '-1' to use all gpus available, '0' to train on cpu
|
||||||
|
|
||||||
@@ -81,7 +83,7 @@ callbacks:
|
|||||||
mode: "max" <- can be "max" or "min"
|
mode: "max" <- can be "max" or "min"
|
||||||
early_stop:
|
early_stop:
|
||||||
monitor: "val_acc" <- name of the logged metric that determines when model is improving
|
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
|
patience: 5 <- how many epochs of not improving until training stops
|
||||||
mode: "max" <- can be "max" or "min"
|
mode: "max" <- can be "max" or "min"
|
||||||
|
|
||||||
printing:
|
printing:
|
||||||
@@ -128,27 +130,13 @@ MNIST_CLASSIFIER_V1:
|
|||||||
|
|
||||||
|
|
||||||
## Workflow
|
## Workflow
|
||||||
1. Add your model to `project/models` folder.<br>
|
1. Add your model to `project/models` folder. You need to create folder with `lightning_module.py` file containing `LitModel` class
|
||||||
You need to create folder with `lightning_module.py` file containing `LitModel` class
|
2. Add your datamodule to `project/data_modules` folder. You need to create folder with `datamodule.py` file containing `DataModule` class
|
||||||
2. Add your datamodule to `project/data_modules` folder.<br>
|
3. Create new run config in [run_configs.yaml](project/run_configs.yaml) (specify there folders containing your model and datamodule)
|
||||||
You need to create folder with `datamodule.py` file containing `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)
|
3. Configure [project_config.yaml](project/project_config.yaml)
|
||||||
4. Run training:<br>
|
4. Run training<br>
|
||||||
Either pass run config name as an argument
|
```bash
|
||||||
```
|
python train.py --use_wandb=True --run_config MNIST_CLASSIFIER_V1
|
||||||
python train.py -r MNIST_CLASSIFIER_V1
|
|
||||||
python train.py --run_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("-r", "--run_conf_name", type=str, default="MNIST_CLASSIFIER_V1")
|
|
||||||
parser.add_argument("-u", "--use_wandb", type=bool, default=True)
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
main(run_config_name=args.run_conf_name, use_wandb=args.use_wandb)
|
|
||||||
```
|
```
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|
||||||
@@ -178,38 +166,53 @@ First, install dependencies
|
|||||||
git clone https://github.com/YourGithubName/your-repo-name
|
git clone https://github.com/YourGithubName/your-repo-name
|
||||||
cd your-repo-name
|
cd your-repo-name
|
||||||
|
|
||||||
# create conda environment
|
# optionally create conda environment
|
||||||
conda update conda
|
conda update conda
|
||||||
conda env create -f conda_env.yaml -n your_env_name
|
conda env create -f conda_env.yaml -n your_env_name
|
||||||
conda activate your_env_name
|
conda activate your_env_name
|
||||||
|
|
||||||
|
# optionally install project with setup.py
|
||||||
|
pip install -e .
|
||||||
|
|
||||||
# install requirements
|
# install requirements
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
Next, you can train model without data logging
|
Next, you can train model without logging
|
||||||
```bash
|
```bash
|
||||||
# train model with chosen run configuration
|
# train model without Weights&Biases
|
||||||
|
# choose run config from project/run_configs.yaml
|
||||||
cd project
|
cd project
|
||||||
python train.py --use_wandb=False --run_conf_name MNIST_CLASSIFIER_V1
|
python train.py --use_wandb=False --run_config MNIST_CLASSIFIER_V1
|
||||||
```
|
```
|
||||||
|
|
||||||
Or you can train model with Weights&Biases data logging
|
Or you can train model with Weights&Biases logging
|
||||||
```yaml
|
```yaml
|
||||||
# set project and enity names in project/project_config.yaml
|
# set project and enity names in project/project_config.yaml
|
||||||
loggers:
|
loggers:
|
||||||
wandb:
|
wandb:
|
||||||
project: "your_project_name"
|
project: "your_project_name"
|
||||||
entity: "your_wandb_user_or_team_name"
|
entity: "your_wandb_username_or_team"
|
||||||
```
|
```
|
||||||
```bash
|
```bash
|
||||||
# log to your wandb account
|
# train model with Weights&Biases
|
||||||
wandb login
|
# choose run config from project/run_configs.yaml
|
||||||
```
|
|
||||||
```bash
|
|
||||||
# train model with chosen run configuration
|
|
||||||
cd project
|
cd project
|
||||||
python train.py --use_wandb=True --run_conf_name MNIST_CLASSIFIER_V1
|
python train.py --use_wandb=True --run_config MNIST_CLASSIFIER_V1
|
||||||
```
|
```
|
||||||
All run configurations are located in [run_configs.yaml](project/run_configs.yaml).
|
<br>
|
||||||
For PyCharm setup read [SETUP.md](SETUP.md).
|
|
||||||
|
|
||||||
|
#### PyCharm setup
|
||||||
|
- open this repository as PyCharm project
|
||||||
|
- set project interpreter:<br>
|
||||||
|
`Ctrl + Shift + A -> type "Project Interpreter"`
|
||||||
|
- mark folder "project" as sources root:<br>
|
||||||
|
`right click on directory -> "Mark Directory as" -> "Sources Root"`
|
||||||
|
- set terminal emulation:<br>
|
||||||
|
`Ctrl + Shift + A -> type "Edit Configurations..." -> select "Emulate terminal in output console"`
|
||||||
|
- run training:<br>
|
||||||
|
`right click on train.py file -> "Run 'train'"`
|
||||||
|
|
||||||
|
#### VS Code setup
|
||||||
|
- TODO
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name='project',
|
||||||
|
version='0.0.0',
|
||||||
|
description='Describe Your Cool Project',
|
||||||
|
author='',
|
||||||
|
author_email='',
|
||||||
|
url='https://github.com/kinoai/deep-learning-project-template', # REPLACE WITH YOUR OWN GITHUB PROJECT LINK
|
||||||
|
install_requires=['pytorch-lightning', 'PyYAML'],
|
||||||
|
packages=find_packages(),
|
||||||
|
)
|
||||||
Reference in new issue
Block a user