diff --git a/DCGAN-PyTorch/01-DCGAN-PL.ipynb b/DCGAN-PyTorch/01-DCGAN-PL.ipynb index a0973d1262fef6a52b6e176a0affd7823b6f5cfc..ea028f9bcf76c2b665f5492bb51e1d7ff2e5f120 100644 --- a/DCGAN-PyTorch/01-DCGAN-PL.ipynb +++ b/DCGAN-PyTorch/01-DCGAN-PL.ipynb @@ -79,7 +79,7 @@ "source": [ "latent_dim = 128\n", " \n", - "generator_class = 'Generator_1'\n", + "generator_class = 'Generator_2'\n", "discriminator_class = 'Discriminator_1' \n", " \n", "scale = .1\n", @@ -169,7 +169,7 @@ "outputs": [], "source": [ "print('\\nInstantiation :\\n')\n", - "generator = Generator_1(latent_dim=latent_dim, data_shape=data_shape)\n", + "generator = Generator_2(latent_dim=latent_dim, data_shape=data_shape)\n", "discriminator = Discriminator_1(latent_dim=latent_dim, data_shape=data_shape)\n", "\n", "print('\\nFew tests :\\n')\n", @@ -308,9 +308,9 @@ ], "metadata": { "kernelspec": { - "display_name": "pytorch-gpu-1.13.0_py3.10.8", + "display_name": "fidle-env", "language": "python", - "name": "module-conda-env-pytorch-gpu-1.13.0_py3.10.8" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -322,7 +322,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.8" + "version": "3.9.2" }, "vscode": { "interpreter": { diff --git a/DCGAN-PyTorch/modules/Generators.py b/DCGAN-PyTorch/modules/Generators.py index 0c49adb051caa8144ce7837ba6ed1e3441c33030..cb187826db83719500650a5042cea4cf170a9dad 100644 --- a/DCGAN-PyTorch/modules/Generators.py +++ b/DCGAN-PyTorch/modules/Generators.py @@ -22,7 +22,7 @@ class Generator_1(nn.Module): super().__init__() self.latent_dim = latent_dim self.img_shape = data_shape - print('init generator : ',latent_dim,' to ',data_shape) + print('init generator 1 : ',latent_dim,' to ',data_shape) self.model = nn.Sequential( @@ -50,4 +50,38 @@ class Generator_1(nn.Module): def forward(self, z): img = self.model(z) img = img.view(img.size(0), *self.img_shape) - return img \ No newline at end of file + return img + + + +class Generator_2(nn.Module): + + def __init__(self, latent_dim=None, data_shape=None): + super().__init__() + self.latent_dim = latent_dim + self.img_shape = data_shape + print('init generator 2 : ',latent_dim,' to ',data_shape) + + self.model = nn.Sequential( + + nn.Linear(latent_dim, 7*7*64), + nn.Unflatten(1, (64,7,7)), + + nn.UpsamplingBilinear2d( scale_factor=2 ), + nn.Conv2d( 64,128, (3,3), stride=(1,1), padding=(1,1) ), + nn.ReLU(), + + nn.UpsamplingBilinear2d( scale_factor=2 ), + nn.Conv2d( 128,256, (3,3), stride=(1,1), padding=(1,1)), + nn.ReLU(), + + nn.Conv2d( 256,1, (5,5), stride=(1,1), padding=(2,2)), + nn.Sigmoid() + + ) + + def forward(self, z): + img = self.model(z) + img = img.view(img.size(0), *self.img_shape) + return img +