Generative Profile Pictures

Another objective of this project was to generate images for the profile pictures of the fake Tinder dating profiles. Early experiments using unedited photos to train the GAN to generate new photos showed that the source images varied too much in terms of their backgrounds, orientations, resolutions and dimensions. Because of this, Generative Adversarial Networks (GANs) I used didn’t produce particularly recognisable results.

To make the image generation problem easier I created some code to crop the faces from each photo. Using cropped faces enabled the learning process for the GAN to be massively simplified, as it increased the level of correlation across the data points in the dataset.

In pictures, the below code would take a photo like this:

A royalty free photo with some people on it.

And get images like the faces below and store them in some new dataset, which the GAN would then learn on.

The faces pulled from the above photo from the code below.

The code makes use of dlib, which has an excellent face detector with a low false positive rate. Of course, constructing a dataset of cropped faces to improve the reconstruction of the GAN discards a massive amount of aesthetic information present previously in the original images downloaded from Tinder. It was a conscious decision to abandon this information to produce pictures that somewhat resembled dating profiles. With more time, it would be fantastic to return to this project without needing to crop the source photos, improving the reconstruction of a dataset of images with more varied background and better framing of individual photos.

Once a dataset of faces was constructed, a neural network could be trained to produce new images of faces. The current state of the art is the Progressive Growing of GANs (PGGAN) from Nvidia that blew everyone away 177 days ago (as of the time of writing this blog post.) Given more time it would have been great to have a crack at implementing this model, as I find the idea of dynamically growing the depth and size of the model as the optimisation progresses fascinating. However there wasn’t enough time for this, or enough of a magnitude of available compute power, which would be needed to hack around with a model of this scale frequently.

The availability of computing power was an issue in this project, due to the scale of the neural networks that I was considering using. I ended up signing up for a free Google Compute cloud account. On signup, you receive $300 worth of your local currency to spend on whatever services you want. Handy tip — you can get the same signup bonus with every new Gmail account you make with them! ;)

When increasing your maximum allocation of GPUs from zero to greater than zero, you will, however, need to pay Google a small amount of money to show you are serious about being able to front the bills if you run out of free credits. Once this is done, you will need to create a new instance on the cloud. If you want a tutorial on that, this might help. When you first SSH into your new instance, I wrote a small script to easily install CUDA 9, CuDNN 7.0, TensorFlow and PyTorch, without any hassle. Hopefully, this is useful (but quite possibly out of date by the time you read this)!

Once I sorted the issue of available compute, I elected to download an implementation of PGGAN to use with the newly created Tinder faces dataset. I chose to use a PyTorch implementation of PGGAN, although since I started using it, the TensorFlow version from the authors of the original paper has officially been released and should probably be your starting point if you are looking to do similar work. The implementation I used was incredibly useful, so kudos to the author, but there were a few issues with saving the model and later loading it, which made inference challenging to get the right resolutions. As a warning, training these kinds of models to resolutions of 256, 512 or higher can take weeks on a single GPU — be sure to make sure the model saves and can be recovered correctly before devoting such time to training it!

After a lot of lengthy training, spanning many weeks, I finally got a model making some relatively decent generative images. For instructions on how to use the models, see the respective GitHub pages.