# xmlyqing00/v-floodnet architecture

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

- Interactive diagram: https://gitdiagram.com/xmlyqing00/v-floodnet
- Repository: https://github.com/xmlyqing00/v-floodnet

## Overview

1. **Repository purpose**
   V-FloodNet is a research pipeline for urban flood analysis. It combines:
   - water segmentation from images or videos,
   - reference-object detection/segmentation/tracking,
   - and water level/depth estimation from the segmented scene.

2. **Top-level flow**
   The main data path is:
   input images or video frames → water segmentation → reference object localization → geometric depth/level estimation → optional comparison/visualization of results.
   Video support adds temporal feature aggregation so the system can use information across frames instead of processing each frame independently.

3. **Primary entry points**
   The repository is organized around a few CLI scripts:
   - `test_image_seg.py` for image segmentation inference
   - `test_video_seg.py` for video segmentation inference
   - `est_waterlevel.py` for water-level/depth estimation
   - `train_image_seg.py` and `train_video_seg.py` for retraining the two segmentation subsystems
   These are the main boundaries an architecture diagram should show as separate execution paths.

4. **Image segmentation subsystem**
   The `image_module/` package contains the dataset and transform logic for single-image water segmentation. It is the simplest inference branch and is used when inputs are still images or extracted video frames. This module is supported by `estimation/` and the shared utilities, but is otherwise independent from the temporal model.

5. **Video segmentation subsystem**
   The `video_module/` package implements the temporal model used for videos. Its structure suggests:
   - a dataset loader under `video_module/dataset/`
   - a segmentation model under `video_module/model/`
   - a feature-bank mechanism (`FeatureBank.py`) for storing and reusing frame features
   - an AFB-URR model (`AFB_URR.py`) for adaptive video segmentation
   This subsystem is the core difference from the image-only path: it exploits temporal context and memory across frames.

6. **Reference object detection and tracking**
   The `estimation/` package handles non-water objects used as scale references. It includes:
   - `object_detection.py`
   - `reference_tracking.py`
   - Detectron2 configuration files for keypoint and instance segmentation models
   The README indicates three reference modes: people, stop sign, and generic reference object. This is the component that turns segmentation output into a measurable physical water depth.

7. **MeshTransformer integration**
   The `MeshTransformer/` submodule is an external dependency used for human detection and 3D mesh alignment when the reference object is a person. This is a distinct subsystem with its own model weights and setup requirements, and it plugs into the estimation branch rather than the segmentation branch.

8. **Shared utilities**
   `myutils/` contains cross-cutting helpers:
   - data handling
   - depth plotting
   - system/runtime helpers
   These utilities are not a standalone subsystem, but they support both inference and evaluation workflows, especially result visualization and file handling.

9. **Data and preprocessing**
   The repository includes dedicated preprocessing/conversion scripts under `scripts/`, such as:
   - video-to-image and image-to-video conversion
   - LabelMe conversion
   - batch evaluation and animation generation
   These are workflow tools around the main pipeline, and they matter because the segmentation models expect frame folders rather than raw videos.

10. **Model configuration and pretrained assets**
   The `estimation/configs/` tree holds Detectron2 model configs, while runtime weights live in `records/` after download. The architecture depends on pretrained components for practical use:
   - water segmentation weights
   - reference detection/segmentation weights
   - MeshTransformer weights and SMPL model files
   This means the system is a composed inference stack rather than a single end-to-end monolith.

11. **Training vs inference boundary**
   Training scripts are split from inference scripts and each branch has its own dataset/transforms. The image and video segmentation models are trained separately, which is important for the architecture diagram: the segmentation stack is modular, not one shared training pipeline.

12. **Outputs and evaluation**
   Outputs include segmentation masks, annotated frames, estimated water-level curves/hydrographs, and animation artifacts. `scripts/cmp_hydrograph.py` compares estimated levels against ground truth, indicating an evaluation layer built on top of the core inference pipeline.

Main entry points: [`est_waterlevel.py`](https://github.com/xmlyqing00/v-floodnet/blob/main/est_waterlevel.py) (Estimate level), [`test_video_seg.py`](https://github.com/xmlyqing00/v-floodnet/blob/main/test_video_seg.py) (Video infer), [`myutils`](https://github.com/xmlyqing00/v-floodnet/tree/main/myutils) (Shared utils), [`scripts`](https://github.com/xmlyqing00/v-floodnet/tree/main/scripts) (Workflow scripts)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_entry["CLI entry points"]
  node_n_test_image["Image infer<br/>CLI<br/>[test_image_seg.py]"]
  node_n_test_video["Video infer<br/>CLI<br/>[test_video_seg.py]"]
  node_n_train_image["Image train<br/>CLI<br/>[train_image_seg.py]"]
  node_n_train_video["Video train<br/>CLI<br/>[train_video_seg.py]"]
  node_n_est_waterlevel["Estimate level<br/>CLI<br/>[est_waterlevel.py]"]
end

subgraph group_grp_seg["Segmentation"]
  node_n_image_ds["Image data<br/>dataset/transforms<br/>[dataset_water.py]"]
  node_n_video_ds["Video data<br/>dataset/transforms<br/>[Water_DS.py]"]
  node_n_afburr["AFB-URR<br/>temporal model<br/>[AFB_URR.py]"]
  node_n_feature_bank[("Feature bank<br/>memory<br/>[FeatureBank.py]")]
end

subgraph group_grp_est["Estimation"]
  node_n_obj_detect["Object detect<br/>detectron2 wrapper"]
  node_n_ref_track["Ref tracking"]
  node_n_mesh["MeshTransformer<br/>external submodule"]
end

subgraph group_grp_support["Support"]
  node_n_myutils["Shared utils<br/>helpers"]
  node_n_scripts["Workflow scripts<br/>conversion/eval"]
  node_n_configs["Model configs"]
end

node_n_test_image -->|"uses"| node_n_image_ds
node_n_train_image -->|"trains on"| node_n_image_ds
node_n_test_video -->|"uses"| node_n_video_ds
node_n_train_video -->|"trains on"| node_n_video_ds
node_n_test_video -->|"runs"| node_n_afburr
node_n_afburr -->|"reads/writes"| node_n_feature_bank
node_n_est_waterlevel -->|"calls"| node_n_obj_detect
node_n_est_waterlevel -->|"calls"| node_n_ref_track
node_n_est_waterlevel -.->|"optional person mode"| node_n_mesh
node_n_obj_detect -->|"configured by"| node_n_configs
node_n_ref_track -->|"uses"| node_n_myutils
node_n_test_image -->|"uses"| node_n_myutils
node_n_test_video -->|"uses"| node_n_myutils
node_n_est_waterlevel -->|"uses"| node_n_myutils
node_n_scripts -.->|"wraps"| node_n_test_video
node_n_scripts -.->|"wraps"| node_n_est_waterlevel
node_n_scripts -.->|"bootstraps"| node_n_mesh

click node_n_test_image "https://github.com/xmlyqing00/v-floodnet/blob/main/test_image_seg.py"
click node_n_test_video "https://github.com/xmlyqing00/v-floodnet/blob/main/test_video_seg.py"
click node_n_train_image "https://github.com/xmlyqing00/v-floodnet/blob/main/train_image_seg.py"
click node_n_train_video "https://github.com/xmlyqing00/v-floodnet/blob/main/train_video_seg.py"
click node_n_est_waterlevel "https://github.com/xmlyqing00/v-floodnet/blob/main/est_waterlevel.py"
click node_n_image_ds "https://github.com/xmlyqing00/v-floodnet/blob/main/image_module/dataset_water.py"
click node_n_video_ds "https://github.com/xmlyqing00/v-floodnet/blob/main/video_module/dataset/Water_DS.py"
click node_n_afburr "https://github.com/xmlyqing00/v-floodnet/blob/main/video_module/model/AFB_URR.py"
click node_n_feature_bank "https://github.com/xmlyqing00/v-floodnet/blob/main/video_module/model/FeatureBank.py"
click node_n_obj_detect "https://github.com/xmlyqing00/v-floodnet/blob/main/estimation/object_detection.py"
click node_n_ref_track "https://github.com/xmlyqing00/v-floodnet/blob/main/estimation/reference_tracking.py"
click node_n_mesh "https://github.com/xmlyqing00/v-floodnet/tree/main/MeshTransformer"
click node_n_myutils "https://github.com/xmlyqing00/v-floodnet/tree/main/myutils"
click node_n_scripts "https://github.com/xmlyqing00/v-floodnet/tree/main/scripts"
click node_n_configs "https://github.com/xmlyqing00/v-floodnet/tree/main/estimation/configs"

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_n_test_image,node_n_test_video,node_n_train_image,node_n_train_video,node_n_est_waterlevel toneBlue
class node_n_image_ds,node_n_video_ds,node_n_afburr,node_n_feature_bank toneAmber
class node_n_obj_detect,node_n_ref_track,node_n_mesh toneMint
class node_n_myutils,node_n_scripts,node_n_configs toneRose
```

## Components

### CLI entry points

Primary training and inference commands for the pipeline.

- [Image infer](https://github.com/xmlyqing00/v-floodnet/blob/main/test_image_seg.py): CLI · Runs water segmentation on still images or extracted frames. · `test_image_seg.py`
- [Video infer](https://github.com/xmlyqing00/v-floodnet/blob/main/test_video_seg.py): CLI · Runs temporal water segmentation on video inputs. · `test_video_seg.py`
- [Image train](https://github.com/xmlyqing00/v-floodnet/blob/main/train_image_seg.py): CLI · Retrains the image segmentation branch. · `train_image_seg.py`
- [Video train](https://github.com/xmlyqing00/v-floodnet/blob/main/train_video_seg.py): CLI · Retrains the video segmentation branch. · `train_video_seg.py`
- [Estimate level](https://github.com/xmlyqing00/v-floodnet/blob/main/est_waterlevel.py): CLI · Orchestrates segmentation output and reference-based water depth estimation. · `est_waterlevel.py`

### Segmentation

Water segmentation subsystems for images and videos.

- [Image data](https://github.com/xmlyqing00/v-floodnet/blob/main/image_module/dataset_water.py): dataset/transforms · Single-image water segmentation dataset and transforms. · `image_module/dataset_water.py`
- [Video data](https://github.com/xmlyqing00/v-floodnet/blob/main/video_module/dataset/Water_DS.py): dataset/transforms · Video-frame dataset and preprocessing for temporal segmentation. · `video_module/dataset/Water_DS.py`
- [AFB-URR](https://github.com/xmlyqing00/v-floodnet/blob/main/video_module/model/AFB_URR.py): temporal model · Adaptive video segmentation model that uses temporal context. · `video_module/model/AFB_URR.py`
- [Feature bank](https://github.com/xmlyqing00/v-floodnet/blob/main/video_module/model/FeatureBank.py): memory · Stores and reuses frame features across time. · `video_module/model/FeatureBank.py`

### Estimation

Reference-object localization and water-level/depth estimation.

- [Object detect](https://github.com/xmlyqing00/v-floodnet/blob/main/estimation/object_detection.py): detectron2 wrapper · Detects or segments reference objects used for scaling. · `estimation/object_detection.py`
- [Ref tracking](https://github.com/xmlyqing00/v-floodnet/blob/main/estimation/reference_tracking.py): tracking · Tracks reference objects through frames for stable measurements. · `estimation/reference_tracking.py`
- [MeshTransformer](https://github.com/xmlyqing00/v-floodnet/tree/main/MeshTransformer): external submodule · Human detection and 3D mesh alignment for person-based reference estimation. · `MeshTransformer`

### Support

Shared utilities, preprocessing scripts, and external mesh tooling.

- [Shared utils](https://github.com/xmlyqing00/v-floodnet/tree/main/myutils): helpers · Common data, plotting, and runtime helpers used across workflows. · `myutils`
- [Workflow scripts](https://github.com/xmlyqing00/v-floodnet/tree/main/scripts): conversion/eval · Video/image conversion, batch runs, label conversion, and hydrograph comparison tools. · `scripts`
- [Model configs](https://github.com/xmlyqing00/v-floodnet/tree/main/estimation/configs): configs · Detectron2 configuration files for reference-object models. · `estimation/configs`

## Connections

- Image infer → Image data: uses · Loads image segmentation data and transforms.
- Image train → Image data: trains on · Uses the image dataset/transforms during retraining.
- Video infer → Video data: uses · Loads video segmentation data and transforms.
- Video train → Video data: trains on · Uses the video dataset/transforms during retraining.
- Video infer → AFB-URR: runs · Executes the temporal segmentation model.
- AFB-URR → Feature bank: reads/writes · Maintains temporal feature memory across frames.
- Estimate level → Object detect: calls · Uses reference-object detection or segmentation for scale estimation.
- Estimate level → Ref tracking: calls · Tracks references to stabilize depth estimation.
- Estimate level → MeshTransformer: optional person mode · Invokes mesh alignment when people are the reference object.
- Object detect → Model configs: configured by · Uses Detectron2 model configuration files.
- Ref tracking → Shared utils: uses · Shares common data and plotting helpers.
- Image infer → Shared utils: uses · Relies on shared utilities for I/O and visualization.
- Video infer → Shared utils: uses · Relies on shared utilities for I/O and visualization.
- Estimate level → Shared utils: uses · Uses shared helpers for result handling and plotting.
- Workflow scripts → Video infer: wraps · Provides batch and conversion workflows around video inference.
- Workflow scripts → Estimate level: wraps · Provides batch evaluation and comparison workflows.
- Workflow scripts → MeshTransformer: bootstraps · Downloads and runs supporting mesh models.
