Skip to content

In this project I tried to get a Generative Adversial Network(short GAN) to work

License

Notifications You must be signed in to change notification settings

LuposX/GenerativeAdversialNetwork

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

GenerativeAdversialNetwork

In this project I tried to get a Generative Adversial Network(short GAN) to work

License: MIT Maintenance Python PyTorch NumPy

header

Description of the Project

Set up:
I used pytorch + pytorch lightning as framework. And used as Datasets MNIST (Number dataset), IRIS Flower dataset and a custom GHIBLI dataset(Hand drawn landscape images from the company ghibli).

Description:
I tried Generating Images which correspond to the dataset Images. For example when training the model with the MNIST dataset i tried to generate Images which look like they have a numbers on them.

Model:
I used different architectures for the models and played around with them.
I used the Generative Adversial Network (GAN) architecture which consists of a multilayer perceptron(MLP) and has a Dicriminator which tries to find fake Images and a Generator which tries to generate Images which look as real as possible in order to fool the Discriminator(See Image above).

I also used a Deep Convolutional Generative Adversial Network(DCGAN) which uses convolutional layer, which are also used in image classification, to improve th Realism of the Images.

I also experimentated with a Conditional Deep Convolutional Generative Adversial Network(CDCGAN) which not only uses the Image as data but also meta information such as label.

Tricks:
I used various tricks such as:

  • Instance Noise in order to get a "better" distribution.
  • Using soft labels
  • Adding experience Replay
  • For further trick check here, here and here.

More Ressources:

Usage

  1. Download the Jupyter Notebook files(.ipynb) you want to use for the corresponding model from the folder code.
  2. Run it with Jupyter Notebook/Lab or Google Colab

Notes:

  • When using google colab all missing packages should be installed by itself.
  • If you use juptyer notebook on a local machine you need to install the missing packages by yourself.
  • Check Disclaimer

Disclaimer

When I did the project a while ago my documentation wasn't very clear/clean. That lead to many different Jupyter Notebooks where the only clue is what the difference between them is the name of the file and the code.

This means when choosing the Jupyter Notebook file to use, look at the file name and the code itself.

Not all Jupyter Notebook files will work on first try, some files might need some tinkering. Thats because:

  • some files dont train the model from scratch(Epoch 0) but load a model and contine training from a checkpoint(e.g. Epoch 50, Epoch 100). You need to turn that off.
    => to do that: comment resume_from_checkpoint="" out in pl.Trainer().

  • some Model train with custom dataset which consist of GHIBLI Images (Hand drawn Movie Images) To use that use a different dataset.
    =>To do that change the train_dataloader and tesz_dataloader function. When using a different Dataset be careful of Image size.

  • The logger is comet_ml where I removed my api key.
    => To fix that use you own comet_ml api key or a different logger.

  • There could be other problem. I dont know of the top of my head :(

Results

I could create good looking number images in different Image sizes such as 16x16, 32x32, 64x64 and 128x128 with using the MNIST dataset upscaled. A problem was the flower dataset and the ghibli dataset, I couldnt get good looking pictures out of them.

  • Standart MLP GAN_MNIST

  • DCGAN "standart" DCGAN_MNIST

  • DCGAN with "tricks"/"Opzimized" DCGAN_V2_MNIST

  • DCGAN with Colored Landscape Images(Way more complicated than MNIST)(Image size: 64x64) DCGAN_V4_2_MNIST

  • DCGAN with Flower Images and bigger Image size(128x128) DCGAN_V6_2_MNIST

  • Dicriminator Losss discriminator_loss

  • Generator Losss generator_loss

If you want to see more results or losss graphics click here.

Meta

Distributed under the MIT license. See LICENSE for more information.

LICENSE Digit-Recognition

Contributing

  1. Fork it (https://github.com/LuposX/GenerativeAdversialNetwork/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

About

In this project I tried to get a Generative Adversial Network(short GAN) to work

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published