Git Product home page Git Product logo

zokovi / cdcgan-mnist Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 3.0 6.94 MB

This Repository contain an IPython notebook of an example implementation of conditional Deep Convolutional Generative Adversarial Networks or cDCGAN or DC cGAN using Tensorflow.Keras Funtional API.

License: BSD 3-Clause "New" or "Revised" License

Jupyter Notebook 100.00%
cdcgan cdcgan-model gan gans mnist discriminator generator

cdcgan-mnist's Introduction

cDCGAN-MNIST

This Repository contain an IPython notebook of an example implementation of conditional Deep Convolutional Generative Adversarial Networks or cDCGAN or DC cGAN using Tensorflow.Keras Funtional API. This cDCGAN model is trained using MNIST handwritten digits data, and after trained the generator can output MNIST-like handwritten digits by just specifying a label (number from 0-9) and a vector of 100 noise.

This implementation is based on DCGAN tutorial by Tensorflow. https://www.tensorflow.org/tutorials/generative/dcgan

The difference is instead of just training the GAN using image only, cGAN also uses label to train the neural network. And also i had to convert the sequential API used by CDGAN to Functional API because the cDCGAN model have to take two inputs (image and label) and the sequential API are not suitable for this purpose.

I also personally believe that cGAN is much more useful than GAN because we can control the output of the generator just by specifying labels.

Model

Below are the model of the Discriminator and the Generator

Discriminator Generator
Discriminator Generator

The discriminator output 1x1 shape of value between 0 and 1. Value of 0 for fake images and 1 for real images. The generator take input of label (in this case 0-9) and a set of noise, then generates 28x28 pixel of image.

Training

The training algorithm is visually described by this helpful graph i found in Mathworks website:

  1. To train the image we just feed the label and a set random noise to the generator. The generator then produces 'fake images'.

  2. Then we fed both the image and label pair of the real image (from the dataset) and 'fake images' to the discriminator.

  3. We want the discriminator to produces value of 1 for real images and 0 for fake images. So we use that to calculate the loss of the discriminator.

  4. We want the generator to produce image that make the discriminator thinks that the generated fake images are a real image. So we also use that to calculate the loss of the generator by comparing the output value of the discriminator to value of 1 when the discriminator was fed fake image.

  5. Then, we calculate the gradient of the discriminator and the generator using their loss respectively and apply those graident to each model accordingly.

Results.

This is the gif of the training process for 200 epoch. For every epoch, I make the generator produces each number from 0 to 9 by specifying label 0 to 9 with a fixed noise.

Closing Statement

This repository is my attempt at learning conditional GAN because i have been blown by the capabilites that the results of generator of GANs model can produce and then the control aspect of the cGAN generator.

Feel free to use, modify, or do something else to the content provieded in this repository to study conditional GAN or any other stuff, Thanks for coming to this repository.

Thanks to kaggle I was able to Train the model in significanly faster for free by utilizing the free GPU compute that they provided.

cdcgan-mnist's People

Contributors

zokovi avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.