Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,49 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
metrics:
|
| 4 |
+
- accuracy
|
| 5 |
+
base_model:
|
| 6 |
+
- google/vit-base-patch16-224-in21k
|
| 7 |
+
pipeline_tag: image-classification
|
| 8 |
+
---
|
| 9 |
+
# Deepfake Image Detection Using Fine-Tuned Vision Transformer (ViT)
|
| 10 |
+
This project focuses on detecting **deepfake images** using a fine-tuned version of the pre-trained model `google/vit-base-patch16-224-in21k`. The approach leverages the power of Vision Transformers (ViT) to classify images as real or fake.
|
| 11 |
+
|
| 12 |
+
## **Model Overview**
|
| 13 |
+
- **Base Model**: [google/vit-base-patch16-224-in21k](https://huggingface.co/google/vit-base-patch16-224-in21k)
|
| 14 |
+
- **Dataset**: [deepfake and real images](https://www.kaggle.com/datasets/manjilkarki/deepfake-and-real-images).
|
| 15 |
+
- **Classes**: Binary classification (`Fake`, `Real`)
|
| 16 |
+
- **Performance**:
|
| 17 |
+
- **Validation Accuracy**: 97%
|
| 18 |
+
- **Test Accuracy**: 92%
|
| 19 |
+
|
| 20 |
+
*Figure 1: Confusion matrix for test data*
|
| 21 |
+
|
| 22 |
+

|
| 23 |
+
|
| 24 |
+
*Figure 2: Confusion matrix for validation data*
|
| 25 |
+
|
| 26 |
+

|
| 27 |
+
|
| 28 |
+
### How to Use the Model
|
| 29 |
+
|
| 30 |
+
Below is an example of how to load and use the model for deepfake classification:
|
| 31 |
+
|
| 32 |
+
```python
|
| 33 |
+
from transformers import AutoImageProcessor, AutoModelForImageClassificationimport torch
|
| 34 |
+
import torch
|
| 35 |
+
from PIL import Image
|
| 36 |
+
|
| 37 |
+
# Load the image_processor and model
|
| 38 |
+
image_processor = AutoImageProcessor.from_pretrained('ashish-001/deepfake-detection-using-ViT')
|
| 39 |
+
model = AutoModelForImageClassification.from_pretrained('ashish-001/deepfake-detection-using-ViT')
|
| 40 |
+
# Example usage
|
| 41 |
+
image = Image.open('path of the image')
|
| 42 |
+
inputs = image_processor(images=image, return_tensors="pt")
|
| 43 |
+
outputs = model(**inputs)
|
| 44 |
+
logits = outputs.logits
|
| 45 |
+
pred = torch.argmax(logits, dim=1).item()
|
| 46 |
+
label = 'Real' if pred == 1 else 'Fake'
|
| 47 |
+
print(f"Predicted type: {Label}")
|
| 48 |
+
|
| 49 |
+
|