YAML Metadata
Warning:
empty or missing yaml metadata in repo card
(https://huggingface.co/docs/hub/model-cards#model-card-metadata)
Deepfake Detector V8 - Foundation Model
Baseline accuracy: 100.00% | F1-Score: 1.0000
This is a foundation model designed for continuous improvement. It provides a solid starting point with room for enhancement.
π Performance
- Accuracy: 100.00%
- F1-Score: 1.0000
- Precision: 1.0000
- Recall: 1.0000
- Training Samples: 4,800
- Validation Samples: 1,200
ποΈ Architecture
- Backbone: EfficientNetV2-S (pretrained on ImageNet)
- Classifier: 3-layer MLP with BatchNorm and Dropout
- Input Size: 224x224 RGB images
- Output: Binary classification (Real vs Fake)
π Files in This Folder
./deepfake_v8_model/
βββ model.safetensors β Model weights (HuggingFace format)
βββ pytorch_model.bin β Fallback weights (if safetensors unavailable)
βββ optimizer.pt β Optimizer state for continuing training
βββ scheduler.pt β Learning rate scheduler state
βββ config.json β Model architecture configuration
βββ training_args.json β All hyperparameters used
βββ rng_state.pth β Random states for reproducibility
βββ metrics.json β Performance metrics
βββ tokenizer.json β HuggingFace compatibility
βββ tokenizer_config.json β HuggingFace compatibility
βββ README.md β This file
π How to Use This Model
Option 1: Inference (Predict on New Images)
import torch
import torch.nn as nn
import timm
from PIL import Image
from torchvision import transforms
# Define model architecture
class DeepfakeDetector(nn.Module):
def __init__(self, dropout=0.5):
super().__init__()
self.backbone = timm.create_model('tf_efficientnetv2_s', pretrained=False, num_classes=0)
self.classifier = nn.Sequential(
nn.Linear(1280, 512), nn.BatchNorm1d(512), nn.SiLU(), nn.Dropout(dropout),
nn.Linear(512, 256), nn.BatchNorm1d(256), nn.SiLU(), nn.Dropout(dropout * 0.8),
nn.Linear(256, 1)
)
def forward(self, x):
return self.classifier(self.backbone(x)).squeeze(-1)
# Load model
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = DeepfakeDetector(0.5)
try:
from safetensors.torch import load_file
state_dict = load_file('./deepfake_v8_model/model.safetensors')
except:
state_dict = torch.load('./deepfake_v8_model/pytorch_model.bin', map_location=device)
model.load_state_dict(state_dict)
model = model.to(device)
model.eval()
# Predict on image
transform = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])
img = Image.open('test_image.jpg').convert('RGB')
img_tensor = transform(img).unsqueeze(0).to(device)
with torch.no_grad():
logit = model(img_tensor)
prob = torch.sigmoid(logit).item()
if prob > 0.7:
print(f"π΄ LIKELY FAKE ({prob:.1%} confidence)")
elif prob > 0.5:
print(f"β οΈ POSSIBLY FAKE ({prob:.1%} confidence)")
elif prob > 0.3:
print(f"β οΈ POSSIBLY REAL ({(1-prob):.1%} confidence)")
else:
print(f"π’ LIKELY REAL ({(1-prob):.1%} confidence)")
Option 2: Continue Training (Improve the Model)
import torch
import torch.nn as nn
import torch.optim as optim
import timm
import json
import random
import numpy as np
# Load training configuration
with open('./deepfake_v8_model/training_args.json', 'r') as f:
config = json.load(f)
# Define model (same architecture as above)
class DeepfakeDetector(nn.Module):
def __init__(self, dropout=0.5):
super().__init__()
self.backbone = timm.create_model('tf_efficientnetv2_s', pretrained=False, num_classes=0)
self.classifier = nn.Sequential(
nn.Linear(1280, 512), nn.BatchNorm1d(512), nn.SiLU(), nn.Dropout(dropout),
nn.Linear(512, 256), nn.BatchNorm1d(256), nn.SiLU(), nn.Dropout(dropout * 0.8),
nn.Linear(256, 1)
)
def forward(self, x):
return self.classifier(self.backbone(x)).squeeze(-1)
# Load model
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = DeepfakeDetector(config['dropout'])
try:
from safetensors.torch import load_file
state_dict = load_file('./deepfake_v8_model/model.safetensors')
except:
state_dict = torch.load('./deepfake_v8_model/pytorch_model.bin', map_location=device)
model.load_state_dict(state_dict)
model = model.to(device)
# Load optimizer
optimizer = optim.AdamW(
filter(lambda p: p.requires_grad, model.parameters()),
lr=config['learning_rate'] * 0.1 # Lower LR for fine-tuning
)
optimizer.load_state_dict(torch.load('./deepfake_v8_model/optimizer.pt'))
# Load scheduler
scheduler = optim.lr_scheduler.CosineAnnealingLR(optimizer, T_max=config['epochs'])
scheduler.load_state_dict(torch.load('./deepfake_v8_model/scheduler.pt'))
# Load RNG state for reproducibility
rng_state = torch.load('./deepfake_v8_model/rng_state.pth')
random.setstate(rng_state['python'])
np.random.set_state(rng_state['numpy'])
torch.set_rng_state(rng_state['torch'])
if torch.cuda.is_available() and rng_state['torch_cuda']:
torch.cuda.set_rng_state_all(rng_state['torch_cuda'])
print("β Model loaded and ready for continued training!")
# Now continue training with:
# - More epochs
# - More/better data
# - Different augmentations
# - Fine-tuning strategies
π€ How to Upload to HuggingFace
Step 1: Install HuggingFace CLI
pip install -U huggingface_hub
Step 2: Login to HuggingFace
from huggingface_hub import notebook_login
notebook_login()
Or via CLI:
huggingface-cli login
Step 3: Upload Your Model
from huggingface_hub import HfApi
api = HfApi()
api.upload_folder(
folder_path="./deepfake_v8_model",
repo_id="YOUR_USERNAME/deepfake-detector-v8",
repo_type="model"
)
print("β Model uploaded to HuggingFace!")
print("Visit: https://huggingface.co/YOUR_USERNAME/deepfake-detector-v8")
Step 4: Load from HuggingFace in New Notebook
from huggingface_hub import hf_hub_download
import torch
# Download files
model_path = hf_hub_download(
repo_id="YOUR_USERNAME/deepfake-detector-v8",
filename="model.safetensors"
)
optimizer_path = hf_hub_download(
repo_id="YOUR_USERNAME/deepfake-detector-v8",
filename="optimizer.pt"
)
# Load and continue training...
π‘ How to Improve This Model
1. Add More Real Data
# In new notebook, load more datasets
from datasets import load_dataset
# Add real AI-generated images
stable_diffusion_images = load_dataset("your_sd_dataset")
dalle_images = load_dataset("your_dalle_dataset")
# Combine with existing model and retrain
2. Train Longer
# Load model (as shown above)
# Then train for 5-10 more epochs
CONFIG['epochs'] = 10 # or more
# Continue training loop...
3. Unfreeze More Layers
# Unfreeze all backbone layers for fine-tuning
for param in model.backbone.parameters():
param.requires_grad = True
# Use lower learning rate
optimizer = optim.AdamW(model.parameters(), lr=1e-5)
4. Use Real Deepfakes
# Load actual deepfake datasets
# - FaceForensics++
# - Celeb-DF
# - DFDC
# And retrain on real deepfakes
5. Ensemble Multiple Models
# Train multiple versions
# Average predictions for better accuracy
π― Improvement Roadmap
Current: 100.0% (Foundation)
Next Steps:
- Add 10K more samples β Target: 93-95%
- Train 5 more epochs β Target: 94-96%
- Add real AI images β Target: 95-97%
- Fine-tune all layers β Target: 96-98%
- Ensemble 3 models β Target: 97-99%
β οΈ Important Notes
- This model was trained on synthetic fakes
- For production use, train on real AI-generated images
- Use confidence thresholds (>0.7 for high confidence)
- Always validate on diverse test sets
- Consider ethical implications of deployment
π License
MIT License - Free to use with attribution
π€ Contributing
This is a foundation model meant to be improved! Feel free to:
- Add more training data
- Experiment with architectures
- Share your improvements
- Create better versions
π§ Contact
For questions or improvements, open an issue on the repository.
Generated by: Deepfake Detector V8 Training Time: 35.1 minutes Date: 2025-10-22 20:27:12
- Downloads last month
- 4
Inference Providers
NEW
This model isn't deployed by any Inference Provider.
π
Ask for provider support