Harshasnade commited on
Commit
b2f966b
·
verified ·
1 Parent(s): a9a48b0

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +43 -7
README.md CHANGED
@@ -14,15 +14,12 @@ metrics:
14
  - f1
15
  pipeline_tag: image-classification
16
  inference: false
17
- widgets:
18
- - text: "Test the DeepGuard Model Live"
19
- src: "https://harshasnade-deepfake-detection-system-v1.hf.space"
20
- - text: "Deepfake Sample"
21
- src: "https://harshasnade-deepfake-detection-system-v1.hf.space"
22
  ---
23
 
24
  # DeepGuard - Deepfake Detection System
25
 
 
 
26
  ## Model Details
27
 
28
  ### Model Description
@@ -54,8 +51,47 @@ The model is designed to classify single images as either **REAL** or **FAKE**.
54
  - **Video Analysis:** While it can analyze individual frames, it does not currently leverage temporal coherence in videos (frame-by-frame analysis only).
55
  - **Audio Deepfakes:** This model is strictly for visual content.
56
  - **Legal Proof:** The model provides a probabilistic assessment and should not be the sole basis for legal judgments.
57
-
58
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
  ## Training Details
61
 
 
14
  - f1
15
  pipeline_tag: image-classification
16
  inference: false
 
 
 
 
 
17
  ---
18
 
19
  # DeepGuard - Deepfake Detection System
20
 
21
+ [![Open in Spaces](https://huggingface.co/datasets/huggingface/badges/raw/main/open-in-hf-spaces-lg.svg)](https://huggingface.co/spaces/Harshasnade/Deepfake_Detection_System_V1)
22
+
23
  ## Model Details
24
 
25
  ### Model Description
 
51
  - **Video Analysis:** While it can analyze individual frames, it does not currently leverage temporal coherence in videos (frame-by-frame analysis only).
52
  - **Audio Deepfakes:** This model is strictly for visual content.
53
  - **Legal Proof:** The model provides a probabilistic assessment and should not be the sole basis for legal judgments.
54
+
55
+ ## How to Get Started with the Model
56
+
57
+ ```python
58
+ import torch
59
+ import torch.nn as nn
60
+ from torchvision import models
61
+ from safetensors.torch import load_file
62
+ import cv2
63
+
64
+ # Define Model Architecture
65
+ class DeepfakeDetector(nn.Module):
66
+ def __init__(self, pretrained=False):
67
+ super(DeepfakeDetector, self).__init__()
68
+ self.efficientnet = models.efficientnet_v2_s(weights='DEFAULT' if pretrained else None)
69
+ self.swin = models.swin_v2_t(weights='DEFAULT' if pretrained else None)
70
+
71
+ self.efficientnet.classifier = nn.Identity()
72
+ self.swin.head = nn.Identity()
73
+
74
+ self.classifier = nn.Sequential(
75
+ nn.Linear(1280 + 768, 512),
76
+ nn.BatchNorm1d(512),
77
+ nn.ReLU(),
78
+ nn.Dropout(0.4),
79
+ nn.Linear(512, 1)
80
+ )
81
+
82
+ def forward(self, x):
83
+ f1 = self.efficientnet(x)
84
+ f2 = self.swin(x)
85
+ combined = torch.cat((f1, f2), dim=1)
86
+ return self.classifier(combined)
87
+
88
+ # Load Model
89
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
90
+ model = DeepfakeDetector(pretrained=False).to(device)
91
+ state_dict = load_file("best_model.safetensors")
92
+ model.load_state_dict(state_dict)
93
+ model.eval()
94
+ ```
95
 
96
  ## Training Details
97