File size: 1,917 Bytes
4f66d78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
---
license: apache-2.0
metrics:
- accuracy
base_model:
- google/vit-base-patch16-224-in21k
pipeline_tag: image-classification
---
# Deepfake Image Detection Using Fine-Tuned Vision Transformer (ViT)
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.

## **Model Overview**
- **Base Model**: [google/vit-base-patch16-224-in21k](https://huggingface.co/google/vit-base-patch16-224-in21k)
- **Dataset**: [deepfake and real images](https://www.kaggle.com/datasets/manjilkarki/deepfake-and-real-images).
- **Classes**: Binary classification (`Fake`, `Real`)
- **Performance**:
  - **Validation Accuracy**: 97%
  - **Test Accuracy**: 92%

*Figure 1: Confusion matrix for test data*

![image/png](https://cdn-uploads.huggingface.co/production/uploads/6585ab80ef59559493941225/Qz4oHFhs8FQNFkf5c97Sg.png)

*Figure 2: Confusion matrix for validation data*

![image/png](https://cdn-uploads.huggingface.co/production/uploads/6585ab80ef59559493941225/mYtuHWMIJOVFk8uI_RlPU.png)

### How to Use the Model

Below is an example of how to load and use the model for deepfake classification:

```python
from transformers import AutoImageProcessor, AutoModelForImageClassificationimport torch
import torch
from PIL import Image

# Load the image_processor and model
image_processor = AutoImageProcessor.from_pretrained('ashish-001/deepfake-detection-using-ViT')
model = AutoModelForImageClassification.from_pretrained('ashish-001/deepfake-detection-using-ViT')
# Example usage
image = Image.open('path of the image')
inputs = image_processor(images=image, return_tensors="pt")
outputs = model(**inputs)
logits = outputs.logits
pred = torch.argmax(logits, dim=1).item()
label = 'Real' if pred == 1 else 'Fake'
print(f"Predicted type: {Label}")