                               Few-Shot Learner Generalizes Across AI-Generated Image Detection


Table 1. Comparison of our FSD with previous studies. We train several classifiers on different subsets and report the accuracy for each
unseen test subset. The best results are highlighted in boldface, while the second-optimal results are marked with underline.

                                                                          Test Subset                                 Avg
                      Method
                                              Midjourney      GLIDE       ADM SD            VQDM        BigGAN       Acc(%)
          Spec (Zhang et al., 2019b)             50.0          64.7        52.8 56.1         56.5         63.0        57.2
         CNNSpot (Wang et al., 2020)             52.8          73.3        55.0 55.9         54.4         66.2        59.6
          F3Net (Qian et al., 2020)              50.1          52.5        66.4 57.0         59.4         50.4        56.0
          GramNet (Liu et al., 2020)             51.3          62.6        53.8 56.8         52.2         57.2        55.7
          DIRE (Wang et al., 2023)               57.9          68.2        57.3 58.2         59.6         50.8        58.7
          LARE2 (Luo et al., 2024)               62.7          80.2        63.5 79.6         76.9         72.0        72.5
               FSD (zero-shot)                   75.1          93.9        74.1 88.0         69.1         62.1        77.1
                FSD (10-shot)                    80.9          97.1        79.2 88.8         76.2         82.2        84.1

pute the prototypical representations following Equation (1).          age detection studies (Zhu et al., 2023; Wang et al., 2023;
If the nearest representation of a test image is labeled as a          Luo et al., 2024), we adopt the accuracy (ACC) and average
synthetic class, the image will be considered fake.                    precision (AP) as our evaluation metrics. The threshold step
                                                                       for computing AP is set to 0.1.
4. Experiment
                                                                       4.2. Implementation Details
In this section, we first introduce the experimental setups
and then provide a comparison between FSD and previous                 To be more comparable with previous works, we adopt the
studies. We also visualize the feature space to highlight the          ResNet-50 (He et al., 2016) pretrained on ImageNet (Deng
superiority of our approach.                                           et al., 2009) as the backbone of our model, which outputs a
                                                                       prototype vector of 1024 dimensions. Following Wang et al.
                                                                       (2023), the input images are first resized to 256 × 256 and
4.1. Datasets and Evaluation Metrics
                                                                       then randomly cropped to 224×224 with random horizontal
Datasets. We evaluate our proposed method on the widely                flipping during training. In contrast, only a center crop to
used GenImage dataset (Zhu et al., 2023), which contains               224 × 224 is performed after resizing the images during
1, 331, 167 real images from ImageNet (Deng et al., 2009)              testing. The distance in the metric space is measured with
and 1, 350, 000 generated images from 7 diffusion models               Squared Euclidean Distance.
and one GAN. The diffusion generators include Midjourney
                                                                       To fit the classification task, we employ different few-shot
(mid, 2022), Stable Diffusion V1.4 (Rombach et al., 2022),
                                                                       strategies for training and testing. Specifically, we select
Stable Diffusion V1.5 (Rombach et al., 2022), Wukong
                                                                       one synthetic subset as the test set and utilize the remaining
(wuk, 2022), ADM (Dhariwal & Nichol, 2021), GLIDE
                                                                       6 subsets to train a classifier. At every training step, 3
(Nichol et al., 2022) and VQDM (Gu et al., 2022). The
                                                                       classes are randomly selected from the training set, with
only GAN utilized is BigGAN (Brock et al., 2019). The
                                                                       5 samples chosen from each class for the support set and
real images are first divided into 8 subsets. Each subset is
                                                                       another 5 samples per class for the query set. We employ
subsequently partitioned into a training part and a test part.
                                                                       Adam as the optimizer to minimize the cross-entropy loss
Each generator is associated with one specific subset and
                                                                       with a base learning rate of 10−4 . We also adopt a StepLR
uses the category labels of the real images within the subset
                                                                       scheduler with γ = 0.5 and step size = 80000. Each
to produce synthetic images. Consequently, the GenImage
                                                                       classifier is trained for 200, 000 steps, with a batch size of
dataset consists of 8 fake-vs-real subsets for analysis.
                                                                       16. During testing, we conduct a binary classification task
In this study, the synthetic images in different subsets are           by comparing the selected test class against the real class.
categorized into distinct classes, while real images from all          For zero-shot detection, we randomly select 1024 samples
subsets are aggregated into a single class. We also observe            from each training subset to compute the metadata vectors.
that 3 diffusion models, SD v1.4, SD v1.5 and Wukong,                  Our method is implemented with the PyTorch library and
share an identical model structure, making it challenging to           all the experiments are conducted on a single A100 with
differentiate among them. Thus, we merge their correspond-             40GB memory.
ing subsets into a unified subset, named Stable Diffusion
(SD). Ultimately, the dataset used in our experiments com-             4.3. Comparison to Existing Methods
prises 7 classes of images from different sources.
                                                                       We compare FSD with several state-of-the-art synthetic im-
Evaluation metrics. Following previous AI-generated im-                age detection methods and summarize the results in Table 1.

                                                                   5
