How likyoo/semicd-vl works
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 FixMatch train · builder.py Model builder · semicd.py SemiCD loader · backbone Backbones
Components 25
Pipeline
Offline pseudo-label generation and semi-supervised training flow.
- APE labels · Generates semantic pseudo labels before training; later converted into change-event supervision.
- CD JSON · Converts VLM semantic outputs into change-detection JSON supervision artifacts.
scripts/gen_cd_map_json.py - CD maps · Builds change-detection maps from pseudo-label inputs for training supervision.
scripts/gen_cd_map.py - FixMatch train · 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 · Builds the full network from config and applies forward-time feature perturbation or wrapping.
model/builder.py - VLM guide · Wraps the vision-language guidance used to inject or consume pseudo supervision.
model/vlm.py - Backbones · Backbone selection for the change detector, including CNN and transformer options.
model/backbone - Semi ResNet · ResNet-style backbone used in the semi-supervised change detector.
model/backbone/semi_resnet.py - Timm ViT · Vision-transformer backbone option built from timm.
model/backbone/timm_vit.py - Decode heads · Change-detection decoders that produce final maps and auxiliary outputs.
model/decode_heads - DLV3P head · DeepLabV3+-style change-decoding head used in one main model variant.
model/decode_heads/dlv3p_head.py - Light head · Lighter-weight decoding head for an alternate model variant.
model/decode_heads/light_head.py - Aux branches · Auxiliary segmentation branches that disentangle temporal semantics and support contrastive regularization.
model/utils.py
Data
Datasets, splits, metadata, and semi-supervised loaders.
- SemiCD loader · UniMatch-derived dataset pipeline adapted for bi-temporal change detection.
third_party/unimatch/dataset/semicd.py - CD transforms · Paired-image transforms for semi-supervised change-detection training.
third_party/unimatch/dataset/transform_cd.py - Split files · Train/val/test and labeled/unlabeled partitions for LEVIR and WHU at multiple label ratios.
splits - Dataset meta · Class names and visualization palettes for change-detection datasets.
datasets/classes.py - Palettes · Color palettes used when rendering class labels and predictions.
datasets/palettes.py
Support
Experiments, configs, utilities, visualization, and outputs.
- Experiments · Expands paper experiments into generated configs and launchable runs.
experiments.py - Model configs · Base model templates for the VLM-enabled DLV3P and Light head variants.
configs/_base_/models - Utilities · Training, plotting, archiving, and visualization support utilities.
utils/train_utils.py - Run outputs · Logs, checkpoints, TensorBoard summaries, and debug images written during training.
Third Party
Inherited UniMatch framework code reused and adapted here.
- UniMatch · Reference semi-supervised framework code adapted for change detection.
third_party/unimatch - UniMatch models · Inherited backbone and DeeplabV3+ semantic segmentation implementations.
third_party/unimatch/model - UniMatch data · Original semi-supervised dataset and transform code reused by this repo.
third_party/unimatch/dataset
Connections 24
- 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.