A robust deepfake image detection system built with TensorFlow/Keras, combining:
- RGB spatial features
- Frequency-domain features (DCT-based)
- Explicit forensic features
The project includes a modular training pipeline, inference API, evaluation scripts, and comprehensive Exploratory Data Analysis (EDA).
- Three-stream EfficientNet architecture (RGB + DCT frequency + explicit forensic features)
- Attention-based stream fusion for combining RGB, frequency, and explicit features
- Comprehensive EDA with automated artifact detection
- Complete data pipeline using tf.data API
- Mixed precision training (FP16) for GPU acceleration
- REST API using FastAPI
- Grad-CAM visualization for model explainability
- TensorBoard integration for monitoring
deepfake-detection-tf/
|-- notebooks/ # Jupyter notebooks for EDA
| |-- 01_data_exploration.ipynb
| |-- 02_feature_analysis.ipynb
| |-- 03_model_experiments.ipynb
| `-- 04_results_analysis.ipynb
|-- eda/ # EDA Python modules
| |-- data_analyzer.py
| |-- visualization.py
| |-- statistical_tests.py
| |-- artifact_detector.py
| `-- report_generator.py
|-- configs/ # Configuration files
| |-- config.yaml
| `-- eda_config.json
|-- data/ # Data pipeline
| |-- dataset_loader.py
| |-- preprocessing.py
| |-- augmentation.py
| `-- face_detection.py
|-- models/ # Model architectures
| |-- three_stream_net.py
| |-- frequency_net.py
| `-- model_factory.py
|-- training/ # Training utilities
| |-- trainer.py
| |-- losses.py
| |-- callbacks.py
| `-- metrics.py
|-- inference/ # Inference utilities
| |-- detector.py
| `-- api.py
|-- utils/ # Utility functions
| |-- visualization.py
| |-- frequency_utils.py
| `-- face_utils.py
|-- train.py # Training script
|-- evaluate.py # Evaluation script
|-- eda_report.py # EDA report generation
|-- serve.py # API server
|-- requirements.txt
|-- Dockerfile
`-- README.md
- Clone the repository:
git clone <repository-url>
cd deepfake-detection-tf- Install dependencies:
pip install -r requirements.txt- (Optional) Install MTCNN for face detection:
pip install mtcnnpython eda_report.py --dataset faceforensics --data_dir ./data/raw --output ./reports --visualize --savepython train.py --config configs/config.yaml --data_dir ./data/rawpython evaluate.py --model_path ./checkpoints/best_model.weights.h5 --data_dir ./data/raw/testpython serve.py --model_path ./checkpoints/best_model.weights.h5 --config configs/config.yaml --host 0.0.0.0 --port 8000The EDA system provides:
- Dataset Statistics: Class distribution, image counts, resolution analysis
- Visual Analysis: Side-by-side comparisons, difference maps, frequency spectra
- Feature Analysis: Frequency domain analysis, PCA/t-SNE visualization
- Artifact Detection: Automated detection of face warping, lighting inconsistencies, blending artifacts
- Statistical Tests: Kolmogorov-Smirnov, Chi-square, t-tests, ANOVA
- Automated Reports: HTML/PDF reports with interactive visualizations
Edit configs/config.yaml to customize:
- Model architecture
- Training parameters
- Data augmentation
- Loss functions
- Callbacks
Edit configs/eda_config.json to customize EDA analysis options.
The three-stream architecture consists of:
- RGB Stream: EfficientNet-B4 backbone pretrained on ImageNet
- Frequency Stream: DCT-based frequency analysis network (FrequencyNet)
- Explicit Feature Stream: MLP over hand-crafted forensic features (ELA, texture/gradient histograms, color moments)
- Fusion + Head: attention over the three stream embeddings + binary classification
Expected directory structure:
data/raw/
real/
image1.jpg
image2.jpg
fake/
image1.jpg
image2.jpg
Once the API server is running, you can make predictions:
curl -X POST "http://localhost:8000/predict" \
-H "accept: application/json" \
-H "Content-Type: multipart/form-data" \
-F "file=@image.jpg"Response:
{
"is_fake": false,
"confidence": 0.95,
"real_probability": 0.95,
"fake_probability": 0.05
}Build and run with Docker:
docker build -t deepfake-detection .
docker run -p 8000:8000 deepfake-detectionThis project uses Git for version control. The repository includes:
.gitignore- Excludes Python cache, virtual environments, model checkpoints, and other generated files.gitattributes- Ensures consistent line endings and handles binary filesCONTRIBUTING.md- Guidelines for contributing to the projectLICENSE- MIT License
If you're cloning this repository:
git clone <repository-url>
cd dfprojectv2# Stage all files
git add .
# Commit with a descriptive message
git commit -m "Initial commit: Deepfake detection system with EDA"
# Push to remote (if you have a remote repository)
git push origin main-
Create a branch for your feature:
git checkout -b feature/your-feature-name
-
Make your changes and commit:
git add . git commit -m "feat: Add new feature"
-
Push and create a Pull Request:
git push origin feature/your-feature-name
See CONTRIBUTING.md for detailed contribution guidelines.
MIT License - See LICENSE file for details
If you use this code, please cite:
@software{deepfake_detection_three_stream,
title = {Deepfake Image Detection Using Three-Stream EfficientNet},
author = {Labeeb K M},
year = {2025},
url = {https://github.com/labeebkm/deepfake-detection-project},
note = {RGB, frequency-domain, and explicit forensic feature fusion}
}To start the training .\dfenv\python.exe train.py --config configs\config.yaml
To launch the website .\dfenv\python.exe serve.py --model_path .\checkpoints\best_model.weights.h5 --config configs\config.yaml --host 127.0.0.1 --port 8000
For eda report generation python eda_report.py --dataset faceforensics --data_dir "C:\Users\HP\Documents\QUEST\deepfake project\dataset" --output ./reports --format html --visualize --save
To test curl.exe -F "file=@C:\Users\HP\Pictures\test.jpg" http://127.0.0.1:8000/predict
.\dfenv\python.exe serve.py --model_path .\checkpoints\final_model.weights.h5 --config configs\config.yaml --host 127.0.0.1 --port 80
#To launch the tensorboard tensorboard --logdir ./logs
#Steps to launch the gradcam (follow these below given steps)
-
Start server bound to IPv4 (new terminal): cd C:\Users\HP\Documents\QUEST\dfprojectv2 python -m http.server 5500 --bind 127.0.0.1
-
Then open new terminal and run these: Start-Process "http://127.0.0.1:5500/demo.html"
-
Now run these: python serve.py --model_path .\checkpoints\best_model.weights.h5 --config .\configs\config.yaml --host 127.0.0.1 --port 8000 --cors_origins "*"