PairCLIP-SWA: Similarity-Guided Balancing and Stochastic Weight Averaging for Generalized Deepfake Image Detection with OpenCLIP
Organizations: Department of Electrical and Electronic Engineering, BUET, Dhaka 1205, Bangladesh
Abstract
Deepfake detectors are almost always deployed as the single checkpoint that scored best on a validation split, yet the reliability of that choice is rarely measured. We measure it with PairCLIP-SWA, a single-backbone detector that adapts an OpenCLIP ViT-L/14 visual tower by progressive block unfreezing on a class-balanced corpus built by CLIP-similarity-guided one-to-one subsampling, and averages the fine-tuning trajectory in weight space. Trained in-domain on the IEEE SP Cup 2025 (DF-Wild-Cup) benchmark under the same protocol as the strongest published three-backbone ensemble, the weight-averaged detector reaches 97.04% accuracy, 98.64% AU-ROC and a 4.07% equal error rate, against 94.46%, 97.60% and 5.00%. Its training log shows why averaging matters: over the averaged epochs the non-averaged checkpoint swings across 5.34 points of validation accuracy while its validation loss more than doubles, whereas the average is never worse and is up to 5.99 points better. On an OpenForensics-derived benchmark the same instability becomes a misranking: the checkpoint that validation accuracy selects (98.43%) scores 88.85% on a disjoint 10,905-image test partition, rejecting 21.1% of genuine photographs, while the terminal average, ranked last on validation, scores 94.76%. A study of twenty-two in-house configurations on the identical DF-Wild-Cup split, including preprocessing ablations, shows that CLIP pre-training rather than ensembling drives accuracy, that secondary face cropping costs about 34 points, and that frequency-domain inputs transfer poorly. We recommend per-class selection criteria measured off the early-stopping split.
Figures & tables
| Step | Setting | Rationale | Evidence | |
| P1 | Input region | Image as released; no secondary face detection or crop | Blending boundaries and face–context inconsistencies are among the most generator-agnostic cues [ 25 , 26 ] ; a tight crop removes them. DF-Wild-Cup images are already aligned by DeepfakeBench [ 8 ] , so a second detector pass compounds rather than removes variation, and fails silently on profile, occluded or low-resolution faces. | dlib crop: val., points below full frame (Table XI ) |
| P2 | Decoding | 3-channel RGB (greyscale and alpha converted) | Matches the input contract of CLIP pre-training; greyscale captures occur in the wild (Fig. 6 ). | design |
| P3 | Resampling | Bilinear resize to , no crop | Reproduces the pre-training token grid ( patches of pixels) so positional embeddings need no interpolation; resizing rather than cropping keeps peripheral boundary evidence; the aspect distortion is identical for both classes and cannot act as a label cue. | design |
| P4 | Normalization | Eq. ( 1 ), CLIP | The frozen patch embedding and at least of the tower cannot adapt to a different input scale; ImageNet statistics would shift the distribution the frozen prefix sees. | Section IV-B : a double rescale compresses inputs |
| P5 | Augmentation | Horizontal flip, , training only | Flipping is label-preserving and leaves pixel statistics untouched; colour jitter, blur, JPEG re-compression and random crops alter exactly the high-frequency and colour evidence of manipulation, or remove peripheral boundaries (P1, P3). | ViT+LoRA: augmentation raises the early peak but the gain is not retained (Table XI ) |
| P6 | Class balancing | One-to-one CLIP-similarity-guided subsample of the fake pool, without replacement (Section III-C ) | One balanced corpus in one training stage, instead of oversampling (repeated reals), reweighting (majority domination), SMOTE (synthetic “reals” are invalid for authenticity) or five sequential stages [ 9 ] ; intended to reduce class-conditional content differences [ 28 ] . | Random undersampling, same backbone, different schedule: (Table XI ) |
| Component | Parameters | Share |
| Patch embedding ( ) | ||
| Class token and positional embedding | ||
| Pre-/post-layer normalization | ||
| Transformer blocks ( M) | ||
| Output projection ( ) | ||
| Linear head ( ) |
| Corpus | Split | Images | Real/Fake | Role |
| DF-Wild- Cup | train ∗ | training | ||
| val. | selection, eval. | |||
| Open- Forensics | train | — | — | training |
| val. | selection | |||
| test | held-out test | |||
| ∗ Stage-1 subsample of training images. | ||||
| Setting | Value |
| Backbone | OpenCLIP ViT-L/14, OpenAI weights |
| Initialization | pre-trained tower, random linear head |
| Preprocessing | Table I (P1–P8) |
| Training corpus | -image subsample |
| Batch size | ( ), T4, DataParallel |
| Optimizer | AdamW, , |
| Split ( ) | Best regular | Best SWA | Final SWA |
| DF-Wild-Cup val. ( ) | 97.04 | 97.04 | |
| 95% CI | [94.89, 96.34] | [96.38, 97.58] | [96.38, 97.58] |
| OpenForensics val. ( ) | 98.43 | 98.43 | |
| 95% CI | [98.30, 98.55] | [98.30, 98.55] | [97.52, 97.81] |
| OpenForensics test ( ) | 94.76 | ||
| 95% CI | [88.24, 89.43] | [88.24, 89.43] | [94.33, 95.17] |
| Training | Non-averaged val. | SWA val. | |||||||
| Epoch | Blocks | Trainable | Loss | Acc. | Loss | Acc. | Loss | Acc. | Gap |
| 12 | 8 | — | |||||||
| 13 | 8 | — | |||||||
| 14 | 9 | ||||||||
| 15 | 9 | ||||||||
| 16 | 10 | ||||||||
| Family | Model | Params | Acc. (%) |
| Spatial CNN | VGG-19 [ 66 ] | M | |
| ResNet-50 [ 67 ] | M | ||
| MobileNet-V2 | M | ||
| ResNet-34 [ 67 ] | M | ||
| Inception-V3 | M | ||
| ResNet-34 SE [ 32 ] | M |
| Metric | CAE-Net | PairCLIP-SWA | |
| a | |||
| Accuracy (%) | 97.04 | ||
| 95% CI | [93.60, 95.22] | [96.38, 97.58] | [96.66, 97.82] |
| Errors / | 91 | ||
| AU-ROC (%) b | 98.64 | ||
| EER (%) b | 4.07 | ||
| Split | Checkpoint | Acc. | Prec. | Rec. | Spec. | MCC | |
| Validation ( ) | Best reg./SWA | 98.43 | 99.03 | 98.43 | 0.969 | ||
| Final SWA | 99.58 | 99.60 | |||||
| Test ( ) | Best reg./SWA | 98.67 | |||||
| Final SWA | 94.76 | 94.97 | 94.92 | 94.79 | 0.895 |
| Corpus | Checkpoint | Probe | Head | ||||
| DF-Wild-Cup | Best regular | 2.033 | |||||
| Best SWA | 97.20 | 97.04 | |||||
| Final SWA | 97.20 | 97.04 | |||||
| Open- Forensics | Best regular | ||||||
| Best SWA | |||||||
| Final SWA | 2.257 |
| Variant | Train | Val. | Ctrl. |
| A. Input representation (P1) | |||
| Full released frame (reported run) | 97.04 | ref. | |
| Face crop (dlib [ 69 ] ) OpenCLIP | — | ||
| FFT-domain input | — | ||
| Wavelet-coefficient input, 30 ep | — | ||
| B. Class balancing (P6), OpenCLIP ViT-L/14 | |||
| Configuration | Data | Init. | Val. |
| ImageNet-initialized CNNs | |||
| ResNet-50, gradual unfreezing, 40 ep | P | — | |
| Xception, 5 ep (two runs) | S | — | , |
| Xception, undersampled to | U | — | |
| Non-CLIP transformers | |||
| ViT, unfrozen (probe), 30 ep | P | ||
Deepfake Detection
Deepfake detection identifies manipulated or AI-generated media to support trustworthy communication, identity verification, and forensic analysis.
See all 246 papers