clean up template

This commit is contained in:
hobogalaxy committed 2020-11-05 02:21:37 +01:00
1 parent 4abd0e2bc9
commit 8fd92337bc
5 files changed
+50 -56

No files matched your search

+19 -22
View File
@@ -1,28 +1,24 @@
max_epochs: 100
batch_size: 128
auto_scale_batch_size: False
learning_rate: 0.001
accumulate_grad_batches: 1
gradient_clip_val: 0.5
num_of_gpus: 1
model:
name: "ModelMNISTv1"
lin1_size: 128
lin2_size: 256
hparams:
max_epochs: 30
batch_size: 128
learning_rate: 0.001
accumulate_grad_batches: 1
gradient_clip_val: 0.5
num_of_gpus: 1
model:
lin1_size: 128
lin2_size: 256
lin3_size: 128
dataset:
use_val: True
val_size: 5_000
use_test: True
test_size: 10_000
resume:
resume_from_ckpt: False
ckpt_path: "logs/checkpoints/model-epoch=04-val_loss=3.85.ckpt"
dataset:
name: "MnistSuperpixelsDataModule"
use_validation_set: True
validation_set_size: 5_000
use_test_set: True
test_set_size: 10_000
use_augmentation: False
loggers:
wandb:
project: "hackathon_template_test"
@@ -34,9 +30,10 @@ loggers:
callbacks:
checkpoint:
monitor: "val_loss"
save_top_k: 3
save_top_k: 1
save_last: True
mode: "min"
early_stop:
monitor: "val_loss"
patience: 5
patience: 10
mode: "min"
+20 -18
View File
@@ -42,52 +42,54 @@ wandb_logger = WandbLogger(
offline=False
)
wandb_logger.watch(model.model, log='all')
wandb_logger.log_hyperparams({
"model_name": model.model.__class__.__name__,
"dataset_name": dataloader.__class__.__name__,
"optimizer": model.configure_optimizers().__class__.__name__,
})
# Init callbacks
callbacks = [
ExampleCallback(),
# ExampleCallback(),
EarlyStopping(
monitor=config["callbacks"]["early_stop"]["monitor"],
patience=config["callbacks"]["early_stop"]["patience"],
mode=config["callbacks"]["early_stop"]["mode"],
verbose=False
),
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"],
verbose=False
)
]
checkpoint_callback = ModelCheckpoint(
monitor=config["callbacks"]["checkpoint"]["monitor"],
save_top_k=config["callbacks"]["checkpoint"]["save_top_k"],
mode=config["callbacks"]["checkpoint"]["mode"]
)
# Init trainer
trainer = pl.Trainer(
gpus=config["num_of_gpus"],
max_epochs=config["max_epochs"],
gpus=config["hparams"]["num_of_gpus"],
max_epochs=config["hparams"]["max_epochs"],
logger=wandb_logger,
callbacks=callbacks,
checkpoint_callback=checkpoint_callback,
resume_from_checkpoint=config["resume"]["ckpt_path"] if config["resume"]["resume_from_ckpt"] else None,
auto_scale_batch_size='power' if config["auto_scale_batch_size"] else False,
accumulate_grad_batches=config["accumulate_grad_batches"],
gradient_clip_val=config["gradient_clip_val"],
progress_bar_refresh_rate=1,
accumulate_grad_batches=config["hparams"]["accumulate_grad_batches"],
gradient_clip_val=config["hparams"]["gradient_clip_val"],
progress_bar_refresh_rate=50,
profiler=SimpleProfiler(),
weights_summary='full',
# fast_dev_run=True,
# limit_train_batches=0.01
# limit_val_batches=0.01
# limit_test_batches=0.01
# auto_scale_batch_size="power",
# min_epochs=10,
# amp_backend='apex',
# precision=16,
)
# Tune trainer (finds biggest possible batch size if enabled)
if config["auto_scale_batch_size"]:
trainer.tune(model=model, datamodule=dataloader)
# Train the model ⚡
trainer.fit(model=model, datamodule=dataloader)
+3 -7
View File
@@ -27,13 +27,9 @@ class MNISTDataModule(pl.LightningDataModule):
MNIST(self.data_dir, train=False, download=True)
def setup(self, stage=None):
# we set up only relevant datasets when stage is specified (automatically set by Pytorch-Lightning)
if stage == 'fit' or stage is None:
mnist_train = MNIST(self.data_dir, train=True, transform=self.transform)
self.data_train, self.data_val = random_split(mnist_train, [55000, 5000])
if stage == 'test' or stage is None:
self.data_test = MNIST(self.data_dir, train=False, transform=self.transform)
mnist_train = MNIST(self.data_dir, train=True, transform=self.transform)
self.data_train, self.data_val = random_split(mnist_train, [55000, 5000])
self.data_test = MNIST(self.data_dir, train=False, transform=self.transform)
def train_dataloader(self):
return DataLoader(self.data_train, batch_size=self.batch_size)
+1 -2
View File
@@ -15,9 +15,8 @@ class LitModel(pl.LightningModule):
def __init__(self, config):
super().__init__()
self.save_hyperparameters(config)
self.save_hyperparameters(config["hparams"])
self.model = ModelMNISTv1(config=self.hparams.model)
# self.model = ModelMNISTv2(config=self.hparams.model)
def forward(self, data):
return self.model(data)
+7 -7
View File
@@ -8,9 +8,9 @@ class ModelMNISTv1(nn.Module):
super().__init__()
# mnist images are (1, 28, 28) (channels, width, height)
self.layer_1 = nn.Linear(28 * 28, 128)
self.layer_2 = nn.Linear(128, 256)
self.layer_3 = nn.Linear(256, 10)
self.layer_1 = nn.Linear(28 * 28, config["lin1_size"])
self.layer_2 = nn.Linear(config["lin1_size"], config["lin2_size"])
self.layer_3 = nn.Linear(config["lin2_size"], 10)
def forward(self, x):
batch_size, channels, width, height = x.size()
@@ -32,10 +32,10 @@ class ModelMNISTv2(nn.Module):
super().__init__()
# mnist images are (1, 28, 28) (channels, width, height)
self.layer_1 = nn.Linear(28 * 28, 256)
self.layer_2 = nn.Linear(256, 128)
self.layer_3 = nn.Linear(128, 64)
self.layer_4 = nn.Linear(64, 10)
self.layer_1 = nn.Linear(28 * 28, config["lin1_size"])
self.layer_2 = nn.Linear(config["lin1_size"], config["lin2_size"])
self.layer_3 = nn.Linear(config["lin2_size"], config["lin3_size"])
self.layer_4 = nn.Linear(config["lin3_size"], 10)
def forward(self, x):
batch_size, channels, width, height = x.size()