# guyfloki/ai-image-detector architecture

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

- Interactive diagram: https://gitdiagram.com/guyfloki/ai-image-detector
- Repository: https://github.com/guyfloki/ai-image-detector

## Overview

##### Project type and purpose
- This is an open-source Python tool for binary image classification (“AI vs. human”).
- It uses a fine-tuned Convolutional Vision Transformer (CvT-13) and PyTorch for training, evaluation, and inference.
- Key use cases: batch evaluation of directories, one-off predictions, training on new data, and generating performance metrics (loss curve, confusion matrix).

##### File structure
- Top-level:
- LICENSE, README.md, notebooks (`ai_image_detector.ipynb`), `metrics/`, `models/` (saved `.pth` weights)
- `src/`: implementation of dataset loader (`custom_dataset.py`), model definition (`model.py`), training (`train.py`), evaluation (`evaluate.py`), and inference (`main.py`).
- No “frontend” or web layer; this is purely a CLI/SDK style ML pipeline.
- External references in README point to Google Drive for large raw datasets and model weights, plus the Hugging Face Transformers API for the CvT-13 backbone.

##### README for additional insights
- Confirms the use of: PyTorch (+ torchvision/torchaudio), Transformers, NumPy, matplotlib, scikit-learn, mlxtend, Pillow, tqdm
- Workflow stages described: data preparation → training → evaluation → prediction.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Sources
    subgraph "Data Sources"
        LocalData(["Local Training/Test Directories"]):::data
        GDriveCloud(["Google Drive"]):::cloud
        HFCloud(["Hugging Face API"]):::cloud
    end

    %% Core Modules
    DataLoader["Data Loader / Preprocessor\n(custom_dataset.py)"]:::code
    ModelDef["Model Definition\n(model.py)"]:::code
    Training["Training Module\n(train.py)"]:::code
    Evaluate["Evaluation Module\n(evaluate.py)"]:::code
    Inference["Inference Module\n(main.py)"]:::code
    Notebook["Interactive Notebook\n(ai_image_detector.ipynb)"]:::notebook

    %% Artifact Storage
    ModelStorage[(models/)]:::storage
    MetricsStorage[(metrics/)]:::storage
    Output(["Predictions (CLI Output)"]):::data

    %% Data Flow
    LocalData --> DataLoader
    GDriveCloud --> DataLoader

    DataLoader -->|preprocessed data| Training
    DataLoader -->|preprocessed data| Evaluate
    DataLoader -->|preprocessed data| Inference
    Notebook --> DataLoader

    Training -->|checkpoints| ModelStorage
    Evaluate -->|metrics & plots| MetricsStorage
    Inference -->|predictions| Output

    %% Dependencies
    Training -.->|uses| ModelDef
    Evaluate -.->|uses| ModelDef
    Inference -.->|uses| ModelDef
    ModelDef -.->|imports| HFCloud

    %% External Weights
    GDriveCloud -.->|initial weights| Training
    GDriveCloud -.->|initial weights| ModelDef

    %% Notebook Paths
    Notebook -.-> Training
    Notebook -.-> Evaluate
    Notebook -.-> Inference

    %% Click Events
    click DataLoader "https://github.com/guyfloki/ai-image-detector/blob/main/src/custom_dataset.py"
    click ModelDef "https://github.com/guyfloki/ai-image-detector/blob/main/src/model.py"
    click Training "https://github.com/guyfloki/ai-image-detector/blob/main/src/train.py"
    click Evaluate "https://github.com/guyfloki/ai-image-detector/blob/main/src/evaluate.py"
    click Inference "https://github.com/guyfloki/ai-image-detector/blob/main/src/main.py"
    click ModelStorage "https://github.com/guyfloki/ai-image-detector/tree/main/models/"
    click MetricsStorage "https://github.com/guyfloki/ai-image-detector/tree/main/metrics/"
    click Notebook "https://github.com/guyfloki/ai-image-detector/blob/main/ai_image_detector.ipynb"

    %% Styles
    classDef code fill:#cce5ff,stroke:#004085,color:#004085,stroke-width:1px
    classDef storage fill:#ffe5b4,stroke:#b36b00,color:#b36b00,stroke-width:1px
    classDef data fill:#d4edda,stroke:#155724,color:#155724,stroke-width:1px
    classDef cloud fill:#e2e3e5,stroke:#6c757d,color:#6c757d,stroke-width:1px
    classDef notebook fill:#fff3cd,stroke:#856404,color:#856404,stroke-width:1px
```
