Project · Generative Model Forensics
Using a diffusion model's own inversion error as an engineered feature that turns a hard non-linear problem into a nearly linearly separable one
IISER Bhopal · Nov 2025
A diffusion model reconstructs its own outputs far better than it reconstructs the real world. That asymmetry is the detection signal, and it is strong enough that most of the work goes into the feature rather than the classifier.
The core hypothesis, following DIRE[1], is that a partially-trained, "brittle" diffusion model can faithfully reconstruct images it generated itself, but will fail on real images that lie outside its learned manifold. The DIffusion Reconstruction Error (DIRE) exploits that failure directly: invert an image to its latent, sample back, and take the per-pixel absolute difference.
For an image x₀, the DIRE map is the per-pixel absolute error between the image and its
reconstruction after a full inversion-and-sampling cycle:
D(x₀) = | x₀ − x₀^recon |
x_T. DDIM's determinism is
what makes this well-defined. A stochastic sampler would inject noise into the round trip and
destroy the signal.
η = 0).
Real faces come back with high, structured error, giving bright maps. Faces generated by the same DDPM come back with near-zero error, giving almost black maps.
Before building any classifier, the exploratory analysis had already made the case. Pixel-intensity histograms of raw real vs. generated faces overlap almost perfectly, so global colour and brightness statistics carry essentially no signal. On DIRE maps the same histograms separate cleanly, with real images concentrated at high error and generated images decaying exponentially toward zero.
PCA makes it starker. Projected onto their first two principal components, raw images form one overlapping blob: the real/fake distinction is real but highly non-linear and subtle. The same projection on DIRE maps shows remarkable near-linear separability.
The DireClassifier: three conv/batchnorm/pool blocks (16 → 32 → 64 channels) into a
256-unit FC layer with dropout, was trained from scratch with BCEWithLogitsLoss and
Adam. Validation accuracy held steadily in the 95–97% range with no significant overfitting.
| Class | Precision | Recall | F1 | Support |
|---|---|---|---|---|
| Real | 0.96 | 0.98 | 0.97 | 1000 |
| Generated | 0.98 | 0.95 | 0.97 | 1000 |
| Overall accuracy | 96.65% | 2000 | ||
Confusion matrix: 979 true negatives and 21 false positives on real images; 954 true positives and 46 false negatives on generated ones, which is balanced performance across both classes.
Two problems are intrinsic to the approach, and both matter more than the headline accuracy:
Future work would start with augmentation applied to the DIRE maps themselves (flips, rotations) to stabilise validation and reduce the minor overfitting observed.