prithivMLmods commited on
Commit
bc23800
·
verified ·
1 Parent(s): adb07b7

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +137 -0
README.md ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model:
4
+ - prithivMLmods/Deep-Fake-Detector-Model
5
+ pipeline_tag: image-classification
6
+ tags:
7
+ - ViT
8
+ - detection
9
+ - Image
10
+ - transformers-4.49.0.dev0
11
+ - deep-fake
12
+ ---
13
+ # **Deep-Fake-Detector-Model**
14
+
15
+ # **Overview**
16
+
17
+ The **Deep-Fake-Detector-Model** is a state-of-the-art deep learning model designed to detect deepfake images. It leverages the **Vision Transformer (ViT)** architecture, specifically the `google/vit-base-patch16-224-in21k` model, fine-tuned on a dataset of real and deepfake images. The model is trained to classify images as either "Real" or "Fake" with high accuracy, making it a powerful tool for detecting manipulated media.
18
+
19
+ **<span style="color:red;">Update :</span>** The previous model checkpoint was obtained using a smaller classification dataset. Although it performed well in evaluation scores, its real-time performance was average due to limited variations in the training set. The new update includes a larger dataset to improve the detection of fake images.
20
+
21
+ | Repository | Link |
22
+ |------------|------|
23
+ | Deep Fake Detector Model | [GitHub Repository](https://github.com/PRITHIVSAKTHIUR/Deep-Fake-Detector-Model) |
24
+
25
+ # **Key Features**
26
+ - **Architecture**: Vision Transformer (ViT) - `google/vit-base-patch16-224-in21k`.
27
+ - **Input**: RGB images resized to 224x224 pixels.
28
+ - **Output**: Binary classification ("Real" or "Fake").
29
+ - **Training Dataset**: A curated dataset of real and deepfake images (e.g., `Hemg/deepfake-and-real-images`).
30
+ - **Fine-Tuning**: The model is fine-tuned using Hugging Face's `Trainer` API with advanced data augmentation techniques.
31
+ - **Performance**: Achieves high accuracy and F1 score on validation and test datasets.
32
+
33
+ # **Model Architecture**
34
+ The model is based on the **Vision Transformer (ViT)**, which treats images as sequences of patches and applies a transformer encoder to learn spatial relationships. Key components include:
35
+ - **Patch Embedding**: Divides the input image into fixed-size patches (16x16 pixels).
36
+ - **Transformer Encoder**: Processes patch embeddings using multi-head self-attention mechanisms.
37
+ - **Classification Head**: A fully connected layer for binary classification.
38
+
39
+ # **Training Details**
40
+ - **Optimizer**: AdamW with a learning rate of `1e-6`.
41
+ - **Batch Size**: 32 for training, 8 for evaluation.
42
+ - **Epochs**: 2.
43
+ - **Data Augmentation**:
44
+ - Random rotation (±90 degrees).
45
+ - Random sharpness adjustment.
46
+ - Random resizing and cropping.
47
+ - **Loss Function**: Cross-Entropy Loss.
48
+ - **Evaluation Metrics**: Accuracy, F1 Score, and Confusion Matrix.
49
+
50
+ # **Inference with Hugging Face Pipeline**
51
+ ```python
52
+ from transformers import pipeline
53
+
54
+ # Load the model
55
+ pipe = pipeline('image-classification', model="prithivMLmods/Deep-Fake-Detector-Model", device=0)
56
+
57
+ # Predict on an image
58
+ result = pipe("path_to_image.jpg")
59
+ print(result)
60
+ ```
61
+
62
+ # **Inference with PyTorch**
63
+ ```python
64
+ from transformers import ViTForImageClassification, ViTImageProcessor
65
+ from PIL import Image
66
+ import torch
67
+
68
+ # Load the model and processor
69
+ model = ViTForImageClassification.from_pretrained("prithivMLmods/Deep-Fake-Detector-Model")
70
+ processor = ViTImageProcessor.from_pretrained("prithivMLmods/Deep-Fake-Detector-Model")
71
+
72
+ # Load and preprocess the image
73
+ image = Image.open("path_to_image.jpg").convert("RGB")
74
+ inputs = processor(images=image, return_tensors="pt")
75
+
76
+ # Perform inference
77
+ with torch.no_grad():
78
+ outputs = model(**inputs)
79
+ logits = outputs.logits
80
+ predicted_class = torch.argmax(logits, dim=1).item()
81
+
82
+ # Map class index to label
83
+ label = model.config.id2label[predicted_class]
84
+ print(f"Predicted Label: {label}")
85
+ ```
86
+ # **Performance Metrics**
87
+ ```
88
+ Classification report:
89
+
90
+ precision recall f1-score support
91
+
92
+ Real 0.6276 0.9823 0.7659 38054
93
+ Fake 0.9594 0.4176 0.5819 38080
94
+
95
+ accuracy 0.6999 76134
96
+ macro avg 0.7935 0.7000 0.6739 76134
97
+ weighted avg 0.7936 0.6999 0.6739 76134
98
+ ```
99
+
100
+ ![Untitled.png](https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/MoxwukbZZZuVpvXHstxsw.png)
101
+
102
+ - **Confusion Matrix**:
103
+ ```
104
+ [[True Positives, False Negatives],
105
+ [False Positives, True Negatives]]
106
+ ```
107
+
108
+ # **Dataset**
109
+ The model is fine-tuned on the dataset, which contains:
110
+ - **Real Images**: Authentic images of human faces.
111
+ - **Fake Images**: Deepfake images generated using advanced AI techniques.
112
+
113
+ # **Limitations**
114
+ The model is trained on a specific dataset and may not generalize well to other deepfake datasets or domains.
115
+ - Performance may degrade on low-resolution or heavily compressed images.
116
+ - The model is designed for image classification and does not detect deepfake videos directly.
117
+
118
+ # **Ethical Considerations**
119
+
120
+ **Misuse**: This model should not be used for malicious purposes, such as creating or spreading deepfakes.
121
+ **Bias**: The model may inherit biases from the training dataset. Care should be taken to ensure fairness and inclusivity.
122
+ **Transparency**: Users should be informed when deepfake detection tools are used to analyze their content.
123
+
124
+ # **Future Work**
125
+ - Extend the model to detect deepfake videos.
126
+ - Improve generalization by training on larger and more diverse datasets.
127
+ - Incorporate explainability techniques to provide insights into model predictions.
128
+
129
+ # **Citation**
130
+
131
+ ```bibtex
132
+ @misc{Deep-Fake-Detector-Model,
133
+ author = {prithivMLmods},
134
+ title = {Deep-Fake-Detector-Model},
135
+ initial = {21 Mar 2024},
136
+ last_updated = {31 Jan 2025}
137
+ }