now config makes even more sense!

This commit is contained in:
hobogalaxy committed 2020-11-24 15:52:06 +01:00
1 parent f1f9de8537
commit d518ddb63d
6 files changed
+69 -47

No files matched your search

+6 -6
View File
@@ -1,10 +1,10 @@
# Hackathon template # 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.
<br>
## Setup ## Setup
Read [SETUP.md](SETUP.md) Read [SETUP.md](SETUP.md)
<br>
## Project structure ## Project structure
The directory structure of new project looks like this: The directory structure of new project looks like this:
@@ -37,7 +37,7 @@ The directory structure of new project looks like this:
├── README.md ├── README.md
└── requirements.txt └── requirements.txt
``` ```
<br>
## Config parameters explanation ## Config parameters explanation
#### [config.yaml](project/config.yaml): #### [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 profiler: False <- True will print mean execution time of all methods at the end of the training
``` ```
<br>
## Tips ## Tips
See [USEFUL_TIPS.md](USEFUL_TIPS.md) Read [TIPS.md](TIPS.md)
View File
File renamed without changes.
+34 -16
View File
@@ -1,9 +1,8 @@
num_of_gpus: -1 num_of_gpus: -1
models: model_configs:
simple_mnist_classifier: simple_mnist_classifier_v1:
hparams:
max_epochs: 3 max_epochs: 3
lr: 0.001 lr: 0.001
weight_decay: 0.000001 weight_decay: 0.000001
@@ -14,25 +13,44 @@ models:
lin1_size: 256 lin1_size: 256
lin2_size: 256 lin2_size: 256
lin3_size: 128 lin3_size: 128
datasets:
MNISTDataModule:
batch_size: 64
train_val_split_ratio: 0.9
num_workers: 1
pin_memory: False
transfer_learning_img_classifier: simple_mnist_classifier_v2:
hparams: max_epochs: 10
max_epochs: 3 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 lr: 0.001
weight_decay: 0.000001 weight_decay: 0.000001
gradient_clip_val: 0.5 gradient_clip_val: 0.5
accumulate_grad_batches: 1 accumulate_grad_batches: 1
output_size: 10 output_size: 10
lin1_size: 256 lin1_size: 512
lin2_size: 256 lin2_size: 256
datasets:
CIFAR10DataModule:
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 batch_size: 64
train_val_split_ratio: 0.9 train_val_split_ratio: 0.9
num_workers: 1 num_workers: 1
@@ -42,7 +60,7 @@ models:
resume_training: resume_training:
lightning_ckpt: lightning_ckpt:
resume_from_ckpt: False resume_from_ckpt: False
ckpt_path: "checkpoints/epoch=2.ckpt" ckpt_path: "logs/checkpoints/epoch=2.ckpt"
wandb: wandb:
resume_wandb_run: False resume_wandb_run: False
wandb_run_id: "8uuomodb" wandb_run_id: "8uuomodb"
+19 -17
View File
@@ -1,18 +1,20 @@
import wandb # import wandb
import train # 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)
# TODO: this file
# 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)
+9 -8
View File
@@ -14,17 +14,18 @@ from models import transfer_learning_img_classifier
def train(config): def train(config):
# CHOOSE MODEL AND DATASET HERE!! # --------------------------------- CHOOSE MODEL, DATASET AND CONFIGS HERE!! --------------------------------- #
MODEL = simple_mnist_classifier MODEL = simple_mnist_classifier
DATASET = MNISTDataModule DATASET = MNISTDataModule
MODEL_PARAMS = config["models"]["simple_mnist_classifier"]["hparams"] MODEL_CONFIG = config["model_configs"]["simple_mnist_classifier_v1"]
DATASET_PARAMS = config["models"]["simple_mnist_classifier"]["datasets"]["MNISTDataModule"] DATASET_CONFIG = config["dataset_configs"]["mnist_digits_v1"]
# ------------------------------------------------------------------------------------------------------------ #
# Init model # Init model
lit_model = MODEL.LitModel(hparams=MODEL_PARAMS) lit_model = MODEL.LitModel(hparams=MODEL_CONFIG)
# Init data # Init data
datamodule = DATASET(**DATASET_PARAMS, transforms=MODEL.train_preprocess) datamodule = DATASET(**DATASET_CONFIG, transforms=MODEL.train_preprocess)
datamodule.prepare_data() datamodule.prepare_data()
datamodule.setup() datamodule.setup()
@@ -61,9 +62,9 @@ def train(config):
if config["resume_training"]["lightning_ckpt"]["resume_from_ckpt"] else None, if config["resume_training"]["lightning_ckpt"]["resume_from_ckpt"] else None,
# model related: # model related:
max_epochs=MODEL_PARAMS["max_epochs"], max_epochs=MODEL_CONFIG["max_epochs"],
accumulate_grad_batches=MODEL_PARAMS["accumulate_grad_batches"], accumulate_grad_batches=MODEL_CONFIG["accumulate_grad_batches"],
gradient_clip_val=MODEL_PARAMS["gradient_clip_val"], gradient_clip_val=MODEL_CONFIG["gradient_clip_val"],
# print related: # print related:
progress_bar_refresh_rate=config["printing"]["progress_bar_refresh_rate"], progress_bar_refresh_rate=config["printing"]["progress_bar_refresh_rate"],
+1
View File
@@ -21,6 +21,7 @@ def get_wandb_logger(config, lit_model, datamodule):
"model_name": lit_model.model.__class__.__name__, "model_name": lit_model.model.__class__.__name__,
"parent_folder": os.path.basename(os.path.dirname((inspect.getfile(lit_model.__class__)))), "parent_folder": os.path.basename(os.path.dirname((inspect.getfile(lit_model.__class__)))),
"datamodule_name": datamodule.__class__.__name__, "datamodule_name": datamodule.__class__.__name__,
"batch_size": datamodule.batch_size,
"optimizer": lit_model.configure_optimizers().__class__.__name__, "optimizer": lit_model.configure_optimizers().__class__.__name__,
"train_size": len(datamodule.data_train) if datamodule.data_train is not None else 0, "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, "val_size": len(datamodule.data_val) if datamodule.data_train is not None else 0,