diff --git a/README.md b/README.md index 547008b..ab7c826 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,16 @@ A convenient starting template for most deep learning projects. Built with Py Click on "Use this template" button above to initialize new repository.
## 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))
@@ -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.
- 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. 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:
- 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
+ ```bash + python train.py --use_wandb=True --run_config MNIST_CLASSIFIER_V1 ```

@@ -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). +
+ + +#### PyCharm setup +- open this repository as PyCharm project +- set project interpreter:
+`Ctrl + Shift + A -> type "Project Interpreter"` +- mark folder "project" as sources root:
+`right click on directory -> "Mark Directory as" -> "Sources Root"` +- set terminal emulation:
+`Ctrl + Shift + A -> type "Edit Configurations..." -> select "Emulate terminal in output console"` +- run training:
+`right click on train.py file -> "Run 'train'"` + +#### VS Code setup +- TODO diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..9fa9614 --- /dev/null +++ b/setup.py @@ -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(), +)