All models running.

This commit is contained in:
Si11ium
2019-08-24 19:05:46 +02:00
parent 7b0b96eaa3
commit 18305a9e7e
6 changed files with 45 additions and 45 deletions

View File

@ -6,6 +6,9 @@ from networks.modules import *
import torch
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
class AdversarialAutoEncoder(AutoEncoder):
def __init__(self, *args, **kwargs):
@ -32,18 +35,18 @@ class AdversarialAELightningOverrides(LightningModuleOverrides):
if optimizer_i == 0:
# ---------------------
# Train Discriminator
# ---------------------
# ---------------------p
# latent_fake, reconstruction
latent_fake, _ = self.network.forward(batch)
latent_real = self.normal.sample(latent_fake.shape)
latent_fake = self.network.encoder.forward(batch)
latent_real = self.normal.sample(latent_fake.shape).to(device)
# Evaluate the input
d_real_prediction = self.network.discriminator.forward(latent_real)
d_fake_prediction = self.network.discriminator.forward(latent_fake)
# Train the discriminator
d_loss_real = mse_loss(d_real_prediction, torch.zeros(d_real_prediction.shape))
d_loss_fake = mse_loss(d_fake_prediction, torch.ones(d_fake_prediction.shape))
d_loss_real = mse_loss(d_real_prediction, torch.zeros(d_real_prediction.shape, device=device))
d_loss_fake = mse_loss(d_fake_prediction, torch.ones(d_fake_prediction.shape, device=device))
# Calculate the mean over both the real and the fake acc
# ToDo: do i need to compute this seperate?

View File

@ -25,9 +25,9 @@ class LightningModuleOverrides:
@data_loader
def tng_dataloader(self):
num_workers = os.cpu_count() // 2
num_workers = 0 # os.cpu_count() // 2
return DataLoader(DataContainer('data', self.size, self.step),
shuffle=True, batch_size=100, num_workers=num_workers)
shuffle=True, batch_size=10000, num_workers=num_workers)
class AbstractNeuralNetwork(Module):

View File

@ -1,21 +1,22 @@
from torch.optim import Adam
from networks.auto_encoder import AutoEncoder
from torch.nn.functional import mse_loss
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, **kwargs):
def __init__(self, latent_dim, features):
super(SeperatingAdversarialAutoEncoder, self).__init__()
self.latent_dim = latent_dim
self.features = features
self.spatial_encoder = PoolingEncoder(self.latent_dim)
self.temporal_encoder = Encoder(self.latent_dim)
self.decoder = Decoder(self.latent_dim, self.features)
self.decoder = Decoder(self.latent_dim * 2, self.features)
self.spatial_discriminator = Discriminator(self.latent_dim, self.features)
self.temporal_discriminator = Discriminator(self.latent_dim, self.features)
@ -43,15 +44,17 @@ class SeparatingAdversarialAELightningOverrides(LightningModuleOverrides):
# Train temporal Discriminator
# ---------------------
# latent_fake, reconstruction
temporal_latent_real = self.normal.sample(temporal_latent_fake.shape)
temporal_latent_real = self.normal.sample(temporal_latent_fake.shape).to(device)
# Evaluate the input
temporal_real_prediction = self.network.temporal_discriminator.forward(temporal_latent_real)
temporal_fake_prediction = self.network.temporal_discriminator.forward(temporal_latent_fake)
# Train the discriminator
temporal_loss_real = mse_loss(temporal_real_prediction, torch.zeros(temporal_real_prediction.shape))
temporal_loss_fake = mse_loss(temporal_fake_prediction, torch.ones(temporal_fake_prediction.shape))
temporal_loss_real = mse_loss(temporal_real_prediction,
torch.zeros(temporal_real_prediction.shape, device=device))
temporal_loss_fake = mse_loss(temporal_fake_prediction,
torch.ones(temporal_fake_prediction.shape, device=device))
# Calculate the mean over bot the real and the fake acc
# ToDo: do i need to compute this seperate?
@ -63,15 +66,17 @@ class SeparatingAdversarialAELightningOverrides(LightningModuleOverrides):
# Train spatial Discriminator
# ---------------------
# latent_fake, reconstruction
spatial_latent_real = self.normal.sample(spatial_latent_fake.shape)
spatial_latent_real = self.normal.sample(spatial_latent_fake.shape).to(device)
# Evaluate the input
spatial_real_prediction = self.network.spatial_discriminator.forward(spatial_latent_real)
spatial_fake_prediction = self.network.spatial_discriminator.forward(spatial_latent_fake)
# Train the discriminator
spatial_loss_real = mse_loss(spatial_real_prediction, torch.zeros(spatial_real_prediction.shape))
spatial_loss_fake = mse_loss(spatial_fake_prediction, torch.ones(spatial_fake_prediction.shape))
spatial_loss_real = mse_loss(spatial_real_prediction,
torch.zeros(spatial_real_prediction.shape, device=device))
spatial_loss_fake = mse_loss(spatial_fake_prediction,
torch.ones(spatial_fake_prediction.shape, device=device))
# Calculate the mean over bot the real and the fake acc
# ToDo: do i need to compute this seperate?