Skip to content
Tony1026Public

About

CPID: Cross-Prototype Intervention for Generalizable AI-Generated Image Detection

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

CPID

Cross-Prototype Intervention for Generalizable AI-Generated Image Detection

Overview

AI-generated image detectors can learn correlations that change across image generators. CPID organizes generated samples into feature-space prototype groups and uses the group structure to construct controlled authenticity-space interventions. The detector is trained to preserve the real/fake decision under these cross-prototype changes.

CPID overview

Architecture

The model uses a frozen CLIP vision encoder followed by two branches:

  • Authenticity branch: maps image tokens to a representation for binary real/fake prediction.
  • Grouping branch: maps generated samples to normalized features and assigns them to fake-only prototypes.

For a fake anchor, CPID selects a sample from another prototype group and translates the anchor using the difference between the corresponding authenticity-space centers. The translated feature shares the authenticity classifier with the original feature. Fake-target supervision and prediction consistency provide the intervention objectives.

The inference path retains only the authenticity route:

image → frozen CLIP → authenticity encoder → real/fake classifier

Code

The training interface accepts frozen CLIP tokens with shape [batch, 257, 1024] and binary labels, where 0 denotes real images and 1 denotes generated images.

Requirements

  • Python 3.10+
  • PyTorch 2.x
  • torchvision
  • transformers
  • Pillow
pip install -r requirements.txt

The default vision backbone is openai/clip-vit-large-patch14.

Inference

python infer.py \
  --input /path/to/image-or-directory \
  --checkpoint /path/to/checkpoint.pth

Native 224-pixel views are aggregated by averaging their logits before computing the fake probability. Use --view center for a single center view.

License

See LICENSE. The code is provided for non-commercial research use. Redistribution, commercial use, and submission of modified code as another person's work require written permission.

About

CPID: Cross-Prototype Intervention for Generalizable AI-Generated Image Detection

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages