File size: 5,943 Bytes
ba95758 bc48c15 a20593f 0d890a3 4b07a88 e36012f |
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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
---
license: mit
language:
- en
metrics:
- accuracy
- f1
- precision
- recall
base_model:
- google/vit-base-patch16-224-in21k
library_name: transformers
tags:
- deepfake detection
- fake-image detection
---
# ViT Deepfake Detection Model
## Model Description
This is a fine-tuned Vision Transformer (ViT) model for binary image classification to detect deepfake images. The model is based on `google/vit-base-patch16-224-in21k` and has been fine-tuned on the OpenForensics dataset to distinguish between real and fake (AI-generated/manipulated) images.
## Model Details
- **Model Type:** Vision Transformer (ViT) for Image Classification
- **Base Model:** google/vit-base-patch16-224-in21k
- **Task:** Binary Image Classification (Real vs Fake Detection)
- **Language:** N/A (Computer Vision)
- **License:** Apache 2.0
## Intended Use
### Primary Use Cases
- Detecting AI-generated or manipulated images
- Content moderation and verification
- Research in deepfake detection
- Media authenticity verification
### Out-of-Scope Use
- This model should not be used as the sole method for making critical decisions about content authenticity
- Not intended for surveillance or privacy-invasive applications
- May not generalize well to deepfake techniques not present in the training data
## Training Data
The model was trained on the **OpenForensics dataset** with the following distribution:
- **Training Set:** 16,000 images
- **Validation Set:** 2000 images
- **Test Set:** 2000 images
Images were preprocessed and transformed using ViTImageProcessor with standard normalization.
## Training Procedure
### Hyperparameters
```python
Training Arguments:
- Batch Size: 24 per device
- Gradient Accumulation Steps: 1
- Mixed Precision: FP16
- Number of Epochs: 10
- Learning Rate: 3e-5
- Weight Decay: 0.02
- Warmup Ratio: 0.08
- LR Scheduler: Cosine
- Label Smoothing: 0.05
- Optimizer: AdamW (default)
```
### Training Hardware
- GPU: Tesla T4
- Training Time: ~14 minutes for 10 epochs
### Data Augmentation
Standard ViT preprocessing with normalization applied via `ViTImageProcessor`.
## Performance
### Validation Set Results (Best Epoch - Epoch 5)
| Metric | Score |
|--------|-------|
| Accuracy | 96.22% |
| F1 Score | 96.22% |
| Precision | 96.30% |
| Recall | 96.22% |
### Test Set Results
| Metric | Score |
|--------|-------|
| Accuracy | **96.56%** |
### Training Progress
The model showed consistent improvement across epochs:
| Epoch | Training Loss | Validation Loss | Accuracy | F1 Score |
|-------|---------------|-----------------|----------|----------|
| 1 | 0.2259 | 0.2567 | 92.89% | 92.88% |
| 2 | 0.2002 | 0.2360 | 93.44% | 93.43% |
| 3 | 0.1388 | 0.1925 | 96.11% | 96.11% |
| 4 | 0.1322 | 0.2161 | 95.67% | 95.67% |
| 5 | 0.1182 | 0.2208 | **96.22%** | **96.22%** |
| 6-10 | 0.1170-0.1171 | 0.2132-0.2142 | 95.67-95.78% | 95.67-95.78% |
## Usage
### Loading the Model
```python
from transformers import ViTImageProcessor, ViTForImageClassification
from PIL import Image
import torch
# Load model and processor
model = ViTForImageClassification.from_pretrained("YOUR_USERNAME/vit-deepfake-detector")
processor = ViTImageProcessor.from_pretrained("YOUR_USERNAME/vit-deepfake-detector")
# Load and preprocess image
image = Image.open("path_to_image.jpg")
inputs = processor(images=image, return_tensors="pt")
# Make prediction
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
predicted_class = logits.argmax(-1).item()
# Get label
labels = {0: "real", 1: "fake"}
print(f"Prediction: {labels[predicted_class]}")
# Get confidence scores
probabilities = torch.nn.functional.softmax(logits, dim=-1)
confidence = probabilities[0][predicted_class].item()
print(f"Confidence: {confidence:.2%}")
```
### Batch Prediction
```python
from transformers import pipeline
# Create classification pipeline
classifier = pipeline("image-classification", model="YOUR_USERNAME/vit-deepfake-detector")
# Predict on single image
result = classifier("path_to_image.jpg")
print(result)
# Predict on multiple images
images = ["image1.jpg", "image2.jpg", "image3.jpg"]
results = classifier(images)
for img, result in zip(images, results):
print(f"{img}: {result}")
```
## Limitations and Biases
### Known Limitations
- **Dataset Bias:** The model was trained on the OpenForensics dataset, which may not represent all types of deepfakes or manipulation techniques
- **Generalization:** Performance may degrade on deepfake generation methods not present in the training data
- **Adversarial Robustness:** The model has not been explicitly tested against adversarial attacks
- **Resolution Dependency:** Best performance on images around 224x224 pixels (ViT input size)
### Potential Biases
- The model's performance may vary across different:
- Image sources and quality levels
- Demographic representations in images
- Types of manipulation techniques
- Content domains (faces, landscapes, objects, etc.)
## Ethical Considerations
- This model should be used responsibly and not for harassment or privacy invasion
- Decisions based on this model should involve human oversight, especially in high-stakes scenarios
- Users should be aware that deepfake detection is an evolving field, and no model is perfect
- False positives and false negatives can have real-world consequences
## Citation
If you use this model, please cite:
```bibtex
@misc{vit-deepfake-detector,
author = {YOUR_NAME},
title = {ViT Deepfake Detection Model},
year = {2024},
publisher = {HuggingFace},
howpublished = {\url{https://huggingface.co/YOUR_USERNAME/vit-deepfake-detector}}
}
```
## Author
- Dr. Lucy Liu
- Muhammad Hamza Sohail
- Ayaan Mohammed
- Shadab Karim
- kirti Dhir
## **Disclaimer:**
his model is provided for research and educational purposes. Users are responsible for ensuring compliance with applicable laws and ethical guidelines when deploying this model. |