# xiaobul/cm-unet architecture

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

- Interactive diagram: https://gitdiagram.com/xiaobul/cm-unet
- Repository: https://github.com/xiaobul/cm-unet

## Overview

CM-UNet is a remote-sensing semantic-segmentation research application for LoveDA, Vaihingen, Potsdam and UAVid imagery. The main workflow configures a dataset and model, trains with segmentation losses and validation metrics, then predicts masks for tiled or large imagery. The repository also contains image-preparation utilities and several segmentation architectures. The graph combines sampled call sites and SOURCE INDEX references; links for unsampled capabilities are omitted where their wiring cannot be established.

Main entry points: [`cmunet/train_supervision.py`](https://github.com/xiaobul/cm-unet/blob/main/cmunet/train_supervision.py) (Training runner), [`cmunet/geoseg/models/networks/vision_mamba.py`](https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/models/networks/vision_mamba.py) (Mamba variants), [`cmunet/tools`](https://github.com/xiaobul/cm-unet/tree/main/cmunet/tools) (Dataset preparation), [`cmunet/config/loveda/mambaunet.py`](https://github.com/xiaobul/cm-unet/blob/main/cmunet/config/loveda/mambaunet.py) (Dataset profiles)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_dataset_loveda["LoveDA dataset<br/>[loveda_dataset.py]"]
  node_dataset_vaihingen["Vaihingen dataset"]
  node_dataset_potsdam["Potsdam dataset<br/>[potsdam_dataset.py]"]
  node_dataset_uavid["UAVid dataset<br/>[uavid_dataset.py]"]
  node_transforms["Image transforms<br/>[transform.py]"]
  node_prep["Dataset preparation"]
end

subgraph group_model["Segmentation models"]
  node_unetformer["UNetFormer<br/>[UNetFormer.py]"]
  node_mamba_entry["Mamba variants<br/>[vision_mamba.py]"]
  node_mamba_sys["Mamba backbone<br/>[mamba_sys.py]"]
  node_mamba_res["Residual Mamba<br/>[mamba_sys_res.py]"]
  node_mamba_swin["Swin Mamba<br/>[mamba_sys_swin.py]"]
  node_mamba_vmamba["VMamba backbone"]
  node_scan["Selective scan"]
end

subgraph group_train["Training and evaluation"]
  node_config["Run configuration<br/>[config.py]"]
  node_profiles["Dataset profiles<br/>[mambaunet.py]"]
  node_trainer["Training runner"]
  node_losses["Segmentation losses"]
  node_metrics["Segmentation metrics<br/>[metric.py]"]
end

subgraph group_predict["Inference"]
  node_infer_huge["Large-image inference"]
  node_infer_uavid["UAVid inference<br/>[inference_uavid.py]"]
  node_infer_dataset["Inference tiles<br/>[inference_uavid.py]"]
end

node_user(("Researcher"))

node_user -.->|"starts training"| node_trainer
node_dataset_loveda -->|"uses transforms"| node_transforms
node_dataset_vaihingen -->|"uses transforms"| node_transforms
node_dataset_potsdam -->|"uses transforms"| node_transforms
node_dataset_uavid -->|"uses transforms"| node_transforms
node_profiles -->|"configures data"| node_dataset_loveda
node_profiles -->|"imports model"| node_unetformer
node_profiles -->|"constructs model"| node_mamba_entry
node_profiles -->|"selects loss"| node_losses
node_trainer -->|"loads settings"| node_config
node_trainer -->|"updates metrics"| node_metrics
node_trainer -.->|"runs network"| node_mamba_entry
node_trainer -.->|"computes loss"| node_losses
node_mamba_entry -->|"selects backbone"| node_mamba_sys
node_mamba_entry -->|"selects backbone"| node_mamba_res
node_mamba_entry -->|"selects backbone"| node_mamba_swin
node_mamba_entry -->|"selects backbone"| node_mamba_vmamba
node_mamba_vmamba -->|"calls scan"| node_scan
node_infer_huge -->|"loads config"| node_config
node_infer_huge -->|"loads checkpoint"| node_trainer
node_infer_uavid -->|"loads config"| node_config
node_infer_uavid -->|"loads checkpoint"| node_trainer
node_infer_uavid -->|"evaluates masks"| node_metrics
node_infer_uavid -->|"batches tiles"| node_infer_dataset
node_prep -.->|"prepares masks"| node_dataset_loveda
node_prep -.->|"splits patches"| node_dataset_vaihingen
node_prep -.->|"splits patches"| node_dataset_potsdam
node_prep -.->|"splits patches"| node_dataset_uavid

click node_dataset_loveda "https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/datasets/loveda_dataset.py"
click node_dataset_vaihingen "https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/datasets/vaihingen_dataset.py"
click node_dataset_potsdam "https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/datasets/potsdam_dataset.py"
click node_dataset_uavid "https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/datasets/uavid_dataset.py"
click node_transforms "https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/datasets/transform.py"
click node_prep "https://github.com/xiaobul/cm-unet/tree/main/cmunet/tools"
click node_config "https://github.com/xiaobul/cm-unet/blob/main/cmunet/config.py"
click node_profiles "https://github.com/xiaobul/cm-unet/blob/main/cmunet/config/loveda/mambaunet.py"
click node_trainer "https://github.com/xiaobul/cm-unet/blob/main/cmunet/train_supervision.py"
click node_losses "https://github.com/xiaobul/cm-unet/tree/main/cmunet/geoseg/losses"
click node_metrics "https://github.com/xiaobul/cm-unet/blob/main/cmunet/tools/metric.py"
click node_unetformer "https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/models/UNetFormer.py"
click node_mamba_entry "https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/models/networks/vision_mamba.py"
click node_mamba_sys "https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/models/networks/mamba_sys.py"
click node_mamba_res "https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/models/networks/mamba_sys_res.py"
click node_mamba_swin "https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/models/networks/mamba_sys_swin.py"
click node_mamba_vmamba "https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/models/networks/mamba_sys_vmamba.py"
click node_scan "https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/Mamba-UNet/mamba/mamba_ssm/ops/selective_scan_interface.py"
click node_infer_huge "https://github.com/xiaobul/cm-unet/blob/main/cmunet/inference_huge_image.py"
click node_infer_uavid "https://github.com/xiaobul/cm-unet/blob/main/cmunet/inference_uavid.py"
click node_infer_dataset "https://github.com/xiaobul/cm-unet/blob/main/cmunet/inference_uavid.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_dataset_loveda,node_dataset_vaihingen,node_dataset_potsdam,node_dataset_uavid,node_transforms,node_prep toneBlue
class node_unetformer,node_mamba_entry,node_mamba_sys,node_mamba_res,node_mamba_swin,node_mamba_vmamba,node_scan toneAmber
class node_config,node_profiles,node_trainer,node_losses,node_metrics toneMint
class node_infer_huge,node_infer_uavid,node_infer_dataset toneRose
class node_user toneIndigo
```

## Components

### Data preparation

- [LoveDA dataset](https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/datasets/loveda_dataset.py): `cmunet/geoseg/datasets/loveda_dataset.py`
- [Vaihingen dataset](https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/datasets/vaihingen_dataset.py): `cmunet/geoseg/datasets/vaihingen_dataset.py`
- [Potsdam dataset](https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/datasets/potsdam_dataset.py): `cmunet/geoseg/datasets/potsdam_dataset.py`
- [UAVid dataset](https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/datasets/uavid_dataset.py): `cmunet/geoseg/datasets/uavid_dataset.py`
- [Image transforms](https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/datasets/transform.py): `cmunet/geoseg/datasets/transform.py`
- [Dataset preparation](https://github.com/xiaobul/cm-unet/tree/main/cmunet/tools): `cmunet/tools`

### Segmentation models

- [UNetFormer](https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/models/UNetFormer.py): `cmunet/geoseg/models/UNetFormer.py`
- [Mamba variants](https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/models/networks/vision_mamba.py): `cmunet/geoseg/models/networks/vision_mamba.py`
- [Mamba backbone](https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/models/networks/mamba_sys.py): `cmunet/geoseg/models/networks/mamba_sys.py`
- [Residual Mamba](https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/models/networks/mamba_sys_res.py): `cmunet/geoseg/models/networks/mamba_sys_res.py`
- [Swin Mamba](https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/models/networks/mamba_sys_swin.py): `cmunet/geoseg/models/networks/mamba_sys_swin.py`
- [VMamba backbone](https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/models/networks/mamba_sys_vmamba.py): `cmunet/geoseg/models/networks/mamba_sys_vmamba.py`
- [Selective scan](https://github.com/xiaobul/cm-unet/blob/main/cmunet/geoseg/Mamba-UNet/mamba/mamba_ssm/ops/selective_scan_interface.py): `cmunet/geoseg/Mamba-UNet/mamba/mamba_ssm/ops/selective_scan_interface.py`

### Training and evaluation

- [Run configuration](https://github.com/xiaobul/cm-unet/blob/main/cmunet/config.py): `cmunet/config.py`
- [Dataset profiles](https://github.com/xiaobul/cm-unet/blob/main/cmunet/config/loveda/mambaunet.py): `cmunet/config/loveda/mambaunet.py`
- [Training runner](https://github.com/xiaobul/cm-unet/blob/main/cmunet/train_supervision.py): `cmunet/train_supervision.py`
- [Segmentation losses](https://github.com/xiaobul/cm-unet/tree/main/cmunet/geoseg/losses): `cmunet/geoseg/losses`
- [Segmentation metrics](https://github.com/xiaobul/cm-unet/blob/main/cmunet/tools/metric.py): `cmunet/tools/metric.py`

### Inference

- [Large-image inference](https://github.com/xiaobul/cm-unet/blob/main/cmunet/inference_huge_image.py): `cmunet/inference_huge_image.py`
- [UAVid inference](https://github.com/xiaobul/cm-unet/blob/main/cmunet/inference_uavid.py): `cmunet/inference_uavid.py`
- [Inference tiles](https://github.com/xiaobul/cm-unet/blob/main/cmunet/inference_uavid.py): `cmunet/inference_uavid.py`

### Other components

- **Researcher**

## Connections

- Researcher → Training runner: starts training
- LoveDA dataset → Image transforms: uses transforms (evidence: `cmunet/geoseg/datasets/loveda_dataset.py`)
- Vaihingen dataset → Image transforms: uses transforms (evidence: `cmunet/geoseg/datasets/vaihingen_dataset.py`)
- Potsdam dataset → Image transforms: uses transforms (evidence: `cmunet/geoseg/datasets/potsdam_dataset.py`)
- UAVid dataset → Image transforms: uses transforms (evidence: `cmunet/geoseg/datasets/uavid_dataset.py`)
- Dataset profiles → LoveDA dataset: configures data (evidence: `cmunet/config/loveda/mambaunet.py`)
- Dataset profiles → UNetFormer: imports model (evidence: `cmunet/config/loveda/mambaunet.py`)
- Dataset profiles → Mamba variants: constructs model (evidence: `cmunet/config/loveda/mambaunet.py`)
- Dataset profiles → Segmentation losses: selects loss (evidence: `cmunet/config/loveda/mambaunet.py`)
- Training runner → Run configuration: loads settings (evidence: `cmunet/train_supervision.py`)
- Training runner → Segmentation metrics: updates metrics (evidence: `cmunet/train_supervision.py`)
- Training runner → Mamba variants: runs network
- Training runner → Segmentation losses: computes loss
- Mamba variants → Mamba backbone: selects backbone (evidence: `cmunet/geoseg/models/networks/vision_mamba.py`)
- Mamba variants → Residual Mamba: selects backbone (evidence: `cmunet/geoseg/models/networks/vision_mamba.py`)
- Mamba variants → Swin Mamba: selects backbone (evidence: `cmunet/geoseg/models/networks/vision_mamba.py`)
- Mamba variants → VMamba backbone: selects backbone (evidence: `cmunet/geoseg/models/networks/vision_mamba.py`)
- VMamba backbone → Selective scan: calls scan (evidence: `cmunet/geoseg/models/networks/mamba_sys_vmamba.py`)
- Large-image inference → Run configuration: loads config (evidence: `cmunet/inference_huge_image.py`)
- Large-image inference → Training runner: loads checkpoint (evidence: `cmunet/inference_huge_image.py`)
- UAVid inference → Run configuration: loads config (evidence: `cmunet/inference_uavid.py`)
- UAVid inference → Training runner: loads checkpoint (evidence: `cmunet/inference_uavid.py`)
- UAVid inference → Segmentation metrics: evaluates masks (evidence: `cmunet/inference_uavid.py`)
- UAVid inference → Inference tiles: batches tiles (evidence: `cmunet/inference_uavid.py`)
- Dataset preparation → LoveDA dataset: prepares masks
- Dataset preparation → Vaihingen dataset: splits patches
- Dataset preparation → Potsdam dataset: splits patches
- Dataset preparation → UAVid dataset: splits patches
