I built an AI image detector alone β€” the model was the easy part
DEV Community

I built an AI image detector alone - the model was the easy part

Every week someone posts a photo in a Discord I'm in and asks "is this AI?" The honest answer is usually "probably, but I can't prove it" - and that gap between probably and provably is the whole design problem of an AI image detector.

I built one as a one-person project: ai-detect.iming.work. It's free, no signup, and it deliberately refuses to give you a single number. This post is about why, and about the parts that broke.

Two signals, not one score

The first version returned one confidence value. That was a mistake, and users told me so in the least helpful way possible: they'd upload a real photo, get "82% AI", and assume the tool was broken - when actually the pixel model was genuinely unsure and the metadata was clean.

Splitting the output fixed the UX and the engineering at the same time. The tool now reports two independent results:

  • Metadata clues - what the file itself claims about its origin.
  • Pixel analysis - a model score computed from the image alone.

They fail in opposite directions, which is exactly why they're worth keeping separate.

Metadata is precise and has terrible recall

When metadata hits, it's near-conclusive. AI tools write their names into files: Midjourney, Stable Diffusion, ComfyUI, NovelAI, DALLΒ·E, Flux. Stable Diffusion WebUI in particular dumps the entire generation parameter string (sampler, steps, CFG, sometimes the prompt) into a PNG tEXt chunk. There's also the AIGC labelling standard some Chinese tools now write.

The negative signal is just as useful: a full EXIF block with a camera body, a lens, aperture, shutter and ISO is strong evidence of a real photograph. AI output almost never carries a plausible camera chain - at best an empty shell of EXIF with the manufacturer field filled in.

Then reality arrives. Every major social platform strips EXIF on upload. A screenshot strips everything. A round trip through WeChat, Weibo or an Instagram re-upload deletes the evidence.

So metadata behaves like a high-precision, low-recall test: a hit proves AI; a miss proves nothing. That asymmetry is the single most useful thing to explain to users, because "no metadata" reads as "clean" to almost everyone.

The pixel model is the mirror image

Pixel analysis doesn't care about metadata, so it survives re-encoding. But it inherits every weakness of a classifier:

  • It's trained on generators that existed at training time. New models drift out from under it.
  • It reads texture and noise statistics, which real photographs also vary wildly in.
  • It has no notion of why - so when it's wrong, it's confidently wrong.

I don't publish an accuracy number, because any single number I could quote would be measured on my own sample and would be wrong for yours. What I do instead is show which signal produced the verdict, so a user can weigh it.

Four processing steps that break pixel models

These account for most of the false positives I've seen, and none of them are "the model is bad":

Screenshots. A screenshot is a re-render at a different resolution through a different sampling filter. High-frequency detail that the model expects from a camera sensor is replaced by screen subpixel structure.

Re-compression. Upload a JPEG, let a platform re-encode it at quality 75, and the compression artifacts the model associates with synthetic images and with photos start to overlap.

AI upscaling and denoise. Ironically, the tools people use to fix a photo make it look more generated. A denoiser removes exactly the sensor noise the model uses as evidence of a real capture.

Aggressive phone processing. Modern phone pipelines stack HDR, multi-frame merge and heavy sharpening. The result has the smoothed, slightly-too-clean texture that generation models also produce.

If you're building anything in this space, handle these four cases explicitly rather than letting the model absorb them.

The boring parts that actually mattered

A few engineering decisions that mattered more than the model:

Detection is asynchronous. A 12 MP image takes a few seconds. The POST returns a task id immediately and the client polls with backoff (500 ms, then 3 s). Before that, the desktop UI waited on a single request and occasionally timed out into an empty result panel - a bug that looked like "detection sometimes doesn't work".

Images are transient by construction. Uploads are relayed through a temporary host that expires the object after five minutes, and the originals never touch my server. Results live in the user's browser. This is a privacy decision, but it's also a scaling decision: no image storage means no storage to leak.

Content pages are static HTML. The guides are generated at build time rather than rendered client-side, because a SPA gives non-JS crawlers an empty page. The homepage additionally ships a static copy of its body text that React removes on mount, so the DOM never contains the text twice.

What I'd do differently

I'd have built the metadata parser first and the model second. The parser is deterministic, testable, fast, and it answers a real question ("what does this file say about itself?"). The model is a probabilistic guess that needs the parser's output to be interpretable.

And I'd have shipped the two-signal UI on day one. Explaining a probability is much harder than showing two pieces of evidence and letting the user cross-check them.

If you want to poke at it: ai-detect.iming.work - PNG, JPEG, WEBP, BMP and TIFF up to 30 MB. Happy to answer questions about the metadata side in the comments; that part I know cold.

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.