← back

computer vision · spring 2024

get real: real vs fake image detection

tl;dr: trained cnns to tell real product photos from ai-generated fakes, hitting 99% accuracy and shipping it as a chrome extension.

get real: real vs fake image detection

the problem

generative ai can produce realistic product images in seconds, which lowers the cost of building scam websites and running social engineering attacks. the goal was to build a model that classifies e-commerce product images as real or ai-generated, so it could plug into a broader scam-detection pipeline alongside signals like domain registration and ip activity.

building the dataset

i built a balanced 6,000-image dataset from scratch. 3,000 real product images were sampled from the amazon berkeley objects dataset, then run through google gemini pro to generate a one-line caption of each object.

those captions were fed to dall-e 2 to generate 3,000 'like-for-like' fake images - the same products, but synthetic. this gave clean, balanced classes and a variety of product types against varying backgrounds, so the model would generalise across the range of images a genai model can produce.

the data generation pipeline: real images captioned by gemini, then regenerated as fakes by dall-e 2.
the data generation pipeline: real images captioned by gemini, then regenerated as fakes by dall-e 2.

what the fakes look like

the synthetic images are convincing enough to pass as real product photos on a storefront, which is the core of the detection problem.

every image here is ai-generated.
every image here is ai-generated.

approach

i used transfer learning on three families of pretrained models - vgg-19, resnet50, and efficientnet (b0, b3, b7) - freezing the backbones and training only the output layer. everything was trained on an a100 gpu on google colab over 20 epochs.

results

efficientnetb7 reached 99.44% accuracy, with resnet50 and the efficientnet variants close behind. vgg-19 lagged, with a noticeably higher false-negative rate.

modelaccuracyfalse negative ratetraining time
vgg-1995.11%6.62%245s
resnet5099.00%0.45%270s
efficientnetb099.22%0.45%293s
efficientnetb399.00%0.89%515s
efficientnetb799.44%0.88%1431s
performance across fine-tuned models.

generalising to newer models

to mimic real-world conditions, i tested the models on unseen dall-e 3 images. accuracy dropped sharply: vgg-19 fell to 24%, resnet50 to 48%, and efficientnetb0 was best at just 50%. efficientnet's squeeze-and-excitation blocks helped it adapt, but the drop is a clear sign of how hard it is to keep detectors current as genai improves.

finally, i embedded the models into a chrome extension so you could check whether images online are real or fake in the browser.