# chenhongruixuan/mambacd architecture

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

- Interactive diagram: https://gitdiagram.com/chenhongruixuan/mambacd
- Repository: https://github.com/chenhongruixuan/mambacd

## Overview

##### Core project purpose and main components
- ChangeMamba is designed for remote sensing change detection. It supports multiple tasks such as binary change detection (MambaBCD), semantic change detection (MambaSCD) and building damage assessment (MambaBDA).
- The overall purpose is to take paired remote sensing imagery (such as T1 and T2 images), process them with a deep learning pipeline built upon a pre-trained backbone (via VMamba and various mmpretrain configurations), and then produce change maps or damage assessment results.

##### Break down the architecture into main modules/components
a. Data Ingestion and Preprocessing:
- Data loaders and utility functions. In “changedetection/datasets,” you have routines to handle different dataset formats (SYSU, LEVIR-CD+, SECOND, xBD).
- Structure for reading “train_list.txt” and “test_list.txt” files, as well as image pre-processing (cropping, resizing, etc.).
b. Configuration and Model Setup:
- Configuration layer which is heavily modularized under both “analyze/mmpretrain_configs” and “changedetection/configs”. These files define dataset parameters, the backbone (encoder) configuration and task-specific settings.
- That the project utilizes pre-trained weight modules (extracted from VMamba) and custom configurations for change detection.
c. Core Model Components:
- Backbone (encoder) module, which is part of the “analysis” folder’s mmpretrain configs and pretrained weight routines. This is responsible for image feature extraction.
- Dedicated changedetection models in the “changedetection/models” folder (e.g., MambaBCD, Mamba_backbone, SemanticDecoder, STMambaBDA/SCD variants). These collectively create the spatio-temporal state space model architecture.
d. Custom GPU Kernels:
- “kernels/selective_scan” folder as a component that provides compiled CUDA extensions for custom operations (for example, forward and backward passes of selective scan operations) that are integrated with the deep learning backend.
e. Training and Inference Pipelines:
- Clearly separate scripts for training and inference. Show that training scripts (under “changedetection/script”) call the appropriate model (Tiny, Small, Base versions) along with the configuration files.
f. Analysis and Evaluation:
- The “analyze” folder contains scripts for evaluating various aspects like loss, FLOPs, model scales and checkpoint extraction. These components are useful for benchmarking and may be embedded as a separate analysis module.

##### Flow and relationships
- Input remote sensing paired images from datasets moving into a Data Loader module.
- The extracted features then circulate into the “state space” change detection head (and possibly semantic decoder for multi-label outputs).
- Flow then proceeds into the loss computation and evaluation modules under training, with parallel routes for inference.
- Use labels for each module (for example “Data Loader”, “Preprocessing”, “Backbone Encoder (VMamba)”, “Change Detection Head”, “Custom GPU Kernels”, “Training Script”, “Inference Engine”, “Evaluation & Analysis”).
- Rectangles for processing modules,
- Rounded rectangles or ellipses for input/output endpoints,
- Hexagons for custom library kernels,

##### Architectural Patterns & Design Principles
- Separation of concerns: configuration files (mmpretrain_configs, changedetection/configs) are abstracted away from the core model definition and training/inference scripts.
- That the system is highly modular – it supports plug-and-play architecture where one can easily swap different backbone models or change detection heads.
- Mention the integration of custom CUDA kernels to accelerate specific operations—a design choice to boost performance.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input & Data
    A1["Paired Remote Sensing Images"]:::input
    B1["Data Loader & Preprocessing"]:::data

    %% Configuration & Model Setup
    C1["Config & Model Setup"]:::config
    C2["Model Config File"]:::config

    %% Backbone & Core Model Components
    D1["Backbone Encoder (VMamba)"]:::model
    E1["Change Detection Module"]:::model
    F1["Classification Module"]:::model

    %% Custom GPU Kernels
    G1["Custom GPU Kernels"]:::gpu

    %% Training & Inference Pipelines
    H1["Training Script (Change Detection)"]:::pipeline
    I1["Main Script (Classification)"]:::pipeline

    %% Analysis & Evaluation
    J1["Analysis & Evaluation"]:::evaluation

    %% Data flow connections
    A1 --> B1
    B1 --> C1
    C1 --> D1
    C2 --> D1
    G1 --> D1
    D1 --> E1
    D1 --> F1
    G1 --> E1
    E1 --> H1
    F1 --> I1
    H1 --> J1
    I1 --> J1

    %% Click Events
    click B1 "https://github.com/chenhongruixuan/mambacd/tree/master/changedetection/datasets"
    click C1 "https://github.com/chenhongruixuan/mambacd/tree/master/analyze/mmpretrain_configs"
    click C2 "https://github.com/chenhongruixuan/mambacd/blob/master/changedetection/configs/config.py"
    click E1 "https://github.com/chenhongruixuan/mambacd/tree/master/changedetection/models"
    click F1 "https://github.com/chenhongruixuan/mambacd/tree/master/classification/models"
    click G1 "https://github.com/chenhongruixuan/mambacd/tree/master/kernels/selective_scan"
    click H1 "https://github.com/chenhongruixuan/mambacd/tree/master/changedetection/script"
    click I1 "https://github.com/chenhongruixuan/mambacd/blob/master/classification/main.py"
    click J1 "https://github.com/chenhongruixuan/mambacd/tree/master/analyze"

    %% Styles
    classDef input fill:#e0e0e0,stroke:#333,stroke-width:2px;
    classDef data fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef config fill:#90ee90,stroke:#333,stroke-width:2px;
    classDef model fill:#fffacd,stroke:#333,stroke-width:2px;
    classDef gpu fill:#ffdead,stroke:#333,stroke-width:2px;
    classDef pipeline fill:#dda0dd,stroke:#333,stroke-width:2px;
    classDef evaluation fill:#ffb6c1,stroke:#333,stroke-width:2px;
```
