Debugging und hparam als Mapping
This commit is contained in:
@@ -3,7 +3,7 @@ from torch import nn
|
|||||||
from torch.optim import Adam
|
from torch.optim import Adam
|
||||||
|
|
||||||
from ml_lib.modules.blocks import ConvModule
|
from ml_lib.modules.blocks import ConvModule
|
||||||
from ml_lib.modules.utils import LightningBaseModule
|
from ml_lib.modules.utils import LightningBaseModule, Flatten
|
||||||
|
|
||||||
|
|
||||||
class BinaryClassifier(LightningBaseModule):
|
class BinaryClassifier(LightningBaseModule):
|
||||||
@@ -12,7 +12,7 @@ class BinaryClassifier(LightningBaseModule):
|
|||||||
return cls.__name__
|
return cls.__name__
|
||||||
|
|
||||||
def configure_optimizers(self):
|
def configure_optimizers(self):
|
||||||
return Adam(lr=self.hparams.train.lr)
|
return Adam(params=self.Parameters, lr=self.hparams.train.lr)
|
||||||
|
|
||||||
def training_step(self, batch_xy, batch_nb, *args, **kwargs):
|
def training_step(self, batch_xy, batch_nb, *args, **kwargs):
|
||||||
batch_x, batch_y = batch_xy
|
batch_x, batch_y = batch_xy
|
||||||
@@ -38,14 +38,29 @@ class BinaryClassifier(LightningBaseModule):
|
|||||||
self.criterion = nn.BCELoss()
|
self.criterion = nn.BCELoss()
|
||||||
|
|
||||||
# Additional parameters
|
# Additional parameters
|
||||||
self.in_shape = self.hparams.model_params.in_shape
|
self.in_shape = self.hparams.in_shape
|
||||||
|
|
||||||
# Model Modules
|
# Model Modules
|
||||||
self.conv_1 = ConvModule(self.in_shape, 32, 5, conv_stride=4, **hparams.model_params)
|
self.conv_1 = ConvModule(self.in_shape, 32, 5, conv_stride=4, **hparams)
|
||||||
self.conv_2 = ConvModule(self.conv_1.shape, 64, 7, conv_stride=2, **hparams.model_params)
|
self.conv_2 = ConvModule(self.conv_1.shape, 64, 7, conv_stride=2, **hparams)
|
||||||
self.conv_3 = ConvModule(self.conv_1.shape, 128, 9, conv_stride=2, **hparams.model_params)
|
self.conv_3 = ConvModule(self.conv_2.shape, 128, 9, conv_stride=2, **hparams)
|
||||||
|
|
||||||
|
self.flat = Flatten(self.conv_3.shape)
|
||||||
|
self.full_1 = nn.Linear(self.flat.shape, 32)
|
||||||
|
self.full_2 = nn.Linear(self.full_1.out_features, self.full_1.out_features // 2)
|
||||||
|
|
||||||
|
self.activation = self.hparams.activation()
|
||||||
|
self.full_out = nn.Linear(self.full_2.out_features, 2)
|
||||||
|
self.sigmoid = nn.Sigmoid()
|
||||||
|
|
||||||
def forward(self, batch, **kwargs):
|
def forward(self, batch, **kwargs):
|
||||||
|
tensor = self.conv_1(batch)
|
||||||
|
tensor = self.conv_2(tensor)
|
||||||
|
tensor = self.conv_3(tensor)
|
||||||
|
tensor = self.full_1(tensor)
|
||||||
|
tensor = self.activation(tensor)
|
||||||
|
tensor = self.full_2(tensor)
|
||||||
|
tensor = self.activation(tensor)
|
||||||
|
tensor = self.full_out(tensor)
|
||||||
|
tensor = self.sigmoid(tensor)
|
||||||
return batch
|
return batch
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user