Skip to content

Latest commit

 

History

18 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deepfake Image Detection System

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.

Report: /Report


Project Overview

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.


Main Features

  • 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 .pth checkpoint files
  • Prediction output with probability and interpretation

Repository Structure

.
├── 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

Dataset

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/

Methodology

1. Spatial-Domain Approach

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

2. Frequency-Domain Approach

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

3. Benford DCT Analysis

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.


Models

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

Results

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.


Application Deployment

1. Create a Virtual Environment

Using Conda:

conda create -n deepfake_app python=3.10
conda activate deepfake_app

Using Python venv:

python -m venv deepfake_app_env

Activate on Windows PowerShell:

deepfake_app_env\Scripts\activate

Activate on Git Bash:

source deepfake_app_env/Scripts/activate

2. Install Dependencies

pip install -r requirements.txt

If no requirements.txt is available:

pip install streamlit torch torchvision opencv-python numpy pandas matplotlib pillow scikit-learn

3. Run the Streamlit App

Go to the frontend folder:

cd Frontend

Run the app:

streamlit run app.py

Open the local URL shown in the terminal:

http://localhost:8501

How to Use the App

  1. Enter the folder path containing the trained .pth model files.
  2. Select a classifier from the dropdown list.
  3. Upload an image.
  4. View the real/fake probability result.
  5. Review the Benford DCT forensic analysis if enabled.

Supported image formats:

.jpg
.jpeg
.png
.bmp
.webp

Example Output

Real Probability: 0.8721
Fake Probability: 0.1279
Decision: Likely real
Risk Level: Moderate-low fake risk

Important Notes

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.


Security Warning

Only load trusted .pth model files. PyTorch checkpoint files from unknown sources may contain unsafe serialized content.


Tools and Libraries

  • Python
  • PyTorch
  • Torchvision
  • OpenCV
  • NumPy
  • Pandas
  • Matplotlib
  • Scikit-learn
  • Streamlit
  • Pillow

License

This project is released under the MIT License.

About

Real vs Fake Image Analysis

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages