diff --git a/README.md b/README.md index c276dba..3fe541c 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # Hackathon template -A convenient starting template for most deep learning projects. Built with PyTorch Lightning and Weights&Biases (wandb). - +A convenient starting template for most deep learning projects. Built with PyTorch Lightning and Weights&Biases. +
## Setup Read [SETUP.md](SETUP.md) - +
## Project structure The directory structure of new project looks like this: @@ -37,7 +37,7 @@ The directory structure of new project looks like this: ├── README.md └── requirements.txt ``` - +
## Config parameters explanation #### [config.yaml](project/config.yaml): @@ -84,7 +84,7 @@ printing: profiler: False <- True will print mean execution time of all methods at the end of the training ``` - +
## Tips -See [USEFUL_TIPS.md](USEFUL_TIPS.md) +Read [TIPS.md](TIPS.md) diff --git a/USEFUL_TIPS.md b/TIPS.md similarity index 100% rename from USEFUL_TIPS.md rename to TIPS.md diff --git a/project/config.yaml b/project/config.yaml index 3ee2b4a..234c171 100644 --- a/project/config.yaml +++ b/project/config.yaml @@ -1,48 +1,66 @@ num_of_gpus: -1 -models: - simple_mnist_classifier: - hparams: - max_epochs: 3 - lr: 0.001 - weight_decay: 0.000001 - gradient_clip_val: 0.5 - accumulate_grad_batches: 1 - input_size: 784 # img size is 28*28*1 - output_size: 10 - lin1_size: 256 - lin2_size: 256 - lin3_size: 128 - datasets: - MNISTDataModule: - batch_size: 64 - train_val_split_ratio: 0.9 - num_workers: 1 - pin_memory: False +model_configs: + simple_mnist_classifier_v1: + max_epochs: 3 + lr: 0.001 + weight_decay: 0.000001 + gradient_clip_val: 0.5 + accumulate_grad_batches: 1 + input_size: 784 # img size is 28*28*1 + output_size: 10 + lin1_size: 256 + lin2_size: 256 + lin3_size: 128 - transfer_learning_img_classifier: - hparams: - max_epochs: 3 - lr: 0.001 - weight_decay: 0.000001 - gradient_clip_val: 0.5 - accumulate_grad_batches: 1 - output_size: 10 - lin1_size: 256 - lin2_size: 256 - datasets: - CIFAR10DataModule: - batch_size: 64 - train_val_split_ratio: 0.9 - num_workers: 1 - pin_memory: False + simple_mnist_classifier_v2: + max_epochs: 10 + lr: 0.0005 + weight_decay: 0.0001 + gradient_clip_val: 0.5 + accumulate_grad_batches: 1 + input_size: 784 + output_size: 10 + lin1_size: 256 + lin2_size: 256 + lin3_size: 128 + + transfer_learning_img_classifier_v1: + max_epochs: 5 + lr: 0.001 + weight_decay: 0.000001 + gradient_clip_val: 0.5 + accumulate_grad_batches: 1 + output_size: 10 + lin1_size: 512 + lin2_size: 256 + + +dataset_configs: + mnist_digits_v1: + batch_size: 64 + train_val_split_ratio: 0.8 + num_workers: 1 + pin_memory: False + + mnist_digits_v2: + batch_size: 256 + train_val_split_ratio: 0.9 + num_workers: 4 + pin_memory: True + + cifar10_v1: + batch_size: 64 + train_val_split_ratio: 0.9 + num_workers: 1 + pin_memory: False resume_training: lightning_ckpt: resume_from_ckpt: False - ckpt_path: "checkpoints/epoch=2.ckpt" + ckpt_path: "logs/checkpoints/epoch=2.ckpt" wandb: resume_wandb_run: False wandb_run_id: "8uuomodb" diff --git a/project/execute_sweep.py b/project/execute_sweep.py index b49a992..171cdad 100644 --- a/project/execute_sweep.py +++ b/project/execute_sweep.py @@ -1,18 +1,20 @@ -import wandb -import train +# import wandb +# import train +# +# +# # Load project config +# config = train.load_config() +# +# # Initialize wandb +# wandb.init() +# +# # Replace project config hyperparameters with the ones loaded from wandb sweep server +# sweep_hparams = wandb.Config._as_dict(wandb.config) +# for key, value in sweep_hparams.items(): +# if key != "_wandb": +# config["hparams"][key] = value +# +# # Execute run +# train.train(config) - -# Load project config -config = train.load_config() - -# Initialize wandb -wandb.init() - -# Replace project config hyperparameters with the ones loaded from wandb sweep server -sweep_hparams = wandb.Config._as_dict(wandb.config) -for key, value in sweep_hparams.items(): - if key != "_wandb": - config["hparams"][key] = value - -# Execute run -train.train(config) +# TODO: this file diff --git a/project/train.py b/project/train.py index e960840..4109354 100644 --- a/project/train.py +++ b/project/train.py @@ -14,17 +14,18 @@ from models import transfer_learning_img_classifier def train(config): - # CHOOSE MODEL AND DATASET HERE!! + # --------------------------------- CHOOSE MODEL, DATASET AND CONFIGS HERE!! --------------------------------- # MODEL = simple_mnist_classifier DATASET = MNISTDataModule - MODEL_PARAMS = config["models"]["simple_mnist_classifier"]["hparams"] - DATASET_PARAMS = config["models"]["simple_mnist_classifier"]["datasets"]["MNISTDataModule"] + MODEL_CONFIG = config["model_configs"]["simple_mnist_classifier_v1"] + DATASET_CONFIG = config["dataset_configs"]["mnist_digits_v1"] + # ------------------------------------------------------------------------------------------------------------ # # Init model - lit_model = MODEL.LitModel(hparams=MODEL_PARAMS) + lit_model = MODEL.LitModel(hparams=MODEL_CONFIG) # Init data - datamodule = DATASET(**DATASET_PARAMS, transforms=MODEL.train_preprocess) + datamodule = DATASET(**DATASET_CONFIG, transforms=MODEL.train_preprocess) datamodule.prepare_data() datamodule.setup() @@ -61,9 +62,9 @@ def train(config): if config["resume_training"]["lightning_ckpt"]["resume_from_ckpt"] else None, # model related: - max_epochs=MODEL_PARAMS["max_epochs"], - accumulate_grad_batches=MODEL_PARAMS["accumulate_grad_batches"], - gradient_clip_val=MODEL_PARAMS["gradient_clip_val"], + max_epochs=MODEL_CONFIG["max_epochs"], + accumulate_grad_batches=MODEL_CONFIG["accumulate_grad_batches"], + gradient_clip_val=MODEL_CONFIG["gradient_clip_val"], # print related: progress_bar_refresh_rate=config["printing"]["progress_bar_refresh_rate"], diff --git a/project/training_modules/loggers.py b/project/training_modules/loggers.py index ba2196d..727e599 100644 --- a/project/training_modules/loggers.py +++ b/project/training_modules/loggers.py @@ -21,6 +21,7 @@ def get_wandb_logger(config, lit_model, datamodule): "model_name": lit_model.model.__class__.__name__, "parent_folder": os.path.basename(os.path.dirname((inspect.getfile(lit_model.__class__)))), "datamodule_name": datamodule.__class__.__name__, + "batch_size": datamodule.batch_size, "optimizer": lit_model.configure_optimizers().__class__.__name__, "train_size": len(datamodule.data_train) if datamodule.data_train is not None else 0, "val_size": len(datamodule.data_val) if datamodule.data_train is not None else 0,