Deep Learning for Images with PyTorch
Michal Oleszak
Machine Learning Engineer
class Generator(nn.Module): def __init__(self, in_dim, out_dim): super(Generator, self).__init__()
self.generator = nn.Sequential( gen_block(in_dim, 256), gen_block(256, 512), gen_block(512, 1024), nn.Linear(1024, out_dim), nn.Sigmoid(), )
def forward(self, x): return self.generator(x)
Generator
classdef gen_block(in_dim, out_dim):
return nn.Sequential(
nn.Linear(in_dim, out_dim),
nn.BatchNorm1d(out_dim),
nn.ReLU(inplace=True)
)
in_dim
out_dim
class Discriminator(nn.Module): def __init__(self, im_dim): super(Discriminator, self).__init__()
self.disc = nn.Sequential( disc_block(im_dim, 1024), disc_block(1024, 512), disc_block(512, 256), nn.Linear(256, 1), )
def forward(self, x): return self.disc(x)
Discriminator
classdef disc_block(in_dim, out_dim):
return nn.Sequential(
nn.Linear(in_dim, out_dim),
nn.LeakyReLU(0.2)
)
in_dim
1
Deep Learning for Images with PyTorch