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).
- 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.
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
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
-
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.
-
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.
-
Clone the repository
git clone https://github.com/krishnab0841/Image_Forgery_Detection_Using_CNN.git cd Image_Forgery_Detection_Using_CNN -
Create a virtual environment
python -m venv venv # Windows venv\Scripts\activate # Linux/Mac source venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
Download the CIFAKE Dataset and place your archive.zip in the project root, then run:
python main.py extractpython main.py train --model_type mesonet --epochs 50 --evaluate# Single image
python main.py predict --model_path models/saved_models/ai_detector_final.h5 --image path/to/image.jpgYou 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 |
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