change the way optimizer config is passed to logger
This commit is contained in:
1 parent
506fe6312f
commit
e93283d890
12 files changed
+159
-177
No files matched your search
@@ -5,28 +5,27 @@ import torch.nn.functional as F
|
||||
import torch
|
||||
|
||||
# import custom architectures
|
||||
from src.architectures.simple_mnist import SimpleMNISTClassifier
|
||||
from src.architectures.simple_dense_net import SimpleDenseNet
|
||||
|
||||
|
||||
class LitModel(pl.LightningModule):
|
||||
class LitModelMNIST(pl.LightningModule):
|
||||
"""
|
||||
This is example of lightning model for MNIST classification.
|
||||
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.
|
||||
To learn how to create lightning models visit:
|
||||
https://pytorch-lightning.readthedocs.io/en/latest/lightning_module.html
|
||||
"""
|
||||
|
||||
def __init__(self, model_config, optimizer_config):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__()
|
||||
hparams = {**model_config["args"], **optimizer_config["args"]}
|
||||
self.save_hyperparameters(hparams)
|
||||
self.optimizer_config = optimizer_config
|
||||
|
||||
self.architecture = SimpleMNISTClassifier(hparams=self.hparams)
|
||||
|
||||
self.save_hyperparameters()
|
||||
self.accuracy = Accuracy()
|
||||
|
||||
# Initialize model architecture
|
||||
if self.hparams["architecture"] == "SimpleDenseNet":
|
||||
self.architecture = SimpleDenseNet(hparams=self.hparams)
|
||||
else:
|
||||
raise Exception("Invalid architecture name")
|
||||
|
||||
def forward(self, x):
|
||||
return self.architecture(x)
|
||||
|
||||
@@ -74,5 +73,6 @@ class LitModel(pl.LightningModule):
|
||||
return loss
|
||||
|
||||
def configure_optimizers(self):
|
||||
Optimizer = load_class(self.optimizer_config["class"])
|
||||
return Optimizer(self.parameters(), **self.optimizer_config["args"])
|
||||
Optimizer = load_class(self.hparams["optimizer_config"]["class"])
|
||||
return Optimizer(self.parameters(), **self.hparams["optimizer_config"]["args"])
|
||||
|
||||
Reference in new issue
Block a user