Upload folder using huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,18 +1,148 @@
|
|
| 1 |
---
|
| 2 |
tags:
|
| 3 |
- deepfake-detection
|
| 4 |
-
-
|
| 5 |
- image-classification
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
library_name: pytorch
|
| 7 |
license: mit
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
# DeepGuard - Deepfake Detection
|
| 11 |
-
|
| 12 |
-
This repository contains the trained weights for the DeepGuard Deepfake Detection System.
|
| 13 |
|
| 14 |
## Model Details
|
| 15 |
-
- **Architecture**: Ensembled EfficientNetV2-S + Swin-V2-T + Custom CNN
|
| 16 |
-
- **Input Size**: 224x224
|
| 17 |
-
- **Format**: SafeTensors (PyTorch)
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
tags:
|
| 3 |
- deepfake-detection
|
| 4 |
+
- computer-vision
|
| 5 |
- image-classification
|
| 6 |
+
- pytorch
|
| 7 |
+
- efficientnet
|
| 8 |
+
- swin-transformer
|
| 9 |
+
- security
|
| 10 |
library_name: pytorch
|
| 11 |
license: mit
|
| 12 |
+
metrics:
|
| 13 |
+
- accuracy
|
| 14 |
+
- f1
|
| 15 |
+
pipeline_tag: image-classification
|
| 16 |
---
|
| 17 |
|
| 18 |
+
# DeepGuard - Deepfake Detection System
|
|
|
|
|
|
|
| 19 |
|
| 20 |
## Model Details
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
### Model Description
|
| 23 |
+
|
| 24 |
+
DeepGuard is a robust Deepfake Detection System designed to identify AI-generated images with high precision. It employs an ensemble architecture combining **EfficientNetV2-S** and **Swin Transformer V2-T** with a custom Convolutional Neural Network (CNN) head. This hybrid approach leverages both local feature extraction (CNN) and global context understanding (Transformers) to spot manipulation artifacts often invisible to the human eye.
|
| 25 |
+
|
| 26 |
+
- **Developed by:** Harshvardhan Asnade
|
| 27 |
+
- **Model type:** Ensemble (EfficientNetV2 + SwinV2 + Custom CNN)
|
| 28 |
+
- **Language(s):** Python, PyTorch
|
| 29 |
+
- **License:** MIT
|
| 30 |
+
- **Finetuned from model:** Torchvision pre-trained weights (ImageNet)
|
| 31 |
+
|
| 32 |
+
### Model Sources
|
| 33 |
+
|
| 34 |
+
- **Repository:** https://github.com/Harshvardhan-Asnade/Deepfake-Model
|
| 35 |
+
- **Demo:** https://deepfakescan.vercel.app/ (Live Web App)
|
| 36 |
+
|
| 37 |
+
## Uses
|
| 38 |
+
|
| 39 |
+
### Direct Use
|
| 40 |
+
|
| 41 |
+
The model is designed to classify single images as either **REAL** or **FAKE**. It outputs a probability score (0.0 - 1.0) and a confidence metric. It is suitable for:
|
| 42 |
+
- Content moderation
|
| 43 |
+
- Social media verification
|
| 44 |
+
- Digital forensics (preliminary analysis)
|
| 45 |
+
|
| 46 |
+
### Out-of-Scope Use
|
| 47 |
+
|
| 48 |
+
- **Video Analysis:** While it can analyze individual frames, it does not currently leverage temporal coherence in videos (frame-by-frame analysis only).
|
| 49 |
+
- **Audio Deepfakes:** This model is strictly for visual content.
|
| 50 |
+
- **Legal Proof:** The model provides a probabilistic assessment and should not be the sole basis for legal judgments.
|
| 51 |
+
|
| 52 |
+
## How to Get Started with the Model
|
| 53 |
+
|
| 54 |
+
```python
|
| 55 |
+
import torch
|
| 56 |
+
import torch.nn as nn
|
| 57 |
+
from torchvision import models
|
| 58 |
+
import albumentations as A
|
| 59 |
+
from albumentations.pytorch import ToTensorV2
|
| 60 |
+
from safetensors.torch import load_file
|
| 61 |
+
import cv2
|
| 62 |
+
|
| 63 |
+
# Define Model Architecture
|
| 64 |
+
class DeepfakeDetector(nn.Module):
|
| 65 |
+
def __init__(self, pretrained=False):
|
| 66 |
+
super(DeepfakeDetector, self).__init__()
|
| 67 |
+
self.efficientnet = models.efficientnet_v2_s(weights='DEFAULT' if pretrained else None)
|
| 68 |
+
self.swin = models.swin_v2_t(weights='DEFAULT' if pretrained else None)
|
| 69 |
+
|
| 70 |
+
self.efficientnet.classifier = nn.Identity()
|
| 71 |
+
self.swin.head = nn.Identity()
|
| 72 |
+
|
| 73 |
+
self.classifier = nn.Sequential(
|
| 74 |
+
nn.Linear(1280 + 768, 512),
|
| 75 |
+
nn.BatchNorm1d(512),
|
| 76 |
+
nn.ReLU(),
|
| 77 |
+
nn.Dropout(0.4),
|
| 78 |
+
nn.Linear(512, 1)
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
def forward(self, x):
|
| 82 |
+
f1 = self.efficientnet(x)
|
| 83 |
+
f2 = self.swin(x)
|
| 84 |
+
combined = torch.cat((f1, f2), dim=1)
|
| 85 |
+
return self.classifier(combined)
|
| 86 |
+
|
| 87 |
+
# Load Model
|
| 88 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 89 |
+
model = DeepfakeDetector(pretrained=False).to(device)
|
| 90 |
+
state_dict = load_file("best_model.safetensors")
|
| 91 |
+
model.load_state_dict(state_dict)
|
| 92 |
+
model.eval()
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
## Training Details
|
| 96 |
+
|
| 97 |
+
### Training Data
|
| 98 |
+
|
| 99 |
+
The model was trained on a diverse dataset comprising:
|
| 100 |
+
- **Real Images:** FFHQ, CelebA-HQ
|
| 101 |
+
- **Deepfake Images:** Generated using StyleGAN2, Diffusion Models, and FaceSwap techniques.
|
| 102 |
+
- **Data Augmentation:** extensive augmentation (compression, noise, blur) was applied to robustify the model against social media re-compression artifacts.
|
| 103 |
+
|
| 104 |
+
### Training Procedure
|
| 105 |
+
|
| 106 |
+
- **Optimizer:** AdamW
|
| 107 |
+
- **Loss Function:** BCEWithLogitsLoss
|
| 108 |
+
- **Scheduler:** OneCycleLR
|
| 109 |
+
- **Epochs:** 10+ with Early Stopping
|
| 110 |
+
- **Input Resolution:** 224x224
|
| 111 |
+
|
| 112 |
+
#### Training Hyperparameters
|
| 113 |
+
|
| 114 |
+
- **Batch Size:** 32
|
| 115 |
+
- **Precision:** Mixed Precision (FP16)
|
| 116 |
+
|
| 117 |
+
## Evaluation
|
| 118 |
+
|
| 119 |
+
### Results
|
| 120 |
+
|
| 121 |
+
The model achieves high accuracy on standard benchmarks:
|
| 122 |
+
- **Test Accuracy:** ~92-95% (on unseen test split)
|
| 123 |
+
- **Generalization:** Shows strong resilience to JPEG compression compared to standard CNNs.
|
| 124 |
+
|
| 125 |
+
## Technical Specifications
|
| 126 |
+
|
| 127 |
+
### Model Architecture
|
| 128 |
+
|
| 129 |
+
The specific ensemble combines:
|
| 130 |
+
1. **EfficientNetV2-S:** Excellent at capturing sharp, high-frequency details (e.g., hair textures, eye reflections).
|
| 131 |
+
2. **Swin Transformer (V2-T):** Captures global semantic inconsistencies (e.g., facial structural alignment).
|
| 132 |
+
|
| 133 |
+
### Compute Infrastructure
|
| 134 |
+
|
| 135 |
+
- **Hardware:** Trained on Mac M-Series (MPS) / NVIDIA GPUs.
|
| 136 |
+
- **Framework:** PyTorch 2.6+
|
| 137 |
+
|
| 138 |
+
## Citation
|
| 139 |
+
|
| 140 |
+
```bibtex
|
| 141 |
+
@misc{deepguard2024,
|
| 142 |
+
author = {Asnade, Harshvardhan},
|
| 143 |
+
title = {DeepGuard: Ensemble Deepfake Detection System},
|
| 144 |
+
year = {2024},
|
| 145 |
+
publisher = {Hugging Face},
|
| 146 |
+
howpublished = {\url{https://huggingface.co/Harshasnade/Deepfake_Detection_System_V1}}
|
| 147 |
+
}
|
| 148 |
+
```
|