File size: 1,606 Bytes
ceb07d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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