Visualization approach 1
This commit is contained in:
@ -50,7 +50,7 @@ class AdversarialAELightningOverrides(LightningModuleOverrides):
|
||||
|
||||
# Calculate the mean over both the real and the fake acc
|
||||
# ToDo: do i need to compute this seperate?
|
||||
d_loss = 0.5 * torch.add(d_loss_real, d_loss_fake)
|
||||
d_loss = 0.5 * torch.add(d_loss_real, d_loss_fake) * 0.001
|
||||
return {'loss': d_loss}
|
||||
|
||||
elif optimizer_i == 1:
|
||||
@ -69,7 +69,7 @@ class AdversarialAELightningOverrides(LightningModuleOverrides):
|
||||
# This is Fucked up, why do i need to put an additional empty list here?
|
||||
def configure_optimizers(self):
|
||||
return [Adam(self.network.discriminator.parameters(), lr=0.02),
|
||||
Adam([*self.network.encoder.parameters(), *self.network.decoder.parameters()], lr=0.02)],\
|
||||
Adam([*self.network.encoder.parameters(), *self.network.decoder.parameters()], lr=0.02), ],\
|
||||
[]
|
||||
|
||||
|
||||
|
48
networks/attention_based_auto_enoder.py
Normal file
48
networks/attention_based_auto_enoder.py
Normal file
@ -0,0 +1,48 @@
|
||||
from torch.optim import Adam
|
||||
|
||||
from .modules import *
|
||||
from torch.nn.functional import mse_loss
|
||||
from torch import Tensor
|
||||
|
||||
|
||||
#######################
|
||||
# Basic AE-Implementation
|
||||
class AutoEncoder(AbstractNeuralNetwork, ABC):
|
||||
|
||||
def __init__(self, latent_dim: int=0, features: int = 0, **kwargs):
|
||||
assert latent_dim and features
|
||||
super(AutoEncoder, self).__init__()
|
||||
self.latent_dim = latent_dim
|
||||
self.features = features
|
||||
self.encoder = Encoder(self.latent_dim)
|
||||
self.decoder = Decoder(self.latent_dim, self.features)
|
||||
|
||||
def forward(self, batch: Tensor):
|
||||
# Encoder
|
||||
# outputs, hidden (Batch, Timesteps aka. Size, Features / Latent Dim Size)
|
||||
z = self.encoder(batch)
|
||||
# Decoder
|
||||
# First repeat the data accordingly to the batch size
|
||||
z_repeatet = Repeater((batch.shape[0], batch.shape[1], -1))(z)
|
||||
x_hat = self.decoder(z_repeatet)
|
||||
return z, x_hat
|
||||
|
||||
|
||||
class AutoEncoderLightningOverrides(LightningModuleOverrides):
|
||||
|
||||
def __init__(self):
|
||||
super(AutoEncoderLightningOverrides, self).__init__()
|
||||
|
||||
def training_step(self, x, batch_nb):
|
||||
# ToDo: We need a new loss function, fullfilling all attention needs
|
||||
# z, x_hat
|
||||
_, x_hat = self.forward(x)
|
||||
loss = mse_loss(x, x_hat)
|
||||
return {'loss': loss}
|
||||
|
||||
def configure_optimizers(self):
|
||||
return [Adam(self.parameters(), lr=0.02)]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
raise PermissionError('Get out of here - never run this module')
|
@ -14,6 +14,9 @@ from torch.utils.data import DataLoader
|
||||
from dataset import DataContainer
|
||||
|
||||
|
||||
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
||||
|
||||
|
||||
class LightningModuleOverrides:
|
||||
|
||||
@property
|
||||
@ -25,8 +28,8 @@ class LightningModuleOverrides:
|
||||
|
||||
@data_loader
|
||||
def tng_dataloader(self):
|
||||
num_workers = 0 # os.cpu_count() // 2
|
||||
return DataLoader(DataContainer('data', self.size, self.step),
|
||||
num_workers = 0 # os.cpu_count() // 2
|
||||
return DataLoader(DataContainer(os.path.join('data', 'training'), self.size, self.step),
|
||||
shuffle=True, batch_size=10000, num_workers=num_workers)
|
||||
|
||||
|
||||
@ -236,6 +239,19 @@ class Encoder(Module):
|
||||
return tensor
|
||||
|
||||
|
||||
class AttentionEncoder(Module):
|
||||
|
||||
def __init__(self):
|
||||
super(AttentionEncoder, self).__init__()
|
||||
self.l_stack = TimeDistributed(EncoderLinearStack())
|
||||
|
||||
def forward(self, x):
|
||||
tensor = self.l_stack(x)
|
||||
torch.bmm() # TODO Add Attention here
|
||||
|
||||
return tensor
|
||||
|
||||
|
||||
class PoolingEncoder(Module):
|
||||
|
||||
def __init__(self, lat_dim, variational=False):
|
||||
|
@ -4,9 +4,6 @@ from networks.modules import *
|
||||
import torch
|
||||
|
||||
|
||||
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
||||
|
||||
|
||||
class SeperatingAdversarialAutoEncoder(Module):
|
||||
|
||||
def __init__(self, latent_dim, features):
|
||||
@ -58,7 +55,7 @@ class SeparatingAdversarialAELightningOverrides(LightningModuleOverrides):
|
||||
|
||||
# Calculate the mean over bot the real and the fake acc
|
||||
# ToDo: do i need to compute this seperate?
|
||||
d_loss = 0.5 * torch.add(temporal_loss_real, temporal_loss_fake)
|
||||
d_loss = 0.5 * torch.add(temporal_loss_real, temporal_loss_fake) * 0.001
|
||||
return {'loss': d_loss}
|
||||
|
||||
if optimizer_i == 1:
|
||||
@ -80,7 +77,7 @@ class SeparatingAdversarialAELightningOverrides(LightningModuleOverrides):
|
||||
|
||||
# Calculate the mean over bot the real and the fake acc
|
||||
# ToDo: do i need to compute this seperate?
|
||||
d_loss = 0.5 * torch.add(spatial_loss_real, spatial_loss_fake)
|
||||
d_loss = 0.5 * torch.add(spatial_loss_real, spatial_loss_fake) * 0.001
|
||||
return {'loss': d_loss}
|
||||
|
||||
elif optimizer_i == 2:
|
||||
|
Reference in New Issue
Block a user