Skip to content

Latest commit

ย 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿง  CIFAKE: An Explainable Deep Learning Framework for AI-Generated Image Detection

Major Project

Bachelor of Technology (B.Tech)

Computer Science & Engineering (Artificial Intelligence & Machine Learning)


๐Ÿ“Œ Project Overview

Artificial Intelligence has significantly advanced image generation technologies through models such as Stable Diffusion, Midjourney, DALLยทE, and other Generative AI systems. Although these technologies provide remarkable creative capabilities, they also introduce serious concerns regarding misinformation, fake media, identity theft, copyright issues, and digital security.

CIFAKE is a deep learning-based image classification system developed to distinguish between Real and AI-Generated (Fake) images. The project utilizes EfficientNetB0 Transfer Learning for accurate binary image classification and integrates Grad-CAM (Gradient-weighted Class Activation Mapping) to provide visual explanations for every prediction.

Unlike traditional black-box classifiers, this system enables users to understand why the model classified an image as Real or Fake by highlighting the most influential regions within the image.


๐ŸŽฏ Problem Statement

The rapid advancement of AI-generated synthetic images has made it increasingly difficult for humans to distinguish fake images from authentic photographs.

Traditional deep learning models often provide only predictions without explaining their decision-making process, reducing user trust and interpretability.

This project aims to develop an explainable deep learning system capable of accurately detecting AI-generated images while providing visual evidence supporting every prediction.


๐ŸŽฏ Objectives

The primary objectives of this project are:

  • Develop an AI-powered image classification system.
  • Detect AI-generated synthetic images with high accuracy.
  • Classify uploaded images into REAL or FAKE categories.
  • Utilize EfficientNetB0 through Transfer Learning.
  • Implement Explainable Artificial Intelligence (Grad-CAM).
  • Build an interactive Flask-based web application.
  • Provide model evaluation through graphical performance analysis.

๐Ÿ“‚ Dataset

This project uses the CIFAKE: Real and AI-Generated Synthetic Images dataset.

Dataset Statistics

Category Images
Training REAL 50,000
Training FAKE 50,000
Testing REAL 10,000
Testing FAKE 10,000

Total Images: 120,000

Note: The dataset is not included in this repository due to its large size. Please download it from the official Kaggle page and place it in the following directory structure:

dataset/
โ”‚
โ”œโ”€โ”€ train/
โ”‚   โ”œโ”€โ”€ REAL/
โ”‚   โ””โ”€โ”€ FAKE/
โ”‚
โ””โ”€โ”€ test/
    โ”œโ”€โ”€ REAL/
    โ””โ”€โ”€ FAKE/

๐Ÿ— Model Architecture

The proposed system is developed using Transfer Learning with EfficientNetB0.

Backbone Network

  • EfficientNetB0 (ImageNet Pre-trained)

Classification Head

  • GlobalAveragePooling2D
  • BatchNormalization
  • Dropout (0.4)
  • Dense Layer (256 Neurons, ReLU)
  • Dropout (0.3)
  • Output Layer (Sigmoid Activation)

Input Image Size

224 ร— 224 ร— 3

โš™ Training Strategy

The model was trained in two sequential stages.

Stage 1 โ€“ Feature Extraction

  • EfficientNetB0 kept frozen.
  • Only custom classification layers trained.

Stage 2 โ€“ Fine-Tuning

  • Last layers of EfficientNetB0 unfrozen.
  • Lower learning rate applied.
  • Fine-tuning improves feature representation and overall accuracy.

๐Ÿง  Explainable Artificial Intelligence (Grad-CAM)

Deep learning models generally behave as black-box systems where predictions are difficult to interpret.

To improve transparency, this project integrates Grad-CAM (Gradient-weighted Class Activation Mapping).

Grad-CAM highlights the important regions of an image that contributed most toward the model's prediction.

For every uploaded image, the system generates:

  • Original Image
  • Grad-CAM Heatmap
  • Heatmap Overlay
  • Human-readable Explanation

This enables users to understand the reasoning behind every prediction.


๐ŸŒ Web Application Modules

The project consists of three major modules.

1. AI Image Detector

  • Upload an image
  • Predict REAL or FAKE
  • Display prediction confidence

2. Explainable AI Module

Generates visual explanations using Grad-CAM.

Outputs include:

  • Heatmap
  • Overlay Visualization
  • Explanation of important image regions

3. Model Insights Dashboard

Provides comprehensive evaluation of the trained model through:

  • Accuracy
  • Precision
  • Recall
  • F1 Score
  • Confusion Matrix
  • ROC Curve
  • Dataset Distribution
  • Prediction Confidence Distribution

๐Ÿ“Š Model Performance

Metric Performance
Accuracy 95.24%
Precision 94.88%
Recall 95.63%
F1 Score 95.25%

๐Ÿ“ˆ Model Insights

The project includes a dedicated Insights Dashboard containing:

  • Model Performance Metrics
  • Confusion Matrix
  • ROC Curve
  • Dataset Distribution
  • Prediction Confidence Distribution

These visualizations help evaluate classification quality and overall model reliability.


๐Ÿ’ป Technologies Used

Programming Language

  • Python

Deep Learning Framework

  • TensorFlow
  • Keras

Machine Learning

  • Scikit-learn

Computer Vision

  • OpenCV
  • Pillow

Data Processing

  • NumPy
  • Pandas

Data Visualization

  • Matplotlib

Web Framework

  • Flask

Frontend Technologies

  • HTML5
  • CSS3
  • Bootstrap 5
  • Font Awesome

๐Ÿ“ Project Structure

CIFAKE/
โ”‚
โ”œโ”€โ”€ app.py
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ README.md
โ”‚
โ”œโ”€โ”€ dataset/
โ”‚   โ”œโ”€โ”€ train/
โ”‚   โ””โ”€โ”€ test/
โ”‚
โ”œโ”€โ”€ explainability/
โ”‚
โ”œโ”€โ”€ models/
โ”‚   โ”œโ”€โ”€ best_model.keras
โ”‚   โ”œโ”€โ”€ final_model.keras
โ”‚   โ”œโ”€โ”€ accuracy_plot.png
โ”‚   โ”œโ”€โ”€ loss_plot.png
โ”‚   โ””โ”€โ”€ training_history.csv
โ”‚
โ”œโ”€โ”€ notebooks/
โ”‚   โ”œโ”€โ”€ 01_dataset_analysis.py
โ”‚   โ”œโ”€โ”€ 02_preprocessing.py
โ”‚   โ”œโ”€โ”€ 03_model_building.py
โ”‚   โ”œโ”€โ”€ 04_train_final.py
โ”‚   โ”œโ”€โ”€ 05_model_evaluation.py
โ”‚   โ”œโ”€โ”€ 06_gradcam.py
โ”‚   โ”œโ”€โ”€ 07_confusion_matrix.py
โ”‚   โ”œโ”€โ”€ 08_roc_curve.py
โ”‚   โ”œโ”€โ”€ 09_dataset_distribution.py
โ”‚   โ””โ”€โ”€ 10_prediction_confidence_distribution.py
โ”‚
โ”œโ”€โ”€ reports/
โ”‚
โ”œโ”€โ”€ static/
โ”‚   โ”œโ”€โ”€ css/
โ”‚   โ”‚   โ””โ”€โ”€ style.css
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ images/
โ”‚   โ”‚   โ”œโ”€โ”€ confusion_matrix.png
โ”‚   โ”‚   โ”œโ”€โ”€ roc_curve.png
โ”‚   โ”‚   โ”œโ”€โ”€ dataset_distribution.png
โ”‚   โ”‚   โ””โ”€โ”€ prediction_confidence_distribution.png
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ uploads/
โ”‚
โ””โ”€โ”€ templates/
    โ”œโ”€โ”€ index.html
    โ”œโ”€โ”€ result.html
    โ””โ”€โ”€ insights.html

๐Ÿ”„ Application Workflow

User Uploads Image
          โ”‚
          โ–ผ
Image Preprocessing
          โ”‚
          โ–ผ
EfficientNetB0 Classification
          โ”‚
          โ–ผ
Prediction (REAL / FAKE)
          โ”‚
          โ–ผ
Confidence Score
          โ”‚
          โ–ผ
Grad-CAM Heatmap Generation
          โ”‚
          โ–ผ
Explainable Visualization
          โ”‚
          โ–ผ
Prediction Result Display

๐Ÿ“ธ Application Screenshots

๐Ÿ  Home Page

The home page allows users to upload an image for authenticity verification using the trained EfficientNetB0 model.


๐Ÿ” Prediction Result Page

After uploading an image, the system predicts whether it is REAL or FAKE, displays the confidence score, and provides Grad-CAM visual explanations.


๐Ÿ“Š Model Insights Dashboard

The Insights Dashboard presents important evaluation metrics and analytical visualizations, including:

  • Accuracy
  • Precision
  • Recall
  • F1 Score
  • Confusion Matrix
  • ROC Curve
  • Dataset Distribution
  • Prediction Confidence Distribution


๐Ÿ”ฎ Future Scope

The project can be further extended by incorporating:

  • Detection of multiple AI image generators.
  • Real-time webcam-based fake image detection.
  • AI-generated video (Deepfake) detection.
  • Mobile application deployment.
  • Cloud deployment using platforms such as Render or AWS.
  • REST API integration.
  • Multi-class AI image generator identification.

๐Ÿ‘ฉโ€๐Ÿ’ป Author

Riya Rani

Bachelor of Technology (B.Tech)

Computer Science & Engineering (AI & ML)

Major Project


๐Ÿ™ Acknowledgements

This project was developed using the following technologies and resources:

  • TensorFlow & Keras
  • EfficientNet Research
  • OpenCV
  • Scikit-learn
  • Flask
  • Bootstrap 5
  • Font Awesome
  • CIFAKE Dataset Contributors

About

CIFAKE is an explainable deep learning framework designed to detect AI-generated synthetic images. Built using EfficientNetB0, TensorFlow, Keras, Grad-CAM, and Flask, the system provides accurate image classification along with visual explanations to improve model transparency and user trust.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages