ash12321 commited on
Commit
fcd620e
·
verified ·
1 Parent(s): dcb481f

Upload folder using huggingface_hub

Browse files
README.md CHANGED
@@ -1,3 +1,63 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # DeepFake Detector V14 🎯
2
+
3
+ **Weighted ensemble of V13 models**
4
+
5
+ ## Overview
6
+
7
+ V14 is a weighted ensemble that combines the three V13 models:
8
+ - Model 13.1 (ConvNeXt-Large): Weight 0.25
9
+ - Model 13.2 (ViT-Large): Weight 0.35
10
+ - Model 13.3 (Swin-Large): Weight 0.40
11
+
12
+ **Expected F1 Score**: 0.9361
13
+
14
+ ## Model Files
15
+
16
+ - `model_1.safetensors` - ConvNeXt-Large (788 MB)
17
+ - `model_2.safetensors` - ViT-Large (1220 MB)
18
+ - `model_3.safetensors` - Swin-Large (783 MB)
19
+ - `ensemble.pth` - Ensemble wrapper weights
20
+ - `config.json` - Configuration
21
+ - `inference_example.py` - Usage example
22
+
23
+ ## Quick Start
24
+
25
+ ```python
26
+ # See inference_example.py for complete code
27
+ # Load all 3 models, run predictions, compute weighted average
28
+ ```
29
+
30
+ ## Performance
31
+
32
+ | Model | Backbone | F1 Score | Ensemble Weight |
33
+ |-------|----------|----------|-----------------|
34
+ | Model 13.1 | ConvNeXt-Large | 0.8971 | 0.25 |
35
+ | Model 13.2 | ViT-Large | 0.9382 | 0.35 |
36
+ | Model 13.3 | Swin-Large | 0.9586 | 0.40 |
37
+
38
+ **Weighted Average F1**: 0.9361
39
+
40
+ ## Requirements
41
+
42
+ ```
43
+ torch>=2.0.0
44
+ timm>=0.9.0
45
+ torchvision>=0.15.0
46
+ safetensors
47
+ pillow
48
+ ```
49
+
50
+ ## Citation
51
+
52
+ ```bibtex
53
+ @model{v14-deepfake-detector,
54
+ title={DeepFake Detector V14},
55
+ author={Ash},
56
+ year={2024},
57
+ publisher={Hugging Face}
58
+ }
59
+ ```
60
+
61
+ ## Predecessor
62
+
63
+ Built on: [`ash12321/deepfake-detector-v13`](https://huggingface.co/ash12321/deepfake-detector-v13)
config.json ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_name": "DeepFake Detector V14",
3
+ "version": "14.0",
4
+ "architecture": "Weighted Ensemble",
5
+ "total_parameters": "699M",
6
+ "description": "Ensemble of 3 V13 models with weighted averaging",
7
+ "models": [
8
+ {
9
+ "id": 1,
10
+ "name": "Model 13.1",
11
+ "backbone": "convnext_large",
12
+ "parameters": "198M",
13
+ "dropout": 0.3,
14
+ "f1_score": 0.8971,
15
+ "ensemble_weight": 0.25,
16
+ "file": "model_1.safetensors"
17
+ },
18
+ {
19
+ "id": 2,
20
+ "name": "Model 13.2",
21
+ "backbone": "vit_large_patch16_224",
22
+ "parameters": "304M",
23
+ "dropout": 0.35,
24
+ "f1_score": 0.9382,
25
+ "ensemble_weight": 0.35,
26
+ "file": "model_2.safetensors"
27
+ },
28
+ {
29
+ "id": 3,
30
+ "name": "Model 13.3",
31
+ "backbone": "swin_large_patch4_window7_224",
32
+ "parameters": "197M",
33
+ "dropout": 0.3,
34
+ "f1_score": 0.9586,
35
+ "ensemble_weight": 0.4,
36
+ "file": "model_3.safetensors"
37
+ }
38
+ ],
39
+ "ensemble": {
40
+ "method": "weighted_average",
41
+ "weights": [
42
+ 0.25,
43
+ 0.35,
44
+ 0.4
45
+ ],
46
+ "expected_f1": 0.9360850000000001
47
+ },
48
+ "usage": {
49
+ "preprocessing": {
50
+ "image_size": 224,
51
+ "normalization": {
52
+ "mean": [
53
+ 0.485,
54
+ 0.456,
55
+ 0.406
56
+ ],
57
+ "std": [
58
+ 0.229,
59
+ 0.224,
60
+ 0.225
61
+ ]
62
+ }
63
+ },
64
+ "inference": "Load all 3 models, get predictions, compute weighted average"
65
+ },
66
+ "predecessor": "ash12321/deepfake-detector-v13"
67
+ }
ensemble.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:56c0ce099d756d0f653facc2b96128c31388a7e06e5eaa5a54ce554e4889f393
3
+ size 2787760605
inference_example.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import timm
3
+ from torchvision import transforms
4
+ from PIL import Image
5
+ from safetensors.torch import load_file
6
+
7
+ class DeepfakeDetector(torch.nn.Module):
8
+ def __init__(self, backbone_name, dropout=0.3):
9
+ super().__init__()
10
+ self.backbone = timm.create_model(backbone_name, pretrained=False, num_classes=0)
11
+
12
+ if hasattr(self.backbone, 'num_features'):
13
+ feat_dim = self.backbone.num_features
14
+ else:
15
+ with torch.no_grad():
16
+ feat_dim = self.backbone(torch.randn(1, 3, 224, 224)).shape[1]
17
+
18
+ self.classifier = torch.nn.Sequential(
19
+ torch.nn.Linear(feat_dim, 512),
20
+ torch.nn.BatchNorm1d(512),
21
+ torch.nn.GELU(),
22
+ torch.nn.Dropout(dropout),
23
+ torch.nn.Linear(512, 128),
24
+ torch.nn.BatchNorm1d(128),
25
+ torch.nn.GELU(),
26
+ torch.nn.Dropout(dropout * 0.5),
27
+ torch.nn.Linear(128, 1)
28
+ )
29
+
30
+ def forward(self, x):
31
+ features = self.backbone(x)
32
+ return self.classifier(features).squeeze(-1)
33
+
34
+ # Load models
35
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
36
+
37
+ configs = [
38
+ ('convnext_large', 0.3, 'model_1.safetensors', 0.25),
39
+ ('vit_large_patch16_224', 0.35, 'model_2.safetensors', 0.35),
40
+ ('swin_large_patch4_window7_224', 0.3, 'model_3.safetensors', 0.40)
41
+ ]
42
+
43
+ models = []
44
+ for backbone, dropout, filename, weight in configs:
45
+ model = DeepfakeDetector(backbone, dropout)
46
+ state_dict = load_file(filename)
47
+ model.load_state_dict(state_dict)
48
+ model = model.to(device)
49
+ model.eval()
50
+ models.append((model, weight))
51
+
52
+ # Preprocess image
53
+ transform = transforms.Compose([
54
+ transforms.Resize((224, 224)),
55
+ transforms.ToTensor(),
56
+ transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
57
+ ])
58
+
59
+ # Predict
60
+ image = Image.open('test.jpg').convert('RGB')
61
+ input_tensor = transform(image).unsqueeze(0).to(device)
62
+
63
+ with torch.no_grad():
64
+ predictions = []
65
+ for model, weight in models:
66
+ logits = model(input_tensor)
67
+ prob = torch.sigmoid(logits).item()
68
+ predictions.append(prob * weight)
69
+
70
+ final_prob = sum(predictions)
71
+ prediction = 'FAKE' if final_prob > 0.5 else 'REAL'
72
+
73
+ print(f"Prediction: {prediction}")
74
+ print(f"Confidence: {final_prob:.2%}")
model_1.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1f70541704e8eba1910990469e1a6f9d8a1badc451b2a4d2909170ee53ba45c9
3
+ size 788381444
model_2.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3878f20c6949953030d9294132f4b333a5d9a4349a3fa91420270ec5f7a8ad8b
3
+ size 1215611244
model_3.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:db558427cfd28173170921b45a0c8f869e122d6e46aff1abd83d55ce6a80f8b8
3
+ size 783441332