remove example model and add arg for disabling wandb

This commit is contained in:
hobogalaxy committed 2020-12-01 19:36:24 +01:00
1 parent 6de644d4f0
commit 54c7c3f53a
12 files changed
+63 -189

No files matched your search

@@ -1,59 +0,0 @@
import pytorch_lightning as pl
import torch.nn.functional as F
import torch
# custom models
from models.example_model.models import *
class LitModel(pl.LightningModule):
"""
This is example of lightning model.
It should always be located in file named 'lightninig_module.py' and always be named 'LitModel'!
The folder name of 'LitModel' used during training should be specified in run config and all parameters from
'model' section will be passed in 'hparams' dictionary.
It enables you to specify what happens during training, validation and test step.
You can just remove 'validation_step()' or 'test_step()' methods if you don't want to have them during training.
See 'simple_mnist_classifier' for more proper example.
"""
def __init__(self, hparams=None):
super().__init__()
if hparams:
self.save_hyperparameters(hparams)
self.model = ExampleModel(hparams=self.hparams)
def forward(self, x):
return self.model(x)
# logic for a single training step
def training_step(self, batch, batch_idx):
x, y = batch
logits = self.model(x)
loss = F.nll_loss(logits, y)
return loss
# logic for a single validation step
def validation_step(self, batch, batch_idx):
x, y = batch
logits = self.model(x)
loss = F.nll_loss(logits, y)
return loss
# logic for a single testing step
def test_step(self, batch, batch_idx):
x, y = batch
logits = self.model(x)
loss = F.nll_loss(logits, y)
return loss
def configure_optimizers(self):
return torch.optim.Adam(self.parameters(), lr=self.hparams.lr, weight_decay=self.hparams.weight_decay)
-21
View File
@@ -1,21 +0,0 @@
from torch import nn
class ExampleModel(nn.Module):
def __init__(self, hparams):
super().__init__()
self.model = nn.Sequential(
nn.Linear(hparams["input_size"], hparams["lin1_size"]),
nn.BatchNorm1d(hparams["lin1_size"]),
nn.ReLU(),
nn.Dropout(p=0.25),
nn.Linear(hparams["lin1_size"], hparams["lin2_size"]),
nn.LogSoftmax(dim=1)
)
def forward(self, x):
batch_size, channels, width, height = x.size()
x = x.view(batch_size, -1)
return self.model(x)
@@ -8,6 +8,17 @@ from models.simple_mnist_classifier.models import *
class LitModel(pl.LightningModule):
"""
This is example of lightning model for MNIST digits classification.
All models should be located in separate folders with file named 'lightning_module.py' containing class which
is always called 'LitModel'!
The folder name of model used during training should be specified in run config and all parameters from
'model' section will be passed in 'hparams' dictionary.
This class enables you to specify what happens during training, validation and test step.
You can just remove 'validation_step()' or 'test_step()' methods if you don't want to have them during training.
"""
def __init__(self, hparams=None):
super().__init__()