Fake Faces Classifier using Tensorflow

Prasant Kumar
4 min readAug 14, 2022

Can you guess which image (from the following 2 images) is real and which one is generated by GAN?

Source: neptune.ai

The fact is that both the images are imagined by a GAN formulation called StyleGAN. StyleGAN is a GAN formulation that is capable of generating very high-resolution images even of 1024*1024 resolution.

Faces generated by StyleGAN are exceptionally good and real that It is very difficult to say that faces are generated. Faces are soo good and real so here comes a responsibility on us to use them wisely and ethically.

Rather than being soo real still, there is some number of “tells” in each image it creates. These vary from image to image — not everyone has all or even many of these glitches — but with a bit of practice, you can learn to spot them at a glance. I learned many of these tricks from the excellent tutorial published by Kyle McDonald in 2018.

Here are some things you can look for when trying to recognize an image produced by a GAN. We’ll focus on faces because they are a common testing ground for researchers, and many of the artifacts most visible in faces also appear in other kinds of images.

Not Clear Background

All sorts of things can go wrong with the backgrounds of the images. The neural net is trained on the face and doesn’t pay as much attention to what is going on at the sides. At the very worst, you get some extremely odd companions, as in the first picture below.

Messy or Straight Hair

Hair is extremely difficult to render realistically. Sometimes there will be disconnected strands of hair on the face or elsewhere. Sometimes hairs are soo straight that it appears to be painted.

Weird Teeth

Teeth are not easy to render. Often teeth are odd or asymmetric. Sometimes a GAN will generate misaligned teeth, or it will stretch or shrink each tooth in unusual ways.

Asymmetry in Eyes and Ears

It can be difficult for a GAN to manage long-distance dependencies in images. While paired accessories like earrings usually match in the dataset, they don’t in the generated images. Or: eyes tend to point in the same direction and they are usually the same color, but the generated images are very frequently crosseyed and heterochromatic. Asymmetry is also commonly visible in ears being at very mismatched heights or sizes.

Signs that a Face is real

Check out that clear background text, those matching earrings, those equally sized teeth, symmetric eyeglasses and earrings, and detailed hairstyles. With all these tricks in mind, try playing this game that tests your ability to distinguish real from the fake and see how many you get right.

Try it out

You can give this a go yourself and use Webapp. I kept all these features in mind and built this classifier.

Try it out on other faces to find the Fake faces (generated faces). It can be used to find Fake Profile Pictures and for many other use-cases.

Source Code

You can find the code for the tool on my GitHub page

I hope you have got some features that will help you differentiate between Real and Generated Fake faces.

Webapp Snapshot

If you like this article give it a clap 👏 and Stay Connected 🙏.

Reference

I have used some reference articles to write this article are listed below

  1. Play a Game: https://www.whichfaceisreal.com/
  2. Images: https://kcimc.medium.com/how-to-recognize-fake-ai-generated-images-4d1f6f9a2842
  3. Learn to spot fake faces at a glance: https://www.whichfaceisreal.com/learn.html

--

--