# likyoo/semicd-vl architecture

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

- Interactive diagram: https://gitdiagram.com/likyoo/semicd-vl
- Repository: https://github.com/likyoo/semicd-vl

## Overview

1. This repository implements SemiCD-VL (formerly DiffMatch), a semi-supervised change-detection system for bi-temporal imagery. The core idea is to combine standard FixMatch-style consistency training with VLM-generated pseudo labels and additional auxiliary branches that disentangle change evidence from noisy supervision.

2. The project has two major operating modes:
   - offline pseudo-label generation from a vision-language model (APE),
   - model training/evaluation for semi-supervised change detection.
   These are separate boundaries: the VLM is not part of the main training loop, but its outputs are consumed as extra supervision.

3. The training entry point is `diffmatch_fixmatch.py`. This is the main orchestration layer that ties together labeled/unlabeled batches, model forward passes, pseudo-label losses, auxiliary segmentation supervision, and contrastive consistency terms. It is the central place where the semi-supervised logic lives.

4. Model construction is split across `model/`:
   - `model/vlm.py` wraps the visual-language guidance side,
   - `model/builder.py` assembles the full network from config and adds a forward wrapper for feature perturbation,
   - `model/backbone/` contains backbone implementations, including ResNet-style semi-supervised backbones and a timm-based ViT option,
   - `model/decode_heads/` contains the change-detection heads, notably `dlv3p_head.py` and `light_head.py`.
   This is the main architectural boundary between feature extraction, decoding, and VLM-guided components.

5. The change detector is not a single head: the README and file layout indicate a dual-projection / multi-branch design. The core change branch predicts the final change map, while auxiliary segmentation decoders explicitly separate temporal semantics from the two input images. These auxiliary branches are important because they receive VLM guidance and feed feature-level contrastive regularization.

6. Data loading for the semi-supervised setting is handled through the UniMatch-derived code in `third_party/unimatch/dataset/semicd.py`, with transforms in `third_party/unimatch/dataset/transform_cd.py`. This indicates the project inherits a semi-supervised data pipeline from UniMatch, then adapts it for paired change-detection inputs rather than single-image segmentation.

7. Dataset organization is driven by `splits/` and the `datasets/` metadata helpers:
   - `splits/levir` and `splits/whu` contain train/val/test splits plus labeled/unlabeled partitions at 5%, 10%, 20%, and 40% label ratios,
   - `datasets/classes.py` and `datasets/palettes.py` define class names and visualization colors.
   The split files are a key architectural input because the same training code is reused across different label budgets.

8. Offline VLM pseudo-label generation is a distinct preprocessing subsystem. The README describes running APE to generate per-image semantic pseudo labels, then converting them into change-event labels via `scripts/gen_cd_map_json.py` and `scripts/gen_cd_map.py`. This stage produces the extra supervision that SemiCD-VL injects into semi-supervised training.

9. Experiment definition and launch are centralized in `experiments.py` and `configs/`. The repository uses config-driven execution:
   - `configs/_base_/models/` stores model templates such as `vlm-dlv3p-r50.py` and `vlm-lighthead-r50.py`,
   - `experiments.py` expands paper experiments into generated configs under `configs/generated/`.
   This makes the architecture largely declarative at the experiment-selection layer.

10. External dependencies and inherited baseline code are clearly separated under `third_party/unimatch/`. That subtree contains the original semi-supervised framework utilities, alternative backbones, and a DeeplabV3+ semantic segmentation baseline. It acts as the reference implementation foundation that this repo extends for change detection.

11. Runtime artifacts are written to `exp/` during training: logs, TensorBoard summaries, checkpoints, and debug images. The repository therefore has a standard offline-training workflow rather than a serving-oriented or interactive architecture.

12. Utility code is organized by function rather than feature:
   - `utils/train_utils.py` and `model/utils.py` hold training/model helpers,
   - `utils/plot_utils.py` and `visualize.py` support inspection and reporting,
   - `scripts/train.sh` provides shell-level launch glue,
   - `utils/gen_code_archive.py` suggests reproducibility packaging.
   These are support layers around the main training and preprocessing pipeline.

13. The main data flow is:
   paired temporal images + labels/splits -> semi-supervised loader -> model builder/backbone/heads -> training losses in `diffmatch_fixmatch.py`, with optional VLM-derived pseudo labels and auxiliary branch supervision. That separation is the key architecture diagram boundary: offline label synthesis, dataset/split management, model inference, and semi-supervised optimization.

14. Overall, the repository is a research training framework rather than a general application. Its architecture is optimized around reproducible experiments, configurable model variants, and a two-stage pipeline that couples external VLM pseudo-label generation with internal semi-supervised change-detection learning.

Main entry points: [`diffmatch_fixmatch.py`](https://github.com/likyoo/semicd-vl/blob/main/diffmatch_fixmatch.py) (FixMatch train), [`model/builder.py`](https://github.com/likyoo/semicd-vl/blob/main/model/builder.py) (Model builder), [`third_party/unimatch/dataset/semicd.py`](https://github.com/likyoo/semicd-vl/blob/main/third_party/unimatch/dataset/semicd.py) (SemiCD loader), [`model/backbone`](https://github.com/likyoo/semicd-vl/tree/main/model/backbone) (Backbones)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_pipeline["Pipeline"]
  node_n_ape["APE labels<br/>offline VLM pseudo-labeling"]
  node_n_cd_json["CD JSON<br/>label conversion<br/>[gen_cd_map_json.py]"]
  node_n_cd_map["CD maps<br/>label conversion<br/>[gen_cd_map.py]"]
  node_n_train["FixMatch train<br/>semi-supervised trainer"]
end

subgraph group_g_model["Model"]
  node_n_builder["Model builder<br/>assembly wrapper<br/>[builder.py]"]
  node_n_vlm["VLM guide<br/>guidance module<br/>[vlm.py]"]
  node_n_backbone["Backbones<br/>feature extractors"]
  node_n_resnet["Semi ResNet<br/>cnn backbone<br/>[semi_resnet.py]"]
  node_n_vit["Timm ViT<br/>transformer backbone<br/>[timm_vit.py]"]
  node_n_heads["Decode heads<br/>prediction heads"]
  node_n_dlv3p["DLV3P head<br/>decoder head<br/>[dlv3p_head.py]"]
  node_n_light["Light head<br/>decoder head<br/>[light_head.py]"]
  node_n_aux["Aux branches<br/>multi-branch supervision<br/>[utils.py]"]
end

subgraph group_g_data["Data"]
  node_n_loader["SemiCD loader<br/>paired-data loader<br/>[semicd.py]"]
  node_n_tf["CD transforms<br/>augmentation pipeline<br/>[transform_cd.py]"]
  node_n_splits["Split files<br/>label budgets"]
  node_n_meta["Dataset meta<br/>labels and colors<br/>[classes.py]"]
  node_n_palette["Palettes<br/>visualization colors<br/>[palettes.py]"]
end

subgraph group_g_support["Support"]
  node_n_experiments["Experiments<br/>config generator<br/>[experiments.py]"]
  node_n_configs["Model configs<br/>declarative config"]
  node_n_utils["Utilities<br/>helpers<br/>[train_utils.py]"]
  node_n_runtime[("Run outputs<br/>artifacts")]
end

subgraph group_g_third_party["Third Party"]
  node_n_unimatch["UniMatch<br/>inherited framework"]
  node_n_unimatch_model["UniMatch models<br/>baseline models"]
  node_n_unimatch_data["UniMatch data<br/>baseline pipeline"]
end

node_n_ape -->|"semantic labels"| node_n_cd_json
node_n_cd_json -->|"change maps"| node_n_cd_map
node_n_cd_map -->|"extra supervision"| node_n_train
node_n_experiments -->|"expansion"| node_n_configs
node_n_configs -->|"selects model"| node_n_builder
node_n_train -->|"builds"| node_n_builder
node_n_builder -->|"wraps"| node_n_vlm
node_n_builder -->|"composes"| node_n_backbone
node_n_backbone -->|"option"| node_n_resnet
node_n_backbone -->|"option"| node_n_vit
node_n_builder -->|"composes"| node_n_heads
node_n_heads -->|"variant"| node_n_dlv3p
node_n_heads -->|"variant"| node_n_light
node_n_builder -->|"adds"| node_n_aux
node_n_train -->|"loads batches"| node_n_loader
node_n_loader -->|"applies"| node_n_tf
node_n_loader -->|"indexes"| node_n_splits
node_n_loader -->|"uses"| node_n_meta
node_n_meta -->|"renders"| node_n_palette
node_n_train -->|"writes"| node_n_runtime
node_n_train -->|"uses"| node_n_utils
node_n_train -.->|"inherits"| node_n_unimatch
node_n_loader -.->|"inherits"| node_n_unimatch_data
node_n_backbone -.->|"inherits"| node_n_unimatch_model

click node_n_cd_json "https://github.com/likyoo/semicd-vl/blob/main/scripts/gen_cd_map_json.py"
click node_n_cd_map "https://github.com/likyoo/semicd-vl/blob/main/scripts/gen_cd_map.py"
click node_n_train "https://github.com/likyoo/semicd-vl/blob/main/diffmatch_fixmatch.py"
click node_n_builder "https://github.com/likyoo/semicd-vl/blob/main/model/builder.py"
click node_n_vlm "https://github.com/likyoo/semicd-vl/blob/main/model/vlm.py"
click node_n_backbone "https://github.com/likyoo/semicd-vl/tree/main/model/backbone"
click node_n_resnet "https://github.com/likyoo/semicd-vl/blob/main/model/backbone/semi_resnet.py"
click node_n_vit "https://github.com/likyoo/semicd-vl/blob/main/model/backbone/timm_vit.py"
click node_n_heads "https://github.com/likyoo/semicd-vl/tree/main/model/decode_heads"
click node_n_dlv3p "https://github.com/likyoo/semicd-vl/blob/main/model/decode_heads/dlv3p_head.py"
click node_n_light "https://github.com/likyoo/semicd-vl/blob/main/model/decode_heads/light_head.py"
click node_n_aux "https://github.com/likyoo/semicd-vl/blob/main/model/utils.py"
click node_n_loader "https://github.com/likyoo/semicd-vl/blob/main/third_party/unimatch/dataset/semicd.py"
click node_n_tf "https://github.com/likyoo/semicd-vl/blob/main/third_party/unimatch/dataset/transform_cd.py"
click node_n_splits "https://github.com/likyoo/semicd-vl/tree/main/splits"
click node_n_meta "https://github.com/likyoo/semicd-vl/blob/main/datasets/classes.py"
click node_n_palette "https://github.com/likyoo/semicd-vl/blob/main/datasets/palettes.py"
click node_n_experiments "https://github.com/likyoo/semicd-vl/blob/main/experiments.py"
click node_n_configs "https://github.com/likyoo/semicd-vl/tree/main/configs/_base_/models"
click node_n_utils "https://github.com/likyoo/semicd-vl/blob/main/utils/train_utils.py"
click node_n_unimatch "https://github.com/likyoo/semicd-vl/tree/main/third_party/unimatch"
click node_n_unimatch_model "https://github.com/likyoo/semicd-vl/tree/main/third_party/unimatch/model"
click node_n_unimatch_data "https://github.com/likyoo/semicd-vl/tree/main/third_party/unimatch/dataset"

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_ape,node_n_cd_json,node_n_cd_map,node_n_train toneBlue
class node_n_builder,node_n_vlm,node_n_backbone,node_n_resnet,node_n_vit,node_n_heads,node_n_dlv3p,node_n_light,node_n_aux toneAmber
class node_n_loader,node_n_tf,node_n_splits,node_n_meta,node_n_palette toneMint
class node_n_experiments,node_n_configs,node_n_utils,node_n_runtime toneRose
class node_n_unimatch,node_n_unimatch_model,node_n_unimatch_data toneIndigo
```

## Components

### Pipeline

Offline pseudo-label generation and semi-supervised training flow.

- **APE labels**: offline VLM pseudo-labeling · Generates semantic pseudo labels before training; later converted into change-event supervision.
- [CD JSON](https://github.com/likyoo/semicd-vl/blob/main/scripts/gen_cd_map_json.py): label conversion · Converts VLM semantic outputs into change-detection JSON supervision artifacts. · `scripts/gen_cd_map_json.py`
- [CD maps](https://github.com/likyoo/semicd-vl/blob/main/scripts/gen_cd_map.py): label conversion · Builds change-detection maps from pseudo-label inputs for training supervision. · `scripts/gen_cd_map.py`
- [FixMatch train](https://github.com/likyoo/semicd-vl/blob/main/diffmatch_fixmatch.py): semi-supervised trainer · Main orchestration entry point for labeled/unlabeled batches, losses, pseudo-labels, auxiliary supervision, and evaluation. · `diffmatch_fixmatch.py`

### Model

Network assembly, backbones, decode heads, and VLM guidance.

- [Model builder](https://github.com/likyoo/semicd-vl/blob/main/model/builder.py): assembly wrapper · Builds the full network from config and applies forward-time feature perturbation or wrapping. · `model/builder.py`
- [VLM guide](https://github.com/likyoo/semicd-vl/blob/main/model/vlm.py): guidance module · Wraps the vision-language guidance used to inject or consume pseudo supervision. · `model/vlm.py`
- [Backbones](https://github.com/likyoo/semicd-vl/tree/main/model/backbone): feature extractors · Backbone selection for the change detector, including CNN and transformer options. · `model/backbone`
- [Semi ResNet](https://github.com/likyoo/semicd-vl/blob/main/model/backbone/semi_resnet.py): cnn backbone · ResNet-style backbone used in the semi-supervised change detector. · `model/backbone/semi_resnet.py`
- [Timm ViT](https://github.com/likyoo/semicd-vl/blob/main/model/backbone/timm_vit.py): transformer backbone · Vision-transformer backbone option built from timm. · `model/backbone/timm_vit.py`
- [Decode heads](https://github.com/likyoo/semicd-vl/tree/main/model/decode_heads): prediction heads · Change-detection decoders that produce final maps and auxiliary outputs. · `model/decode_heads`
- [DLV3P head](https://github.com/likyoo/semicd-vl/blob/main/model/decode_heads/dlv3p_head.py): decoder head · DeepLabV3+-style change-decoding head used in one main model variant. · `model/decode_heads/dlv3p_head.py`
- [Light head](https://github.com/likyoo/semicd-vl/blob/main/model/decode_heads/light_head.py): decoder head · Lighter-weight decoding head for an alternate model variant. · `model/decode_heads/light_head.py`
- [Aux branches](https://github.com/likyoo/semicd-vl/blob/main/model/utils.py): multi-branch supervision · Auxiliary segmentation branches that disentangle temporal semantics and support contrastive regularization. · `model/utils.py`

### Data

Datasets, splits, metadata, and semi-supervised loaders.

- [SemiCD loader](https://github.com/likyoo/semicd-vl/blob/main/third_party/unimatch/dataset/semicd.py): paired-data loader · UniMatch-derived dataset pipeline adapted for bi-temporal change detection. · `third_party/unimatch/dataset/semicd.py`
- [CD transforms](https://github.com/likyoo/semicd-vl/blob/main/third_party/unimatch/dataset/transform_cd.py): augmentation pipeline · Paired-image transforms for semi-supervised change-detection training. · `third_party/unimatch/dataset/transform_cd.py`
- [Split files](https://github.com/likyoo/semicd-vl/tree/main/splits): label budgets · Train/val/test and labeled/unlabeled partitions for LEVIR and WHU at multiple label ratios. · `splits`
- [Dataset meta](https://github.com/likyoo/semicd-vl/blob/main/datasets/classes.py): labels and colors · Class names and visualization palettes for change-detection datasets. · `datasets/classes.py`
- [Palettes](https://github.com/likyoo/semicd-vl/blob/main/datasets/palettes.py): visualization colors · Color palettes used when rendering class labels and predictions. · `datasets/palettes.py`

### Support

Experiments, configs, utilities, visualization, and outputs.

- [Experiments](https://github.com/likyoo/semicd-vl/blob/main/experiments.py): config generator · Expands paper experiments into generated configs and launchable runs. · `experiments.py`
- [Model configs](https://github.com/likyoo/semicd-vl/tree/main/configs/_base_/models): declarative config · Base model templates for the VLM-enabled DLV3P and Light head variants. · `configs/_base_/models`
- [Utilities](https://github.com/likyoo/semicd-vl/blob/main/utils/train_utils.py): helpers · Training, plotting, archiving, and visualization support utilities. · `utils/train_utils.py`
- **Run outputs**: artifacts · Logs, checkpoints, TensorBoard summaries, and debug images written during training.

### Third Party

Inherited UniMatch framework code reused and adapted here.

- [UniMatch](https://github.com/likyoo/semicd-vl/tree/main/third_party/unimatch): inherited framework · Reference semi-supervised framework code adapted for change detection. · `third_party/unimatch`
- [UniMatch models](https://github.com/likyoo/semicd-vl/tree/main/third_party/unimatch/model): baseline models · Inherited backbone and DeeplabV3+ semantic segmentation implementations. · `third_party/unimatch/model`
- [UniMatch data](https://github.com/likyoo/semicd-vl/tree/main/third_party/unimatch/dataset): baseline pipeline · Original semi-supervised dataset and transform code reused by this repo. · `third_party/unimatch/dataset`

## Connections

- APE labels → CD JSON: semantic labels · Offline VLM outputs are formatted as JSON supervision artifacts.
- CD JSON → CD maps: change maps · JSON artifacts are converted into change-detection maps.
- CD maps → FixMatch train: extra supervision · Generated change maps are consumed by the training loop.
- Experiments → Model configs: expansion · Experiment definitions generate concrete model configs.
- Model configs → Model builder: selects model · Config choice determines the assembled network variant.
- FixMatch train → Model builder: builds · Training entry point instantiates the model through the builder.
- Model builder → VLM guide: wraps · Builder connects the VLM guidance module into the full network.
- Model builder → Backbones: composes · Builder attaches a backbone to the change detector.
- Backbones → Semi ResNet: option · ResNet is one supported backbone implementation.
- Backbones → Timm ViT: option · ViT is an alternative backbone implementation.
- Model builder → Decode heads: composes · Builder connects decode heads to backbone features.
- Decode heads → DLV3P head: variant · DLV3P is one decoder choice.
- Decode heads → Light head: variant · Light head is another decoder choice.
- Model builder → Aux branches: adds · Auxiliary branches are attached for disentanglement and contrastive regularization.
- FixMatch train → SemiCD loader: loads batches · Trainer consumes paired labeled/unlabeled change-detection batches.
- SemiCD loader → CD transforms: applies · Dataset pipeline uses paired transforms.
- SemiCD loader → Split files: indexes · Split files define labeled and unlabeled subsets.
- SemiCD loader → Dataset meta: uses · Dataset metadata drives class naming and label interpretation.
- Dataset meta → Palettes: renders · Palette definitions support visualization of dataset classes.
- FixMatch train → Run outputs: writes · Training produces logs, checkpoints, and diagnostics.
- FixMatch train → Utilities: uses · Trainer relies on helper utilities for optimization and reporting.
- FixMatch train → UniMatch: inherits · Semi-supervised training builds on UniMatch conventions and utilities.
- SemiCD loader → UniMatch data: inherits · Dataset pipeline extends UniMatch data code.
- Backbones → UniMatch models: inherits · Backbone implementations reuse baseline model code paths.
