Downloads · 30 days
12
36% of all-time downloads
ash12321/deepfake-detector-timesformer
deepfake-detector-timesformer 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.
This is an EnhancedTimeSformer model trained for video anomaly detection and deepfake detection using a one-class learning approach. The model was trained exclusively on real videos from WebVid-10M and learns to recon…
Downloads · 30 days
12
36% of all-time downloads
All-time downloads
33
Public
Repo size
1.1 GB
Likes
0
Public
Click a slice to open those files.
.ckpt1.1 GB · 100%
From the Hugging Face model README
This is an EnhancedTimeSformer model trained for video anomaly detection and deepfake detection using a one-class learning approach. The model was trained exclusively on real videos from WebVid-10M and learns to reconstruct normal video frames. Anomalies (including deepfakes) are detected by measuring reconstruction error.
import torch
import torch.nn.functional as F
from model import create_model
# Load model
model = create_model()
checkpoint = torch.load("pytorch_model.ckpt", map_location='cuda')
# Extract state dict
if 'state_dict' in checkpoint:
state_dict = checkpoint['state_dict']
else:
state_dict = checkpoint
# Clean state dict (remove prefixes)
new_state_dict = {}
for k, v in state_dict.items():
if k.startswith('model.model.'):
new_key = k.replace('model.model.', '')
new_state_dict[new_key] = v
elif k.startswith('model.'):
new_key = k.replace('model.', '')
new_state_dict[new_key] = v
else:
new_state_dict[k] = v
model.load_state_dict(new_state_dict, strict=False)
model.eval()
model = model.cuda()
# Prepare video (B, C, T, H, W) with values in [-1, 1]
video_tensor = preprocess_video(video_path) # Your preprocessing
video_tensor = video_tensor.cuda()
# Get prediction
with torch.no_grad():
frame_pred, flow_pred = model(video_tensor)
# Calculate reconstruction error
mid_frame = video_tensor.shape[2] // 2
target = video_tensor[:, :, mid_frame]
mse_error = F.mse_loss(frame_pred, target).item()
# Detect deepfake
THRESHOLD = 0.3137
is_fake = mse_error > THRESHOLD
print(f"MSE: {mse_error:.4f}")
print(f"Prediction: {'FAKE' if is_fake else 'REAL'}")
If you use this model, please cite:
@misc{timesformer-deepfake-detector,
author = {ash12321},
title = {Video Anomaly Detection with TimeSformer},
year = {2024},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/ash12321/deepfake-detector-timesformer}}
}
MIT License - See repository for details
For questions or issues, please open an issue on the Hugging Face repository.
Note: This model represents a research approach to deepfake detection through one-class learning. For production deployments, consider using an ensemble of multiple detection methods including supervised classifiers, biological signal detectors, and temporal consistency checkers.