Skip to content

πŸ–ΌοΈ Image Forgery Detection using CNN to classify images as real or forged (AI-generated/tampered). Includes dataset extraction, image preprocessing, CNN-based feature learning (MesoNet), model training, and prediction for digital forensics.

Notifications You must be signed in to change notification settings

krishnab0841/Image_Forgery_Detection_Using_CNN

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Image Forgery / AI Image Detection System

A specialized deep learning system for detecting AI-generated images (Deepfakes) using the MesoNet-4 architecture. This project is optimized for the CIFAKE dataset (Real vs. AI).

πŸš€ Features

  • MesoNet-4 Architecture: Compact and efficient 4-layer CNN designed for forensic analysis.
  • CIFAKE Dataset Support: Built-in tools to extract and organize the CIFAKE dataset (Real/AI).
  • Multiple Model Variants: Support for standard MesoNet-4 and MesoInception-4.
  • Visual Workflow: Clear visualization of the detection pipeline.
  • CLI Interface: Simple command-line tools for extraction, training, evaluation, and prediction.

🌊 System Workflow

The system follows a streamlined pipeline from raw data to prediction.

graph LR
    A[Raw Archive<br/>archive.zip] -->|Extract| B[Dataset Split<br/>Train/Test]
    B -->|Input Image<br/>256x256| C[MesoNet-4 Model]
    
    subgraph CNN Process
    C -->|Feature Extraction| D[Conv Layers]
    D -->|Classification| E[Dense Layers]
    end
    
    E -->|Sigmoid| F[Output Probability]
    F -->|Threshold > 0.5| G[AI Generated]
    F -->|Threshold < 0.5| H[Real Image]
    
    style C fill:#f9f,stroke:#333,stroke-width:2px
    style G fill:#ff9999,stroke:#333
    style H fill:#99ff99,stroke:#333
Loading

🧠 Model Architecture: MesoNet-4

MesoNet-4 is designed to detect "mesoscopic" properties of imagesβ€”subtle artifacts introduced by AI generation processes that are invisible to the human eye but detectable by a specialized neural network.

graph TD
    Input[Input Image<br/>256x256x3] --> Conv1[Conv2D<br/>8 filters, 3x3]
    Conv1 --> Pool1[MaxPooling<br/>2x2]
    Pool1 --> Conv2[Conv2D<br/>8 filters, 5x5]
    Conv2 --> Pool2[MaxPooling<br/>2x2]
    Pool2 --> Conv3[Conv2D<br/>16 filters, 5x5]
    Conv3 --> Pool3[MaxPooling<br/>2x2]
    Pool3 --> Conv4[Conv2D<br/>16 filters, 5x5]
    Conv4 --> Pool4[MaxPooling<br/>4x4]
    
    Pool4 --> Flatten[Flatten]
    Flatten --> D1[Dense 16<br/>Dropout 0.5]
    D1 --> Output[Dense 1<br/>Sigmoid Activation]
    
    style Input fill:#e1f5fe
    style Output fill:#fff9c4
Loading

Understanding the CNN Workflow

  1. Feature Extraction (Convolutional Layers)

    • The network applies a series of learnable filters (kernels) to the image.
    • Layer 1-2: Detect low-level features like edges, textures, and noise patterns (often where AI artifacts reside).
    • Layer 3-4: Combine these features to detect higher-level structures and complex artifact patterns specific to GANs or Diffusion models.
    • MaxPooling: Reduces the image size while retaining the most important features, making the model computationally efficient.
  2. Classification (Dense Layers)

    • Flatten: Converts the 2D feature maps into a 1D vector.
    • Dense Layer: Analyzes the feature vector to make a decision. Dropout is used here to prevent overfitting (memorizing the training data).
    • Output Layer: Produces a single score between 0 and 1.
      • 0: High confidence it is REAL.
      • 1: High confidence it is AI/FAKE.

πŸ› οΈ Installation

  1. Clone the repository

    git clone https://github.com/krishnab0841/Image_Forgery_Detection_Using_CNN.git
    cd Image_Forgery_Detection_Using_CNN
  2. Create a virtual environment

    python -m venv venv
    # Windows
    venv\Scripts\activate
    # Linux/Mac
    source venv/bin/activate
  3. Install dependencies

    pip install -r requirements.txt

🚦 Quick Start

1. Process Dataset

Download the CIFAKE Dataset and place your archive.zip in the project root, then run:

python main.py extract

2. Train Model

python main.py train --model_type mesonet --epochs 50 --evaluate

3. Make Predictions

# Single image
python main.py predict --model_path models/saved_models/ai_detector_final.h5 --image path/to/image.jpg

βš™οΈ Configuration

You can tweak the system in src/utils/config.py:

Parameter Default Description
IMG_SIZE (256, 256) Input resolution for the model
BATCH_SIZE 32 Number of images processed per step
EPOCHS 50 Total training iterations
LEARNING_RATE 0.001 Speed of model optimization

πŸ“ Project Structure

image-forgery-detection/
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ raw/                  # CIFAKE dataset (Real/AI)
β”‚   └── processed/            # Processed data
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ saved_models/         # Trained .h5 models
β”‚   └── logs/                 # TensorBoard logs
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ models/               # MesoNet and CNN architectures
β”‚   β”œβ”€β”€ training/             # Training loop and callbacks
β”‚   β”œβ”€β”€ inference/            # Prediction logic
β”‚   └── utils/                # Configuration and helpers
β”œβ”€β”€ main.py                   # Main CLI entry point
β”œβ”€β”€ extract_dataset.py        # Dataset extraction script
└── requirements.txt          # Dependencies

About

πŸ–ΌοΈ Image Forgery Detection using CNN to classify images as real or forged (AI-generated/tampered). Includes dataset extraction, image preprocessing, CNN-based feature learning (MesoNet), model training, and prediction for digital forensics.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages