pokemon-gan / model.py
Mycsina's picture
Publish trained generator
75d3db5 verified
Raw
History Blame Contribute Delete
968 Bytes
import torch.nn as nn
LATENT_DIM = 100
class Generator(nn.Module):
def __init__(self, latent_dim=LATENT_DIM):
super().__init__()
self.latent_dim = latent_dim
self.network = nn.Sequential(
nn.ConvTranspose2d(latent_dim, 512, 4, 1, 0, bias=False),
nn.BatchNorm2d(512),
nn.ReLU(inplace=True),
nn.ConvTranspose2d(512, 256, 4, 2, 1, bias=False),
nn.BatchNorm2d(256),
nn.ReLU(inplace=True),
nn.ConvTranspose2d(256, 128, 4, 2, 1, bias=False),
nn.BatchNorm2d(128),
nn.ReLU(inplace=True),
nn.ConvTranspose2d(128, 64, 4, 2, 1, bias=False),
nn.BatchNorm2d(64),
nn.ReLU(inplace=True),
nn.ConvTranspose2d(64, 3, 4, 2, 1),
nn.Tanh(),
)
def forward(self, noise):
if noise.ndim == 2:
noise = noise[:, :, None, None]
return self.network(noise)