Last active
May 16, 2020 03:37
-
-
Save udithhaputhanthri/258422747c1fd4cd4012615c1a99a819 to your computer and use it in GitHub Desktop.
Introduction to DCGAN using PyTorch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Generator(nn.Module): | |
def __init__(self,noise_channels,img_channels,hidden_G): | |
super(Generator,self).__init__() | |
self.G=nn.Sequential( | |
conv_trans_block(noise_channels,hidden_G*16,kernal_size=4,stride=1,padding=0), | |
conv_trans_block(hidden_G*16,hidden_G*8), | |
conv_trans_block(hidden_G*8,hidden_G*4), | |
conv_trans_block(hidden_G*4,hidden_G*2), | |
nn.ConvTranspose2d(hidden_G*2,img_channels,kernel_size=4,stride=2,padding=1), | |
nn.Tanh() | |
) | |
def forward(self,x): | |
return self.G(x) | |
class Discriminator(nn.Module): | |
def __init__(self,img_channels,hidden_D): | |
super(Discriminator,self).__init__() | |
self.D=nn.Sequential( | |
conv_block(img_channels,hidden_G), | |
conv_block(hidden_G,hidden_G*2), | |
conv_block(hidden_G*2,hidden_G*4), | |
conv_block(hidden_G*4,hidden_G*8), | |
nn.Conv2d(hidden_G*8,1,kernel_size=4,stride=2,padding=0), | |
nn.Sigmoid()) | |
def forward(self,x): | |
return self.D(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment