A deepfake image detection project that compares spatial-domain and frequency-domain approaches using ResNet50-based transfer learning. The project also includes a Streamlit frontend application that allows users to upload an image and receive a real/fake prediction with supporting forensic analysis.
Youtube Demo: https://youtu.be/8PiLAn2j9gw
User guide: https://app.notion.com/p/Deepfake-Detection-App-Deployment-Guide-36f96cbb7977808dbf5ad980da497ecc?source=copy_link
Deepfake and AI-generated images are becoming increasingly realistic, making it difficult for users to identify whether an image is genuine or manipulated. This project develops a fake image detection system using deep learning and image forensic techniques.
The project focuses on two main classifier approaches:
- Spatial ResNet50 — uses original RGB images.
- DFT-ResNet50 — uses frequency-domain DFT magnitude spectrum images.
In addition, the frontend application includes Benford DCT analysis as a supplementary forensic indicator.
- Real/fake image classification
- Spatial-domain ResNet50 model
- Frequency-domain DFT-ResNet50 model
- DFT/FFT magnitude spectrum preprocessing
- Benford’s Law forensic feature analysis
- Streamlit-based graphical user interface
- Model selection using
.pthcheckpoint files - Prediction output with probability and interpretation
.
├── Frontend/
│ └── Streamlit application files
│
├── Model/
│ └── Trained model checkpoints and model-related files
│
├── Model_Training/
│ └── Training scripts for Spatial ResNet50 and DFT-ResNet50
│
├── Poster/
│ └── Project poster materials
│
├── Pre-process/
│ └── Image preprocessing and DFT conversion scripts
│
├── Reflection/
│ └── Reflection and documentation materials
│
├── LICENSE
├── cnn.ipynb
└── cnn.ipynb - Colab.pdf
This project uses the DeepFakeFace dataset.
The dataset contains real and fake images generated from different sources. For this project, the dataset was organised into the following structure:
DeepFakeFace_binary/
├── train/
│ ├── fake/
│ └── real/
│
├── val/
│ ├── fake/
│ └── real/
│
└── test/
├── fake/
└── real/
For the frequency-domain experiment, a second dataset was generated by converting the original RGB images into DFT magnitude spectrum images:
DeepFakeFace_fft/
├── train/
│ ├── fake/
│ └── real/
│
├── val/
│ ├── fake/
│ └── real/
│
└── test/
├── fake/
└── real/
The Spatial ResNet50 model uses the original RGB images as input.
Processing workflow:
Original RGB Image
→ Resize to 256 × 256
→ Apply Training Augmentation
→ Convert to Tensor
→ Normalize using ImageNet Mean and Standard Deviation
→ Input to ResNet50
→ Binary Classification Output: Real / Fake
This model learns visible image features such as:
- Facial texture
- Colour consistency
- Lighting
- Edges
- Local manipulation artefacts
The DFT-ResNet50 model uses frequency-domain magnitude spectrum images as input.
Processing workflow:
Original RGB Image
→ Resize to 256 × 256
→ Split Image into RGB Channels
→ Apply 2D DFT to Each Channel
→ Apply fftshift
→ Calculate Magnitude Spectrum
→ Apply Logarithmic Scaling
→ Normalize to 0–255
→ Merge Transformed Channels
→ Save as PNG
→ Input to ResNet50
→ Binary Classification Output: Real / Fake
This model learns frequency-level patterns such as:
- Noise distribution
- Texture irregularities
- Edge frequency
- Compression traces
- Synthetic generation artefacts
The Streamlit frontend also includes Benford’s Law analysis as a supplementary forensic indicator.
Workflow:
Uploaded Image
→ Convert to Grayscale
→ Apply DCT
→ Extract DCT Coefficients
→ Extract First-Digit Distribution
→ Compare with Benford’s Law
→ Calculate Divergence Score
A lower Benford divergence score suggests that the image follows a more normal statistical pattern. A higher score suggests stronger statistical irregularity. However, this is only used as supporting evidence and not as the final classification decision.
The main models used in this project are:
| Model | Input Type | Description |
|---|---|---|
| Spatial ResNet50 | RGB image | Fine-tuned ResNet50 using original spatial-domain images |
| DFT-ResNet50 | DFT magnitude spectrum image | Fine-tuned ResNet50 using frequency-domain images |
Both models use ImageNet-pretrained ResNet50 weights and are fine-tuned for binary classification:
fake = 0
real = 1
| Model | Accuracy (%) | F1 Score | AUC |
|---|---|---|---|
| HuggingFace Baseline | 53.63 | 0.5340 | 0.5329 |
| DFT-ResNet50 | 70.10 | 0.6994 | 0.7697 |
| Spatial ResNet50 | 87.72 | 0.8761 | 0.9664 |
The results show that the Spatial ResNet50 achieved the strongest performance among the tested models. This suggests that spatial RGB features were more effective than frequency-domain-only features for this dataset. However, frequency-domain analysis still provides useful forensic insight and can support further investigation.
Using Conda:
conda create -n deepfake_app python=3.10
conda activate deepfake_appUsing Python venv:
python -m venv deepfake_app_envActivate on Windows PowerShell:
deepfake_app_env\Scripts\activateActivate on Git Bash:
source deepfake_app_env/Scripts/activatepip install -r requirements.txtIf no requirements.txt is available:
pip install streamlit torch torchvision opencv-python numpy pandas matplotlib pillow scikit-learnGo to the frontend folder:
cd FrontendRun the app:
streamlit run app.pyOpen the local URL shown in the terminal:
http://localhost:8501
- Enter the folder path containing the trained
.pthmodel files. - Select a classifier from the dropdown list.
- Upload an image.
- View the real/fake probability result.
- Review the Benford DCT forensic analysis if enabled.
Supported image formats:
.jpg
.jpeg
.png
.bmp
.webp
Real Probability: 0.8721
Fake Probability: 0.1279
Decision: Likely real
Risk Level: Moderate-low fake risk
The prediction may be affected by:
- Image compression
- Low resolution
- Blur
- Filters
- Screenshots
- Strong lighting
- Unseen deepfake generation methods
Therefore, the result should be treated as supporting information only, not as absolute forensic proof.
Only load trusted .pth model files. PyTorch checkpoint files from unknown sources may contain unsafe serialized content.
- Python
- PyTorch
- Torchvision
- OpenCV
- NumPy
- Pandas
- Matplotlib
- Scikit-learn
- Streamlit
- Pillow
This project is released under the MIT License.