Recursively instantiate SimpleDenseNet using Hydra (#209)

* Add recursive instantiation of `net` object which is passed to `MNISTLitModule` on init
This commit is contained in:
Nils Werner authored and GitHub committed 2022-03-03 01:31:50 +01:00
1 parent 5b7fde8e3a
commit d0803d4e63
6 files changed
+48 -38

No files matched your search

+3 -7
View File
@@ -25,11 +25,7 @@ class MNISTLitModule(LightningModule):
def __init__(
self,
input_size: int = 784,
lin1_size: int = 256,
lin2_size: int = 256,
lin3_size: int = 256,
output_size: int = 10,
net: torch.nn.Module,
lr: float = 0.001,
weight_decay: float = 0.0005,
):
@@ -39,7 +35,7 @@ class MNISTLitModule(LightningModule):
# it also ensures init params will be stored in ckpt
self.save_hyperparameters(logger=False)
self.model = SimpleDenseNet(hparams=self.hparams)
self.net = net
# loss function
self.criterion = torch.nn.CrossEntropyLoss()
@@ -54,7 +50,7 @@ class MNISTLitModule(LightningModule):
self.val_acc_best = MaxMetric()
def forward(self, x: torch.Tensor):
return self.model(x)
return self.net(x)
def step(self, batch: Any):
x, y = batch