# experiencor/keras-yolo2 architecture

> Architecture diagram of the GitHub repository experiencor/keras-yolo2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/experiencor/keras-yolo2
- Repository: https://github.com/experiencor/keras-yolo2

## Overview

##### Project type and purpose
- This is a stand-alone Python-based deep learning library and demo suite implementing YOLOv2 (object detection) in Keras with a TensorFlow backend.
- It provides end-to-end pipelines for:
- Data preparation (VOC/COCO style annotations)
- Anchor generation
- Model construction (various backbones and YOLO heads)
- Training (train.py)
- Inference/prediction (predict.py)
- Jupyter notebooks for step-by-step walkthroughs and demos

##### File structure
- Top-level scripts:
- train.py: orchestrates reading config → data loader → model → training loop → save weights
- gen_anchors.py: reads dataset statistics → k-means anchors → prints results
- backend.py / frontend.py: define the network components
- preprocessing.py: image and annotation loading, augmentation (utils.py)
- config.json: central configuration for model hyperparams, file paths, anchors, labels
- requirements.txt: dependencies (keras, tensorflow, imgaug, etc.)
- Examples & notebooks illustrate usage; experimental folder holds side scripts (yolo3_detect.py).
- There is no separate “frontend/backend” in the web sense—rather “frontend.py” defines the YOLO prediction head, “backend.py” builds the feature extractor (MobileNet, ResNet, etc.)

##### README for additional insights
- README outlines:
- Supported backbones (MobileNet, Inception3, SqueezeNet, etc.)
- Detailed config schema
- Workflow for data prep → config editing → anchors → training → prediction
- Dependency on external pretrained weights (hosted on Google Drive)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Data Layer
    subgraph "Data Layer"
        DataDir["Image Dataset (images/)"]:::data
        Preproc["Preprocessing Module"]:::data
    end

    %% Model Construction
    subgraph "Model Construction"
        Backend["Backbone Factory"]:::model
        Frontend["YOLO Head"]:::model
    end

    %% Core Library
    subgraph "Core Library"
        Config["Configuration Manager"]:::orchestration
        Utils["Utilities (helpers, losses, IO)"]:::model
    end

    %% Scripts
    subgraph "Scripts"
        AnchorGen["Anchor Generator"]:::orchestration
        Train["Training Engine"]:::orchestration
        Predict["Inference Engine"]:::orchestration
        ExpScript["Experimental Script"]:::orchestration
    end

    %% Demos
    subgraph "Demos"
        DemoNotebook1["Yolo Step-by-Step.ipynb"]:::demo
        DemoNotebook2["Blood Cell Detection.ipynb"]:::demo
    end

    %% External Dependencies
    subgraph "External Dependencies"
        Requirements["requirements.txt"]:::external
        TF["Keras/TensorFlow/imgaug"]:::external
        RemoteDrive["Pretrained Weights (Google Drive)"]:::external
        SavedWeights["Saved Weights (best_weights.h5)"]:::external
    end

    %% Connections: Config to all modules
    Config --> AnchorGen
    Config --> Backend
    Config --> Frontend
    Config --> Train
    Config --> Predict

    %% Data pipeline
    DataDir --> Preproc
    Preproc --> Train

    %% Anchor generation
    AnchorGen --> Train

    %% Model construction to scripts
    Backend --> Train
    Frontend --> Train
    Utils --> Train

    %% Training to weights
    Train --> SavedWeights
    SavedWeights --> Predict

    %% Inference pipeline
    Preproc --> Predict
    Backend --> Predict
    Frontend --> Predict
    Utils --> Predict

    %% Experimental script dependencies
    ExpScript --> Backend
    ExpScript --> Frontend

    %% Demos dependencies
    DemoNotebook1 --> Preproc
    DemoNotebook1 --> Backend
    DemoNotebook1 --> Frontend
    DemoNotebook2 --> Preproc
    DemoNotebook2 --> Backend
    DemoNotebook2 --> Frontend

    %% External dependencies usage
    Requirements --> Preproc
    Requirements --> Backend
    Requirements --> Frontend
    Requirements --> Train
    Requirements --> Predict

    RemoteDrive --> Train
    RemoteDrive --> Predict
    TF --> Preproc
    TF --> Backend
    TF --> Frontend
    TF --> Train
    TF --> Predict

    %% Click Events
    click Config "https://github.com/experiencor/keras-yolo2/blob/master/config.json"
    click DataDir "https://github.com/experiencor/keras-yolo2/tree/master/images/"
    click Preproc "https://github.com/experiencor/keras-yolo2/blob/master/preprocessing.py"
    click AnchorGen "https://github.com/experiencor/keras-yolo2/blob/master/gen_anchors.py"
    click Backend "https://github.com/experiencor/keras-yolo2/blob/master/backend.py"
    click Frontend "https://github.com/experiencor/keras-yolo2/blob/master/frontend.py"
    click Train "https://github.com/experiencor/keras-yolo2/blob/master/train.py"
    click Predict "https://github.com/experiencor/keras-yolo2/blob/master/predict.py"
    click Utils "https://github.com/experiencor/keras-yolo2/blob/master/utils.py"
    click DemoNotebook1 "https://github.com/experiencor/keras-yolo2/blob/master/Yolo Step-by-Step.ipynb"
    click DemoNotebook2 "https://github.com/experiencor/keras-yolo2/blob/master/examples/Blood Cell Detection.ipynb"
    click ExpScript "https://github.com/experiencor/keras-yolo2/blob/master/experimental/yolo3_detect.py"
    click Requirements "https://github.com/experiencor/keras-yolo2/blob/master/requirements.txt"

    %% Styles
    classDef data fill:#bbdefb,stroke:#1e88e5;
    classDef model fill:#c8e6c9,stroke:#43a047;
    classDef orchestration fill:#ffe0b2,stroke:#fb8c00;
    classDef external fill:#eeeeee,stroke:#9e9e9e;
    classDef demo fill:#f3e5f5,stroke:#8e24aa;
```
