Skip to content

Instantly share code, notes, and snippets.

@IanCarrasco
Last active July 31, 2020 17:50
Show Gist options
  • Save IanCarrasco/7d22da400856fa7a81521939b0380947 to your computer and use it in GitHub Desktop.
Save IanCarrasco/7d22da400856fa7a81521939b0380947 to your computer and use it in GitHub Desktop.
#md | DCGAN Generator
#mdi | https://miro.medium.com/max/1400/1*5ALjnfAqwcWbOsledTBXsw.png
class generator(nn.Module):
# initializers
def __init__(self, d=128):
super(generator, self).__init__()
self.deconv1 = nn.ConvTranspose2d(100, d*8, 4, 1, 0) #md | Deconvolution | sub
self.deconv1_bn = nn.BatchNorm2d(d*8) #md | Batch Normalization | sub
self.deconv2 = nn.ConvTranspose2d(d*8, d*4, 4, 2, 1)
self.deconv2_bn = nn.BatchNorm2d(d*4)
self.deconv3 = nn.ConvTranspose2d(d*4, d*2, 4, 2, 1)
self.deconv3_bn = nn.BatchNorm2d(d*2)
self.deconv4 = nn.ConvTranspose2d(d*2, d, 4, 2, 1)
self.deconv4_bn = nn.BatchNorm2d(d)
self.deconv5 = nn.ConvTranspose2d(d, 3, 4, 2, 1)
#md | Model Benchmarks
for m in self._modules:
normal_init(self._modules[m], mean, std)
# forward method
def forward(self, input):
# x = F.relu(self.deconv1(input))
x = F.relu(self.deconv1_bn(self.deconv1(input)))
x = F.relu(self.deconv2_bn(self.deconv2(x)))
x = F.relu(self.deconv3_bn(self.deconv3(x)))
x = F.relu(self.deconv4_bn(self.deconv4(x)))
x = F.tanh(self.deconv5(x))
return x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment