File size: 4,207 Bytes
4920abb 2235b7a 4920abb 2235b7a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | ---
license: mit
library_name: onnx
pipeline_tag: image-classification
tags:
- image-classification
- onnx
- efficientnet
- deepfake-detection
- ai-generated-image-detection
- cifake
- transfer-learning
- pytorch
- binary-classification
datasets:
- birdy654/cifake-real-and-ai-generated-synthetic-images
metrics:
- accuracy
model-index:
- name: CIFAKE-EfficientNet-B0
results:
- task:
type: image-classification
name: Binary Image Classification
dataset:
name: CIFAKE
type: birdy654/cifake-real-and-ai-generated-synthetic-images
metrics:
- type: accuracy
value: 97.85
name: Test Accuracy
---
# CIFAKE — Real vs AI-Generated Image Classifier
A binary image classifier that distinguishes **real photographs** from **AI-generated (synthetic) images**, built with **EfficientNet-B0** and transfer learning.
## Model Description
This model was trained to detect AI-generated images using the [CIFAKE dataset](https://www.kaggle.com/datasets/birdy654/cifake-real-and-ai-generated-synthetic-images), which contains 120,000 images (60K real from CIFAR-10 + 60K synthetic from Stable Diffusion v1.4).
- **Architecture**: EfficientNet-B0 (pretrained on ImageNet)
- **Task**: Binary classification (Real vs Fake)
- **Output**: Single logit → apply sigmoid to get P(Real)
- **Format**: ONNX (opset 17)
- **Input**: RGB image tensor of shape `[batch, 3, 224, 224]`, normalized with ImageNet statistics
## Training Details
### Two-Phase Training Strategy
| Phase | Epochs | Strategy | Learning Rate | Scheduler |
|-------|--------|----------|---------------|-----------|
| 1 | 10 | Feature extraction (backbone frozen) | 3e-4 | — |
| 2 | 5 | Full fine-tuning (all layers) | 3e-5 | CosineAnnealingLR |
- **Optimizer**: AdamW (weight_decay=1e-2)
- **Loss**: BCEWithLogitsLoss
- **Batch Size**: 128
- **Mixed Precision**: FP16 via `torch.autocast`
### Preprocessing
```python
transforms.Resize((224, 224), interpolation=InterpolationMode.BICUBIC, antialias=True)
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
```
## Performance
| Metric | Value |
|--------|-------|
| **Test Accuracy** | **97.85%** |
Evaluated on 20,000 test images (10K real + 10K AI-generated).
## Usage
### Python (ONNX Runtime)
```python
import numpy as np
import onnxruntime as ort
from PIL import Image
from torchvision import transforms
from torchvision.transforms import InterpolationMode
# Load model
session = ort.InferenceSession("model.onnx")
# Preprocess image
transform = transforms.Compose([
transforms.Resize((224, 224), interpolation=InterpolationMode.BICUBIC, antialias=True),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])
image = Image.open("your_image.jpg").convert("RGB")
input_tensor = transform(image).unsqueeze(0).numpy()
# Run inference
logit = session.run(None, {"input": input_tensor})[0]
probability = 1 / (1 + np.exp(-logit)) # sigmoid
label = "REAL" if probability >= 0.5 else "FAKE"
confidence = float(probability) if label == "REAL" else float(1 - probability)
print(f"{label} ({confidence * 100:.2f}% confidence)")
```
## Labels
| Index | Class | Description |
|-------|-------|-------------|
| 0 | FAKE | AI-generated synthetic image |
| 1 | REAL | Real photograph (from CIFAR-10) |
The model outputs a single logit. After applying sigmoid:
- `sigmoid(logit) >= 0.5` → **REAL**
- `sigmoid(logit) < 0.5` → **FAKE**
## Dataset
The [CIFAKE dataset](https://www.kaggle.com/datasets/birdy654/cifake-real-and-ai-generated-synthetic-images) consists of:
| Split | Real | Fake | Total |
|-------|------|------|-------|
| Train | 50,000 | 50,000 | 100,000 |
| Test | 10,000 | 10,000 | 20,000 |
## Citation
```bibtex
@article{bird2024cifake,
title={CIFAKE: Image Classification and Explainable Identification of AI-Generated Synthetic Images},
author={Bird, Jordan J and Lotfi, Ahmad},
journal={IEEE Access},
year={2024},
doi={10.1109/ACCESS.2024.3356122}
}
```
## License
This model is released under the [MIT License](https://opensource.org/licenses/MIT).
|