# zaki1003/yolo-crowd architecture

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

- Interactive diagram: https://gitdiagram.com/zaki1003/yolo-crowd
- Repository: https://github.com/zaki1003/yolo-crowd

## Overview

##### Project type and purpose
- YOLO-CROWD is an open-source, edge-deployable, deep-learning–based crowd counting and face detection tool.
- It extends the one-stage YOLOv5s detector with custom modules (RFE, SEAM), novel losses (NWD, Repulsion) and supports both training and real-time inference on devices (CPU/GPU/TensorRT).

##### File structure
Top‐level directories & files:
- train.py / detect.py / test.py – entry points for training, inference and quick tests
- models/ – PyTorch model definitions, experiment presets, export utilities, hub YAMLs
- utils/ – preprocessing, dataset loaders, loss/metric functions, AWS scripts, GAE deployment files, WandB logging
- data/ – dataset config YAMLs (COCO, VOC, Argoverse), image folders, download scripts
- weights/ – scripts to fetch pretrained/checkpointed weights
- notebooks (.ipynb) – tutorials for training, converting to TensorRT and running inference
- Dockerfile – containerization for reproducible environment
- requirements.txt – Python dependencies

##### README insights
- Describes problem domain, model architecture enhancements (RFE, SEAM), performance metrics, and training/inference workflows.
- Specifies external services: Roboflow dataset, Google Drive/TensorRT engine downloads, WandB for experiment tracking, optional GAE deployment.

##### Main components & their relationships
A. Data Ingestion & Storage
- Raw images/labels (data/images, data/*.yaml)
- Download scripts → automated data acquisition (data/scripts)
B. Training Pipeline
- train.py loads dataset via utils/datasets.py
- Model architecture defined in models/yolo*.py + hubconf.yaml
- Losses from utils/loss.py (NWD, Repulsion) & metrics in utils/metrics.py
- Logging to WandB (utils/wandb_logging)
- Checkpoints written to weights/ & results dir
C. Model Registry & Export
- models/export.py for TorchScript/ONNX/TensorRT conversion
- notebooks (Yolov5_TensortRT_Convert_and_detect.ipynb) demonstrate conversion
D. Inference Pipeline
- Real-time streams: webcam, RTSP, YouTube, files
E. Deployment & Environment
- Dockerfile for containerized inference/training
- Google App Engine scripts (utils/google_app_engine) for cloud hosting
- AWS userdata/mime for EC2 provisioning (utils/aws)

##### Architectural patterns & design principles
- Modular separation of concerns (models vs utils vs data vs scripts)
- Hub pattern: YAML-driven model configurations
- Pluggable loss/metric modules for rapid experimentation
- Clear train/infer split with shared preprocessing

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    subgraph "Data Layer"
        direction TB
        RawImages[(data/images/)]:::datastore
        ArgoYAML[(data/argoverse_hd.yaml)]:::datastore
        CocoYAML[(data/coco.yaml)]:::datastore
        Coco128YAML[(data/coco128.yaml)]:::datastore
        VocYAML[(data/voc.yaml)]:::datastore
        HypFine[(data/hyp.finetune.yaml)]:::datastore
        HypScratch[(data/hyp.scratch.yaml)]:::datastore
        ScriptArgo[data/scripts/get_argoverse_hd.sh]:::service
        ScriptCoco[data/scripts/get_coco.sh]:::service
        ScriptVoc[data/scripts/get_voc.sh]:::service
    end

    %% Training Layer
    subgraph "Training Layer"
        direction TB
        TrainPY["train.py"]:::training
        Datasets["utils/datasets.py"]:::training
        ModelYolo["models/yolo.py"]:::training
        ModelCommon["models/common.py"]:::training
        ModelExp["models/experimental.py"]:::training
        ModelConfig["models/yolo_crowd.yaml"]:::training
        Loss["utils/loss.py"]:::training
        Metrics["utils/metrics.py"]:::training
        LogDataset["utils/wandb_logging/log_dataset.py"]:::training
        WandbUtils["utils/wandb_logging/wandb_utils.py"]:::training
        DownloadWeights["weights/download_weights.sh"]:::service
    end

    %% Export Layer
    subgraph "Export Layer"
        direction TB
        ExportPY["models/export.py"]:::export
        Hubconf["hubconf.py"]:::export
        Anchors["models/hub/anchors.yaml"]:::export
        Yolov3Hub["models/hub/yolov3*.yaml"]:::export
        Yolov5Hub["models/hub/yolov5*.yaml"]:::export
        ConvertNB[Yolov5_TensortRT_Convert_and_detect.ipynb]:::export
    end

    %% Inference Layer
    subgraph "Inference Layer"
        direction TB
        DetectPY["detect.py"]:::inference
        TorchUtils["utils/torch_utils.py"]:::inference
        Plots["utils/plots.py"]:::inference
        TestPY["test.py"]:::inference
    end

    %% Deployment Layer
    subgraph "Deployment Layer"
        direction TB
        Dockerfile["Dockerfile"]:::deployment
        GAEApp["utils/google_app_engine/app.yaml"]:::deployment
        GAEDocker["utils/google_app_engine/Dockerfile"]:::deployment
        GAEReq["utils/google_app_engine/additional_requirements.txt"]:::deployment
        AWSUser["utils/aws/userdata.sh"]:::deployment
        AWSMime["utils/aws/mime.sh"]:::deployment
        AWSResume["utils/aws/resume.py"]:::deployment
        ReqTxt["requirements.txt"]:::deployment
    end

    %% External Services
    WandBCloud([WandB]):::cloud
    AWSCloud([AWS EC2]):::cloud
    GAECloud([Google App Engine]):::cloud

    %% Flows
    RawImages -->|images+labels| Datasets
    ArgoYAML --> Datasets
    CocoYAML --> Datasets
    Coco128YAML --> Datasets
    VocYAML --> Datasets
    HypFine --> TrainPY
    HypScratch --> TrainPY
    ScriptArgo --> RawImages
    ScriptCoco --> RawImages
    ScriptVoc --> RawImages

    Datasets --> TrainPY
    ModelYolo --> TrainPY
    ModelCommon --> TrainPY
    ModelExp --> TrainPY
    ModelConfig --> TrainPY
    Loss --> TrainPY
    Metrics --> TrainPY
    TrainPY -->|checkpoint| DownloadWeights
    DownloadWeights -->|writes| weights

    TrainPY -->|PyTorch checkpoint| ExportPY
    ExportPY --> Hubconf
    Hubconf --> Anchors
    Hubconf --> Yolov3Hub
    Hubconf --> Yolov5Hub
    ExportPY -->|ONNX/TensorRT| DetectPY

    DetectPY --> TorchUtils
    DetectPY --> Plots
    DetectPY --> TestPY

    TrainPY -->|logs| WandBCloud
    LogDataset --> WandBCloud
    WandbUtils --> WandBCloud

    Dockerfile --> DetectPY
    Dockerfile --> TrainPY
    AWSUser --> AWSCloud
    AWSMime --> AWSCloud
    AWSResume --> AWSCloud
    GAEApp --> GAECloud
    GAEDocker --> GAECloud
    GAEReq --> GAECloud
    ReqTxt -->|dependencies| Dockerfile

    %% Click events
    click RawImages "https://github.com/zaki1003/yolo-crowd/tree/main/data/images/"
    click ArgoYAML "https://github.com/zaki1003/yolo-crowd/blob/main/data/argoverse_hd.yaml"
    click CocoYAML "https://github.com/zaki1003/yolo-crowd/blob/main/data/coco.yaml"
    click Coco128YAML "https://github.com/zaki1003/yolo-crowd/blob/main/data/coco128.yaml"
    click VocYAML "https://github.com/zaki1003/yolo-crowd/blob/main/data/voc.yaml"
    click HypFine "https://github.com/zaki1003/yolo-crowd/blob/main/data/hyp.finetune.yaml"
    click HypScratch "https://github.com/zaki1003/yolo-crowd/blob/main/data/hyp.scratch.yaml"
    click ScriptArgo "https://github.com/zaki1003/yolo-crowd/blob/main/data/scripts/get_argoverse_hd.sh"
    click ScriptCoco "https://github.com/zaki1003/yolo-crowd/blob/main/data/scripts/get_coco.sh"
    click ScriptVoc "https://github.com/zaki1003/yolo-crowd/blob/main/data/scripts/get_voc.sh"
    click TrainPY "https://github.com/zaki1003/yolo-crowd/blob/main/train.py"
    click Datasets "https://github.com/zaki1003/yolo-crowd/blob/main/utils/datasets.py"
    click ModelYolo "https://github.com/zaki1003/yolo-crowd/blob/main/models/yolo.py"
    click ModelCommon "https://github.com/zaki1003/yolo-crowd/blob/main/models/common.py"
    click ModelExp "https://github.com/zaki1003/yolo-crowd/blob/main/models/experimental.py"
    click ModelConfig "https://github.com/zaki1003/yolo-crowd/blob/main/models/yolo_crowd.yaml"
    click Loss "https://github.com/zaki1003/yolo-crowd/blob/main/utils/loss.py"
    click Metrics "https://github.com/zaki1003/yolo-crowd/blob/main/utils/metrics.py"
    click LogDataset "https://github.com/zaki1003/yolo-crowd/blob/main/utils/wandb_logging/log_dataset.py"
    click WandbUtils "https://github.com/zaki1003/yolo-crowd/blob/main/utils/wandb_logging/wandb_utils.py"
    click DownloadWeights "https://github.com/zaki1003/yolo-crowd/blob/main/weights/download_weights.sh"
    click ExportPY "https://github.com/zaki1003/yolo-crowd/blob/main/models/export.py"
    click Hubconf "https://github.com/zaki1003/yolo-crowd/blob/main/hubconf.py"
    click Anchors "https://github.com/zaki1003/yolo-crowd/blob/main/models/hub/anchors.yaml"
    click Yolov3Hub "https://github.com/zaki1003/yolo-crowd/blob/main/models/hub/yolov3*.yaml"
    click Yolov5Hub "https://github.com/zaki1003/yolo-crowd/blob/main/models/hub/yolov5*.yaml"
    click DetectPY "https://github.com/zaki1003/yolo-crowd/blob/main/detect.py"
    click TorchUtils "https://github.com/zaki1003/yolo-crowd/blob/main/utils/torch_utils.py"
    click Plots "https://github.com/zaki1003/yolo-crowd/blob/main/utils/plots.py"
    click TestPY "https://github.com/zaki1003/yolo-crowd/blob/main/test.py"
    click Dockerfile "https://github.com/zaki1003/yolo-crowd/tree/main/Dockerfile"
    click GAEApp "https://github.com/zaki1003/yolo-crowd/blob/main/utils/google_app_engine/app.yaml"
    click GAEDocker "https://github.com/zaki1003/yolo-crowd/tree/main/utils/google_app_engine/Dockerfile"
    click GAEReq "https://github.com/zaki1003/yolo-crowd/blob/main/utils/google_app_engine/additional_requirements.txt"
    click AWSUser "https://github.com/zaki1003/yolo-crowd/blob/main/utils/aws/userdata.sh"
    click AWSMime "https://github.com/zaki1003/yolo-crowd/blob/main/utils/aws/mime.sh"
    click AWSResume "https://github.com/zaki1003/yolo-crowd/blob/main/utils/aws/resume.py"
    click ReqTxt "https://github.com/zaki1003/yolo-crowd/blob/main/requirements.txt"

    %% Styles
    classDef datastore fill:#e2f3e4,stroke:#333,stroke-width:1px
    classDef service fill:#cfe8fc,stroke:#333,stroke-width:1px
    classDef training fill:#e3f4fe,stroke:#333,stroke-width:1px
    classDef export fill:#ffe4b5,stroke:#333,stroke-width:1px
    classDef inference fill:#f4e3fe,stroke:#333,stroke-width:1px
    classDef deployment fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef cloud fill:#fff2cc,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
```
