this is slowly becoming actually useful
This commit is contained in:
1 parent
d518ddb63d
commit
8628600ea3
15 files changed
+190
-176
No files matched your search
+29
-45
@@ -1,56 +1,31 @@
|
||||
from pytorch_lightning.callbacks import ModelCheckpoint, EarlyStopping
|
||||
from pytorch_lightning.profiler import SimpleProfiler
|
||||
import yaml
|
||||
|
||||
# training modules
|
||||
from training_modules.datamodules import *
|
||||
from training_modules.callbacks import *
|
||||
from training_modules.loggers import *
|
||||
|
||||
# custom models
|
||||
from models import simple_mnist_classifier
|
||||
from models import transfer_learning_img_classifier
|
||||
# lightning modules
|
||||
from lightning_modules.init_utils import *
|
||||
from lightning_modules.callbacks import *
|
||||
|
||||
|
||||
def train(config):
|
||||
def train(config, model_config):
|
||||
|
||||
# --------------------------------- CHOOSE MODEL, DATASET AND CONFIGS HERE!! --------------------------------- #
|
||||
MODEL = simple_mnist_classifier
|
||||
DATASET = MNISTDataModule
|
||||
MODEL_CONFIG = config["model_configs"]["simple_mnist_classifier_v1"]
|
||||
DATASET_CONFIG = config["dataset_configs"]["mnist_digits_v1"]
|
||||
# ------------------------------------------------------------------------------------------------------------ #
|
||||
# Init lightning model
|
||||
lit_model = init_lit_model(model_config)
|
||||
|
||||
# Init model
|
||||
lit_model = MODEL.LitModel(hparams=MODEL_CONFIG)
|
||||
|
||||
# Init data
|
||||
datamodule = DATASET(**DATASET_CONFIG, transforms=MODEL.train_preprocess)
|
||||
datamodule.prepare_data()
|
||||
datamodule.setup()
|
||||
# Init lightning datamodule
|
||||
datamodule = init_datamodule(model_config)
|
||||
|
||||
# Init logger
|
||||
logger = get_wandb_logger(config, lit_model, datamodule)
|
||||
logger = init_wandb_logger(config, lit_model, datamodule)
|
||||
|
||||
# Init callbacks
|
||||
callbacks = [
|
||||
EarlyStopping(
|
||||
monitor=config["callbacks"]["early_stop"]["monitor"],
|
||||
patience=config["callbacks"]["early_stop"]["patience"],
|
||||
mode=config["callbacks"]["early_stop"]["mode"],
|
||||
),
|
||||
ModelCheckpoint(
|
||||
monitor=config["callbacks"]["checkpoint"]["monitor"],
|
||||
save_top_k=config["callbacks"]["checkpoint"]["save_top_k"],
|
||||
mode=config["callbacks"]["checkpoint"]["mode"],
|
||||
save_last=config["callbacks"]["checkpoint"]["save_last"],
|
||||
),
|
||||
callbacks = init_main_callbacks(config)
|
||||
callbacks.extend([
|
||||
# MetricsHeatmapLoggerCallback(),
|
||||
# UnfreezeModelCallback(wait_epochs=5),
|
||||
# ImagePredictionLoggerCallback(datamodule=datamodule),
|
||||
SaveCodeToWandbCallback(wandb_save_dir=logger.save_dir, model=MODEL),
|
||||
SaveCodeToWandbCallback(wandb_save_dir=logger.save_dir, lit_model=lit_model),
|
||||
# SaveOnnxModelToWandbCallback(datamodule=datamodule, save_dir=logger.save_dir)
|
||||
]
|
||||
])
|
||||
|
||||
# Init trainer
|
||||
trainer = pl.Trainer(
|
||||
@@ -62,16 +37,16 @@ def train(config):
|
||||
if config["resume_training"]["lightning_ckpt"]["resume_from_ckpt"] else None,
|
||||
|
||||
# model related:
|
||||
max_epochs=MODEL_CONFIG["max_epochs"],
|
||||
accumulate_grad_batches=MODEL_CONFIG["accumulate_grad_batches"],
|
||||
gradient_clip_val=MODEL_CONFIG["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"],
|
||||
profiler=SimpleProfiler() if config["printing"]["profiler"] else None,
|
||||
weights_summary=config["printing"]["weights_summary"],
|
||||
|
||||
# these are mostly for debugging:
|
||||
# these are mostly for debugging (read TIPS.md for explanation):
|
||||
fast_dev_run=False,
|
||||
num_sanity_val_steps=3,
|
||||
limit_train_batches=1.0,
|
||||
@@ -83,9 +58,9 @@ def train(config):
|
||||
)
|
||||
|
||||
# Test before training
|
||||
# trainer.test(model=model, datamodule=datamodule)
|
||||
# trainer.test(model=lit_model, datamodule=datamodule)
|
||||
|
||||
# Save randomly initialized model
|
||||
# Save checkpoint
|
||||
# trainer.save_checkpoint("random.ckpt")
|
||||
|
||||
# Train the model ⚡
|
||||
@@ -102,4 +77,13 @@ def load_config():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
train(config=load_config())
|
||||
conf = load_config()
|
||||
|
||||
# --------------------------------------- CHOOSE YOUR MODEL HEREEE ↓↓↓ --------------------------------------- #
|
||||
|
||||
model_conf = conf["model_configs"]["simple_mnist_classifier_v1"]
|
||||
# model_conf = conf["model_configs"]["transfer_learning_cifar10_classifier_v1"]
|
||||
|
||||
# --------------------------------------- CHOOSE YOUR MODEL HEREEE ↑↑↑ --------------------------------------- #
|
||||
|
||||
train(config=conf, model_config=model_conf)
|
||||
Reference in new issue
Block a user