From 5ff284ec42baccf2913bd961ecfe2d702350679f Mon Sep 17 00:00:00 2001 From: hobogalaxy Date: Thu, 14 Jan 2021 20:04:54 +0100 Subject: [PATCH] small improvements --- README.md | 11 +++--- .../configs/callbacks/mnist_callbacks.yaml | 12 ++++++ .../configs/callbacks/wandb_callbacks.yaml | 37 ++++++++++--------- project/configs/config.yaml | 7 +--- project/configs/model/mnist_model.yaml | 3 -- project/configs/trainer/debug_trainer.yaml | 6 ++- project/configs/trainer/default_trainer.yaml | 6 ++- 7 files changed, 48 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 10950f6..fd2de5d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ ## Deep learning project template -This is my starting template and pipeline for most deep learning projects 🔥
+This is my starting template and pipeline for most deep learning projects.
Built with PyTorch Lightning, Hydra and Weights&Biases.
It's supposed to be enchancement/expansion on original [deep-learninig-project-template](https://github.com/PyTorchLightning/deep-learning-project-template) repository.
+ The goal is to: - structure ML code the same so that work can easily be extended and replicated - allow for quick and efficient experimentation process thanks to automating pipeline with config files @@ -72,7 +73,7 @@ The directory structure of new project looks like this: ├── LICENSE <- Project license ├── README.md <- Readme ├── conda_env.yaml <- File for installing conda environment -├── requirements.txt <- List of python dependencies +├── requirements.txt <- File for installing python dependencies └── setup.py <- File for installing project as a package ```
@@ -83,7 +84,7 @@ The directory structure of new project looks like this: # specify here default training configuration defaults: - trainer: default_trainer.yaml # choose trainer from 'configs/trainer/' folder - - model: mnist_model.yaml # choose model from 'configs/model/' folder + - model: mnist_model.yaml # choose model from 'configs/model/' folder - datamodule: mnist_datamodule.yaml # choose datamodule from 'configs/datamodule/' folder - optimizer: adam.yaml # choose optimizer from 'configs/optimizer/' folder - seeds: default_seeds.yaml # set this to null if you don't want to use seeds @@ -127,7 +128,7 @@ Example experiment configuration: ```yaml defaults: - override /trainer: default_trainer.yaml # choose trainer from 'configs/trainer/' - - override /model: mnist_model.yaml # choose model from 'configs/model/' + - override /model: mnist_model.yaml # choose model from 'configs/model/' - override /datamodule: mnist_datamodule.yaml # choose datamodule from 'configs/datamodule/' - override /optimizer: adam.yaml # choose optimizer from 'configs/optimizer/' - override /seeds: default_seeds.yaml # choose seeds from 'configs/seeds/' @@ -186,7 +187,7 @@ Logs are created automatically with the following structure: │ │ └── ... │ │ │ ├── multiruns # Folder for logs generated from sweeps -│ │ ├── 2021-02-15_16-50-49 # Date and hour of executing run +│ │ ├── 2021-02-15_16-50-49 # Date and hour of executing sweep │ │ │ ├── 0 # Job number │ │ │ │ ├── .hydra # Hydra logs │ │ │ │ ├── wandb # Weights&Biases logs diff --git a/project/configs/callbacks/mnist_callbacks.yaml b/project/configs/callbacks/mnist_callbacks.yaml index 34e7b77..9060e0f 100644 --- a/project/configs/callbacks/mnist_callbacks.yaml +++ b/project/configs/callbacks/mnist_callbacks.yaml @@ -3,3 +3,15 @@ defaults: - default_callbacks.yaml - wandb_callbacks.yaml + + +save_confusion_matrix_to_wandb: + class: src.callbacks.wandb_callbacks.SaveConfusionMatrixToWandb + args: + class_names: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] + + +save_f1_precision_recall_heatmap_to_wandb: + class: src.callbacks.wandb_callbacks.SaveMetricsHeatmapToWandb + args: + class_names: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] diff --git a/project/configs/callbacks/wandb_callbacks.yaml b/project/configs/callbacks/wandb_callbacks.yaml index d9fbf88..6675c4b 100644 --- a/project/configs/callbacks/wandb_callbacks.yaml +++ b/project/configs/callbacks/wandb_callbacks.yaml @@ -1,31 +1,34 @@ # @package _group_ +defaults: + - default_callbacks.yaml + + save_best_metric_scores_to_wandb: class: src.callbacks.wandb_callbacks.SaveBestMetricScoresToWandb args: {} +upload_code_to_wandb_as_artifact: + class: src.callbacks.wandb_callbacks.SaveCodeToWandb + args: + code_dir: ${work_dir}/ + + +upload_ckpts_to_wandb_as_artifact: + class: src.callbacks.wandb_callbacks.UploadAllCheckpointsToWandb + args: + ckpt_dir: "checkpoints/" + upload_best_only: False + + #save_confusion_matrix_to_wandb: # class: src.callbacks.wandb_callbacks.SaveConfusionMatrixToWandb # args: # class_names: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] -# -# + + #save_f1_precision_recall_heatmap_to_wandb: # class: src.callbacks.wandb_callbacks.SaveMetricsHeatmapToWandb # args: -# class_names: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] - - -#upload_code_to_wandb_as_artifact: -# class: src.callbacks.wandb_callbacks.SaveCodeToWandb -# args: -# code_dir: ${work_dir}/ - - -#upload_ckpts_to_wandb_as_artifact: -# class: src.callbacks.wandb_callbacks.UploadAllCheckpointsToWandb -# args: -# ckpt_dir: "checkpoints/" -# upload_best_only: True - +# class_names: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] \ No newline at end of file diff --git a/project/configs/config.yaml b/project/configs/config.yaml index 86b95d4..f9a3122 100644 --- a/project/configs/config.yaml +++ b/project/configs/config.yaml @@ -9,8 +9,8 @@ defaults: - callbacks: default_callbacks.yaml # set this to null if you don't want to use callbacks - logger: null # set logger here or use command line (e.g. `python train.py logger=wandb`) - - override hydra/job_logging: colorlog - - override hydra/hydra_logging: colorlog +# - override hydra/job_logging: colorlog +# - override hydra/hydra_logging: colorlog # path to working directory (the directory that `train.py` was executed from in command line) work_dir: ${hydra:runtime.cwd} @@ -29,13 +29,10 @@ hydra: # extra things that are logged by all loggers as hyperparameters extra_logs: log_seeds: True - log_trainer_args: False log_datamodule_args: True - log_model_class: True log_optimizer_class: True log_datamodule_class: True log_model_architecture_class: True - log_train_val_test_sizes: False diff --git a/project/configs/model/mnist_model.yaml b/project/configs/model/mnist_model.yaml index 4d8f282..c276460 100644 --- a/project/configs/model/mnist_model.yaml +++ b/project/configs/model/mnist_model.yaml @@ -2,11 +2,8 @@ class: src.models.simple_mnist_classifier.LitModel args: - lr: 0.001 - weight_decay: 0.00001 input_size: 784 output_size: 10 lin1_size: 256 lin2_size: 256 lin3_size: 128 - diff --git a/project/configs/trainer/debug_trainer.yaml b/project/configs/trainer/debug_trainer.yaml index 8cfe1ed..c200895 100644 --- a/project/configs/trainer/debug_trainer.yaml +++ b/project/configs/trainer/debug_trainer.yaml @@ -2,8 +2,10 @@ # trainer args for debugging model args: - gpus: -1 # set -1 to train on all GPUs abailable, set 0 to train on CPU only - auto_select_gpus: True + gpus: 0 # set -1 to train on all GPUs abailable, set 0 to train on CPU only +# auto_select_gpus: True + + gradient_clip_val: 0.5 # fast_dev_run: True # bugged :( limit_train_batches: 1.0 diff --git a/project/configs/trainer/default_trainer.yaml b/project/configs/trainer/default_trainer.yaml index 80a2f39..257a95b 100644 --- a/project/configs/trainer/default_trainer.yaml +++ b/project/configs/trainer/default_trainer.yaml @@ -3,9 +3,11 @@ # default args passed to Lightning Trainer on every experiment # they can be combined or overwritten with args set in experiment config args: - gpus: -1 # set -1 to train on all GPUs available, set 0 to train on CPU only - auto_select_gpus: True + gpus: 0 # set -1 to train on all GPUs available, set 0 to train on CPU only +# auto_select_gpus: True + max_epochs: 10 + gradient_clip_val: 0.5 num_sanity_val_steps: 3 progress_bar_refresh_rate: 10 weights_summary: null # null in yaml represents python None value