| # One-Class Deepfake Detector | |
| ## Model Details | |
| - **Architecture**: Hybrid CNN + ViT + FFT Frequency Features | |
| - **Training Images**: 50,000 real images only | |
| - **Final Radius**: 352.6608 | |
| - **Final Loss**: 124397.0862 | |
| - **Embedding Dim**: 512 | |
| ## How It Works | |
| This is a **one-class anomaly detector** using DeepSVDD (Deep Support Vector Data Description). | |
| It learns a "hypersphere" around real images in embedding space. Images far from this | |
| hypersphere are considered anomalous (fake). | |
| ## Usage | |
| ```python | |
| import torch | |
| from PIL import Image | |
| import torchvision.transforms as transforms | |
| # Load model | |
| model_data = torch.load('deepfake_detector_model/deepsvdd_model.pth') | |
| # Initialize your model and load weights | |
| # model.load_state_dict(model_data['model_state_dict']) | |
| # Preprocess image | |
| transform = transforms.Compose([ | |
| transforms.Resize((224, 224)), | |
| transforms.ToTensor(), | |
| transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) | |
| ]) | |
| image = Image.open('test.jpg').convert('RGB') | |
| image_tensor = transform(image).unsqueeze(0) | |
| # Get hypersphere distance | |
| with torch.no_grad(): | |
| embedding = model(image_tensor) | |
| distance = model.get_distance(embedding).item() | |
| # Compare to threshold | |
| threshold = model_data['radius'].item() * 1.5 | |
| is_fake = distance > threshold | |
| print(f"Distance: {distance:.4f}, Threshold: {threshold:.4f}, Fake: {is_fake}") | |
| ``` | |
| ## Files | |
| - `deepsvdd_model.pth`: Complete model with center and radius | |
| - `encoder.pth`: Encoder weights only | |
| - `config.json`: Training configuration | |
| - `training_history.json`: Training metrics | |
| Generated: 2025-11-28 11:22:17 | |