# 5hatim5/yolov5-vehicles-type-detection-and-counting architecture

> Architecture diagram of the GitHub repository 5hatim5/yolov5-vehicles-type-detection-and-counting, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/5hatim5/yolov5-vehicles-type-detection-and-counting
- Repository: https://github.com/5hatim5/yolov5-vehicles-type-detection-and-counting

## Overview

##### Project type and purpose
- This is a full-stack computer-vision application for “Vehicles Type Detection and Counting.”

##### File structure
- Top-level:
- CONFIG.py – central configuration for source, ROI, thresholds, output paths
- run.py – entry point for the Flask web server
- inference_tracking.py & inference_RIO_Line.py – two CLI scripts implementing the two counting methods
- requirements.txt, weights/ – environment and model artifacts
- app/ (Flask MVC):
- app/views.py & app/templates/index.html – controller and view for the web UI
- app/static/temp – temporary storage for generated images/videos
- app/utils/utils.py – helper functions for the web layer
- deep_sort/ – implementation of the Deep SORT tracker (Kalman filter, assignment, feature extractor, etc.)
- models/ – YOLOv5 model definitions (common, experimental, hub), TF wrapper, YAML configs
- utils/ – utility functions powering YOLO preprocessing, loss, metrics, plotting, data loading, etc.

##### README for additional insights
- Confirms two inference modes: ROI-line and object tracking
- Emphasizes outputs: annotated video/images + per-class counts in CSV
- Lists configuration parameters in CONFIG.py (ROI area, line offset, NMS thresholds, image size, model weights path, etc.)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Entry Points
    subgraph "Frontends"
        CLI_ROI["ROI-Line CLI"]:::frontend
        CLI_Tracking["DeepSort CLI"]:::frontend
        Web_Server["Flask Server"]:::frontend
    end

    %% Web UI Components
    subgraph "Web UI"
        Controller["Flask Controller"]:::frontend
        Template["HTML Template"]:::frontend
        Helpers["Utility Helpers"]:::util
        Static_Temp["Temp Storage"]:::storage
    end

    %% Core Pipeline
    subgraph "Core Pipeline"
        Config["CONFIG.py"]:::config
        Source["Video/Image Source"]:::core
        Detector["YOLOv5 Detector"]:::model
        PrePost["Pre/Post-Processing"]:::util
        Tracker["Deep SORT Tracker"]:::model
        Counter["Counting Logic"]:::core
        Exporter["Exporter (CSV/Annotated)"]:::core
    end

    %% Model Artifacts
    subgraph "Artifacts"
        Weights["Model Weights"]:::model
        ModelDefs["Model Definitions & Configs"]:::model
    end

    %% File System Output
    FileSystem["Output Folder (CSV, Videos)"]:::storage

    %% Browser Display
    Browser["Browser View"]:::frontend

    %% Relationships
    CLI_ROI -->|reads params| Config
    CLI_Tracking -->|reads params| Config
    Web_Server -->|reads params| Config

    CLI_ROI -->|initiates frames| Source
    CLI_Tracking -->|initiates frames| Source
    Controller -->|launches pipeline| Config
    Controller -->|launches pipeline| Source
    Controller -->|uses helpers| Helpers
    Controller -->|renders view| Template
    Controller -->|serves static| Static_Temp
    Controller -->|responds to| Browser

    Source -->|frames| PrePost
    PrePost -->|processed frames| Detector
    ModelDefs --> Detector
    Weights --> Detector

    Detector -->|bboxes & classes| Tracker
    Tracker -->|track IDs| Counter
    Config --> Tracker
    Counter -->|counts & annotated frames| Exporter

    Exporter -->|writes| FileSystem
    Exporter -->|writes| Static_Temp
    Static_Temp -->|serves| Browser
    FileSystem -->|archive| Browser

    %% Click Events
    click CLI_ROI "https://github.com/5hatim5/yolov5-vehicles-type-detection-and-counting/blob/main/inference_RIO_Line.py"
    click CLI_Tracking "https://github.com/5hatim5/yolov5-vehicles-type-detection-and-counting/blob/main/inference_tracking.py"
    click Web_Server "https://github.com/5hatim5/yolov5-vehicles-type-detection-and-counting/blob/main/run.py"
    click Controller "https://github.com/5hatim5/yolov5-vehicles-type-detection-and-counting/blob/main/app/views.py"
    click Template "https://github.com/5hatim5/yolov5-vehicles-type-detection-and-counting/blob/main/app/templates/index.html"
    click Helpers "https://github.com/5hatim5/yolov5-vehicles-type-detection-and-counting/blob/main/app/utils/utils.py"
    click Static_Temp "https://github.com/5hatim5/yolov5-vehicles-type-detection-and-counting/tree/main/app/static/temp"
    click Config "https://github.com/5hatim5/yolov5-vehicles-type-detection-and-counting/blob/main/CONFIG.py"
    click ModelDefs "https://github.com/5hatim5/yolov5-vehicles-type-detection-and-counting/tree/main/models/"
    click PrePost "https://github.com/5hatim5/yolov5-vehicles-type-detection-and-counting/tree/main/utils/"
    click Tracker "https://github.com/5hatim5/yolov5-vehicles-type-detection-and-counting/tree/main/deep_sort/"
    click Weights "https://github.com/5hatim5/yolov5-vehicles-type-detection-and-counting/tree/main/weights/"

    %% Styles
    classDef frontend fill:#8DD3C7,stroke:#333,stroke-width:1px
    classDef core fill:#BEBADA,stroke:#333,stroke-width:1px
    classDef model fill:#FB8072,stroke:#333,stroke-width:1px
    classDef util fill:#80B1D3,stroke:#333,stroke-width:1px
    classDef config fill:#FDB462,stroke:#333,stroke-width:1px
    classDef storage fill:#B3DE69,stroke:#333,stroke-width:1px
```
