# tejasweesahu/deepfake-image-detector architecture

> Architecture diagram of the GitHub repository tejasweesahu/deepfake-image-detector, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tejasweesahu/deepfake-image-detector
- Repository: https://github.com/tejasweesahu/deepfake-image-detector

## Overview

##### Project type and purpose
- This is an ML‐based pipeline for detecting deepfake images.
- It trains a CNN (optionally with transfer learning) on labeled “real” vs. “fake” images, then produces JSON predictions for unseen test images.

##### File structure
- Top level:
- Bishop_Boys.ipynb – contains all data ingestion, preprocessing, model definition, training, evaluation, and inference code.
- README.md – project description, approach, architecture, results.
- LICENSE.
- No separate “src” or “data” folders—code and documentation are bundled in the notebook.

##### README for additional insights
- Data sources: fake_cifake_images/, real_cifake_images/, JSON label files, test/ images.
- Steps: preprocessing (resize, normalize, label conversion), CNN model (conv, pooling, dropout, dense), evaluation (train/val split), inference (produce JSON).

a. Main components:
1. Data Storage
– Raw image directories (real, fake, test)
– JSON label files
2. Data Preprocessing
– Image loader & resizer (224×224)
– Normalization step
– Label encoder
3. Model Training
– CNN architecture (or ResNet transfer‐learning block)
– Training loop (loss calculation, optimizer)
4. Evaluation
– Train/validation split
– Metrics calculator (accuracy, robustness)
5. Inference
– Load trained weights
– Predict on test images
– Format output JSON
6. Output Storage
– Predictions JSON file

b. Relationships and data flows:
– Inference → Output Storage.
– Feedback loop from Evaluation back to Model Training (hyperparameter tuning).

c. Architectural patterns and principles:
– Pipeline pattern: distinct stages (ingest → preprocess → train → evaluate → infer).
– Modular separation (data, compute, output).
– Optional micro-batch processing of images.
– Reusability: same preprocessing code for train/test.

d. Key technologies:
– Jupyter Notebook (Bishop_Boys.ipynb) as execution environment.
– Python libraries: TensorFlow/PyTorch (CNN and transfer learning), OpenCV/Pillow (image ops), JSON lib.
– JSON files for labels and output.

##### Elements
– Clear labels: “Raw Images”, “Preprocessing Module”, “CNN Trainer”, “Evaluator”, “Inference Engine”, “Output JSON”.

##### Detailed capture of architectural elements
- Break Preprocessing into “Resize” and “Normalize” sub‐components.
- In the Model block, subdivide into “Conv + Pool Layers”, “Dropout”, “Dense”.
- Evaluation metrics branching off the Trainer.

## Diagram (Mermaid)

```mermaid
flowchart TD
    RawImages[(Raw Images & JSON Labels)]:::datastore
    subgraph "Preprocessing"
        Resize["Resize Images (224×224)"]:::compute
        Normalize["Normalize"]:::compute
        LabelEncode["Label Encoding"]:::compute
    end
    subgraph "Model Training"
        ConvPool["Conv + Pool Layers"]:::compute
        Dropout["Dropout"]:::compute
        Dense["Dense Layers"]:::compute
    end
    Evaluate["Evaluator (Train/Val Split & Metrics)"]:::eval
    Inference["Inference Engine (Load Weights & Predict)"]:::compute
    Output[(Predictions JSON)]:::datastore
    Documentation["Project Documentation"]:::doc
    License["License Information"]:::doc

    RawImages --> Resize
    Resize --> Normalize
    Normalize --> LabelEncode
    LabelEncode --> ConvPool
    ConvPool --> Dropout
    Dropout --> Dense
    Dense --> Evaluate
    Evaluate --> ConvPool
    Dense --> Inference
    Inference --> Output

    click RawImages "https://github.com/tejasweesahu/deepfake-image-detector/blob/main/Bishop_Boys.ipynb"
    click Resize "https://github.com/tejasweesahu/deepfake-image-detector/blob/main/Bishop_Boys.ipynb"
    click Normalize "https://github.com/tejasweesahu/deepfake-image-detector/blob/main/Bishop_Boys.ipynb"
    click LabelEncode "https://github.com/tejasweesahu/deepfake-image-detector/blob/main/Bishop_Boys.ipynb"
    click ConvPool "https://github.com/tejasweesahu/deepfake-image-detector/blob/main/Bishop_Boys.ipynb"
    click Dropout "https://github.com/tejasweesahu/deepfake-image-detector/blob/main/Bishop_Boys.ipynb"
    click Dense "https://github.com/tejasweesahu/deepfake-image-detector/blob/main/Bishop_Boys.ipynb"
    click Evaluate "https://github.com/tejasweesahu/deepfake-image-detector/blob/main/Bishop_Boys.ipynb"
    click Inference "https://github.com/tejasweesahu/deepfake-image-detector/blob/main/Bishop_Boys.ipynb"
    click Output "https://github.com/tejasweesahu/deepfake-image-detector/blob/main/Bishop_Boys.ipynb"
    click Documentation "https://github.com/tejasweesahu/deepfake-image-detector/blob/main/README.md"
    click License "https://github.com/tejasweesahu/deepfake-image-detector/tree/main/LICENSE"

    classDef datastore fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef compute fill:#90EE90,stroke:#333,stroke-width:1px;
    classDef eval fill:#FFD580,stroke:#333,stroke-width:1px;
    classDef doc fill:#D3D3D3,stroke:#333,stroke-width:1px;
```
