Downloads · 30 days
6
29% of all-time downloads
ash12321/deepfake-detector-v15
deepfake-detector-v15 is a machine learning model from ash12321. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
Self-Learning Deepfake Detector with Web Search Integration
Downloads · 30 days
6
29% of all-time downloads
All-time downloads
21
Public
Parameters
196M
783 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors783 MB · 100%
From the Hugging Face model README
Self-Learning Deepfake Detector with Web Search Integration
| Component | Parameters | Trainable |
|---|---|---|
| Swin-Large Backbone | 197M | ❌ Frozen |
| Adapter Layers | 1.5M | ✅ Yes |
| Total | 198.5M | 1.5M |
import torch
import timm
from safetensors.torch import load_file
from torchvision import transforms
from PIL import Image
class DeepfakeDetector(torch.nn.Module):
def __init__(self):
super().__init__()
self.backbone = timm.create_model('swin_large_patch4_window7_224',
pretrained=False, num_classes=0)
feat_dim = 1536
self.adapter = torch.nn.Sequential(
torch.nn.Linear(feat_dim, 512),
torch.nn.LayerNorm(512),
torch.nn.ReLU(),
torch.nn.Dropout(0.1),
torch.nn.Linear(512, feat_dim)
)
self.classifier = torch.nn.Sequential(
torch.nn.Linear(feat_dim, 512),
torch.nn.BatchNorm1d(512),
torch.nn.GELU(),
torch.nn.Dropout(0.3),
torch.nn.Linear(512, 128),
torch.nn.BatchNorm1d(128),
torch.nn.GELU(),
torch.nn.Dropout(0.15),
torch.nn.Linear(128, 1)
)
def forward(self, x):
features = self.backbone(x)
adapted = features + 0.1 * self.adapter(features)
return self.classifier(adapted).squeeze(-1)
# Load
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = DeepfakeDetector()
model.load_state_dict(load_file("model.safetensors"))
model = model.to(device)
model.eval()
# Preprocess
transform = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])
# Predict
image = Image.open("test.jpg").convert("RGB")
with torch.no_grad():
prob = torch.sigmoid(model(transform(image).unsqueeze(0).to(device))).item()
print(f"Fake: {prob:.1%}" if prob > 0.5 else f"Real: {1-prob:.1%}")
| Version | F1 Score | Improvement |
|---|---|---|
| V14 Base | 0.9586 | - |
| V15 (+50 samples) | ~0.962 | +0.3% |
| V15 (+200 samples) | ~0.968 | +1.0% |
| V15 (+500 samples) | ~0.975 | +1.6% |
V15 uses two APIs for verification:
Uses Elastic Weight Consolidation (EWC) to:
V12 → V13 → V14 → V15 (Self-Learning)
MIT
Built with PyTorch, timm, and Gradio