diff --git a/README.md b/README.md
index 32551c7..22247af 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ Click on "Use this template" button above to initialize new repository.
-## Project config parameters ([project_config.yaml](project/project_config.yaml))
+## Project config parameters ([project_config.yaml](project_config.yaml))
Example project configuration:
```yaml
num_of_gpus: -1 <- '-1' to train on all GPUs available, '0' to train on CPU
@@ -151,7 +151,7 @@ Every parameter specified in datamodule hparams section will be passed to your d
- specify path to your model class
- specify path to your datamodule class
- you can add there any hyperparameters you want!
-3. Configure your project in [project_config.yaml](project/project_config.yaml)
+3. Configure your project in [project_config.yaml](project_config.yaml)
4. Run training with chosen run config
```bash
python train.py --run_config SIMPLE_CONFIG_EXAMPLE_MNIST
diff --git a/project/configs/callbacks_configs/mnist_callbacks.yaml b/project/configs/callbacks_configs/mnist_callbacks.yaml
deleted file mode 100644
index f86281f..0000000
--- a/project/configs/callbacks_configs/mnist_callbacks.yaml
+++ /dev/null
@@ -1,16 +0,0 @@
-EarlyStopping: # name of PyTorch Lightning class for early stopping callback
- monitor: "val_acc"
- patience: 5
- mode: "max"
-
-ModelCheckpoint: # name of PyTorch Lightning class for checkpointing callback
- monitor: "val_acc"
- save_top_k: 1
- save_last: True
- mode: "max"
-
-ConfusionMatrixWandbLoggerCallback: # some custom callback class from template_utils/wandb_callbacks.py
- class_names: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
-
-MetricsHeatmapWandbLoggerCallback: # some custom callback class from template_utils/wandb_callbacks.py
- class_names: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
diff --git a/project/configs/experiment_configs/mnist_experiments/mnist_classifier_advanced_conf.yaml b/project/configs/experiment_configs/mnist_experiments/advanced_conf.yaml
similarity index 83%
rename from project/configs/experiment_configs/mnist_experiments/mnist_classifier_advanced_conf.yaml
rename to project/configs/experiment_configs/mnist_experiments/advanced_conf.yaml
index 9aa548c..6e564d8 100644
--- a/project/configs/experiment_configs/mnist_experiments/mnist_classifier_advanced_conf.yaml
+++ b/project/configs/experiment_configs/mnist_experiments/advanced_conf.yaml
@@ -1,10 +1,17 @@
# to execute this experiment run:
-# python train.py --exp_conf configs/experiment_configs/mnist_experiments/mnist_classifier_advanced_conf.yaml
+# python train.py --exp_conf configs/experiment/mnist_experiments/advanced_conf.yaml
+
+
+# (optional section)
+# pytorch seed for this experiment
+# it also affects random_split() method used in mnist_datamodule.py
+# overwrites default pytorch seed set in project_config.yaml
+seed: 1234
# (required section)
trainer_args:
min_epochs: 1 # train for at least this many epochs (denies early stopping)
- max_epochs: 10
+ max_epochs: 10 # train for maximum this many epochs
gradient_clip_val: 0.5 # gradient clipping (helps with exploding gradient issues)
accumulate_grad_batches: 2 # perform optimization step after accumulating gradient from 2 batches
fast_dev_run: False # execute 1 training, 1 validation and 1 test epoch only
@@ -38,13 +45,6 @@ datamodule:
num_workers: 1 # num of processes used for loading data in parallel
pin_memory: False # dataloaders will copy tensors into CUDA pinned memory before returning them
-# (optional section)
-# pytorch seed for this experiment
-# it also affects random_split() method used in mnist_datamodule.py
-# overwrites default pytorch seed set in project_config.yaml
-pytorch_seed:
- use_seed: True
- pytorch_seed: 1234
# (optional section)
# Weights&Biases logger args
@@ -55,10 +55,6 @@ wandb_args:
tags: ["v2", "uwu"]
notes: "This is example run."
-# (optional section)
-# path to .yaml file containing configurations of all callbacks which will be used for this experiment
-# this will be combained with default callbacks set in project_config.yaml (overwrites repeating callbacks)
-callbacks_configs_path: "configs/callbacks_configs/mnist_callabcks.yaml"
# (optional section)
# use this if you want to resume training from checkpoint
diff --git a/project/configs/experiment_configs/mnist_experiments/mnist_classifier_simple_conf.yaml b/project/configs/experiment_configs/mnist_experiments/mnist_classifier_simple_conf.yaml
deleted file mode 100644
index 4073603..0000000
--- a/project/configs/experiment_configs/mnist_experiments/mnist_classifier_simple_conf.yaml
+++ /dev/null
@@ -1,26 +0,0 @@
-# to execute this experiment run:
-# python train.py --exp_conf configs/experiment_configs/mnist_experiments/mnist_classifier_simple_conf.yaml
-
-trainer_args:
- max_epochs: 10
-
-model:
- load_from:
- model_path: "pytorch_modules/lightning_models/simple_mnist_classifier.py"
- model_class: "LitModel"
- hparams:
- lr: 0.001
- weight_decay: 0.00001
- input_size: 784
- output_size: 10
- lin1_size: 256
- lin2_size: 256
- lin3_size: 128
-
-datamodule:
- load_from:
- datamodule_path: "lightning_datamodules/mnist_datamodule/mnist_datamodule.py"
- datamodule_class: "MNISTDataModule"
- hparams:
- batch_size: 64
- train_val_test_split: [55_000, 5_000, 10_000]
diff --git a/project/configs/experiment_configs/mnist_experiments/simple_conf.yaml b/project/configs/experiment_configs/mnist_experiments/simple_conf.yaml
new file mode 100644
index 0000000..45fad18
--- /dev/null
+++ b/project/configs/experiment_configs/mnist_experiments/simple_conf.yaml
@@ -0,0 +1,25 @@
+# to execute this experiment run:
+# python train.py --exp_conf configs/experiment/mnist_experiments/simple_conf.yaml
+
+
+seed: 1234
+
+trainer_args:
+ max_epochs: 10
+
+model:
+ class: "pytorch_modules.lightning_models.simple_mnist_classifier.LitModel"
+ hparams:
+ lr: 0.001
+ weight_decay: 0.00001
+ input_size: 784
+ output_size: 10
+ lin1_size: 256
+ lin2_size: 256
+ lin3_size: 128
+
+datamodule:
+ class: "lightning_datamodules.mnist_datamodule.mnist_datamodule.MNISTDataModule"
+ hparams:
+ batch_size: 64
+ train_val_test_split: [55_000, 5_000, 10_000]
diff --git a/project/configs/project_config.yaml b/project/configs/project_config.yaml
new file mode 100644
index 0000000..4666265
--- /dev/null
+++ b/project/configs/project_config.yaml
@@ -0,0 +1,14 @@
+defaults:
+ - project_config/trainer: default_trainer
+# - model: simple_mnist_classifier
+# - datamodule: mnist_datamodule
+# - logger: comet
+# - callbacks: mnist_callbacks
+
+
+# path to data folder (either absolute or relative to placement of 'train.py' file)
+data_dir: "data/"
+
+
+# path to logs folder (either absolute or relative to placement of 'train.py' file)
+logs_dir: "logs/"
diff --git a/project/configs/project_config/callbacks/mnist_callbacks.yaml b/project/configs/project_config/callbacks/mnist_callbacks.yaml
new file mode 100644
index 0000000..c36fa30
--- /dev/null
+++ b/project/configs/project_config/callbacks/mnist_callbacks.yaml
@@ -0,0 +1,17 @@
+# @package _group_
+
+model_checkpoint:
+ class: "pytorch_lightning.callbacks.ModelCheckpoint"
+ args:
+ monitor: "val_acc" # name of the logged metric which determines when model is improving
+ save_top_k: 1 # save k best lightning_models (determined by above metric)
+ save_last: True # additionaly always save model from last epoch
+ mode: "max" # can be "max" or "min"
+
+
+early_stopping:
+ class: "pytorch_lightning.callbacks.EarlyStopping"
+ args:
+ monitor: "val_acc" # name of the logged metric which determines when model is improving
+ patience: 5 # how many epochs of not improving until training stops
+ mode: "max" # can be "max" or "min"
diff --git a/project/configs/project_config/datamodule/mnist_datamodule.yaml b/project/configs/project_config/datamodule/mnist_datamodule.yaml
new file mode 100644
index 0000000..d0ec339
--- /dev/null
+++ b/project/configs/project_config/datamodule/mnist_datamodule.yaml
@@ -0,0 +1,12 @@
+# @package _group_
+
+class: "pytorch_modules.lightning_datamodules.mnist_datamodule.MNISTDataModule"
+
+hparams:
+ 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/project_config/logger/comet.yaml b/project/configs/project_config/logger/comet.yaml
new file mode 100644
index 0000000..83182f2
--- /dev/null
+++ b/project/configs/project_config/logger/comet.yaml
@@ -0,0 +1,10 @@
+# @package _group_
+# Comet logger config
+
+args:
+ api_key: "sadfhgadfhsdfhadgkajdgsdg"
+ project_name: "project_template_test"
+
+extra_options:
+ log_optimizer_name: True
+ log_train_val_test_sizes: True
diff --git a/project/configs/project_config/logger/tensorboard.yaml b/project/configs/project_config/logger/tensorboard.yaml
new file mode 100644
index 0000000..ad67a99
--- /dev/null
+++ b/project/configs/project_config/logger/tensorboard.yaml
@@ -0,0 +1,5 @@
+# Tensorboard logger config
+
+args: {}
+
+extra_options: {}
diff --git a/project/configs/project_config/logger/wandb.yaml b/project/configs/project_config/logger/wandb.yaml
new file mode 100644
index 0000000..ec03aec
--- /dev/null
+++ b/project/configs/project_config/logger/wandb.yaml
@@ -0,0 +1,12 @@
+# Weights&Biases logger config
+
+args:
+ project: "project_template_test"
+ entity: "" # change to your username or name of your team on wandb
+ log_model: True # set True to automatically upload model checkpoint to wandb cloud after training
+ offline: False # set True to store all logs only locally
+
+extra_options:
+ log_gradients: False # set True to log gradient histograms (avoid this for very big lightning_models)
+ log_optimizer_name: True
+ log_train_val_test_sizes: True
diff --git a/project/configs/project_config/model/simple_mnist_classifier.yaml b/project/configs/project_config/model/simple_mnist_classifier.yaml
new file mode 100644
index 0000000..f2c3453
--- /dev/null
+++ b/project/configs/project_config/model/simple_mnist_classifier.yaml
@@ -0,0 +1,12 @@
+# @package _group_
+
+class: "pytorch_modules.lightning_models.simple_mnist_classifier.LitModel"
+
+hparams:
+ 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/project_config/trainer/default_trainer.yaml b/project/configs/project_config/trainer/default_trainer.yaml
new file mode 100644
index 0000000..8b0487a
--- /dev/null
+++ b/project/configs/project_config/trainer/default_trainer.yaml
@@ -0,0 +1,13 @@
+# @package _group_
+
+# args passed to Lightning Trainer on every experiment
+# they will be combined with trainer args specified in experiment config
+# (if the argument repeats in experiment config, then it will override the one set here)
+args:
+ num_of_gpus: -1 # set -1 to train on all GPUs abailable, set 0 to train on CPU only
+ auto_select_gpus: True
+ num_sanity_val_steps: 3
+ progress_bar_refresh_rate: 10
+ weights_summary: "top"
+ max_epochs: 100
+ profiler: "simple" # use profiler to print execution time profiling after training ends
diff --git a/project/project_config.yaml b/project/project_config.yaml
deleted file mode 100644
index 70192c4..0000000
--- a/project/project_config.yaml
+++ /dev/null
@@ -1,66 +0,0 @@
-# default args passed to Lightning Trainer on every run/experiment
-# if you specify the same args in experiment config then they will overwrite the ones set here
-default_trainer_args:
- num_of_gpus: 0 # set -1 to train on all GPUs abailable, set 0 to train on CPU only
- progress_bar_refresh_rate: 10 # refresh terminal every 10 batches
- weights_summary: "top" # print model summary (alternatively "full")
-
-
-# default pytorch seed used on every run/experiment
-# this can be overwritten by
-default_pytorch_seed:
- use_seed: True
- pytorch_seed: 1234
-
-
-# default loggers initialised on every run/experiment
-# if you specify this section in experiment config then it will be totally overwritten
-default_loggers:
- wandb: # Weights&Biases config (just remove this section if you don't want tu ever use Weights&Biases)
- use_wandb: True
- log_gradients: False # set True to log gradient histograms (avoid this for very big lightning_models)
- log_optimizer_name: True
- log_train_val_test_data_lengths: True
- default_args:
- project: "project_template_test"
- entity: "kino" # change to your username or name of your team on wandb
- log_model: True # set True to automatically upload model checkpoint to wandb cloud after training
- offline: False # set True to store all logs only locally
- tensorboard:
- use_tensorboard: False
- default_args: {}
-
-
-# default lightning_callbacks initialised on every run/experiment
-# you can just remove this section or certain callback if you don't want tu use it
-# if you specify the same callback class also in experiment config then it will overwrite the one set here
-# all of the callback parameters will be passed to it on initialization
-default_callbacks:
- chekpointing:
- class: "pytorch_lightning.callbacks.ModelCheckpoint"
- args:
- monitor: "val_acc" # name of the logged metric which determines when model is improving
- save_top_k: 1 # save k best lightning_models (determined by above metric)
- save_last: True # additionaly always save model from last epoch
- mode: "max" # can be "max" or "min"
- early_stopping:
- class: "pytorch_lightning.callbacks.EarlyStopping"
- args:
- monitor: "val_acc" # name of the logged metric which determines when model is improving
- patience: 5 # how many epochs of not improving until training stops
- mode: "max" # can be "max" or "min"
-
-
-# use profiler to print execution time profiling after training ends
-profiler:
- use_profiler: True
- class: "pytorch_lightning.profiler.SimpleProfiler"
- args: {}
-
-
-# path to data folder (either absolute or relative to placement of 'train.py' file)
-data_dir: "data/"
-
-
-# path to logs folder (either absolute or relative to placement of 'train.py' file)
-logs_dir: "logs/"
diff --git a/project/pytorch_modules/lightning_datamodules/mnist_datamodule.py b/project/pytorch_modules/lightning_datamodules/mnist_datamodule.py
index 3470394..6978c53 100644
--- a/project/pytorch_modules/lightning_datamodules/mnist_datamodule.py
+++ b/project/pytorch_modules/lightning_datamodules/mnist_datamodule.py
@@ -10,6 +10,9 @@ class MNISTDataModule(LightningDataModule):
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)
+
+ To learn how to create datamodules visit:
+ https://pytorch-lightning.readthedocs.io/en/latest/datamodules.html
"""
def __init__(self, data_dir: str, hparams: dict):
diff --git a/project/pytorch_modules/lightning_models/simple_mnist_classifier.py b/project/pytorch_modules/lightning_models/simple_mnist_classifier.py
index 27960d2..746ac64 100644
--- a/project/pytorch_modules/lightning_models/simple_mnist_classifier.py
+++ b/project/pytorch_modules/lightning_models/simple_mnist_classifier.py
@@ -3,8 +3,8 @@ import pytorch_lightning as pl
import torch.nn.functional as F
import torch
-# import custom lightning_models
-from pytorch_modules.lightning_models.simple_mnist_classifier.models import *
+# import custom architectures
+from pytorch_modules.architectures.simple_mnist import SimpleMNISTClassifier
class LitModel(pl.LightningModule):
@@ -16,6 +16,9 @@ class LitModel(pl.LightningModule):
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.
+
+ To learn how to create lightning models visit:
+ https://pytorch-lightning.readthedocs.io/en/latest/lightning_module.html
"""
def __init__(self, hparams: dict = None):
diff --git a/project/template_utils/initializers.py b/project/template_utils/initializers.py
index 22d29e3..43e182e 100644
--- a/project/template_utils/initializers.py
+++ b/project/template_utils/initializers.py
@@ -1,5 +1,5 @@
# pytorch lightning imports
-from pytorch_lightning.loggers import WandbLogger
+from pytorch_lightning.loggers import WandbLogger, CometLogger
from pytorch_lightning.profiler import SimpleProfiler
import pytorch_lightning as pl
@@ -287,3 +287,11 @@ def init_tensorboard_logger() -> pl.loggers.TensorBoardLogger:
"""Initialize tensorboard logger"""
# TODO
return None
+
+
+def init_comet_logger(project_config: dict,
+ run_config: dict,
+ model: pl.LightningModule,
+ datamodule: pl.LightningDataModule) -> pl.loggers.CometLogger:
+
+ comet_logger = CometLogger()
diff --git a/project/inference/predict_example.py b/project/template_utils/predict_example.py
similarity index 100%
rename from project/inference/predict_example.py
rename to project/template_utils/predict_example.py
diff --git a/project_config.yaml b/project_config.yaml
new file mode 100644
index 0000000..ef8f9c6
--- /dev/null
+++ b/project_config.yaml
@@ -0,0 +1,54 @@
+# default args passed to Lightning Trainer on every run/experiment
+# they will be combined with trainer args specified in experiment config
+default_args:
+ num_of_gpus: -1 # set -1 to train on all GPUs abailable, set 0 to train on CPU only
+ auto_select_gpus: True
+ num_sanity_val_steps: 3
+ progress_bar_refresh_rate: 10 # refresh terminal every 10 batches
+ weights_summary: "top" # print model summary before training starts (alternatively "full")
+
+
+# use profiler to print execution time profiling after training ends
+profiler:
+ use_profiler: True
+ class: "pytorch_lightning.profiler.SimpleProfiler"
+ args: {}
+
+
+loggers:
+
+ # Comet logger config
+ comet:
+ use_comet: True
+ default_args:
+ api_key: "sadfhgadfhsdfhadgkajdgsdg"
+ project_name: "project_template_test"
+ extra_options:
+ log_optimizer_name: True
+ log_train_val_test_sizes: True
+
+ # Weights&Biases logger config
+ wandb:
+ use_wandb: False
+ default_args:
+ project: "project_template_test"
+ entity: "" # change to your username or name of your team on wandb
+ log_model: True # set True to automatically upload model checkpoint to wandb cloud after training
+ offline: False # set True to store all logs only locally
+ extra_options:
+ log_gradients: False # set True to log gradient histograms (avoid this for very big lightning_models)
+ log_optimizer_name: True
+ log_train_val_test_sizes: True
+
+ # Tensorboard logger config
+ tensorboard:
+ use_tensorboard: False
+ default_args: {}
+
+
+# path to data folder (either absolute or relative to placement of 'train.py' file)
+data_dir: "data/"
+
+
+# path to logs folder (either absolute or relative to placement of 'train.py' file)
+logs_dir: "logs/"