gh-rgupta
Add demo web application for fake vs real image detection
6bfb0e3

A newer version of the Gradio SDK is available: 6.1.0

Upgrade

AI-Generated Image Detector Demo

A simple Streamlit web application for detecting AI-generated images using the ARNIQA perceptual feature extractor.

Features

  • Upload images (PNG, JPG, JPEG)
  • Detect if image is real or AI-generated
  • Display confidence scores and probability breakdown
  • Simple, clean interface
  • CPU-friendly (no GPU required)

Requirements

  • Python 3.8+
  • Trained ARNIQA classifier checkpoint at: checkpoints/GenImage/extensive/MarginContrastiveLoss_CrossEntropy/arniqa/best_model.ckpt

Setup

  1. Install dependencies:

    cd demo
    pip install -r requirements.txt
    
  2. Verify checkpoint exists: Make sure the trained model checkpoint is at the correct location relative to the project root:

    ../checkpoints/GenImage/extensive/MarginContrastiveLoss_CrossEntropy/arniqa/best_model.ckpt
    

Running the Demo

From the demo directory:

streamlit run app.py

The app will open in your browser at http://localhost:8501

How It Works

  1. Feature Extraction: Uses ARNIQA (loaded via torch.hub) to extract perceptual features from images
  2. Classification: A trained 2-layer MLP classifier processes the features
  3. Prediction: Outputs probability of image being real vs AI-generated

Model Architecture

  • Feature Extractor: ARNIQA encoder (4096-dim features)
  • Classifier: 2-layer MLP (4096 → 1024 → 2)
  • Training Dataset: GenImage dataset
  • Threshold: 0.5 for binary classification

Troubleshooting

Model not loading

  • Ensure checkpoint file exists at the specified path
  • Check that you're running from the demo/ directory
  • Verify Python path includes parent directory

Out of memory

  • The app runs on CPU by default
  • Close other applications to free up RAM
  • Image is automatically resized to 224x224 for processing

ARNIQA not loading

  • First run downloads ARNIQA model from torch.hub
  • Requires internet connection for initial download
  • Model is cached locally after first download

Deployment (Future)

This demo can be deployed to:

  • Oracle Cloud (CPU instances)
  • Streamlit Cloud
  • Docker containers

Docker support coming soon!

Credits

Based on research in detecting AI-generated images using perceptual features from Image Quality Assessment models.