File size: 2,950 Bytes
7d6cd13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
---

# CNN-Based Deepfake Detection Model

This repository contains a Convolutional Neural Network (CNN)-based model fine-tuned for deepfake detection. The model has been trained to classify images as either "real" or "fake" (deepfake) using a custom dataset of processed images.

## Model Overview

This model is a custom CNN architecture built specifically for deepfake detection. It has been designed to efficiently distinguish between real and fake images through a series of convolutional and pooling layers, followed by fully connected layers for classification.

### Key Features:
- **Model Architecture:** Convolutional Neural Network (CNN)
- **Input Size:** 128x128 pixels
- **Number of Classes:** 2 (Real, Fake)
- **Activation Function:** ReLU in hidden layers, Sigmoid for binary classification
- **Regularization:** L2 regularization and Dropout layers to prevent overfitting
- **Optimizer:** Adam with a learning rate of 0.0001
- **Training Epochs:** 100 epochs (with early stopping based on validation loss)

## Training Details

The model was trained on a custom dataset of real and deepfake images, using data augmentation techniques to improve generalization. The training process involved the following components:

- **Data Augmentation:** Random rotations, shifts, flips, and brightness adjustments.
- **Loss Function:** Binary Cross-Entropy Loss
- **Optimizer:** Adam with a learning rate of 0.0001
- **Callbacks:** Early stopping, learning rate scheduler, and model checkpointing were used to optimize training.

## Model Performance

The model was evaluated on a held-out test set. Below is the key performance metric:

- **Test Accuracy:** 71%

This accuracy reflects the model's ability to correctly identify real and deepfake images.

## Usage

You can use this model for inference by loading the model and running predictions on new images. Below is an example using TensorFlow/Keras:

```python
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing import image
import numpy as np

# Load the trained model
model = load_model('cnn_model.h5')

# Load and preprocess the image
img_path = 'path_to_your_image.jpg'
img = image.load_img(img_path, target_size=(128, 128))
img_array = image.img_to_array(img) / 255.0
img_array = np.expand_dims(img_array, axis=0)

# Make a prediction
prediction = model.predict(img_array)
print('Real' if prediction[0][0] < 0.5 else 'Fake')
```

## How to Use

1. **Clone the repository**:
    ```bash
    git clone https://github.com/MaanVader/DeepFake-Detection-model.git
    cd DeepFake-Detection-model.git
    ```

2. **Run Inference**:
    Use the provided script or the sample code above to run inference on your images.

## License

This project is licensed under the MIT License. Feel free to use and modify the model as needed.

## Acknowledgments

Thanks to the various open-source projects and contributors whose work has made this project possible.

---