# qunmasj-vision-studio/construction-dataset232 architecture

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

- Interactive diagram: https://gitdiagram.com/qunmasj-vision-studio/construction-dataset232
- Repository: https://github.com/qunmasj-vision-studio/construction-dataset232

## Overview

##### Project type and purpose
- This is a Python-based **object-detection system** built around an improved YOLOv11 model, specialized for detecting 39 classes of construction-site objects (concrete mixers, cranes, personnel, pipelines, etc.).
- It provides three core scripts—`train.py` (training, mentioned in the README), `val.py` (validation/metrics), and `predict.py` (inference)—plus a UI front end (`ui.py`) to load models, adjust thresholds, and run detection on images, video or live camera.

##### File structure
- Top-level files:
– README.md / README.docx for project background, data and usage.
– `predict.py`: inference component (inherits `BasePredictor`).
– `val.py`: validation component (inherits `BaseValidator`).
– `ui.py`: web/desktop UI to wrap predictor, accept user inputs (confidence, IOU, weight file), display/save results.
- Training (`train.py`) is described in README but not shown; treat it as a sibling script that outputs model weights (`best.pt`).
- Key external dependencies: PyTorch, ultralytics, OpenCV (for video/camera), a web framework or GUI toolkit in `ui.py`.

##### Extract architecture insights from README
- Modular design following separation of concerns:
– **Data layer** (datasets of images annotated in YOLOv8 format)
– **Training layer** (`train.py`, uses ultralytics engine, various custom blocks like C3k2, C2PSA, RepViT, attention modules)
– **Validation layer** (`val.py`) computing mAP, confusion matrix
– **Presentation layer** (`ui.py`) exposing a UI that loads weights, sets thresholds, visualizes and exports results.
- Architectural patterns:
– **Pipeline pattern** for training/validation/inference (preprocess → model → postprocess → results).
– **Component modularity**: each script encapsulates one responsibility.
– **Layered separation** between core ML code (ultralytics/PyTorch) and UI code.

##### Main components & relationships
a. Components:
1) **Dataset Storage**: raw images + annotations
2) **Training Engine** (`train.py`, ultralytics) → produces `best.pt`
3) **Validator** (`val.py`) → consumes model & val data → outputs metrics
4) **Predictor** (`predict.py`) → consumes model & data → outputs detection results
5) **UI Layer** (`ui.py`) → wraps predictor → user interactions (thresholds, weight loading, export)
6) **Model Files**: `.pt` weight files
7) **External Libraries**: PyTorch, ultralytics, OpenCV, GUI/web framework

b. Interactions:
- **Training**: Dataset → `train.py` → YOLOv11 submodules → Weights
- **Validation**: Weights + Validation split → `val.py` → Metrics, Confusion Matrix
- **Inference**: Weights + Input (image/video/camera) → `predict.py` → Raw detections → post-NMS → Results

##### Architectural patterns and design principles
- **Single Responsibility**: each script handles one stage of the ML lifecycle.
- **Pipeline Stages**: clear preprocess → forward → postprocess → metrics/results.
- **Extensibility**: new YOLO blocks (C3k2, PSA, RepViT, attention) are encapsulated in custom modules, easily pluggable.
- **Layered UI**: separates ML logic from presentation, enabling swapping of UI (CLI, web, desktop).

##### Technologies and frameworks
- Core ML: PyTorch, ultralytics engine (BasePredictor, BaseValidator, Ops, Results)
- Data I/O: OpenCV/video, standard Python file I/O, Excel exporter
- UI: likely Flask, FastAPI or a GUI toolkit (Tkinter, PyQt) in `ui.py`
- Annotation Format: YOLOv8 text files, COCO style conversions

##### Suggested component breakdown
- Data Layer:
– “Dataset (YOLOv8 annotations + Images)”
- ML Core Layer:
– “Training Engine (train.py + custom blocks)”
- Inside: C3k2, C2PSA, RepViTBlock, attention modules
– “Validation (val.py → DetMetrics, ConfusionMatrix)”
– “Inference (predict.py → NMS, Results)”
- UI Layer:
– “UI (ui.py)”
- Load weights (.pt)
- Set conf & IOU thresholds
- Input sources: Camera / Image / Video
- Output views: BBox overlay, Export Excel
- External:
– “Frameworks” cluster (PyTorch, ultralytics, OpenCV, Web/GUI)

## Diagram (Mermaid)

```mermaid
flowchart TD
    Docs["Documentation<br/>(README.md, README.docx)"]:::doc
    click Docs "https://github.com/qunmasj-vision-studio/construction-dataset232/blob/main/README.md"
    click Docs "https://github.com/qunmasj-vision-studio/construction-dataset232/blob/main/README.docx"

    subgraph "Data Layer"
        DS["Dataset<br/>(YOLOv8 annotations + Images)"]:::data
    end

    subgraph "ML Core Layer"
        subgraph "Training Engine<br/>(train.py + custom blocks)" 
            TB1["C3k2"]:::mlsub
            TB2["C2PSA"]:::mlsub
            TB3["RepViTBlock"]:::mlsub
            TB4["AttentionModules"]:::mlsub
        end
        Val["Validation<br/>(val.py)"]:::ml
        Predict["Inference<br/>(predict.py)"]:::ml
    end
    click Val "https://github.com/qunmasj-vision-studio/construction-dataset232/blob/main/val.py"
    click Predict "https://github.com/qunmasj-vision-studio/construction-dataset232/blob/main/predict.py"

    Metrics["Metrics<br/>(mAP, ConfusionMatrix)"]:::data
    RawDet["Raw Detections<br/>(boxes, scores)"]:::data
    Results["Results"]:::data

    subgraph "UI Layer"
        UI["UI<br/>(ui.py)"]:::ui
    end
    click UI "https://github.com/qunmasj-vision-studio/construction-dataset232/blob/main/ui.py"

    InputSrc["Input Source<br/>(Image/Video/Camera)"]:::data
    Excel["Excel File<br/>(Export)"]:::data

    subgraph "External Frameworks"
        Torch["PyTorch"]:::ext
        Ultra["ultralytics"]:::ext
        CV["OpenCV"]:::ext
        GUI["Web/GUI Framework"]:::ext
    end

    %% Data flow
    Docs --> DS
    Docs --> TB1
    Docs --> UI

    DS -->|"images + labels"| TB1
    TB1 -->|"best.pt weights"| Val
    TB1 -->|"best.pt weights"| Predict

    Val -->|"metrics output"| Metrics
    Predict -->|"raw output"| RawDet
    RawDet -->|"post-NMS"| Results

    InputSrc --> UI
    UI -->|"calls Predictor"| Predict
    UI -->|"load weights"| TB1
    Results --> UI
    UI -->|"export"| Excel

    %% External dependencies
    Torch --> TB1
    Ultra --> TB1
    Torch --> Val
    Ultra --> Val
    Torch --> Predict
    Ultra --> Predict
    CV --> Predict
    CV --> UI
    GUI --> UI

    %% Styles
    classDef data fill:#BBDEFB,stroke:#0D47A1,color:#0D47A1;
    classDef ml fill:#C8E6C9,stroke:#1B5E20,color:#1B5E20;
    classDef mlsub fill:#E8F5E9,stroke:#2E7D32,color:#2E7D32;
    classDef ui fill:#FFF9C4,stroke:#F57F17,color:#F57F17;
    classDef ext fill:#ECEFF1,stroke:#37474F,color:#37474F;
    classDef doc fill:#F5F5F5,stroke:#9E9E9E,color:#616161;
```
