8000 GitHub - indranil143/Real-or-AI-Generated-Face-Detection: AI-generated or real face? These Deep Learning-based models can expose digital imposters before they ghost you, so no more falling for flawless deepfake faces!!
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

AI-generated or real face? These Deep Learning-based models can expose digital imposters before they ghost you, so no more falling for flawless deepfake faces!!

License

Notifications You must be signed in to change notification settings

indranil143/Real-or-AI-Generated-Face-Detection

Repository files navigation

Deepfake Face Detection using Deep Learning 🤖👤

(Real-or-AI-Generated-Face-Detection)

Python Deep Learning TensorFlow NumPy Matplotlib Seaborn Scikit-learn OpenCV Model: Xception Evaluation: K-Fold CV Jupyter License: MIT

📌 Project Overview

AI-generated images are now almost everywhere, making it crucial to detect them before misinformation spreads or you get catfished!! 🎭
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).

👤 Problem Statement

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. Therefore, we have developed advanced deep learning models specifically designed to identify AI-generated faces!

🚀 Main Approach: Xception-based Transfer Learning with K-Fold CV

The core solution, detailed in Deepfake-Face-Detection-with-Xception.ipynb, employs:

  • Data Handling: Images from 'real' and 'fake' directories are resized to (224, 224) pixels, normalized, and augmented (flips, brightness, contrast, etc.).
  • 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.
  • Two-Phase Training (Adam optimizer):
    1. Train custom head (Xception frozen): 20 epochs, initial Learning Rate 0.001. Callbacks: Early Stopping (patience 10), ReduceLROnPlateau (patience 4).
    2. Fine-tune full model (Xception unfrozen): 30 epochs, lower Learning Rate 1e-5. Callbacks: Early Stopping (patience 15), ReduceLROnPlateau (patience 7).
  • Cross-Validation: 5-Fold Cross-Validation (SEED = 42) for robust performance estimation and model checkpointing per fold.
  • Evaluation: Metrics include Accuracy, Precision, Recall, F1-Score, AUC. Generates Classification Reports, Confusion Matrices (from pooled predictions), Training History Plots, and ROC Curves.
  • Prediction: Loads saved .keras models for new image/directory predictions using a 0.5 probability threshold.

🗂️ Dataset (Main Approach)

  • Name: RVF10K
  • Source: Kaggle - sachchitkunichetty/rvf10k
  • Structure: Expected at /kaggle/input/rvf10k/rvf10k/train with real and fake subdirectories.
  • Size: Approximately 7000 images.

Some example images - some image examples

✅ Results (Main Approach)

Based on 5-Fold Cross-Validation on the RVF10K dataset:

K-Fold Cross-Validation Summary:

Metric Value
Average Accuracy 0.7840 ± 0.0102
Average AUC 0.8609 ± 0.0106

Overall Metrics (Pooled Predictions Across All Folds):

Metric Precision Recall F1-Score Support
0.0 (Real) 0.79 0.77 0.78 3500
1.0 (Fake) 0.77 0.80 0.79 3500
Accuracy 0.78 7000
Macro Avg 0.78 0.78 0.78 7000
Weighted Avg 0.78 0.78 0.78 7000
  • Overall ROC Curve:

    Overall ROC Curve

Prediction Examples:

  • Example 1:

    Example 1 Prediction

    • Filename: LJE2ZPJRWRX.jpg
    • Prediction: Fake
    • Probability (Fake): 0.9294
    • Comment: A correct prediction with high confidence that the image is Fake.
  • Example 2:

    Example 2 Prediction

    • Filename: 46915.jpg
    • Prediction: Real
    • Probability (Fake): 0.0561
    • Comment: A correct prediction with high confidence that the image is Real.

🔄 Alternative Approach: Custom CNN Model (the old project)

An earlier project detailed in Real vs. AI-Generated Face Classification model.ipynb explored a custom CNN:

  • Architecture: Input (256, 256, 3), multiple Conv2D & MaxPooling2D layers, Flatten, Dense layers with ReLU, and a Sigmoid output.
  • Training: Adam optimizer, Binary Crossentropy loss.
  • Dataset: Custom collected real and GAN-generated faces ( 💡or build your own, e.g., using browser extensions to scrape images).
  • Result Example: Example Result Achieved high accuracy on its specific training set; generalization benefits from techniques like dropout and data augmentation.

🛠️ Setup and Installation

  1. Dependencies: Install Python (3.x), TensorFlow, NumPy, Matplotlib, Seaborn, Scikit-learn, OpenCV.
  2. Datasets:
    • Obtain RVF10K and update the path in Deepfake-Face-Detection-with-Xception.ipynb.
    • For the custom CNN, prepare your dataset (e.g., in an imagedata directory) or use your own and update the path in Real vs. AI-Generated Face Classification model.ipynb.
  3. Run Notebooks: Open and execute the cells in the respective .ipynb files.

✨ Future Improvements

  • Dataset Expansion: Train on larger, more diverse datasets.
  • Hyperparameter Tuning: Optimize for both model architectures.
  • Explore Other Architectures: Investigate Vision Transformers (ViTs), other advanced CNNs, or specialized deepfake detection methods.
  • Anomaly Detection: Frame deepfake detection as an anomaly problem.
  • Deployment: Develop a user-friendly interface for prediction.

Feel free to contribute by opening issues or submitting pull requests!

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


© 2025 indranil143

About

AI-generated or real face? These Deep Learning-based models can expose digital imposters before they ghost you, so no more falling for flawless deepfake faces!!

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0