Generative Adversarial Networks on Azure

Today I got something different. Instead of game development I want to talk about machine learning.

I recently stumbled across a tech demo by nvidia showcasing the generation of fake images using a Generative Adversarial Network (GAN):

nvidia gan

Just to give you a quick idea of what a GAN is:

A GAN consists of two neural networks, the ‘discriminator‘ and the ‘generator‘.
The discriminator receives real data (eg images) and learns that those images are real.
The generator on the other side produces fake data (eg fake images) and feeds them into the discriminator. So, the discriminator will try to distinguish between fake and real data.

Both neural networks learn over the course of the training. The discriminator gets better at telling real and fake data apart and the generator gets better at fooling the discriminator.
But eventually after enough training the generator will become so good that it is impossible for the discriminator to decide what is fake and what is real.

Since the computations needed are pretty complex they take a very long time when running on a CPU. Luckily you can use your GPU for that. For that to work you could use nvidias CUDA (if you own a supported nvidia graphics card) or you can setup a preconfigured Azure Virtual Machine.

Microsoft Azure features a template for deep learning virtual machines called the “Deep Learning Virtual Machine” (surprise). It has all the necessary stuff already installed like python and tensorflow (and a lot more) and is also configured to utilize the GPU for computation.

If you want to know more about GANs I highly recommend the following youtube video:
(Also, if you are interested in machine learning I recommend the whole channel).

So I wanted to give it a try and used the code provided in that youtube video. (Github)
The code is writte in python and uses Tensorflow as machine learning library. The original code tries to create new Pokemon based on the 150 (151?) original Pokemon but the result weren’t really satisfying:


So I tried something different. Instead of Pokemon the discriminator was now training on parts of the mnist set (a collection of handwritten digits often used as a simple example of image classification). In particular I only used the digit 4 and wanted to see if the generator would be able to produce something that looks like a 4. Here are the results:

Nothing to see yet..

After 10 iterations you can make out something that could become a 4.

After 20 iterations you can see some almost perfect 4’s along with some images that look like a 9 or maybe even an ‘A’.

Strangely after that it got worse again:

Iteration 30

Iteration 40

Iteration 50

So at that point I stopped with the mnist data set. I am currently trying to create images of me but I actually expect something like the generated “Pokemon” instead of actual faces.

That’s it for now. If my GAN actually produces something that looks like a face I will let you know.

Leave a Reply