clean up template
This commit is contained in:
1 parent
4abd0e2bc9
commit
8fd92337bc
5 files changed
+37
-43
No files matched your search
+11
-14
@@ -1,28 +1,24 @@
|
|||||||
max_epochs: 100
|
hparams:
|
||||||
|
max_epochs: 30
|
||||||
batch_size: 128
|
batch_size: 128
|
||||||
auto_scale_batch_size: False
|
|
||||||
learning_rate: 0.001
|
learning_rate: 0.001
|
||||||
accumulate_grad_batches: 1
|
accumulate_grad_batches: 1
|
||||||
gradient_clip_val: 0.5
|
gradient_clip_val: 0.5
|
||||||
num_of_gpus: 1
|
num_of_gpus: 1
|
||||||
|
|
||||||
model:
|
model:
|
||||||
name: "ModelMNISTv1"
|
|
||||||
lin1_size: 128
|
lin1_size: 128
|
||||||
lin2_size: 256
|
lin2_size: 256
|
||||||
|
lin3_size: 128
|
||||||
|
dataset:
|
||||||
|
use_val: True
|
||||||
|
val_size: 5_000
|
||||||
|
use_test: True
|
||||||
|
test_size: 10_000
|
||||||
|
|
||||||
resume:
|
resume:
|
||||||
resume_from_ckpt: False
|
resume_from_ckpt: False
|
||||||
ckpt_path: "logs/checkpoints/model-epoch=04-val_loss=3.85.ckpt"
|
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:
|
loggers:
|
||||||
wandb:
|
wandb:
|
||||||
project: "hackathon_template_test"
|
project: "hackathon_template_test"
|
||||||
@@ -34,9 +30,10 @@ loggers:
|
|||||||
callbacks:
|
callbacks:
|
||||||
checkpoint:
|
checkpoint:
|
||||||
monitor: "val_loss"
|
monitor: "val_loss"
|
||||||
save_top_k: 3
|
save_top_k: 1
|
||||||
|
save_last: True
|
||||||
mode: "min"
|
mode: "min"
|
||||||
early_stop:
|
early_stop:
|
||||||
monitor: "val_loss"
|
monitor: "val_loss"
|
||||||
patience: 5
|
patience: 10
|
||||||
mode: "min"
|
mode: "min"
|
||||||
@@ -42,52 +42,54 @@ wandb_logger = WandbLogger(
|
|||||||
offline=False
|
offline=False
|
||||||
)
|
)
|
||||||
wandb_logger.watch(model.model, log='all')
|
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
|
# Init callbacks
|
||||||
callbacks = [
|
callbacks = [
|
||||||
ExampleCallback(),
|
# ExampleCallback(),
|
||||||
EarlyStopping(
|
EarlyStopping(
|
||||||
monitor=config["callbacks"]["early_stop"]["monitor"],
|
monitor=config["callbacks"]["early_stop"]["monitor"],
|
||||||
patience=config["callbacks"]["early_stop"]["patience"],
|
patience=config["callbacks"]["early_stop"]["patience"],
|
||||||
mode=config["callbacks"]["early_stop"]["mode"],
|
mode=config["callbacks"]["early_stop"]["mode"],
|
||||||
verbose=False
|
verbose=False
|
||||||
),
|
),
|
||||||
]
|
ModelCheckpoint(
|
||||||
|
|
||||||
checkpoint_callback = ModelCheckpoint(
|
|
||||||
monitor=config["callbacks"]["checkpoint"]["monitor"],
|
monitor=config["callbacks"]["checkpoint"]["monitor"],
|
||||||
save_top_k=config["callbacks"]["checkpoint"]["save_top_k"],
|
save_top_k=config["callbacks"]["checkpoint"]["save_top_k"],
|
||||||
mode=config["callbacks"]["checkpoint"]["mode"]
|
mode=config["callbacks"]["checkpoint"]["mode"],
|
||||||
|
save_last=config["callbacks"]["checkpoint"]["save_last"],
|
||||||
|
verbose=False
|
||||||
)
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
# Init trainer
|
# Init trainer
|
||||||
trainer = pl.Trainer(
|
trainer = pl.Trainer(
|
||||||
gpus=config["num_of_gpus"],
|
gpus=config["hparams"]["num_of_gpus"],
|
||||||
max_epochs=config["max_epochs"],
|
max_epochs=config["hparams"]["max_epochs"],
|
||||||
logger=wandb_logger,
|
logger=wandb_logger,
|
||||||
callbacks=callbacks,
|
callbacks=callbacks,
|
||||||
checkpoint_callback=checkpoint_callback,
|
|
||||||
resume_from_checkpoint=config["resume"]["ckpt_path"] if config["resume"]["resume_from_ckpt"] else None,
|
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["hparams"]["accumulate_grad_batches"],
|
||||||
accumulate_grad_batches=config["accumulate_grad_batches"],
|
gradient_clip_val=config["hparams"]["gradient_clip_val"],
|
||||||
gradient_clip_val=config["gradient_clip_val"],
|
progress_bar_refresh_rate=50,
|
||||||
progress_bar_refresh_rate=1,
|
|
||||||
profiler=SimpleProfiler(),
|
profiler=SimpleProfiler(),
|
||||||
weights_summary='full',
|
weights_summary='full',
|
||||||
# fast_dev_run=True,
|
# fast_dev_run=True,
|
||||||
# limit_train_batches=0.01
|
# limit_train_batches=0.01
|
||||||
# limit_val_batches=0.01
|
# limit_val_batches=0.01
|
||||||
# limit_test_batches=0.01
|
# limit_test_batches=0.01
|
||||||
|
# auto_scale_batch_size="power",
|
||||||
|
# min_epochs=10,
|
||||||
# amp_backend='apex',
|
# amp_backend='apex',
|
||||||
# precision=16,
|
# 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 ⚡
|
# Train the model ⚡
|
||||||
trainer.fit(model=model, datamodule=dataloader)
|
trainer.fit(model=model, datamodule=dataloader)
|
||||||
|
|
||||||
|
|||||||
@@ -27,12 +27,8 @@ class MNISTDataModule(pl.LightningDataModule):
|
|||||||
MNIST(self.data_dir, train=False, download=True)
|
MNIST(self.data_dir, train=False, download=True)
|
||||||
|
|
||||||
def setup(self, stage=None):
|
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)
|
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_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)
|
self.data_test = MNIST(self.data_dir, train=False, transform=self.transform)
|
||||||
|
|
||||||
def train_dataloader(self):
|
def train_dataloader(self):
|
||||||
|
|||||||
@@ -15,9 +15,8 @@ class LitModel(pl.LightningModule):
|
|||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.save_hyperparameters(config)
|
self.save_hyperparameters(config["hparams"])
|
||||||
self.model = ModelMNISTv1(config=self.hparams.model)
|
self.model = ModelMNISTv1(config=self.hparams.model)
|
||||||
# self.model = ModelMNISTv2(config=self.hparams.model)
|
|
||||||
|
|
||||||
def forward(self, data):
|
def forward(self, data):
|
||||||
return self.model(data)
|
return self.model(data)
|
||||||
|
|||||||
+7
-7
@@ -8,9 +8,9 @@ class ModelMNISTv1(nn.Module):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
# mnist images are (1, 28, 28) (channels, width, height)
|
# mnist images are (1, 28, 28) (channels, width, height)
|
||||||
self.layer_1 = nn.Linear(28 * 28, 128)
|
self.layer_1 = nn.Linear(28 * 28, config["lin1_size"])
|
||||||
self.layer_2 = nn.Linear(128, 256)
|
self.layer_2 = nn.Linear(config["lin1_size"], config["lin2_size"])
|
||||||
self.layer_3 = nn.Linear(256, 10)
|
self.layer_3 = nn.Linear(config["lin2_size"], 10)
|
||||||
|
|
||||||
def forward(self, x):
|
def forward(self, x):
|
||||||
batch_size, channels, width, height = x.size()
|
batch_size, channels, width, height = x.size()
|
||||||
@@ -32,10 +32,10 @@ class ModelMNISTv2(nn.Module):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
# mnist images are (1, 28, 28) (channels, width, height)
|
# mnist images are (1, 28, 28) (channels, width, height)
|
||||||
self.layer_1 = nn.Linear(28 * 28, 256)
|
self.layer_1 = nn.Linear(28 * 28, config["lin1_size"])
|
||||||
self.layer_2 = nn.Linear(256, 128)
|
self.layer_2 = nn.Linear(config["lin1_size"], config["lin2_size"])
|
||||||
self.layer_3 = nn.Linear(128, 64)
|
self.layer_3 = nn.Linear(config["lin2_size"], config["lin3_size"])
|
||||||
self.layer_4 = nn.Linear(64, 10)
|
self.layer_4 = nn.Linear(config["lin3_size"], 10)
|
||||||
|
|
||||||
def forward(self, x):
|
def forward(self, x):
|
||||||
batch_size, channels, width, height = x.size()
|
batch_size, channels, width, height = x.size()
|
||||||
|
|||||||
Reference in new issue
Block a user