├── SS ├── Example (1).png ├── Example (2).png ├── Screenshot 2025-05-14 194643.png ├── Screenshot 2025-05-14 194747.png ├── Screenshot 2025-05-14 194855.png └── Screenshot_example_result (1).jpeg ├── mymodels ├── AI_or_Realface_imageclassifier.h5 ├── fold_1_phase1_best_model.keras ├── fold_1_phase2_best_model.keras ├── fold_2_phase1_best_model.keras ├── fold_2_phase2_best_model.keras ├── fold_3_phase1_best_model.keras ├── fold_3_phase2_best_model.keras ├── fold_4_phase1_best_model.keras ├── fold_4_phase2_best_model.keras ├── fold_5_phase1_best_model.keras ├── fold_5_phase2_best_model.keras └── AI_or_Realface_imageclassifier.keras ├── .gitattributes ├── LICENSE └── README.md /SS/Example (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/indranil143/Real-or-AI-Generated-Face-Detection/HEAD/SS/Example (1).png -------------------------------------------------------------------------------- /SS/Example (2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/indranil143/Real-or-AI-Generated-Face-Detection/HEAD/SS/Example (2).png -------------------------------------------------------------------------------- /SS/Screenshot 2025-05-14 194643.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/indranil143/Real-or-AI-Generated-Face-Detection/HEAD/SS/Screenshot 2025-05-14 194643.png -------------------------------------------------------------------------------- /SS/Screenshot 2025-05-14 194747.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/indranil143/Real-or-AI-Generated-Face-Detection/HEAD/SS/Screenshot 2025-05-14 194747.png -------------------------------------------------------------------------------- /SS/Screenshot 2025-05-14 194855.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/indranil143/Real-or-AI-Generated-Face-Detection/HEAD/SS/Screenshot 2025-05-14 194855.png -------------------------------------------------------------------------------- /SS/Screenshot_example_result (1).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/indranil143/Real-or-AI-Generated-Face-Detection/HEAD/SS/Screenshot_example_result (1).jpeg -------------------------------------------------------------------------------- /mymodels/AI_or_Realface_imageclassifier.h5: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:b5a02f47b0703ac66734c3f3fc854666eaaffc86846b03c8e1c69afedd550258 3 | size 44394376 4 | -------------------------------------------------------------------------------- /mymodels/fold_1_phase1_best_model.keras: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:a90019f1659ac57165f22242221628413b363bc27d2dfaaa47910f3501343183 3 | size 90682405 4 | -------------------------------------------------------------------------------- /mymodels/fold_1_phase2_best_model.keras: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:c3a3f42a99ae43e2a15d9f2a151a034b6f9d62e48c6147a66a7a4198ad02f7b1 3 | size 90682405 4 | -------------------------------------------------------------------------------- /mymodels/fold_2_phase1_best_model.keras: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:7790f13b4e24f61b222bb457a2fb000ca86391a7b4f5f2053e52219c3573dafc 3 | size 90682325 4 | -------------------------------------------------------------------------------- /mymodels/fold_2_phase2_best_model.keras: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:64fac6ecd0dde2e167f068699ede0a7adb8466145d68963673782f8d7402efb8 3 | size 90682325 4 | -------------------------------------------------------------------------------- /mymodels/fold_3_phase1_best_model.keras: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:3432392921ed69752dc577141622164e0b36fcde99f196f5408c87f265072125 3 | size 90682325 4 | -------------------------------------------------------------------------------- /mymodels/fold_3_phase2_best_model.keras: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:136a5fc964bf4b3271f7fa648a159fa25c60fa1ba7eec239f0295b1968433b81 3 | size 90682325 4 | -------------------------------------------------------------------------------- /mymodels/fold_4_phase1_best_model.keras: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:8fd82ca3393319a0725f8d6bcd84ad07d1718a4a101c5db138ddd8e38e1074c9 3 | size 90682325 4 | -------------------------------------------------------------------------------- /mymodels/fold_4_phase2_best_model.keras: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:e31cdf95af7addf8258bdd4a01e401d1a414677d7bc2f3a1daa940b014c0a739 3 | size 90682325 4 | -------------------------------------------------------------------------------- /mymodels/fold_5_phase1_best_model.keras: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:d6f654809d857326b948e61e6f49374bd32de44c6a837bea713c5db913c4ddaa 3 | size 90682325 4 | -------------------------------------------------------------------------------- /mymodels/fold_5_phase2_best_model.keras: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:3361119e4abd61db7c0881c35f4d8704cffeeec4fafbde6d1dfa27b7a19c55d5 3 | size 90682325 4 | -------------------------------------------------------------------------------- /mymodels/AI_or_Realface_imageclassifier.keras: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:7d4c32c4fdb2b5fd9659c17c4976771819986f0e147823df641dcd678de412a6 3 | size 44398298 4 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pt filter=lfs diff=lfs merge=lfs -text 2 | *.pkl filter=lfs diff=lfs merge=lfs -text 3 | *.h5 filter=lfs diff=lfs merge=lfs -text 4 | *.keras filter=lfs diff=lfs merge=lfs -text 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Indranil Bandyopadhyay 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deepfake Face Detection using Deep Learning 🤖👤 2 | **(Real-or-AI-Generated-Face-Detection)** 3 | 4 | [](https://www.python.org/) 5 | [](https://en.wikipedia.org/wiki/Deep_learning) 6 | [](https://www.tensorflow.org/) 7 | [](https://numpy.org/) 8 | [](https://matplotlib.org/) 9 | [](https://seaborn.pydata.org/) 10 | [](https://scikit-learn.org/stable/) 11 | [](https://opencv.org/) 12 | [](https://keras.io/api/applications/xception/) 13 | [](https://scikit-learn.org/stable/modules/cross_validation.html) 14 | [](https://jupyter.org/) 15 | [](https://opensource.org/licenses/MIT) 16 | 17 | ## 📌 Project Overview 18 | AI-generated images are now almost everywhere, making it crucial to detect them before misinformation spreads or you get catfished!! 🎭 19 | There is a critical need to reliably detect AI-generated facial images (deepfakes) to mitigate these risks. This repository showcases a robust primary approach utilizing the **Xception network with transfer learning and K-Fold cross-validation**, alongside an alternative approach using custom Convolutional Neural Network (CNN). 20 | 21 | ## 👤 Problem Statement 22 | The increasing realism of GAN-generated faces makes it hard to distinguish them from real ones, posing significant threats such as the proliferation of disinformation and potential reputational damage. 23 | Therefore, we have developed advanced deep learning models specifically designed to identify AI-generated faces! 24 | 25 | ## 🚀 Main Approach: Xception-based Transfer Learning with K-Fold CV 26 | The core solution, detailed in `Deepfake-Face-Detection-with-Xception.ipynb`, employs: 27 | 28 | * **Data Handling:** Images from 'real' and 'fake' directories are resized to **(224, 224)** pixels, normalized, and augmented (flips, brightness, contrast, etc.). 29 | * **Model Architecture:** **Xception** (ImageNet pre-trained) base with a custom head: Global Average Pooling, Dense layers (**L2 regularization: 0.0001, Dropout: 0.3**), Batch Normalization, and a `sigmoid` output. 30 | * **Two-Phase Training (Adam optimizer):** 31 | 1. Train custom head (Xception frozen): **20 epochs**, initial Learning Rate **0.001**. Callbacks: Early Stopping (patience 10), ReduceLROnPlateau (patience 4). 32 | 2. Fine-tune full model (Xception unfrozen): **30 epochs**, lower Learning Rate **1e-5**. Callbacks: Early Stopping (patience 15), ReduceLROnPlateau (patience 7). 33 | * **Cross-Validation:** **5-Fold Cross-Validation (SEED = 42)** for robust performance estimation and model checkpointing per fold. 34 | * **Evaluation:** Metrics include Accuracy, Precision, Recall, F1-Score, AUC. Generates Classification Reports, Confusion Matrices (from pooled predictions), Training History Plots, and ROC Curves. 35 | * **Prediction:** Loads saved `.keras` models for new image/directory predictions using a **0.5 probability threshold**. 36 | 37 | ## 🗂️ Dataset (Main Approach) 38 | * **Name:** RVF10K 39 | * **Source:** Kaggle - `sachchitkunichetty/rvf10k` 40 | * **Structure:** Expected at `/kaggle/input/rvf10k/rvf10k/train` with `real` and `fake` subdirectories. 41 | * **Size:** Approximately 7000 images. 42 | 43 | **Some example images -**  44 | 45 | ## ✅ Results (Main Approach) 46 | Based on 5-Fold Cross-Validation on the RVF10K dataset: 47 |
69 |
70 |
.png)