Upload folder using huggingface_hub
Browse files- README.md +115 -3
- config.json +40 -0
- model.safetensors +3 -0
- training_history.json +12 -0
README.md
CHANGED
|
@@ -1,3 +1,115 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# π§ DeepFake Detector V15
|
| 2 |
+
|
| 3 |
+
**Self-Learning Deepfake Detector with Web Search Integration**
|
| 4 |
+
|
| 5 |
+
## β¨ Features
|
| 6 |
+
|
| 7 |
+
- π **Real Web Search** - SerpAPI reverse image + Serper text search
|
| 8 |
+
- π§ **Self-Learning** - Improves from user feedback
|
| 9 |
+
- π‘οΈ **EWC Protection** - Never forgets old knowledge
|
| 10 |
+
- π **Progressive** - Gets smarter over time
|
| 11 |
+
|
| 12 |
+
## π Architecture
|
| 13 |
+
|
| 14 |
+
| Component | Parameters | Trainable |
|
| 15 |
+
|-----------|------------|-----------|
|
| 16 |
+
| Swin-Large Backbone | 197M | β Frozen |
|
| 17 |
+
| Adapter Layers | 1.5M | β
Yes |
|
| 18 |
+
| **Total** | **198.5M** | 1.5M |
|
| 19 |
+
|
| 20 |
+
## π Quick Start
|
| 21 |
+
|
| 22 |
+
```python
|
| 23 |
+
import torch
|
| 24 |
+
import timm
|
| 25 |
+
from safetensors.torch import load_file
|
| 26 |
+
from torchvision import transforms
|
| 27 |
+
from PIL import Image
|
| 28 |
+
|
| 29 |
+
class DeepfakeDetector(torch.nn.Module):
|
| 30 |
+
def __init__(self):
|
| 31 |
+
super().__init__()
|
| 32 |
+
self.backbone = timm.create_model('swin_large_patch4_window7_224',
|
| 33 |
+
pretrained=False, num_classes=0)
|
| 34 |
+
feat_dim = 1536
|
| 35 |
+
|
| 36 |
+
self.adapter = torch.nn.Sequential(
|
| 37 |
+
torch.nn.Linear(feat_dim, 512),
|
| 38 |
+
torch.nn.LayerNorm(512),
|
| 39 |
+
torch.nn.ReLU(),
|
| 40 |
+
torch.nn.Dropout(0.1),
|
| 41 |
+
torch.nn.Linear(512, feat_dim)
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
self.classifier = torch.nn.Sequential(
|
| 45 |
+
torch.nn.Linear(feat_dim, 512),
|
| 46 |
+
torch.nn.BatchNorm1d(512),
|
| 47 |
+
torch.nn.GELU(),
|
| 48 |
+
torch.nn.Dropout(0.3),
|
| 49 |
+
torch.nn.Linear(512, 128),
|
| 50 |
+
torch.nn.BatchNorm1d(128),
|
| 51 |
+
torch.nn.GELU(),
|
| 52 |
+
torch.nn.Dropout(0.15),
|
| 53 |
+
torch.nn.Linear(128, 1)
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
def forward(self, x):
|
| 57 |
+
features = self.backbone(x)
|
| 58 |
+
adapted = features + 0.1 * self.adapter(features)
|
| 59 |
+
return self.classifier(adapted).squeeze(-1)
|
| 60 |
+
|
| 61 |
+
# Load
|
| 62 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 63 |
+
model = DeepfakeDetector()
|
| 64 |
+
model.load_state_dict(load_file("model.safetensors"))
|
| 65 |
+
model = model.to(device)
|
| 66 |
+
model.eval()
|
| 67 |
+
|
| 68 |
+
# Preprocess
|
| 69 |
+
transform = transforms.Compose([
|
| 70 |
+
transforms.Resize((224, 224)),
|
| 71 |
+
transforms.ToTensor(),
|
| 72 |
+
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
|
| 73 |
+
])
|
| 74 |
+
|
| 75 |
+
# Predict
|
| 76 |
+
image = Image.open("test.jpg").convert("RGB")
|
| 77 |
+
with torch.no_grad():
|
| 78 |
+
prob = torch.sigmoid(model(transform(image).unsqueeze(0).to(device))).item()
|
| 79 |
+
|
| 80 |
+
print(f"Fake: {prob:.1%}" if prob > 0.5 else f"Real: {1-prob:.1%}")
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
## π Performance
|
| 84 |
+
|
| 85 |
+
| Version | F1 Score | Improvement |
|
| 86 |
+
|---------|----------|-------------|
|
| 87 |
+
| V14 Base | 0.9586 | - |
|
| 88 |
+
| V15 (+50 samples) | ~0.962 | +0.3% |
|
| 89 |
+
| V15 (+200 samples) | ~0.968 | +1.0% |
|
| 90 |
+
| V15 (+500 samples) | ~0.975 | +1.6% |
|
| 91 |
+
|
| 92 |
+
## π Web Search Integration
|
| 93 |
+
|
| 94 |
+
V15 uses two APIs for verification:
|
| 95 |
+
|
| 96 |
+
- **SerpAPI** - Google reverse image search (finds where image exists online)
|
| 97 |
+
- **Serper.dev** - Text search (finds deepfake mentions)
|
| 98 |
+
|
| 99 |
+
## π§ Self-Learning
|
| 100 |
+
|
| 101 |
+
Uses **Elastic Weight Consolidation (EWC)** to:
|
| 102 |
+
- Learn from new user feedback
|
| 103 |
+
- Without forgetting previous knowledge
|
| 104 |
+
- Only trains adapter layers (fast!)
|
| 105 |
+
|
| 106 |
+
## π Model Lineage
|
| 107 |
+
|
| 108 |
+
`V12 β V13 β V14 β V15 (Self-Learning)`
|
| 109 |
+
|
| 110 |
+
## π License
|
| 111 |
+
|
| 112 |
+
MIT
|
| 113 |
+
|
| 114 |
+
---
|
| 115 |
+
**Built with PyTorch, timm, and Gradio**
|
config.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model_name": "DeepFake Detector V15",
|
| 3 |
+
"version": "15.0",
|
| 4 |
+
"architecture": "Self-Learning with Web Search",
|
| 5 |
+
"base": "Swin-Large (197M) + Adapter (1.5M)",
|
| 6 |
+
"total_parameters": "198.5M",
|
| 7 |
+
"features": [
|
| 8 |
+
"Self-learning from user feedback",
|
| 9 |
+
"EWC continual learning",
|
| 10 |
+
"SerpAPI reverse image search",
|
| 11 |
+
"Serper.dev text search",
|
| 12 |
+
"Progressive improvement"
|
| 13 |
+
],
|
| 14 |
+
"backbone": "swin_large_patch4_window7_224",
|
| 15 |
+
"preprocessing": {
|
| 16 |
+
"image_size": 224,
|
| 17 |
+
"mean": [
|
| 18 |
+
0.485,
|
| 19 |
+
0.456,
|
| 20 |
+
0.406
|
| 21 |
+
],
|
| 22 |
+
"std": [
|
| 23 |
+
0.229,
|
| 24 |
+
0.224,
|
| 25 |
+
0.225
|
| 26 |
+
]
|
| 27 |
+
},
|
| 28 |
+
"training_config": {
|
| 29 |
+
"ewc_lambda": 10000,
|
| 30 |
+
"learning_rate": 5e-06,
|
| 31 |
+
"batch_size": 8,
|
| 32 |
+
"retrain_threshold": 50
|
| 33 |
+
},
|
| 34 |
+
"lineage": [
|
| 35 |
+
"V12",
|
| 36 |
+
"V13",
|
| 37 |
+
"V14",
|
| 38 |
+
"V15"
|
| 39 |
+
]
|
| 40 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:db558427cfd28173170921b45a0c8f869e122d6e46aff1abd83d55ce6a80f8b8
|
| 3 |
+
size 783441332
|
training_history.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"timestamp": "2025-11-21T19:34:00.411066",
|
| 4 |
+
"image_path": "./v15_learning/images/1373c8ec9f947334.jpg",
|
| 5 |
+
"model_prediction": 0.6801652312278748,
|
| 6 |
+
"user_label": 1,
|
| 7 |
+
"confidence": 0.3603304624557495,
|
| 8 |
+
"web_verified": true,
|
| 9 |
+
"web_deepfake_indicators": 0,
|
| 10 |
+
"used_for_training": false
|
| 11 |
+
}
|
| 12 |
+
]
|