# jnr-10/stereovision_depthestimation-objectdetection architecture

> Architecture diagram of the GitHub repository jnr-10/stereovision_depthestimation-objectdetection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jnr-10/stereovision_depthestimation-objectdetection
- Repository: https://github.com/jnr-10/stereovision_depthestimation-objectdetection

## Overview

1. **Overall shape**
   - This is an **inference/demo repository** for stereo depth estimation, not a single model project.
   - The architecture is centered on a **model selector + demo pipeline** that can run multiple stereo disparity networks and then convert disparity into depth/point-cloud outputs.

2. **Main entry point**
   - `demo.py` is the top-level orchestrator.
   - It reads runtime settings from `config.py`, loads the selected stereo model, processes KITTI left/right images, and drives visualization/output generation.

3. **Configuration boundary**
   - `config.py` is the main control plane for the whole repo.
   - It holds:
     - KITTI image and calibration paths
     - pretrained checkpoint paths
     - device selection (`cuda` vs CPU)
     - feature flags for disparity display, 3D projection, and point-cloud export
     - the active architecture choice from the supported model list
   - This means the repo’s behavior is mostly changed by configuration rather than code changes.

4. **Disparity estimation subsystem**
   - `disparity_estimator/` acts as the **adapter layer** between the demo and the individual model implementations.
   - Each file there is a wrapper for one supported architecture:
     - RAFT-Stereo
     - FastACVNet
     - BGNet
     - GwcNet
     - PAM/PSMNet family
     - CREStereo
     - HITNet
   - This layer likely normalizes different model APIs into a common “estimate disparity for a stereo pair” interface.

5. **Model zoo organization**
   - `networks/` contains the **actual upstream model implementations**, separated by architecture.
   - Each subdirectory is largely self-contained and mirrors the internal structure of that model family:
     - `models/`, `core/`, or `nets/`
     - attention/correlation/update/extractor modules where relevant
     - model-specific utilities, losses, metrics, and preprocessing
   - Architecturally, this is a vendorized model library rather than a shared framework.

6. **Primary data flow**
   - The core runtime flow is:
     - read stereo image pair
     - run chosen disparity network
     - produce disparity map
     - use calibration files to convert disparity into depth
     - optionally overlay object detection results and/or generate 3D point cloud
   - The README explicitly notes that **depth estimation depends on the stereo disparity map**.

7. **Object detection integration**
   - `object_detector.py` is a separate subsystem that likely loads YOLO weights for 2D object detection.
   - In the demo, detection is combined with depth estimation so bounding boxes can be annotated with distance information.
   - This is a parallel consumer of the input frames, not part of the stereo network itself.

8. **3D output / visualization**
   - The repo supports two notable outputs:
     - a **disparity visualization video**
     - a **point-cloud / 3D projection output**
   - `assets/demo_output.mp4` and `assets/point_cloud.mp4` show the intended output style.
   - The 3D projection depends on the KITTI calibration files and the computed depth values.

9. **Model-specific implementation boundaries**
   - Each architecture package contains its own internal dependencies:
     - RAFT-Stereo: correlation, extractor, update, dataset utilities
     - CREStereo: attention, transformer, corr, update
     - HITNet: tile warping/update and feature extraction
     - BGNet / FastACVNet / PSMNet / GwcNet / PASMNet: custom submodules and losses
   - These packages are not meant to be mixed; the estimator wrapper is the boundary that isolates them.

10. **Runtime and dependencies**
   - The project is Python-based and appears to run on **PyTorch** with GPU support as the intended path.
   - `environment.yml`, `requirements.txt`, and the setup scripts indicate a reproducible local environment workflow.
   - This is important architecturally because model selection and inference speed are tied to CUDA-enabled execution.

11. **External assets and checkpoints**
   - The repo does not bundle model weights; pretrained checkpoints must be downloaded separately and referenced from `config.py`.
   - It also depends on a downloadable **YOLO object detector** and the **KITTI stereo dataset** plus calibration files.
   - So the repo is a thin runtime over external assets rather than a self-contained training package.

12. **Utility and packaging layer**
   - `utils.py` and the model-specific `utils/` folders provide supporting functions such as preprocessing, metrics, visualization, file I/O, and persistence.
   - `scripts/` contains environment/bootstrap helpers and a demo test script, which suggests the expected workflow is: prepare environment, download weights, set config, run demo.

13. **What an architecture diagram should show**
   - A good diagram would show:
     - **Input layer:** KITTI stereo images + calibration
     - **Control layer:** `config.py` selecting one of several disparity engines
     - **Inference layer:** `disparity_estimator/` dispatching into one of the `networks/*` model stacks
     - **Post-processing layer:** disparity-to-depth conversion, object detection, 3D projection/point cloud generation
     - **Outputs:** disparity video, annotated demo video, point cloud visualization
   - The key architectural idea is a **single demo pipeline fronting a pluggable multi-model stereo backend**.

Main entry points: [`demo.py`](https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/demo.py) (Demo runner), [`config.py`](https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/config.py) (Config), [`disparity_estimator/raftstereo_disparity_estimator.py`](https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/disparity_estimator/raftstereo_disparity_estimator.py) (RAFT-Stereo adapter), [`disparity_estimator/fastacv_disparity_estimator.py`](https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/disparity_estimator/fastacv_disparity_estimator.py) (FastACV adapter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Control"]
  node_demo["Demo runner<br/>orchestrator<br/>[demo.py]"]
  node_config["Config<br/>[config.py]"]
end

subgraph group_adapters["Disparity adapters"]
  node_raft_wrap["RAFT-Stereo adapter<br/>disparity adapter"]
  node_fastacv_wrap["FastACV adapter<br/>disparity adapter"]
  node_bgnet_wrap["BGNet adapter<br/>disparity adapter"]
  node_gwc_wrap["GwcNet adapter<br/>disparity adapter"]
  node_psm_wrap["PSM/PASM adapter<br/>disparity adapter"]
  node_pasm_wrap["PASM adapter<br/>disparity adapter"]
  node_crestereo_wrap["CREStereo adapter<br/>disparity adapter"]
  node_hitnet_wrap["HITNet adapter<br/>disparity adapter"]
end

subgraph group_models["Model zoo"]
  node_raft_core["RAFT core<br/>stereo network<br/>[raft_stereo.py]"]
  node_fastacv_model["FastACVNet<br/>stereo network<br/>[Fast_ACV.py]"]
  node_bgnet_model["BGNet<br/>stereo network<br/>[bgnet.py]"]
  node_gwc_model["GwcNet<br/>stereo network<br/>[gwcnet.py]"]
  node_psm_model["PSMNet<br/>stereo network<br/>[stackhourglass.py]"]
  node_pasm_model["PASMNet<br/>stereo network<br/>[PASMnet.py]"]
  node_crestereo_model["CREStereo<br/>stereo network<br/>[crestereo.py]"]
  node_hitnet_model["HITNet<br/>stereo network<br/>[HITNet.py]"]
end

subgraph group_post["Post-processing"]
  node_detector["Object detector<br/>yolo wrapper<br/>[object_detector.py]"]
  node_utils["Shared utils<br/>helpers<br/>[utils.py]"]
end

node_config -->|"runtime settings"| node_demo
node_demo -->|"selects"| node_raft_wrap
node_demo -->|"selects"| node_fastacv_wrap
node_demo -->|"selects"| node_bgnet_wrap
node_demo -->|"selects"| node_gwc_wrap
node_demo -->|"selects"| node_psm_wrap
node_demo -->|"selects"| node_pasm_wrap
node_demo -->|"selects"| node_crestereo_wrap
node_demo -->|"selects"| node_hitnet_wrap
node_demo -->|"runs"| node_detector
node_demo -->|"uses"| node_utils
node_raft_wrap -->|"adapts"| node_raft_core
node_fastacv_wrap -->|"adapts"| node_fastacv_model
node_bgnet_wrap -->|"adapts"| node_bgnet_model
node_gwc_wrap -->|"adapts"| node_gwc_model
node_psm_wrap -->|"adapts"| node_psm_model
node_pasm_wrap -->|"adapts"| node_pasm_model
node_crestereo_wrap -->|"adapts"| node_crestereo_model
node_hitnet_wrap -->|"adapts"| node_hitnet_model
node_demo -->|"controls"| node_config
node_demo -->|"outputs"| node_utils

click node_demo "https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/demo.py"
click node_config "https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/config.py"
click node_detector "https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/object_detector.py"
click node_utils "https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/utils.py"
click node_raft_wrap "https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/disparity_estimator/raftstereo_disparity_estimator.py"
click node_fastacv_wrap "https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/disparity_estimator/fastacv_disparity_estimator.py"
click node_bgnet_wrap "https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/disparity_estimator/bgnet_disparity_estimator.py"
click node_gwc_wrap "https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/disparity_estimator/gwcnet_disparity_estimator.py"
click node_psm_wrap "https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/disparity_estimator/psmnet_disparity_estimator.py"
click node_pasm_wrap "https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/disparity_estimator/pasmnet_disparity_estimator.py"
click node_crestereo_wrap "https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/disparity_estimator/crestereo_disparity_estimator.py"
click node_hitnet_wrap "https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/disparity_estimator/hitnet_disparity_estimator.py"
click node_raft_core "https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/networks/RAFTStereo/core/raft_stereo.py"
click node_fastacv_model "https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/networks/FastACVNet/models/Fast_ACV.py"
click node_bgnet_model "https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/networks/BGNet/models/bgnet.py"
click node_gwc_model "https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/networks/GwcNet/models/gwcnet.py"
click node_psm_model "https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/networks/PSMNet/models/stackhourglass.py"
click node_pasm_model "https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/networks/PASMNet/models/PASMnet.py"
click node_crestereo_model "https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/networks/CREStereo/nets/crestereo.py"
click node_hitnet_model "https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/networks/HitNet/models/HITNet.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_demo,node_config toneBlue
class node_raft_wrap,node_fastacv_wrap,node_bgnet_wrap,node_gwc_wrap,node_psm_wrap,node_pasm_wrap,node_crestereo_wrap,node_hitnet_wrap toneAmber
class node_raft_core,node_fastacv_model,node_bgnet_model,node_gwc_model,node_psm_model,node_pasm_model,node_crestereo_model,node_hitnet_model toneMint
class node_detector,node_utils toneRose
```

## Components

### Control

Runtime configuration and orchestration

- [Demo runner](https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/demo.py): orchestrator · Top-level pipeline that loads inputs, selects a model, and drives inference/output generation · `demo.py`
- [Config](https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/config.py): runtime config · Central control plane for paths, device choice, model selection, and feature flags · `config.py`

### Disparity adapters

Thin wrappers that normalize model-specific stereo inference

- [RAFT-Stereo adapter](https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/disparity_estimator/raftstereo_disparity_estimator.py): disparity adapter · Adapter entry for the RAFT-Stereo backend · `disparity_estimator/raftstereo_disparity_estimator.py`
- [FastACV adapter](https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/disparity_estimator/fastacv_disparity_estimator.py): disparity adapter · Adapter entry for the FastACVNet backend · `disparity_estimator/fastacv_disparity_estimator.py`
- [BGNet adapter](https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/disparity_estimator/bgnet_disparity_estimator.py): disparity adapter · Adapter entry for the BGNet backend · `disparity_estimator/bgnet_disparity_estimator.py`
- [GwcNet adapter](https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/disparity_estimator/gwcnet_disparity_estimator.py): disparity adapter · Adapter entry for the GwcNet backend · `disparity_estimator/gwcnet_disparity_estimator.py`
- [PSM/PASM adapter](https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/disparity_estimator/psmnet_disparity_estimator.py): disparity adapter · Adapter entry for the PSMNet and PASMNet backends · `disparity_estimator/psmnet_disparity_estimator.py`
- [PASM adapter](https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/disparity_estimator/pasmnet_disparity_estimator.py): disparity adapter · Adapter entry for the PASMNet backend · `disparity_estimator/pasmnet_disparity_estimator.py`
- [CREStereo adapter](https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/disparity_estimator/crestereo_disparity_estimator.py): disparity adapter · Adapter entry for the CREStereo backend · `disparity_estimator/crestereo_disparity_estimator.py`
- [HITNet adapter](https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/disparity_estimator/hitnet_disparity_estimator.py): disparity adapter · Adapter entry for the HITNet backend · `disparity_estimator/hitnet_disparity_estimator.py`

### Model zoo

Vendorized stereo network implementations

- [RAFT core](https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/networks/RAFTStereo/core/raft_stereo.py): stereo network · Correlation, feature extraction, and iterative update core for RAFT-Stereo · `networks/RAFTStereo/core/raft_stereo.py`
- [FastACVNet](https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/networks/FastACVNet/models/Fast_ACV.py): stereo network · Fast ACVNet model stack for disparity prediction · `networks/FastACVNet/models/Fast_ACV.py`
- [BGNet](https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/networks/BGNet/models/bgnet.py): stereo network · BGNet model family with feature extraction and 2D/3D submodules · `networks/BGNet/models/bgnet.py`
- [GwcNet](https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/networks/GwcNet/models/gwcnet.py): stereo network · Group-wise correlation stereo network · `networks/GwcNet/models/gwcnet.py`
- [PSMNet](https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/networks/PSMNet/models/stackhourglass.py): stereo network · PSMNet stack-hourglass stereo model · `networks/PSMNet/models/stackhourglass.py`
- [PASMNet](https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/networks/PASMNet/models/PASMnet.py): stereo network · PASMNet model implementation and modules · `networks/PASMNet/models/PASMnet.py`
- [CREStereo](https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/networks/CREStereo/nets/crestereo.py): stereo network · CREStereo network with attention, correlation, and update blocks · `networks/CREStereo/nets/crestereo.py`
- [HITNet](https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/networks/HitNet/models/HITNet.py): stereo network · HITNet stereo network with tile warping and tile updates · `networks/HitNet/models/HITNet.py`

### Post-processing

Detection, depth conversion, and visualization outputs

- [Object detector](https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/object_detector.py): yolo wrapper · Separate 2D detection subsystem used to annotate frames with distance-aware boxes · `object_detector.py`
- [Shared utils](https://github.com/jnr-10/stereovision_depthestimation-objectdetection/blob/main/utils.py): helpers · Cross-cutting helpers for preprocessing, I/O, and visualization support · `utils.py`

## Connections

- Config → Demo runner: runtime settings · Demo reads model choice, paths, device, and output flags from configuration
- Demo runner → RAFT-Stereo adapter: selects · Demo dispatches to the chosen disparity adapter
- Demo runner → FastACV adapter: selects · Demo dispatches to the chosen disparity adapter
- Demo runner → BGNet adapter: selects · Demo dispatches to the chosen disparity adapter
- Demo runner → GwcNet adapter: selects · Demo dispatches to the chosen disparity adapter
- Demo runner → PSM/PASM adapter: selects · Demo dispatches to the chosen disparity adapter
- Demo runner → PASM adapter: selects · Demo dispatches to the chosen disparity adapter
- Demo runner → CREStereo adapter: selects · Demo dispatches to the chosen disparity adapter
- Demo runner → HITNet adapter: selects · Demo dispatches to the chosen disparity adapter
- Demo runner → Object detector: runs · Object detection is applied alongside stereo inference for annotated demo output
- Demo runner → Shared utils: uses · Shared helpers support I/O, preprocessing, and visualization
- RAFT-Stereo adapter → RAFT core: adapts · Wrapper normalizes the RAFT-Stereo backend into the demo interface
- FastACV adapter → FastACVNet: adapts · Wrapper normalizes the FastACVNet backend into the demo interface
- BGNet adapter → BGNet: adapts · Wrapper normalizes the BGNet backend into the demo interface
- GwcNet adapter → GwcNet: adapts · Wrapper normalizes the GwcNet backend into the demo interface
- PSM/PASM adapter → PSMNet: adapts · Wrapper normalizes the PSMNet backend into the demo interface
- PASM adapter → PASMNet: adapts · Wrapper normalizes the PASMNet backend into the demo interface
- CREStereo adapter → CREStereo: adapts · Wrapper normalizes the CREStereo backend into the demo interface
- HITNet adapter → HITNet: adapts · Wrapper normalizes the HITNet backend into the demo interface
- Demo runner → Config: controls · Selected architecture and feature flags determine the runtime path
- Demo runner → Shared utils: outputs · Shared utilities help produce disparity video, depth overlay, and point-cloud artifacts
