Crocodiles are those reptilian creatures that can be seen in freshwater or saltwater bodies, but here in the Philippines, we have a particularly special kind of crocodile more at home in the Senate or Congress. The Buwaya in Filipino, is colloquial for those greedy politicians that run the country.

This post tries to generate politicians' faces from existing politicians' pictures using a Generative Adversarial Network.


Generative Adversarial Networks

Generative Adversarial Networks, or GAN for short is another kind of artificial intelligence technique that is implemented by using two neural networks competing each other. The first network is a generative model while the other one is a discriminative model.

Basically, the first model (the generator) generates a sample of the dataset. The second model (the discriminator) evaluates if the generated sample data came from the training data. The goal is for the generator to fool the discriminator to think that the sample data that was generated by the first model came from the training data.

GANs are capable on generating an image like this trained from a lot of celebrity images:


In this post, a GAN was used to generate different faces of Philippine politicians. HyperGAN, a open source implementation of GAN built with Tensorflow was used.

Before anything else could be done, training data was, well, obviously needed. The training data was scraped at congress.gov.ph. The initial dataset only used the images of each representative in 17th congress. The scraper successfully gathered 294 images of the representatives. They were then cropped and resized into 80x80 using ImageMagick. The images were resized to save memory from the GPU.

1st training

The training was done in an Ubuntu 16 machine with an Nvidia GeForce GTX 750 Ti as the GPU. CUDA was also installed to make use of the GPU. During the training the utilization of the GPU was nearly 100% and consumed almost the memory all the time.

As shown in the GIF below, the training displays a nice visualization on how it produces images. It started with random pixels then slowly the shape of the face was starting to show up. Eventually, different parts of the face started to appear.


After two hours of training, the image below returned the best quality. The face, hair, eyes, nose, mouth and even their attires were distinguishable.

Although, the results were still blurry. The reason for this might be from the lack of training data. As mentioned earlier, only 294 images were used for the initial run.

2nd training

To improve the results, additional images were scraped from another page at congress.gov.ph. This time, the images were obtained from 12th to 15th congress. The newly extracted images were also cropped and resized to 80x80 using ImageMagick. In total, the dataset now contains 809 images. The GIF below shows the training using the updated dataset.


The training was fascinating to watch. It almost took three hours to create the image below, which is one of the best results produced by the second training.

The result was much better than the initial run despite having still having blurry generated images. The training data was still lacking in comparison to the ~200 thousand celebrity images used to generate the example shown above. In any case, this post still showed the capability of GAN in generating different images based on the given data set.

Sources