# daflh/yolo11-distance-estimation architecture

> Architecture diagram of the GitHub repository daflh/yolo11-distance-estimation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/daflh/yolo11-distance-estimation
- Repository: https://github.com/daflh/yolo11-distance-estimation

## Overview

This repository adapts Ultralytics YOLO11 for monocular distance estimation: detections include class, bounding box, and real-world distance from a single RGB image. The documented workflow prepares KITTI labels, trains the modified model, evaluates detection and distance accuracy, then runs inference or exports for edge deployment. The graph preserves the shared Ultralytics data, model, and engine layers alongside the distance-specific stages. Source excerpts do not show the customized head or training call paths, so those links rely on README statements; unsampled details are not inferred.

Main entry points: [`ultralytics/engine/predictor.py`](https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/engine/predictor.py) (Inference Engine), [`ultralytics/data/dataset.py`](https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/data/dataset.py) (Dataset Loading), [`ultralytics/engine/model.py`](https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/engine/model.py) (YOLO Model API), [`ultralytics/nn/tasks.py`](https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/nn/tasks.py) (YOLO Model Graph)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_distance["Distance Model"]
  node_model_graph["YOLO Model Graph<br/>[tasks.py]"]
  node_distance_head["Distance Head<br/>[head.py]"]
  node_distance_loss["Distance Loss<br/>[loss.py]"]
end

subgraph group_data["KITTI Data"]
  node_labels["KITTI Label Conversion"]
  node_dataset["Dataset Loading<br/>[dataset.py]"]
  node_augment["Image Augmentation<br/>[augment.py]"]
end

subgraph group_runtime["Model Runtime"]
  node_model_api["YOLO Model API<br/>[model.py]"]
  node_trainer["Training Engine<br/>[trainer.py]"]
  node_validator["Validation Engine<br/>[validator.py]"]
  node_predictor["Inference Engine<br/>[predictor.py]"]
  node_backend["Inference Backend<br/>[autobackend.py]"]
  node_results["Prediction Results<br/>[results.py]"]
end

subgraph group_deployment["Evaluation &amp; Deployment"]
  node_distance_metrics["Distance Metrics<br/>[metrics.py]"]
  node_exporter["Model Export<br/>[exporter.py]"]
  node_benchmark["Performance Benchmark<br/>[benchmarks.py]"]
  node_ncnn["NCNN Inference Example"]
end

node_user(("Engineer"))
node_external_camera(("RGB Camera / Images"))

node_user -->|"prepares labels"| node_labels
node_labels -->|"provides labels"| node_dataset
node_user -->|"trains model"| node_model_api
node_dataset -.->|"supplies training data"| node_trainer
node_augment -->|"augments samples"| node_dataset
node_trainer -.->|"trains"| node_model_graph
node_model_graph -->|"includes distance branch"| node_distance_head
node_distance_head -->|"optimizes with WMSE"| node_distance_loss
node_user -->|"evaluates model"| node_validator
node_validator -->|"reports distance errors"| node_distance_metrics
node_user -->|"provides RGB input"| node_external_camera
node_user -->|"runs inference"| node_model_api
node_model_api -.->|"dispatches prediction"| node_predictor
node_predictor -.->|"runs model"| node_backend
node_predictor -.->|"returns predictions"| node_results
node_user -->|"exports model"| node_exporter
node_user -.->|"measures performance"| node_benchmark
node_user -->|"runs edge inference"| node_ncnn

click node_labels "https://github.com/daflh/yolo11-distance-estimation/blob/main/scripts/convert_KITTI_to_YOLOv11_labels.py"
click node_dataset "https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/data/dataset.py"
click node_augment "https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/data/augment.py"
click node_model_api "https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/engine/model.py"
click node_model_graph "https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/nn/tasks.py"
click node_distance_head "https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/nn/modules/head.py"
click node_distance_loss "https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/utils/loss.py"
click node_trainer "https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/engine/trainer.py"
click node_validator "https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/engine/validator.py"
click node_distance_metrics "https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/utils/metrics.py"
click node_predictor "https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/engine/predictor.py"
click node_backend "https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/nn/autobackend.py"
click node_results "https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/engine/results.py"
click node_exporter "https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/engine/exporter.py"
click node_benchmark "https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/utils/benchmarks.py"
click node_ncnn "https://github.com/daflh/yolo11-distance-estimation/blob/main/model_ncnn_infer.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_model_graph,node_distance_head,node_distance_loss toneBlue
class node_labels,node_dataset,node_augment toneAmber
class node_model_api,node_trainer,node_validator,node_predictor,node_backend,node_results toneMint
class node_distance_metrics,node_exporter,node_benchmark,node_ncnn toneRose
class node_user,node_external_camera toneIndigo
```

## Components

### Distance Model

- [YOLO Model Graph](https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/nn/tasks.py): `ultralytics/nn/tasks.py`
- [Distance Head](https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/nn/modules/head.py): `ultralytics/nn/modules/head.py`
- [Distance Loss](https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/utils/loss.py): `ultralytics/utils/loss.py`

### KITTI Data

- [KITTI Label Conversion](https://github.com/daflh/yolo11-distance-estimation/blob/main/scripts/convert_KITTI_to_YOLOv11_labels.py): `scripts/convert_KITTI_to_YOLOv11_labels.py`
- [Dataset Loading](https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/data/dataset.py): `ultralytics/data/dataset.py`
- [Image Augmentation](https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/data/augment.py): `ultralytics/data/augment.py`

### Model Runtime

- [YOLO Model API](https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/engine/model.py): `ultralytics/engine/model.py`
- [Training Engine](https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/engine/trainer.py): `ultralytics/engine/trainer.py`
- [Validation Engine](https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/engine/validator.py): `ultralytics/engine/validator.py`
- [Inference Engine](https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/engine/predictor.py): `ultralytics/engine/predictor.py`
- [Inference Backend](https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/nn/autobackend.py): `ultralytics/nn/autobackend.py`
- [Prediction Results](https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/engine/results.py): `ultralytics/engine/results.py`

### Evaluation & Deployment

- [Distance Metrics](https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/utils/metrics.py): `ultralytics/utils/metrics.py`
- [Model Export](https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/engine/exporter.py): `ultralytics/engine/exporter.py`
- [Performance Benchmark](https://github.com/daflh/yolo11-distance-estimation/blob/main/ultralytics/utils/benchmarks.py): `ultralytics/utils/benchmarks.py`
- [NCNN Inference Example](https://github.com/daflh/yolo11-distance-estimation/blob/main/model_ncnn_infer.py): `model_ncnn_infer.py`

### Other components

- **Engineer**
- **RGB Camera / Images**

## Connections

- Engineer → KITTI Label Conversion: prepares labels
- KITTI Label Conversion → Dataset Loading: provides labels
- Engineer → YOLO Model API: trains model
- Dataset Loading → Training Engine: supplies training data
- Image Augmentation → Dataset Loading: augments samples (evidence: `ultralytics/data/augment.py`)
- Training Engine → YOLO Model Graph: trains
- YOLO Model Graph → Distance Head: includes distance branch
- Distance Head → Distance Loss: optimizes with WMSE
- Engineer → Validation Engine: evaluates model
- Validation Engine → Distance Metrics: reports distance errors (evidence: `ultralytics/utils/metrics.py`)
- Engineer → RGB Camera / Images: provides RGB input
- Engineer → YOLO Model API: runs inference
- YOLO Model API → Inference Engine: dispatches prediction
- Inference Engine → Inference Backend: runs model
- Inference Engine → Prediction Results: returns predictions
- Engineer → Model Export: exports model
- Engineer → Performance Benchmark: measures performance
- Engineer → NCNN Inference Example: runs edge inference
