Conspirador Norteño Profile picture
Data Scientist/Musician/Participant in the General Confusion @trutherbotprop Resist autocracy and research/counter disinformation. I serve the realm.

Apr 10, 2021, 9 tweets

None of these cats exist. All are GAN-generated images obtained from thiscatdoesnotexist.com. Can we come up with a way to detect GAN-generated cat pics? #CaturdayShenaniGANs

(GAN = "generative adversarial network", the AI technique used to create the images)

cc: @ZellaQuixote

For this project, we used the following datasets (all images 512x512):

• 2000 GAN-generated cats from thiscatdoesnotexist.com
• 1195 real cat faces, cropped from images at kaggle.com/crawford/cat-d…
• a test set of 1000 GAN-generated and 1000 real cats (same sources as above)

Unlike the GAN-generated human face pics provided by thispersondoesnotexist.com etc, the placement of the major facial features on the GAN-generated cat pics from thiscatdoesnotexist.com varies from image to image. There are other anomalies in the fake cat pics, however. . .

We blended 2000 GAN-generated cat pics and altered the color scheme so that each pixel's brightness corresponds to how different that pixel's color is from the average color of the image. This reveals various horizontal and vertical bands in the GAN-generated cat images.

We can emphasize this banding further by blending all the pixels in the same row or column of the image and calculating the difference between adjacent values. This results in a distinctive pattern of peaks every other pixel and slightly less visible peaks every 8 pixels.

The same pattern shows up (albeit less visibly) when we apply the same process to a single GAN-generated cat image. Notably, this pattern is largely absent from real cat face pics, both single and blended.

We used these results to train a simple neural network to classify cat face images as "real" or "GAN-generated". Results are encouraging - within a few hours of training we ended up with a model that achieved 94.2% accuracy on 2000 images it hadn't been trained on.

Here's the code we used for both training and classification. It is presently hardcoded to use 512x512 pixel images (the size generated by thiscatdoesnotexist.com) and will likely require tweaking for other image sizes.
pastebin.com/hqPtD5CD

A couple of disclaimers:

• This method is unlikely to produce useful results on images that aren't of cat faces.
• If using it on Twitter profile pics, you will want to obtain the full-resolution version of the pics for best results (more detail here: developer.twitter.com/en/docs/twitte…).

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling