add setup.py

This commit is contained in:
hobogalaxy committed 2020-12-05 02:00:47 +01:00
1 parent 249992ee0a
commit ec7cb25364
2 files changed
+55 -38

No files matched your search

+41 -38
View File
@@ -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>
## Features
- All advantages of Pytorch Lightning
- All advantages of PyTorch Lightning
- Predefined folder structure
- 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))
- 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
- Hyperparameter search with Weights&Biases sweeps ([execute_sweep.py](project/utils/execute_sweep.py))
- Built in requirements ([requirements.txt](requirements.txt))
- Built in conda environment initialization ([conda_env.yaml](conda_env.yaml))
- Built in package setup ([setup.py](setup.py))
- Example with MNIST digits classification
- Useful example callbacks ([callbacks.py](project/utils/callbacks.py))
<br>
@@ -55,7 +56,7 @@ The directory structure of new project looks like this:
├── .gitignore
├── LICENSE
├── README.md
├── SETUP.md
├── setup.py
├── conda_env.yaml
└── 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))
Example project configuration:
```yaml
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"
early_stop:
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"
printing:
@@ -128,27 +130,13 @@ MNIST_CLASSIFIER_V1:
## 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 containing `DataModule` class
3. Add your run config to [run_configs.yaml](project/run_configs.yaml) (specify there folders containing your model and datamodule)
1. Add your model to `project/models` folder. 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
3. Create new run config in [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 -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)
4. Run training<br>
```bash
python train.py --use_wandb=True --run_config MNIST_CLASSIFIER_V1
```
<br><br>
@@ -178,38 +166,53 @@ First, install dependencies
git clone https://github.com/YourGithubName/your-repo-name
cd your-repo-name
# create conda environment
# optionally create conda environment
conda update conda
conda env create -f conda_env.yaml -n your_env_name
conda activate your_env_name
# optionally install project with setup.py
pip install -e .
# install requirements
pip install -r requirements.txt
```
Next, you can train model without data logging
Next, you can train model without logging
```bash
# train model with chosen run configuration
# train model without Weights&Biases
# choose run config from project/run_configs.yaml
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
# set project and enity names in project/project_config.yaml
loggers:
wandb:
project: "your_project_name"
entity: "your_wandb_user_or_team_name"
entity: "your_wandb_username_or_team"
```
```bash
# log to your wandb account
wandb login
```
```bash
# train model with chosen run configuration
# train model with Weights&Biases
# choose run config from project/run_configs.yaml
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).
For PyCharm setup read [SETUP.md](SETUP.md).
<br>
#### 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