Views
No views yet
1from huggingface_hub import hf_hub_download
2import torch
3from model import ResidualConvAutoencoder
4from torchvision import transforms
5from PIL import Image
6import json
7
8# Download model and thresholds
9checkpoint_path = hf_hub_download(
10 repo_id="ash12321/deepfake-autoencoder-cifar10-v2",
11 filename="model_universal_best.ckpt"
12)
13threshold_path = hf_hub_download(
14 repo_id="ash12321/deepfake-autoencoder-cifar10-v2",
15 filename="thresholds_calibrated.json"
16)
17
18# Load model
19device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
20model = ResidualConvAutoencoder(latent_dim=512, dropout=0.1).to(device)
21checkpoint = torch.load(checkpoint_path, map_location=device)
22model.load_state_dict(checkpoint['model_state_dict'])
23model.eval()
24
25# Load thresholds
26with open(threshold_path) as f:
27 thresholds = json.load(f)
28
29# Prepare image
30transform = transforms.Compose([
31 transforms.Resize((128, 128)),
32 transforms.ToTensor(),
33 transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
34])
35
36image = Image.open("your_image.jpg").convert('RGB')
37image_tensor = transform(image).unsqueeze(0).to(device)
38
39# Get reconstruction error
40with torch.no_grad():
41 error = model.reconstruction_error(image_tensor)
42 error_value = error.item()
43 print(f"Reconstruction error: {error_value:.6f}")
44
45# Check against threshold (balanced mode)
46balanced_threshold = thresholds['reconstruction_thresholds']['thresholds']['balanced']['value']
47if error_value > balanced_threshold:
48 print("⚠️ Potential deepfake detected!")
49else:
50 print("✅ Image appears authentic")| Mode | Threshold | False Positive Rate | Description |
|---|---|---|---|
| Strict | 0.055737 | ~1% | Very low false positives |
| Balanced | 0.039442 | ~5% | Recommended for general use |
| Sensitive | ~0.039 | ~2.5% | More sensitive detection |
model_universal_best.ckpt - Full checkpoint (418MB)thresholds_calibrated.json - Calibrated thresholdsmodel.py - Model architectureconfig.json - Training configurationREADME.md - This file1@misc{deepfake_autoencoder_2024,
2 title={Residual Convolutional Autoencoder for Deepfake Detection},
3 author={Your Name},
4 year={2024},
5 publisher={HuggingFace},
6 url={https://huggingface.co/ash12321/deepfake-autoencoder-cifar10-v2}
7}