Multi-task U-Net: land cover and forest-cover loss, Kaziranga / Karbi Anglong (Assam, India)
Final-year project: Satellite Image Segmentation for Land Cover and Deforestation Mapping Using Deep Learning. Code, pipeline and full documentation: https://github.com/Shashwat-Vijayvergiya/Satellite
One TensorFlow/Keras multi-task U-Net predicts two pixel-level maps from bi-temporal Sentinel-2 composites at 30 m:
| Output | Shape | Meaning |
|---|---|---|
landcover | (H, W, 5) softmax | 0 tree cover, 1 grassland, 2 cropland, 3 built-up, 4 water (ESA WorldCover 2021 classes) |
deforestation | (H, W, 1) sigmoid | probability of gross forest-cover loss 2021–2023 (Hansen GFC v1.12 definition) |
The root of this repository is the final model (experiment E3). All other trained models are in experiments/.
Scores measure agreement with the reference labels (ESA WorldCover 2021, Hansen Global Forest Change v1.12) on a held-out geographic test region. They are not independently verified ground-truth accuracy. "Forest loss" means gross stand-replacement forest-cover loss (it includes harvest, shifting cultivation, fire and river change), not strictly deforestation.
Results (held-out geographic test region, 108 patches of 128 x 128 px)
| Task | Metric | Final model (E3) | Baseline | Trivial baseline |
|---|---|---|---|---|
| Land cover | Overall accuracy | 0.889 | 0.877 | 0.644 (majority class) |
| Land cover | Mean IoU / mean Dice | 0.600 / 0.708 | 0.561 / 0.669 | 0.129 |
| Land cover | IoU tree / crop / water / built-up / grass | 0.900 / 0.744 / 0.789 / 0.398 / 0.169 | 0.890 / 0.720 / 0.771 / 0.266 / 0.159 | |
| Forest loss | Precision / Recall / F1 / IoU | 0.449 / 0.694 / 0.545 / 0.375 | 0.391 / 0.702 / 0.502 / 0.335 | |
| Forest loss | PR-AUC | 0.584 | 0.558 | 0.0105 (random) |
| Forest loss | Decision threshold (tuned on validation) | 0.70 | 0.43 |
Model selection (validation only; the test region was used once, for the winner)
| Folder | Model | Change | Val mIoU | Val PR-AUC | Score |
|---|---|---|---|---|---|
experiments/baseline | Baseline | 12 bands, transposed-conv decoder, class-weight cap 10 | 0.581 | 0.462 | 1.044 |
experiments/e1 | E1 | + bilinear upsampling, class-weight cap 3 | 0.573 | 0.485 | 1.057 |
experiments/e2 | E2 | + NDVI/NBR pre, post and change channels (18 inputs) | 0.591 | 0.478 | 1.069 |
| root | E3 (final) | + overlapping training patches (stride 64) | 0.628 | 0.502 | 1.130 |
experiments/baseline_repeat | Baseline, 2nd run | same config as baseline (run-to-run check) | — | — | test OA 0.877, mIoU 0.559, F1 0.511, PR-AUC 0.558 |
Files in each model folder
| File | Content |
|---|---|
best.keras | trained model (best validation loss); load with compile=False |
band_stats.json | normalisation statistics (train region only); required for inference |
run_config.yaml | exact configuration used for training |
metadata.json, train_info.json | lineage, class weights, epochs, parameters |
history.csv, training_curves.png | per-epoch training and validation metrics |
metrics.json | test + validation metrics (final model, baseline, baseline_repeat) |
metrics_val_only.json | validation-only selection metrics |
threshold.json (root) | forest-loss threshold tuned on validation |
figures/ (root) | confusion matrices, PR curve, threshold sweep, test examples, full-scene preview |
Input
Two Sentinel-2 L2A median composites (dry season), surface reflectance x 10000 (uint16), resampled to 30 m:
pre = 1 Nov 2020 – 28 Feb 2021, post = 1 Nov 2023 – 29 Feb 2024; bands B2, B3, B4, B8, B11, B12 each.
Channel order: pre_B2, pre_B3, pre_B4, pre_B8, pre_B11, pre_B12, post_B2, …, post_B12 (12 raw channels).
Model input (E1 and baseline use only the first 12 channels; E2 and E3 use all 18):
- The 12 bands, each clipped to
[p_low, p_high]and standardised withmean,stdfromband_stats.json. - E2/E3 only: NDVI = (B8−B4)/(B8+B4) and NBR = (B8−B12)/(B8+B12) from the raw values, for pre, post and post − pre, in the order
ndvi_pre, ndvi_post, ndvi_change, nbr_pre, nbr_post, nbr_change(0 where the denominator is 0).
Usage
import json, numpy as np, keras
from huggingface_hub import hf_hub_download
repo = "ShashwatVj/assam-landcover-forest-loss-unet"
model = keras.models.load_model(hf_hub_download(repo, "best.keras"), compile=False)
stats = json.load(open(hf_hub_download(repo, "band_stats.json")))
threshold = json.load(open(hf_hub_download(repo, "threshold.json")))["value"] # 0.70
def model_input(raw): # raw: (H, W, 12) uint16, channel order above
x = np.clip(raw.astype(np.float32), stats["p_low"], stats["p_high"])
x = (x - np.float32(stats["mean"])) / np.float32(stats["std"])
ch = stats["channels"]
def nd(date, a, b):
p, q = raw[..., ch.index(f"{date}_{a}")].astype(np.float32), raw[..., ch.index(f"{date}_{b}")].astype(np.float32)
return np.divide(p - q, p + q, out=np.zeros_like(p), where=(p + q) > 0)
idx = []
for a, b in (("B8", "B4"), ("B8", "B12")): # NDVI, NBR
pre, post = nd("pre", a, b), nd("post", a, b)
idx += [pre, post, post - pre]
return np.concatenate([x, np.stack(idx, -1)], -1) # (H, W, 18)
patch = ... # (128, 128, 12) uint16 window
out = model.predict(model_input(patch)[None])
landcover = out["landcover"][0].argmax(-1) # 0..4
loss_mask = out["deforestation"][0, ..., 0] >= threshold # bool
Input height and width must be multiples of 16; the training patches were 128 x 128. For full scenes, the project's scripts/predict.py tiles the image with overlap and writes GeoTIFFs.
Training
- Study area: Kaziranga / Karbi Anglong, Assam, India. EPSG:32646, 30 m, 3009 x 3704 px (≈10,031 km²).
- Labels:
- ESA WorldCover 2021 v200, remapped to 5 classes. Shrubland, bare and wetland are ignored. Land cover is also ignored on 2021–23 loss pixels.
- Hansen GFC v1.12
loss_target: loss in 2021–2023 on ≥ 30 % canopy (2000).
- Spatial split:
- 512 px blocks are assigned to train/val/test before patching, with a 1-patch buffer.
- 317 / 71 / 108 base patches. E3 adds 765 overlapping train patches that lie fully inside the train region.
- Model:
- Shared encoder (16-32-64-128, bottleneck 256, dropout 0.2) and two separate decoders.
- E3 uses bilinear upsampling + 3x3 convolutions in the decoders; 3,146,726 parameters.
- Losses:
- Land cover: masked class-weighted cross-entropy, sqrt inverse-frequency weights.
- Forest loss: masked positive-weighted BCE (pos_weight 7.59) + soft Dice.
- Optimisation: Adam 1e-3, batch 8, early stopping (patience 8). E3 trained for 37.6 min on a 12-thread CPU (best epoch 14 of 22).
Limitations
- One region, one geographic split, one training run per experiment.
- The reference labels are model-derived products:
- WorldCover grassland and cropland are often confused.
- Hansen labels are speckled at 30 m.
- Grassland is weak (IoU 0.17); built-up is moderate (IoU 0.40).
- The F1-tuned threshold favours recall, so full-scene loss area is over-estimated: 248.5 km² predicted vs 135.6 km² in Hansen. Use the maps for where loss occurs, not how much.
- The model is unlikely to transfer to other regions, seasons or sensors without retraining.
Data sources and citations
- Sentinel-2: Copernicus Sentinel-2 L2A (harmonized) and Cloud Score+, via Google Earth Engine.
- WorldCover: Zanaga et al. 2022, ESA WorldCover 10 m 2021 v200, doi:10.5281/zenodo.7254221 (CC-BY-4.0).
- Hansen GFC: Hansen et al. 2013, Science 342:850–853, doi:10.1126/science.1244693; GFC v1.12 (CC-BY-4.0).
- U-Net: Ronneberger et al. 2015, U-Net, MICCAI.