A Difference-in-Difference Approach to Detecting AI-Generated Images Xinyi Qi, Kai Ye, Chengchun Shi, Ying Yang, Hongyi Zhou, Jin Zhu Abstract Diffusion models are able to produce AI-generated images that are almost indistinguishable from real ones. This raises concerns about their potential misuse and poses substantial challenges for detecting them. Many existing detectors rely on reconstruction error — the difference between the input image and its reconstructed version — as the basis for distinguishing real from fake images. However, these detectors become less effective as modern AI-generated images become increasingly similar to real ones. To address this challenge, we propose a novel difference-in-difference method. Instead of directly using the reconstruction error (a first-order difference), we compute the difference in reconstruction error – a second-order difference – for variance reduction and improving detection accuracy. Extensive experiments demonstrate that our method achieves strong generalization performance, enabling reliable detection of AI-generated images in the era of generative AI. 1 Introduction The rapid evolution of large-scale generative models has led to groundbreaking progress in image generation in recent years 2 ; 9 ; 4 ; 69 ; 6 . Diffusion models, in particular, have become the foundation of modern image generation. However, the proliferation of AI-generated images has raised substantial concerns about authenticity and public trust, creating an urgent need for effective detectors that can distinguish AI-generated images from real ones. Figure 1 : Left: The real image x and its distribution on the manifold \mathcal{M} are shown in blue, whereas the synthetic image y and its distribution are shown in orange. Right: Reconstructions of the real and synthetic images. \Delta_{\textrm{fake}} and \Delta_{\textrm{real}} denote the reconstruction errors of synthetic and real images, respectively, and \Pi_{\mathcal{M}} represents the projection of the real image onto \mathcal{M} . Top: The generator is weak, resulting in a large discrepancy between the real and synthetic image distributions. Consequently, the reconstruction error of the synthetic image, \Delta_{\textrm{fake}}(y) , is much larger than that of the real image, \Delta_{\textrm{real}}(x) , making detection easier. Bottom: The generator is strong, so the real and synthetic image distributions are close. Here, \Delta_{\textrm{fake}}(y) is similar to \Delta_{\textrm{real}}(x) , making AI-generated images difficult to detect. There is a growing literature on detecting AI-generated images; see Section 2 for a detailed review. Early detection algorithms were tailored for specific models and exploited model-based artifacts — such as inconsistencies in the frequency domain, irregularities in color filter responses, or statistical traces introduced by up-sampling layers 28 ; 95 ; 21 . Although these methods achieved strong performance in detecting images from specific generators, they lacked robustness across different models. More recently, reconstruction-based algorithms have emerged as both conceptually intuitive and effective practically. As suggested by their name, these methods (a) reconstruct the image to be detected using a generative model (e.g., a diffusion model), (b) compute the reconstruction error as the difference between the original and reconstructed images, and (c) classify the image as real or synthetic based on that error. Their core idea is straightforward: given a particular generative model for reconstruction, synthetic images that lie on or near the model manifold should be reconstructed with smaller residual errors than real images, which reside outside that manifold (see the upper panel of Figure 1 for an illustration). This line of work, represented by DIRE 80 and its variants LaRE 2 and FIRE 49 ; 19 , has generalized well across different generative models, while maintaining a transparent interpretation. Figure 2 : Visualizations of our DID detector. \Delta denotes the differencing operator that computes the pixel-wise difference between two images. However, the effectiveness of existing reconstruction-based algorithms relies on a sufficiently large gap between real and AI-generated images to be detectable. As generative models advance rapidly, this assumption becomes increasingly invalid. Meanwhile, images found on the internet are often post-processed, through resizing, compression, or partial AI editing (where only specific regions are synthesized), which further confounds detection signals. Recent studies have empirically observed that as the quality of the image generator improves or under adversarial scenarios (e.g., with partial AI edits), reconstruction-based algorithms struggle to detect AI-generated content effectively 19 ; 79 . See also, the bottom panel of Figure 1 for an illustration. Therefore, as high-fidelity diffusion models become prevalent, it is necessary to move beyond existing reconstruction-based methods and develop more effective algorithms capable of detecting subtler differences between real and AI-generated content. This paper proposes a new algorithm, termed difference-in-differences (DID), for detecting AI-generated content. Instead of relying solely on the reconstruction error – which can be viewed as a first-order difference between the input image and its reconstruction – we compute a second-order difference by taking the difference between the reconstruction error of the input image and the reconstruction error of its reconstructed version. Our analytical analysis in Section 3 shows that this second-order differencing can effectively remove fluctuations introduced during synthetic image generation, thus amplifying the detection signal particularly when it is weak. We next employ both first-order and second-order differences as the basis for detection (see Figure 2 for an illustration of our proposal). Empirically, our extensive numerical experiments demonstrate that DID consistently outperforms existing detectors across diverse combinations of image datasets and generative models, achieving improvements around 20% - 30% over the strongest baseline. Moreover, our findings shed light on the effectiveness of DID: in simpler settings where AI-generated images are sufficiently different from real ones, first-order differences alone are adequate for detection; however, in more complex experimental settings, employing the second-order difference substantially improves the detection accuracy. These observations are consistent with our analytical insights. By leveraging both orders of differences, our method generalizes robustly across a wide range of detection tasks. 2 Related Works This section is organized as follows. We begin by reviewing various diffusion models used for image generation. We then review existing algorithms for AI-image detection. Finally, we introduce the difference-in-difference (DID) method from econometrics, which is conceptually related to our proposal but fundamentally different in terms of its problem setting and application. 2.1 Diffusion Models Diffusion models have become a cornerstone of modern image generation and multimodal large language models ( 36 ; 90 , MLLMs,) , powering a wide range of tasks such as text-to-image, text-to-3D generation, and text-to-video generation 55 ; 23 ; 31 ; 63 ; 67 ; 62 ; 66 ; 92 ; 87 ; 43 ; 59 ; 33 . They constitute an important family of probabilistic generative models that progressively perturb data with noise and learn a reverse process to generate synthetic samples 89 . Broadly speaking, these models can be categorized into three main types: denoising diffusion probabilistic models 70 ; 34 , score-based generative models 73 ; 74 , and stochastic differential equation (SDE)-based models 75 ; 72 . Building on the three types of models described above, each can be further decomposed into two subtypes: unconditional and conditional diffusion models. For unconditional diffusion models, prior research has focused on three directions: (i) accelerating the sampling process ( 73 ; 81 ; 26 ; 39 ; 93 ; 94 ) , (ii) tightening the variational lower bound on the data log-likelihood ( 71 ; 40 ; 56 ; 7 ; 48 ) , and (iii) extending the model to accommodate new data modalities ( 57 ; 77 ; 12 ; 35 ; 38 ) . By contrast, research on conditional diffusion models has focused on guiding the generation process to produce content that aligns with users’ desired specifications. For instance, ADM uses an auxiliary classifier to improve the quality of generated samples 25 . ImageReward 84 and Diffusion-DPO 78 leverage reinforcement learning from human feedback to align diffusion models with human preferences. Scalable diffusion models 60 replace standard layer normalization in transformers with adaptive layer normalization to more effectively encode conditioning variables. DiffuSeq 29 , unCLIP 63 , ConPreDif 86 , and RPG 88 focus on guiding diffusion models with textual inputs. 2.2 AI-Generated Image Detection With the rapid advancement of AI image generators, there is an urgent need to detect AI-generated images; see 45 for a recent review of detection algorithms. Early works leverage physical 51 ; 52 ; 27 ; 11 and physiological features 20 in the images, such as inconsistencies in color, perspective, shadows, reflections or human anatomy for detection. These methods rely on the assumption that AI-generated images often fail to adhere to real-world physical and physiological constraints. Later approaches employ spatial-domain features, such as the image texture to build classifiers ( 47 ; 54 ; 96 ) . However, such classifiers often fail to capture frequency-domain artifacts 82 . To overcome this limitation, several methods have been proposed that combine spatial- and frequency-domain features for detection 82 ; 5 ; 83 ; 41 . Other approaches leverage alternative features, such as the negative log-likelihood of the input image 22 , or directly fine-tune an MLLM 44 for detection. Different from the aforementioned approaches, our proposal is most closely related to reconstruction-based detection algorithms. As discussed in the introduction, a representative example is DIRE 80 , which employs a diffusion model with a forward diffusion process and a reverse denoising process to obtain the reconstruction, computes the difference from the original image as the reconstruction error, and trains the classifier using this reconstruction error. SeDID 50 extends this approach by considering not only the final reconstruction error between the reconstructed and input image, but also the intermediate errors accumulated along the forward diffusion and reverse denoising processes. Other variants, such as DRCT 17 , modify the objective function by employing a contrastive loss to train the classifier based on the reconstruction error. One potential limitation of DIRE is its computational time required to obtain the reconstruction, as the forward diffusion and reverse denoising processes involve multiple steps and can be time-consuming. To address this, LaRE 2 49 projects the image into a latent space and applies the forward and reverse procedures only once, computing the reconstruction error in the latent space to speed up the computation. AEROBLADE 64 adopts a training-free strategy: instead of training a classifier with the reconstruction error, it relies on simple statistical measures derived from the reconstruction error for detection. FakeInversion 16 inverts an open-source stable diffusion process model to compute the reconstruction error. Finally, FIRE additionally leverages frequency-domain information to compute reconstruction errors, which enhances the detector’s robustness in adversarial settings and across different generative models 19 . 2.3 Difference-in-Differences Our proposal is conceptually similar to the difference-in-difference approach for causal inference, which estimates the treatment effect of a particular policy. DID originated in social science research on quasi-experimental designs 37 ; 14 and was later systematized and popularized in the econometrics literature for analyzing panel data with multiple subjects observed over time 3 ; 15 ; 10 . In the typical DID setting, some subjects are continuously exposed to a control policy, while others switch from the control to a new policy at a certain time point. For the latter group, one can compute a first-order difference in their average outcomes before and after the policy change. However, this difference captures not only the effect of the policy but also any time-related effects. To remove the confounding effect of time, a corresponding first-order difference is computed for the control group, and a second-order difference between the two first-order differences is then taken to isolate the treatment effect. For more details, refer to 1 ; 13 ; 30 ; 76 . Despite sharing the same name and similar conceptual ideas, our proposal is designed for a fundamentally different application of AI-generated image detection, as opposed to causal inference. 3 Methodology This section first provides background on diffusion models (Section 3.1 ), then discusses the intuition and limitations of existing reconstruction-based methods (Section 3.2 ), which motivates our use of DID (Section 3.3 ). Finally, we detail our proposal (Section 3.4 ). 3.1 Background on Diffusion Models Image generation via diffusion models typically consists of two processes: a forward diffusion process that gradually corrupts data with Gaussian noise, and a reverse denoising process that reconstructs the underlying image signal from noise. Specifically, in the forward process, an image x_{0} is progressively transformed into a sequence of noisy images \{x_{t}\}_{t=1}^{T} according to x_{t}=\sqrt{\alpha_{t}}x_{t-1}+\sqrt{1-\bar{\alpha}_{t}}\,\epsilon_{t}, for t=1,\dots,T , where x_{t} denotes the noisy image at timestep t , and \bar{\alpha}_{t}=\prod_{i=1}^{t}\alpha_{i} for a sequence of pre-defined weights \{\alpha_{t}\}_{t} that controls the signal-to-noise ratio and \epsilon_{t}\sim\mathcal{N}(0,I) is the Gaussian noise. In contrast, during the reverse process, the model learns to iteratively denoise x_{t} back to a clean sample using a parameterized neural network \epsilon_{\theta}(x_{t},t) that takes x_{t} and t as input and aims to predict the added noise \epsilon_{t} . This process can be mathematically represented by x_{t-1}=\frac{1}{\sqrt{\alpha_{t}}}\left(x_{t}-\frac{1-\alpha_{t}}{\sqrt{1-\bar{\alpha}_{t}}}\,\epsilon_{\theta}(x_{t},t)\right)+\sqrt{1-\alpha_{t-1}}\,\epsilon_{t}, for t=T,\dots,1 , where \epsilon_{\theta}(x_{t},t) is trained to minimize the prediction error between the true and the predicted noise. 3.2 Intuition and Limitations in Reconstruction-Based Detection Let \mathcal{X}\subseteq\mathbb{R}^{3\times 256\times 256} denote the space of all natural images, and \mathcal{M} represent the manifold of images generated by a given pre-trained diffusion model. In general, \mathcal{M} does not coincide with \mathcal{X} , as the model’s learned distribution cannot perfectly align with the true image distribution. However, as generative models become increasingly expressive, \mathcal{M} tends to approximate \mathcal{X} more closely, forming a high-fidelity submanifold near the real image space. The reconstruction can thus be interpreted as a projection of an input image x onto the generative manifold \mathcal{M} , followed by a stochastic perturbation 1 1 1 Similar interpretations have been proposed in the context of LLM-generated text detection ( 98 ) . : \mathcal{R}(x)=\Pi_{\mathcal{M}}(x)+\delta(x), (1) where \mathcal{R}(\bullet) denotes the reconstruction operator, \Pi_{\mathcal{M}}(x) denotes the projection of x onto \mathcal{M} , and \delta(x) is a perturbation term capturing the randomness introduced during the reconstruction. Consequently, for a synthetic image x\in\mathcal{M} , its projection onto \mathcal{M} equals x itself, resulting in a reconstruction error of \Delta_{\text{fake}}(x)=|\delta(x)|, (2) where the absolute value is taken elementwise. In contrast, for a real image x\in\mathcal{X} , its reconstruction error is given by \Delta_{\text{real}}(x)=|x-\Pi_{\mathcal{M}}(x)-\delta(x)|. (3) When the generative model is weak, the discrepancy between \mathcal{M} and \mathcal{X} is large, so |x-\Pi_{\mathcal{M}}(x)| dominates the reconstruction error. As a result, the real image achieves a much larger reconstruction error than the synthetic image (see the upper panel of Figure 1 for an illustration), and we classify an image as synthetic if its reconstruction error is small. This explains the rationale behind existing reconstruction-based methods. When the generative model is strong, however, the real and synthetic image distributions are closely aligned, so the signal |x-\Pi_{\mathcal{M}}(x)| becomes small. Consequently, the reconstruction errors of both real and synthetic images are dominated by the perturbation and become similar (see the bottom panel of Figure 1 ), and existing reconstruction-based methods struggle to distinguish real from synthetic images. In summary, existing reconstruction-based methods are limited in settings where synthetic images closely resemble real ones, due to the strong capacity of modern generative models. This indicates that relying solely on first-order differences is insufficient in such challenging scenarios, which motivates our difference-in-difference approach that seeks higher-order differences to remove perturbation errors while amplifying the weak signal. We will demonstrate how DID addresses this challenge in the next section. 3.3 Difference-In-Differences Unlike existing methods which conduct reconstruction only once, DID performs two consecutive reconstructions using the same pre-trained diffusion model: x^{\prime}=\mathcal{R}(x),\hskip 10.00002ptx^{\prime\prime}=\mathcal{R}(x^{\prime}), where \mathcal{R}(\bullet) is the reconstruction operator defined in ( 1 ), x^{\prime} denotes the reconstruction of the input image x and x^{\prime\prime} denotes the reconstruction of the reconstructed image. Taking the difference between x^{\prime} and x yields the first-order reconstruction error, \Delta(x)=|x-\mathcal{R}(x)| , which forms the basis of existing reconstruction-based detectors for classification. However, as discussed in the previous section, relying solely on the first-order reconstruction error is limited when the signal |x-\Pi_{\mathcal{M}}(x)| for a real image is small, causing the reconstruction error to be dominated by the perturbation \delta(x) . To address this limitation, DID computes the second-order difference between the two reconstruction errors: \Delta^{2}(x)=|x-x^{\prime}|-|x^{\prime}-x^{\prime\prime}|. (4) To illustrate the intuition behind DID, note that, similar to ( 2 ) and ( 3 ), one can derive that for a synthetic image x , the second-order reconstruction error is given by \Delta_{\text{fake}}^{2}(x)=|\delta(x)|-|\delta(x^{\prime})|, (5) whereas for a real image, it is \Delta_{\text{real}}^{2}(x)=|x-\Pi_{\mathcal{M}}(x)-\delta(x)|-|\delta(x^{\prime})|. (6) When the signal is weak, x is close to x^{\prime} . In this case, if the perturbation error \delta is highly correlated across space, then \delta(x)\approx\delta(x^{\prime}) . As a result, the two perturbations cancel out, and ( 5 ) and ( 6 ) simplify to \Delta_{\text{fake}}^{2}(x)\approx 0, (7) and |\Delta_{\text{real}}^{2}(x)|=|x-\Pi_{\mathcal{M}}(x)-\delta(x)+\delta(x^{\prime})|\approx|x-\Pi_{\mathcal{M}}(x)|, (8) where the first equality holds because the weak signal makes the magnitude of |x-\Pi_{\mathcal{M}}(x)| much smaller than that of |\delta(x)| , so that the sign of x-\Pi_{\mathcal{M}}(x)-\delta(x) is dominated by that of -\delta(x) . Comparing ( 7 ) and ( 8 ) with ( 2 ) and ( 3 ), it becomes clear that, unlike the first-order difference, the second-order difference is no longer confounded by the perturbation error and depends only on the signal, even when it is weak. This highlights the advantage of DID over existing reconstruction-based algorithms: by taking a second-order difference, it effectively removes the perturbation noise and uncovers the subtle signal. 3.4 Our Proposal We present the details of our proposed method in this section. Based on the aforementioned analysis, the first-order reconstruction error \Delta(x)=|x-x^{\prime}| is effective for distinguishing real from synthetic images when their discrepancy is large, whereas the second-order reconstruction error \Delta^{2}(x)=|x-x^{\prime}|-|x^{\prime}-x^{\prime\prime}| remains reliable when real and synthetic images are highly similar. To handle both cases simultaneously, our detector integrates both first- and second-order reconstruction errors for robust detection (Figure 3 ); more visualizations are reported in the Appendix Section 12 . Specifically, we train two classifiers independently based on \Delta(x) and \Delta^{2}(x) , respectively, using the standard cross-entropy loss: \mathcal{L}=-\frac{1}{N}\sum_{i=1}^{N}\big[y_{i}\log(y^{\prime}_{i})+(1-y_{i})\log(1-y^{\prime}_{i})\big], (9) where y_{i} denotes the ground-truth label indicating whether the image is real or synthetic, y^{\prime}_{i} is the predicted probability produced by the classifier, and N is the number of training samples. Each classifier outputs a numerical probability score and predicts an image as real if the score is smaller than a predefined threshold c . Finally, an image is classified as real only when both classifiers identify it as real. 4 Experiments Table 1 : Accuracy (%) of different detectors when trained on ImageNet & ADM . The best results are highlighted in bold , while the second best results are underlined . All averages are computed from the raw values and then rounded to two decimals. Train set & Gen. model ImageNet & ADM Eval set Gen. model DID DIRE LaRE 2 AERO. UFD LSUN-B ADM 99.5 99.5 50.0 52.3 63.9 PNDM 97.6 97.6 55.4 49.5 91.8 DDPM 99.5 99.8 56.6 56.7 76.5 iDDPM 99.4 99.6 50.0 50.3 85.1 SDv1 99.7 99.9 100 50.6 94.5 Avg. 99.12 99.25 62.39 51.87 82.36 ImageNet ADM 100 100 100 51.0 85.8 SDv1 99.3 98.9 99.2 37.0 79.9 Avg. 99.64 99.44 99.60 43.99 82.80 LAION Kan.3 99.5 99.3 64.5 66.7 72.6 SDXL 99.6 99.4 66.4 55.5 69.5 Vega 99.7 99.5 66.4 52.2 68.6 Playground v2.5 99.8 99.8 66.0 53.1 82.8 Stable Cascade 99.6 99.4 66.3 73.4 81.4 Avg. 99.60 99.45 65.89 60.14 75.95 Total average 99.41 99.37 70.05 54.00 79.35 Real kandinsky3 SDXL playground-25 LSUN-B w. ADM ImageNet w. SDv1 (a) x (b) \Delta(x) (c) \Delta(x^{\prime}) (d) \Delta^{2}(x) Figure 3 : Visualizations of (a) input image x ; (b) its first-order reconstruction error \Delta(x) ; (c) the reconstruction error of the reconstructed image x^{\prime} ; and (d) the second-order reconstruction error \Delta^{2}(x) . Compared to the first-order error \Delta(x) , the second-order error \Delta^{2}(x) better distinguishes real from fake images: real images produce more stable and brighter responses, while fake images exhibit noticeably weaker signals, resulting in a larger gap between the two categories. In this section, we conduct extensive numerical experiments to investigate the finite-sample performance of the proposed detector. We begin by describing the experimental setting in Section 4.1 . We next report the results of our detector and compare its performance against existing state-of-the-art detectors in Section 4.2 and Appendix Section 9 . Finally, we conduct a sensitivity analysis and an ablation study to examine the robustness of our detector and the contribution of the second-order difference in Sections 4.3 and 4.4 , respectively. 4.1 Experimental Setup To comprehensively evaluate the effectiveness of each detector, we consider a variety of datasets and generative models. Our evaluation benchmark closely follows those used in DIRE 80 , FIRE 19 , and FakeInversion 16 . Specifically, we use two datasets – ImageNet 24 and LAION 68 – to train the classifier for each detector, with one large-scale training set (40k real and 40k synthetic images) and one smaller set (10k real and 10k synthetic images). For ImageNet, we randomly sample 40,000 real images and 40,000 synthetic images generated by ADM 25 . For LAION, we randomly sample 10,000 real images and generate 10,000 synthetic images using open-source text-to-image models such as Kandinsky 3.0 2 and SDXL 62 , with prompts collected from Midjourney. For testing, it is crucial to evaluate each detector on unseen datasets to assess how well it generalizes. Therefore, we use three test datasets – LAION 68 , ImageNet 24 , and LSUN-Bedroom 91 (which is excluded from training) – and generate synthetic images using a more diverse set of generative models than those used in training, including ADM 25 , PNDM 46 , DDPM 34 , iDDPM 56 , SDv1 65 , Segmind Vega 32 , Playground v2.5 42 , Stable Cascade 61 . Further details on dataset construction and data setup are reported to the Appendix Section 6 . We use the ADM model pretrained on LSUN-Bedroom to obtain the reconstructed image. After obtaining the two reconstructions, both the first- and second-order differences are fed into a ResNet-50 classifier for detection. All input images are resized to 256\times 256 . For all baseline detectors, the classification threshold is fixed at the default level c=0.5 . Our method, however, uses two classifiers and labels an input as real only when both classifiers predict it as real. To allow for a fair comparison, we set the threshold of each classifier in DID to 1-\sqrt{0.5}\approx 0.29 , so that its overall false positive rate matches that of using a single classifier with a threshold of 0.5. Accuracy (ACC) is reported as the primary evaluation metric. All our experiments are run on NVIDIA H800 GPUs ; the computation and memory cost is reported in the Appendix Section 10 . Table 2 : Accuracy (%) of different detectors when trained on LAION & Kan.3 (left block) and LAION & SDXL (right block). The best results are highlighted in bold , while the second best results are underlined . All averages are computed from the raw values and then rounded to two decimals. The last column of each block reports the improvement of DID over the second-best baseline. Train set & Gen. model LAION & Kan.3 Imp. LAION & SDXL Imp. Eval set Gen. model DID DIRE LaRE 2 AERO. UFD DID DIRE LaRE 2 AERO. UFD LSUN-B ADM 90.7 88.1 50.3 50.0 50.8 21.85% 95.0 94.3 50.2 50.0 50.3 13.04% PNDM 78.2 73.5 71.2 49.8 51.5 17.55% 81.7 74.6 51.6 49.8 50.9 27.95% DDPM 88.7 85.2 56.5 56.4 51.5 24.05% 95.1 93.3 57.1 56.4 50.5 27.73% iDDPM 80.1 77.5 50.0 49.8 54.2 11.33% 89.0 86.8 50.0 49.8 53.3 16.29% SDv1 98.6 97.8 99.9 49.8 49.7 - 98.4 98.3 99.7 49.8 50.5 - Avg. 87.25 84.41 65.56 51.13 51.52 18.23% 91.83 89.44 61.70 51.13 51.09 22.58% ImageNet ADM 99.1 96.7 89.5 50.7 58.7 74.03% 99.6 96.3 93.3 50.7 61.1 89.65% SDv1 99.2 97.7 94.4 35.0 65.4 65.33% 99.1 96.1 95.5 35.0 67.3 75.73% Avg. 99.16 97.16 91.91 42.83 62.03 70.46% 99.34 96.22 94.40 42.83 64.18 82.47% LAION Kan.3 100 100 100 58.7 93.7 - 99.8 99.3 97.6 58.7 92.9 64.29% SDXL 100 99.9 99.4 52.5 87.0 100% 99.9 99.9 99.9 52.5 92.3 - Vega 100 99.4 95.5 51.0 79.9 100% 99.9 99.8 99.7 51.0 83.8 50.00% Playground v2.5 100 100 97.9 51.1 93.2 - 99.9 99.9 99.4 51.1 93.3 - Stable Cascade 100 100 99.6 64.7 95.7 - 99.8 99.5 99.5 64.7 95.4 54.55% Avg. 100 99.84 98.45 55.57 89.87 100% 99.84 99.67 99.20 55.57 91.50 51.52% Total average 94.55 92.96 83.66 51.60 69.25 22.52% 96.42 94.83 82.78 51.60 70.11 30.66% 4.2 Comparision against Existing Baselines We compare our proposal against the following five state-of-the-art algorithms, using their official open-source implementations for both training and inference. These baseline methods include four reconstruction-based algorithms – (i) DIRE 80 , (ii) LaRE 2 49 , and (iii) AEROBLADE 64 (denoted as AERO. ) – as well as (iv) a non–reconstruction-based approach, UniversalFakeDetect (denoted as UFD ) 58 , which leverages a feature space not explicitly trained to distinguish real from synthetic images. Further details for our method and all baselines are reported in the Appendix Section 7 . Performance with a Larger Training Dataset. When trained on the ImageNet dataset with 40k real images and 40k synthetic images generated by ADM, we report the accuracy of different detectors in Table 1 . DID achieves performance very similar to DIRE. This is expected for two reasons. First, the training dataset contains a large number of samples. Second, we also use ADM for reconstruction, so the generative model used to produce the synthetic training images aligns with the one used for reconstruction. Under this large-sample and well-aligned setting, the first-order reconstruction error is already highly discriminative for distinguishing real from AI-generated images. As a result, both DID and DIRE achieve classification accuracy close to 100%. In contrast, other methods such as AEROBLADE, LaRE 2 and UFD may perform competitively on certain datasets but are less robust across datasets, and their accuracy generally falls behind both DIRE and our DID. Performance with a Smaller Training Dataset. We report the accuracy of various detectors trained on the LAION dataset in Table 2 . This represents a more challenging setting for two reasons: (i) the sample size is smaller, with only 10k real and 10k synthetic images; (ii) the generators used to create the synthetic training datasets (Kan3 and SDXL) differ from the ADM model used for reconstruction. In such cases, the first-order reconstruction discrepancy alone is no longer sufficiently reliable. Consequently, DID benefits from its second-order reconstruction error and outperforms DIRE in almost all settings, particularly when evaluated on LSUN-B and ImageNet, where the test images differ from the training dataset LAION. Across these cases, our total improvement ranges from 20–30%. This demonstrates that our second-order reconstruction error plays a crucial role in more complex tasks, especially when the sample size is smaller or when the generator differs from the reconstruction model. Other baseline detectors, such as LaRE 2 and UFD, perform well when the training and testing datasets are the same, but their performance drops significantly when the datasets differ. This demonstrates their limited generalization ability. AERO. also fails in most cases. 4.3 Sensitivity Analysis Table 3 : Detection accuracy (%) on GAN-generated images under different training settings. Best in bold , second best underlined . All averages are computed from the raw values and then rounded to two decimals. The last column reports the improvement of DID over the second-best baseline. Train set & Gen. model Eval set Gen. model Accuracy (%) Imp. DID DIRE LaRE 2 AERO. UFD LAION & Kan.3 LSUN-B StyleGAN 95.8 94.3 50.4 49.8 50.8 26.32% ProjectedGAN 93.4 91.0 51.2 49.8 50.7 26.52% Diff-ProjectedGAN 92.7 90.2 51.9 49.8 51.1 25.51% Avg. 93.95 91.82 51.12 49.75 50.85 26.07% LAION & SDXL LSUN-B StyleGAN 96.8 96.3 50.7 49.8 50.9 12.16% ProjectedGAN 94.8 93.8 52.8 49.8 50.9 16.13% Diff-ProjectedGAN 93.1 92.1 53.6 49.8 50.9 12.66% Avg. 94.88 94.07 52.37 49.75 50.88 13.76% Total average 94.42 92.94 51.74 49.75 50.87 20.90% In Section 4.2 , all synthetic images were generated using diffusion models. In this section, we further evaluate each detector’s generalization ability by testing it on images produced by generative adversarial networks (GANs). We consider three GAN models, such as StyleGAN, ProjectedGAN, and Diff-ProjectedGAN, and report the ACC of each detector in Table 3 . Although our model is trained exclusively on diffusion-generated data from “Kandinsky3” or “SDXL,” it consistently achieves the highest accuracy across all three GAN variants. In every setting, our method outperforms DIRE, with improvements of up to 20.90%. The performance gap becomes even more pronounced when compared with LaRE 2 , and AEROBLADE, all of which fail to generalize to these GAN-generated distributions. UniversalFakeDetect also struggles in this scenario. These results demonstrate that our detector – despite being trained solely on diffusion-generated images – remains robust to synthetic images produced by substantially different generative mechanisms. We also conduct a complementary sensitivity analysis on image formats (JPEG vs. PNG); details are provided in the Appendix Section 8 . 4.4 Ablation Study In this section, we conduct an ablation study to compare our DID with a variant (denoted as \Delta^{2} ) that uses only the second-order reconstruction error and excludes the first-order term. For completeness, we also include DIRE as a reference. To facilitate the computation, we train a lightweight model using only 10% of the LAION training data and report the results in Table 4 . We make several observations. First, in most settings, \Delta^{2} outperforms DIRE, demonstrating that second-order differences are more effective than first-order differences at capturing subtle discrepancies between real and synthetic images. Second, in settings where LSUN is used as the evaluation dataset and synthetic images are generated by ADM, DIRE outperforms \Delta^{2} . A closer inspection reveals that this corresponds to a simple scenario in which the synthetic images are produced by the same model used for reconstruction. This is consistent with our analysis in Section 3 , which shows that first-order differences are sufficient in simpler settings. Finally, DID outperforms or performs comparably to both \Delta^{2} and DIRE across all settings, illustrating the advantages of leveraging both first- and second-order differences for classification. Additional ablations on the fusion strategy are reported in the Appendix Section 11 . Table 4 : Accuracy (%) on various evaluation datasets when trained on LAION & Kan3. Eval set Gen. model Accuracy (%) DID \Delta^{2} DIRE LSUN-B ADM 86.5 69.0 84.0 PNDM 83.0 81.5 67.5 DDPM 82.0 78.0 71.5 ImageNet ADM 98.9 98.4 91.0 SDv1 98.9 98.7 93.5 LAION Kan.3 99.9 100 99.9 SDXL 99.9 99.9 99.2 Vega 99.9 99.9 98.8 5 Discussion This paper studies the detection of AI-generated images. A popular approach is reconstruction-based, which relies on the first-order difference between an input image and its reconstruction as the basis for classification. Although these algorithms perform well when real and AI-generated images differ substantially, they often fail when the two appear highly similar. To address this challenge, we propose a difference-in-difference approach that utilizes a second-order difference. Our analysis in Section 3.3 shows that the second-order difference effectively removes perturbation noise and uncovers subtle discrepancies between real and AI-generated images. We then integrate both first- and second-order differences into our classifier to simultaneously handle both settings. Extensive experiments demonstrate that our detector outperforms state-of-the-art algorithms (Section 4.2 ); an sensitivity analysis shows that its performance is robust across different generative models (Section 4.3 ); and an ablation study confirms the critical role of the second-order difference (Section 4.4 ). We focus on using second-order differences for detection, but our idea naturally extends to even higher-order differences. For example, one may define a third-order difference as \Delta^{3}(x)=|\Delta^{2}(x)-\Delta^{2}(x^{\prime})|, (10) for an imput image x and its reconstruction x^{\prime} . In principle, one could incorporate all higher-order differences into the classifier to capture weak signals. However, computing a K th-order difference requires reconstructing the image K times, which significantly increases the computation. Thus, there is an inherent trade-off: higher-order differences may uncover more subtle discrepancies between real and AI-generated images, but at the cost of reduced computational efficiency. Determining the optimal order that balances detection performance and computational cost remains an open question for our future work. Finally, we note that although DID is proposed for detecting AI-generated images, the same principle can be readily generalized to the detection of LLM-generated text ( 53 ; 8 ; 97 ; 99 , see e.g.,) . Supplementary Material The Supplementary Material is organized as follows. Section 6 describes how the training and test sets are constructed and details the generative models we use. Section 7 details the training and evaluation pipelines for our model and all baselines. Section 12 shows example visualizations from the various datasets used to evaluate DIRE and DID. 6 More Details of Data 6.1 Training Data We train models seperately on each training sets for all baseline methods and our method. Our training data includes the following three training sets: ImageNet & ablated diffusion model , LAION & Kandinsky 3 , and LAION & Stable Diffusion XL . • ImageNet & ablated diffusion model. This training set contains 40k real images from the 1k classes of ImageNet 24 and 40k fake images generated by an ablated diffusion model 25 constructed and released by the authors of DIRE 80 . We access the data through the official repository at this link . • LAION & Kandinsky 3. This training set consists of 10k real images randomly sampled from LAION 68 and 10k fake images generated with Kandinsky 3 2 using prompts randomly drawn from the Midjourney prompt set. The detailed generation process is described in Section 6.2 . • LAION & Stable Diffusion XL. This training set likewise consists of 10k real images randomly sampled from LAION 68 and 10k fake images generated with Stable Diffusion XL (SDXL) 62 , using the same pool of Midjourney prompts. The detailed generation process is described in Section 6.2 . 6.2 Evaluation Data Our evaluation includes both in-distribution and out-of-distribution datasets. For each dataset, the real images are combined with fake images from different sources. Real images. For each evaluation set, the real images are drawn respectively from three sources: 5k images from 24 , 1k images from LAION 68 , and 1k images from LSUN-B 91 . Fake images. In ImageNet and LSUN-B based evaluation sets, we directly use all the test samples that the DIRE 80 authors provide in the official datasets at this link . In the LAION-based evaluation sets, we conidered a more challenging setting. We first randomly sample 1k prompts from Midjourney and then generate images using several state-of-the-art text-to-image models on Hugging Face. • Kandinsky 3. For Kandinsky 3 images, we use the Kandinsky 3 model 2 from Hugging Face ( kandinsky-community/kandinsky-3 ), with the default generation parameters. • Stable Diffusion XL. For SDXL images, we follow the standard two-stage Stable Diffusion XL pipeline 62 from Hugging Face: we first generate an initial image with the base model ( stabilityai/stable-diffusion-xl-base-1.0 ) and then refine it with the refiner model ( stabilityai/stable-diffusion-xl-refiner-1.0 ), while keeping all other parameters at their default values. • Segmind Vega. For Segmind Vega images, we use the Segmind Vega model 32 from Hugging Face ( segmind/Segmind-Vega ), again with the default generation parameters. • Playground v2.5. For Playground v2.5 images, we use the Playground v2.5 model 42 from Hugging Face ( playgroundai/playground-v2.5-1024px-aesthetic ), with the default parameters in their usage example. • Stable Cascade. For Stable Cascade images, we follow the official two-stage Stable Cascade 61 setup from Hugging Face: we first sample image latents using the StableCascadePriorPipeline ( stabilityai/stable-cascade-prior ), and then decode these latents into RGB images using the StableCascadeDecoderPipeline ( stabilityai/stable-cascade ), keeping all other parameters at their default values. 6.3 Validation Data The validation set follows the same construction pattern as the training data and contains 2k samples from LAION & Kandinsky 3 , 2k from LAION & Stable Diffusion XL , and 10k from ImageNet & the ablated diffusion model , respectively, for each training. It is used solely for early stopping to select the best checkpoint. As several baselines are originally implemented with different early stopping strategies in their public codebases, we retain their strategy primarily to guarantee that the baseline models reach their best performance, and we apply the same protocol as DIRE 80 to our method for a strictly fair comparison on the test sets. 7 More Details of Experiment Implementation Table 5 : Accuracy (%) of DID trained on the PNG-only variant. Left block: trained on LAION & Kan.3 . Right block: trained on LAION & SDXL . Models are evaluated on PNG, JPEG 95, and JPEG 75 versions of each test set. All averages are computed from raw values and then rounded to two decimals. Gen. model LAION & Kan.3 (PNG-only training) LAION & SDXL PNG JPG95 JPG75 PNG JPG95 JPG75 Kan.3 97.2 98.9 95.1 90.6 85.4 70.4 SDXL 93.2 88.9 76.3 97.3 97.1 85.6 Vega 89.1 84.3 72.3 95.2 93.0 76.3 Playground v2.5 94.9 92.9 82.7 91.6 88.0 73.4 Stable Cascade 96.2 95.6 89.4 94.4 87.2 71.7 Avg. 94.09 92.09 83.15 93.81 90.13 75.46 7.1 Reconstruction Module This section provides implementation details of the reconstruction module used in the \Delta and \Delta^{\prime} branches. The reconstruction operator itself follows the standard inversion–reconstruction pipeline described in the main paper (Section 3 ). Here, we focus solely on the practical settings required for reproducibility, rather than repeating the theoretical formulation. Inversion and First Reconstruction Each input image is resized or cropped to 256\times 256 and normalized according to the pretrained diffusion model. We apply deterministic DDIM inversion to obtain the corresponding latent noise representation. During reconstruction, we use DDIM sampling with 20 steps ( timestep_respacing="ddim20" ) and a fixed \eta=0 . A single sampling pass produces the first reconstructed image x^{\prime}_{0} , from which we compute the element-wise absolute reconstruction error \Delta=|x_{0}-x^{\prime}_{0}| . Second Reconstruction and DiffRecon Features Using x^{\prime}_{0} as the new input, we apply the same DDIM-20 inversion–reconstruction procedure to obtain a second reconstructed image x^{\prime\prime}_{0} . The second-order reconstruction error is defined as \Delta^{\prime}=|x^{\prime}_{0}-x^{\prime\prime}_{0}| . We then compute the DiffRecon feature as \Delta^{2}=\Delta-\Delta^{\prime} . The resulting error maps are mapped to the standard 8-bit intensity range [0,255] and saved as images, which are subsequently used as inputs to the downstream classifier. Fixed Inference Without Parameter Updates The reconstruction module operates strictly in inference mode, and all U-Net and diffusion-scheduler parameters remain frozen. We use publicly released ADM checkpoints and adopt a fixed DDIM-20 configuration ( \eta=0 ). Except for the image resolution and sampling settings, the reconstruction module introduces no additional hyperparameters . Dataset-Specific ADM Checkpoints All reconstructions are performed with fixed, publicly released ADM checkpoints. LSUN real and fake images are processed using the ADM model trained on LSUN. All ImageNet and LAION images—including their synthetic variants—are reconstructed using the unconditional ImageNet 256\times 256 ADM model. No fine-tuning or parameter adaptation is applied; only the appropriate dataset-specific checkpoint is selected, while all other inversion and sampling configurations remain unchanged. 7.2 Training Details DID ( \Delta , \Delta^{2} ) The two branches of DID are trained independently using the \Delta and \Delta^{2} features generated offline by the reconstruction module. During training, no gradients are back-propagated through the reconstruction process or the diffusion model; only the classifier parameters are updated. We adopt a ResNet-50 classifier initialized with ImageNet-pretrained weights. All input images are first resized to 256\times 256 . During training, we apply light augmentation consisting of random cropping to 224\times 224 and random horizontal flipping, while validation and testing use a center crop to 224\times 224 . All inputs are normalized. The classifier is optimized using Adam (default parameters \beta_{1}=0.9 , \beta_{2}=0.999 ) with an initial learning rate of 10^{-4} . Binary cross-entropy is used as the loss function. A unified batch size of 256 is used for all methods. Training runs for up to 100 epochs with early stopping based on validation accuracy, and the best validation checkpoint is used for all reported results. DIRE DIRE is trained in the same way as DID, using the \Delta feature as input and following identical preprocessing and classifier settings in their official repository . LaRE 2 We reproduce LaRE 2 using the official implementation released by the authors and employ the provided CLipClassifierWMapV6 as the classifier. The model uses CLIP RN50 as the visual backbone with official pretrained weights. Before being fed into the network, input images are normalized and padded–center-cropped to 224\times 224 . Random cropping is applied during training, while validation and testing use a center crop. The classifier is optimized with Adam ( \beta_{1}=0.9 , \beta_{2}=0.999 ) using a learning rate of 10^{-4} and a batch size of 256. The learning rate is adaptively reduced using ReduceLROnPlateau based on validation accuracy, with a minimum learning rate of 10^{-7} . AEROBLADE (AERO.) AEROBLADE is used as a training–free baseline. The official implementation computes reconstruction errors with the pretrained diffusion autoencoder and evaluates them using ROC–based metrics such as AUC, without introducing any learning or threshold selection. We follow this setting and keep the autoencoder fixed throughout. For consistent evaluation across all methods, we introduce a lightweight calibration step: reconstruction scores are computed on the training split and a fixed operating threshold is chosen as the 95 th percentile of the training scores. This threshold is applied to the test split to compute the reported ACC. No parameter optimization is involved, and AEROBLADE remains fully training–free. UniversalFakeDetect (UFD) UniversalFakeDetect is used as a supervised baseline. Following the official implementation and released configuration, we use a pretrained CLIP ViT-L/14 backbone together with a linear binary classifier for distinguishing real and generated images. The backbone is kept frozen during training, and only the classification head is updated on the training split. All images are resized to 256\times 256 , cropped to 224\times 224 , augmented with random cropping and horizontal flipping during training, and normalized. The classifier head is trained with BCE-with-logits loss using the AdamW optimizer (\beta_{1}=0.9,\beta_{2}=0.999) , a batch size of 256, and an initial learning rate of 10^{-4} . Validation accuracy is used for model selection, and the best checkpoint is reported on the test split. 8 Sensitivity to image formats. In the main experiments, real images are provided in JPEG format while generated images are stored as PNG files, following the original DIRE setup. To verify that DID does not rely on such JPEG/PNG container differences, we conduct an additional sensitivity analysis. We rebuild the training set so that all real images come from their official PNG releases (the fake images are already PNG), making the entire training set natively PNG. We then train DID on this PNG-only data and evaluate the resulting model on three test variants: native PNG, JPEG 95, and JPEG 75, all derived from the same PNG originals. As shown in Table 5 , DID maintains consistently high performance across all formats. This demonstrates that DID does not depend on JPEG/PNG encoding artifacts and instead captures intrinsic differences between real and generated images. 9 New baselines and datasets We further compare DID with two newly added baselines, Effort 85 and DDA 18 , under two training setups: training all models on (i) GenImage 101 (Table 6 ) and (ii) ImageNet (Table 7 ). We then evaluate these models on GenImage 101 , GenDet 100 , and our two original test datasets, LAION and ImageNet . In addition to the original ACC metric, we also report two newly added metrics, ROC-AUC and FPR@TPR95. Across both tables, DID consistently outperforms all baselines. Table 6 : Acc (%) / AUROC / FPR@TPR95 (%) of DID (with two thresholds) and two additional baselines ( Effort and DDA ). All detectors are trained on GenImage and evaluated on GenImage , GenDet , and our two original test datasets. To avoid excessive 1.00 values, we report AUROC with three decimal places. Eval set Gen. model DID 0.29 DID 0.5 Effort DDA GenImage ADM 99.90 / 1.000 / 0.00 100.00 / 1.000 / 0.00 98.55/ 0.999 /0.40 99.30/ 1.000 / 0.20 BigGAN 99.90 / 1.000 / 0.00 99.95 / 1.000 / 0.00 95.45/0.995/2.60 98.70/ 0.999 / 0.50 GLIDE 99.90 / 1.000 / 0.00 100.00 / 1.000 / 0.00 98.35/ 0.999 / 0.20 99.20/ 1.000 / 0.20 Midjourney 99.70 / 1.000 / 0.00 99.70 / 1.000 / 0.00 57.25 /0.744/80.00 54.95/ 0.845 / 56.30 SD-v1.4 99.45 / 1.000 / 0.00 99.50 / 1.000 / 0.00 86.70/ 0.975 / 13.00 72.81/0.965/15.60 SD-v1.5 99.50 / 1.000 / 0.00 99.40 / 1.000 / 0.00 83.95/ 0.975 / 11.30 72.65/0.962/16.50 VQDM 99.90 / 1.000 / 0.00 99.90 / 1.000 / 0.00 97.00/ 0.997 /1.80 99.50 / 1.000 / 0.30 Wukong 99.20 / 1.000 / 0.00 99.15 / 1.000 / 0.00 83.05/ 0.969 /15.60 74.50/0.968/ 11.00 Avg. 99.68 / 1.000 / 0.00 99.70 / 1.000 / 0.00 87.54/0.957/15.61 83.95/ 0.967 / 12.33 GenDet BigGAN 99.95 / 1.000 / 0.00 99.95 / 1.000 / 0.00 98.55/ 1.000 / 0.10 99.20 / 1.000 / 0.00 CRN 99.95 / 1.000 / 0.00 99.95 / 1.000 / 0.00 98.15/0.998/0.60 98.45 / 0.999 / 0.40 DeepFake 99.65 / 1.000 / 0.00 99.45 / 1.000 / 0.00 96.35/ 0.995 /2.50 99.20/ 1.000 / 0.00 GauGAN 99.95 / 1.000 / 0.00 99.95 / 1.000 / 0.00 97.45/ 0.997 /0.90 99.35 / 1.000 / 0.00 IMLE 99.95 / 1.000 / 0.00 99.95 / 1.000 / 0.00 98.70 / 1.000 / 0.10 97.70/ 0.998 /1.00 StarGAN 99.95 / 1.000 / 0.00 99.95 / 1.000 / 0.00 98.50 / 0.999 /0.20 99.35/ 1.000 / 0.00 Avg. 99.90 / 1.000 / 0.00 99.87 / 1.000 / 0.00 97.95/0.998/0.73 98.88/ 0.999 / 0.23 LAION Kan.3 99.60 / 1.000 / 0.00 99.60 / 1.000 / 0.00 63.85 / 0.845 /61.00 57.10/0.832/ 48.20 SDXL 99.60 / 0.999 / 0.00 99.50 / 0.999 / 0.00 66.85/0.870/59.20 67.70/ 0.907 / 31.50 Vega 98.90 / 0.999 / 0.00 98.75 / 0.999 / 0.00 57.50/0.753/78.10 76.90/ 0.943 / 23.30 Playground v2.5 99.60 / 1.000 / 0.00 99.55 / 1.000 / 0.00 67.05/0.865/62.70 81.55/ 0.959 / 17.70 Stable Cascade 99.65 / 1.000 / 0.00 99.55 / 1.000 / 0.00 81.20/ 0.960 / 20.00 69.20/0.920/28.00 Avg. 99.47 / 0.999 / 0.00 99.39 / 0.999 / 0.00 67.29/0.859/56.20 70.49/ 0.912 / 29.74 ImageNet ADM 99.65 / 1.000 / 0.00 99.65 / 1.000 / 0.00 97.20/ 0.996 /1.20 99.05 / 1.000 / 0.20 SDv1 99.35 / 1.000 / 0.00 98.70 / 1.000 / 0.00 84.70/0.963/18.10 71.05/ 0.967 / 12.10 Avg. 99.50 / 1.000 / 0.00 99.17 / 1.000 / 0.00 90.95/0.979/9.65 85.05/ 0.983 / 6.15 Total average 99.68 / 1.000 / 0.00 99.62 / 1.000 / 0.00 86.02/0.947/20.46 85.11/ 0.965 / 12.43 Table 7 : Acc (%) / AUROC / FPR@TPR95 (%) of DID (with two thresholds) and two additional baselines ( Effort and DDA ). All detectors are trained on ImageNet and evaluated on GenImage , GenDet , and our two original test datasets, LAION and ImageNet . To avoid excessive 1.00 values, we report AUROC with three decimal places. Eval set Gen. model DID 0.29 DID 0.5 Effort DDA GenImage ADM 99.20 / 1.000 / 0.00 99.50 / 1.000 / 0.00 86.30/ 0.986 /6.70 98.30/ 0.999 / 0.10 BigGAN 99.10 / 1.000 / 0.00 99.40 / 1.000 / 0.00 80.15/0.878/ 39.00 98.50/ 1.000 / 0.00 GLIDE 99.20 / 1.000 / 0.00 99.50 / 1.000 / 0.00 85.85/0.973/12.80 97.50/ 0.998 / 0.90 Midjourney 99.20 / 1.000 / 0.00 99.50 / 1.000 / 0.00 57.00/0.597/ 90.20 56.15/ 0.810 / 58.80 SD-v1.4 99.20 / 1.000 / 0.00 99.50 / 1.000 / 0.00 85.30/0.958/19.10 82.91/ 0.969 / 13.30 SD-v1.5 99.20 / 1.000 / 0.00 99.50 / 1.000 / 0.00 84.75/0.950/22.10 83.60/ 0.967 / 17.00 VQDM 99.20 / 1.000 / 0.00 99.50 / 1.000 / 0.00 86.45/0.991/ 5.40 98.55/ 1.000 / 0.00 Wukong 99.20 / 1.000 / 0.00 99.45 / 1.000 / 0.00 84.40/0.949/22.80 84.10/ 0.973 / 12.70 Avg. 99.19 / 1.000 / 0.00 99.48 / 1.000 / 0.00 81.28/0.910/27.26 87.45/ 0.964 / 12.85 GenDet BigGAN 99.85 / 1.000 / 0.00 99.90 / 1.000 / 0.00 99.70/ 1.000 / 0.00 99.45/1.000/ 0.00 CRN 99.85 / 1.000 / 0.00 99.90 / 1.000 / 0.00 98.80/ 1.000 /0.30 99.35/0.999/ 0.10 DeepFake 99.50 / 1.000 / 0.10 99.20/ 1.000 / 0.10 96.75/0.997/0.80 99.30 / 1.000 / 0.00 GauGAN 99.85 / 1.000 / 0.00 99.90 / 1.000 / 0.00 99.65/ 1.000 / 0.00 99.60/ 1.000 / 0.00 IMLE 99.85 / 1.000 / 0.00 99.90 / 1.000 / 0.00 99.75/ 1.000 / 0.00 99.40/1.000/ 0.10 StarGAN 99.85 / 1.000 / 0.00 99.90 / 1.000 / 0.00 99.65/1.000/ 0.00 99.60/ 1.000 / 0.00 Avg. 99.79 / 1.000 / 0.02 99.78 / 1.000 / 0.02 99.05/0.999/0.18 99.45/ 1.000 / 0.03 LAION Kan.3 99.30 / 1.000 / 0.00 99.55 / 1.000 / 0.00 80.75/ 0.934 / 31.30 59.05/0.826/47.70 Playground v2.5 99.30 / 1.000 / 0.00 99.60 / 1.000 / 0.00 83.95/0.941/28.60 87.00/ 0.962 / 14.80 SDXL 99.25 / 0.999 / 0.00 99.55 / 0.999 / 0.00 85.00/ 0.953 / 21.30 76.30/0.911/35.20 Stable Cascade 99.35 / 1.000 / 0.00 99.65 / 1.000 / 0.00 90.60/ 0.976 / 12.60 75.50/0.928/25.40 Vega 99.25 / 1.000 / 0.00 99.55 / 1.000 / 0.00 79.85/0.922/34.30 80.80/ 0.944 / 22.30 Avg. 99.29 / 1.000 / 0.00 99.58 / 1.000 / 0.00 84.03/ 0.945 / 25.62 75.73/0.914/29.08 ImageNet ADM 99.85 / 1.000 / 0.00 99.90 / 1.000 / 0.00 99.40/0.999/ 0.00 99.55/ 1.000 / 0.00 SDv1 99.85 / 1.000 / 0.00 99.90 / 1.000 / 0.00 98.10/ 0.999 / 0.30 83.45/0.987/6.40 Avg. 99.85 / 1.000 / 0.00 99.90 / 1.000 / 0.00 98.75/ 1.000 / 0.15 91.50/0.993/3.20 Total average 99.45 / 1.000 / 0.00 99.63 / 1.000 / 0.00 88.67/0.953/16.55 88.47/ 0.965 / 12.13 Table 8: Per-image inference time (seconds) and memory usage (MB) for LaRE2, DIRE, and DID. Method Reconstruction Testing Time (Memory) Time (Memory) LaRE2 0.09 (33.34) 0.66 (9.74) DIRE 1.01 (396.48) 0.34 (21.77) DID 2.01 (398.39) 0.45 (22.55) 10 Computation and Memory Cost Table 8 reports the inference cost on a single NVIDIA A800 GPU. DID takes 2.46 seconds per image, including both reconstruction and testing. For comparison, DIRE and LaRE take 1.35s and 0.75s per image, respectively. Although DID is slower, it provides a clear accuracy gain (Table 1 in the main text). DID’s peak GPU memory is similar to DIRE (Table 8 ), so it can run on a single GPU. Table 9 : Acc(%) / AUROC / FPR@TPR95(%) of DID 0.29 and a variant that fits both 1st- and 2nd-order signals into a single classifier (DID SC ). Train set Eval set LAION ImageNet ImageNet DID 0.29 99.29/1.00/0.00 99.85/1.00/0.00 DID SC 99.03/1.00/0.00 99.45/1.00/0.00 11 Ablation on Fusion Strategy Our method uses two separate classifiers to process 1st- and 2nd-order signals, and combines their outputs with an additive gate. This section studies the fusion strategy. Specifically, we compare our score-level fusion (two classifiers with an additive gate) with a feature-level variant that concatenates 1st- and 2nd-order features and feeds them into a single classifier. As shown in Table 9 , the single-classifier variant achieves performance comparable to our main design. We keep the two-classifier design mainly for simplicity and interpretability. Since 1st- and 2nd-order reconstruction errors capture different signals, separating them makes the contribution of each signal easier to analyze. The two-classifier design is also more memory-efficient, as it uses fewer parameters than the single-classifier variant. 12 More Visualization About DID In this section, we provide additional visualizations to illustrate how DID behaves across real images and a wide range of generative models. Figure 4 summarizes the key differences between first–order and second–order residuals, while Figures 5 – 11 present more detailed residual matrices for each model. Together, these visualizations highlight the limitations of first–order residuals and the improved consistency achieved by our second–order module. Real ADM Kan.3 Vega SDXL Playground-2.5 Stable Cascade \underbrace{\rule{238.48886pt}{0.0pt}}_{{\bm{\Delta}(x)}} \underbrace{\rule{238.48886pt}{0.0pt}}_{{\bm{\Delta}^{2}(x)}} Figure 4 : Comparison of first–order and second–order residuals across real and generated images. The DIRE framework 80 shows that real images typically produce sharper and more structured first-order residuals \Delta x , whereas fake images tend to yield weaker patterns. However, in broader evaluation across diverse and strong generative models, first-order residuals are not always stable when the real and synthetic distributions are close. In more challenging cases, fake images can even produce stronger residual signals than real images, leading to potential misclassification. In contrast, our proposed second-order residual module \Delta^{2}x provides more consistent separability between real and fake samples by taking the difference between the reconstruction error of the input image and that of its reconstructed version. x x^{\prime} \Delta x x^{\prime\prime} \Delta x^{\prime} \Delta^{2}x Figure 5 : Visualization of real images across the DID pipeline. We show the original image x , the first reconstruction x^{\prime} , the second reconstruction x^{\prime\prime} , and their corresponding residual maps \Delta x , \Delta x^{\prime} , and \Delta^{2}x . x x^{\prime} \Delta x x^{\prime\prime} \Delta x^{\prime} \Delta^{2}x Figure 6 : Visualization of ADM-generated fake images from the ImageNet subset constructed in the DIRE dataset. For each ImageNet class (“A photo of class”, class from ImageNet 24 ), we show the ADM-generated image x , its first reconstruction x^{\prime} , the second reconstruction x^{\prime\prime} , and their corresponding residual maps \Delta x , \Delta x^{\prime} , and \Delta^{2}x . x x^{\prime} \Delta x x^{\prime\prime} \Delta x^{\prime} \Delta^{2}x Figure 7 : Visualization of Kan3-generated images constructed for our dataset. For each sample, we show the original synthesized image x , the first reconstruction x^{\prime} , the second reconstruction x^{\prime\prime} , and their corresponding residual maps \Delta x , \Delta x^{\prime} , and \Delta^{2}x . All Kan3 images are generated using prompts collected from Midjourney. x x^{\prime} \Delta x x^{\prime\prime} \Delta x^{\prime} \Delta^{2}x Figure 8 : Visualization of Vega-generated images constructed for our dataset. For each sample, we show the original synthesized image x , the first reconstruction x^{\prime} , the second reconstruction x^{\prime\prime} , and their corresponding residual maps \Delta x , \Delta x^{\prime} , and \Delta^{2}x . All Vega images are generated using prompts collected from Midjourney. x x^{\prime} \Delta x x^{\prime\prime} \Delta x^{\prime} \Delta^{2}x Figure 9 : Visualization of SDXL-generated images constructed for our dataset. For each sample, we show the original synthesized image x , the first reconstruction x^{\prime} , the second reconstruction x^{\prime\prime} , and their corresponding residual maps \Delta x , \Delta x^{\prime} , and \Delta^{2}x . All SDXL images are generated using prompts collected from Midjourney. x x^{\prime} \Delta x x^{\prime\prime} \Delta x^{\prime} \Delta^{2}x Figure 10 : Visualization of playground-2.5-generated images constructed for our dataset. For each sample, we show the original synthesized image x , the first reconstruction x^{\prime} , the second reconstruction x^{\prime\prime} , and their corresponding residual maps \Delta x , \Delta x^{\prime} , and \Delta^{2}x . All playground-2.5 images are generated using prompts collected from Midjourney. x x^{\prime} \Delta x x^{\prime\prime} \Delta x^{\prime} \Delta^{2}x Figure 11 : Visualization of Stable Cascade-generated images constructed for our dataset. For each sample, we show the original synthesized image x , the first reconstruction x^{\prime} , the second reconstruction x^{\prime\prime} , and their corresponding residual maps \Delta x , \Delta x^{\prime} , and \Delta^{2}x . All Stable Cascad images are generated using prompts collected from Midjourney.