# liumency/cropland-cd architecture

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

- Interactive diagram: https://gitdiagram.com/liumency/cropland-cd
- Repository: https://github.com/liumency/cropland-cd

## Overview

Cropland-CD is a PyTorch implementation of MSCANet for binary cropland change detection from paired images. Its main workflow loads and augments time-paired images and labels, trains a multi-scale change detector with cross-entropy, validates by IoU, and saves selected weights; prediction evaluates pairs and saves change maps. The model combines a CNN backbone with transformer context aggregation and multi-scale classifiers. The prediction script imports `models.mscanet.network`, which does not match the supplied tree’s `model/network.py`; that connection is therefore not asserted. Arrows reflect shown calls or README descriptions.

Main entry points: [`train.py`](https://github.com/liumency/cropland-cd/blob/main/train.py) (Training loop), [`model/network.py`](https://github.com/liumency/cropland-cd/blob/main/model/network.py) (Change detector), [`predict.py`](https://github.com/liumency/cropland-cd/blob/main/predict.py) (Prediction script), [`data_utils.py`](https://github.com/liumency/cropland-cd/blob/main/data_utils.py) (Dataset loaders)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Paired data"]
  node_dataset["Dataset loaders<br/>[data_utils.py]"]
  node_augment["Pair augmentation<br/>[data_utils.py]"]
  node_testdata["Test dataset<br/>[data_utils.py]"]
end

subgraph group_model["Detection model"]
  node_cdnet["Change detector<br/>[network.py]"]
  node_backbone["CNN backbone<br/>[backbone.py]"]
  node_context["Transformer context<br/>[network.py]"]
  node_transformer["Attention modules<br/>[modules.py]"]
  node_classifier["Multi-scale heads<br/>[network.py]"]
end

subgraph group_train["Training and evaluation"]
  node_trainer["Training loop<br/>[train.py]"]
  node_options["Training options<br/>[train_options.py]"]
  node_loss["Cross-entropy<br/>[losses.py]"]
  node_metrics["IoU metric<br/>[data_utils.py]"]
  node_checkpoint[("Weight saving<br/>[train.py]")]
end

subgraph group_predict["Prediction"]
  node_predictor["Prediction script<br/>[predict.py]"]
  node_changemaps["Saved change maps<br/>[predict.py]"]
end

node_operator(("Engineer"))

node_operator -->|"starts training"| node_trainer
node_options -->|"configures"| node_trainer
node_trainer -->|"loads pairs"| node_dataset
node_dataset -->|"applies"| node_augment
node_trainer -->|"runs forward"| node_cdnet
node_cdnet -->|"extracts features"| node_backbone
node_cdnet -->|"aggregates context"| node_context
node_context -->|"uses attention"| node_transformer
node_cdnet -->|"classifies scales"| node_classifier
node_trainer -->|"computes loss"| node_loss
node_trainer -->|"measures IoU"| node_metrics
node_trainer -->|"saves weights"| node_checkpoint
node_operator -->|"starts prediction"| node_predictor
node_predictor -->|"loads test pairs"| node_testdata
node_predictor -->|"measures IoU"| node_metrics
node_predictor -->|"saves maps"| node_changemaps

click node_dataset "https://github.com/liumency/cropland-cd/blob/main/data_utils.py"
click node_augment "https://github.com/liumency/cropland-cd/blob/main/data_utils.py"
click node_trainer "https://github.com/liumency/cropland-cd/blob/main/train.py"
click node_options "https://github.com/liumency/cropland-cd/blob/main/train_options.py"
click node_loss "https://github.com/liumency/cropland-cd/blob/main/loss/losses.py"
click node_metrics "https://github.com/liumency/cropland-cd/blob/main/data_utils.py"
click node_checkpoint "https://github.com/liumency/cropland-cd/blob/main/train.py"
click node_cdnet "https://github.com/liumency/cropland-cd/blob/main/model/network.py"
click node_backbone "https://github.com/liumency/cropland-cd/blob/main/model/backbone.py"
click node_context "https://github.com/liumency/cropland-cd/blob/main/model/network.py"
click node_transformer "https://github.com/liumency/cropland-cd/blob/main/model/modules.py"
click node_classifier "https://github.com/liumency/cropland-cd/blob/main/model/network.py"
click node_predictor "https://github.com/liumency/cropland-cd/blob/main/predict.py"
click node_testdata "https://github.com/liumency/cropland-cd/blob/main/data_utils.py"
click node_changemaps "https://github.com/liumency/cropland-cd/blob/main/predict.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,node_augment,node_testdata toneBlue
class node_cdnet,node_backbone,node_context,node_transformer,node_classifier toneAmber
class node_trainer,node_options,node_loss,node_metrics,node_checkpoint toneMint
class node_predictor,node_changemaps toneRose
class node_operator toneIndigo
```

## Components

### Paired data

- [Dataset loaders](https://github.com/liumency/cropland-cd/blob/main/data_utils.py): `data_utils.py`
- [Pair augmentation](https://github.com/liumency/cropland-cd/blob/main/data_utils.py): `data_utils.py`
- [Test dataset](https://github.com/liumency/cropland-cd/blob/main/data_utils.py): `data_utils.py`

### Detection model

- [Change detector](https://github.com/liumency/cropland-cd/blob/main/model/network.py): `model/network.py`
- [CNN backbone](https://github.com/liumency/cropland-cd/blob/main/model/backbone.py): `model/backbone.py`
- [Transformer context](https://github.com/liumency/cropland-cd/blob/main/model/network.py): `model/network.py`
- [Attention modules](https://github.com/liumency/cropland-cd/blob/main/model/modules.py): `model/modules.py`
- [Multi-scale heads](https://github.com/liumency/cropland-cd/blob/main/model/network.py): `model/network.py`

### Training and evaluation

- [Training loop](https://github.com/liumency/cropland-cd/blob/main/train.py): `train.py`
- [Training options](https://github.com/liumency/cropland-cd/blob/main/train_options.py): `train_options.py`
- [Cross-entropy](https://github.com/liumency/cropland-cd/blob/main/loss/losses.py): `loss/losses.py`
- [IoU metric](https://github.com/liumency/cropland-cd/blob/main/data_utils.py): `data_utils.py`
- [Weight saving](https://github.com/liumency/cropland-cd/blob/main/train.py): `train.py`

### Prediction

- [Prediction script](https://github.com/liumency/cropland-cd/blob/main/predict.py): `predict.py`
- [Saved change maps](https://github.com/liumency/cropland-cd/blob/main/predict.py): `predict.py`

### Other components

- **Engineer**

## Connections

- Engineer → Training loop: starts training (evidence: `train.py`)
- Training options → Training loop: configures (evidence: `train.py`)
- Training loop → Dataset loaders: loads pairs (evidence: `train.py`)
- Dataset loaders → Pair augmentation: applies (evidence: `data_utils.py`)
- Training loop → Change detector: runs forward (evidence: `train.py`)
- Change detector → CNN backbone: extracts features (evidence: `model/network.py`)
- Change detector → Transformer context: aggregates context (evidence: `model/network.py`)
- Transformer context → Attention modules: uses attention (evidence: `model/network.py`)
- Change detector → Multi-scale heads: classifies scales (evidence: `model/network.py`)
- Training loop → Cross-entropy: computes loss (evidence: `train.py`)
- Training loop → IoU metric: measures IoU (evidence: `train.py`)
- Training loop → Weight saving: saves weights (evidence: `train.py`)
- Engineer → Prediction script: starts prediction (evidence: `predict.py`)
- Prediction script → Test dataset: loads test pairs (evidence: `predict.py`)
- Prediction script → IoU metric: measures IoU (evidence: `predict.py`)
- Prediction script → Saved change maps: saves maps (evidence: `predict.py`)
