File size: 8,951 Bytes
9ec5995 370c8ad 9ec5995 370c8ad 9ec5995 370c8ad 9ec5995 ec89b51 9ec5995 370c8ad 9ec5995 370c8ad 9ec5995 370c8ad 9ec5995 6daa104 9ec5995 ec89b51 370c8ad ec89b51 6daa104 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | # Dynamic World land-cover segmentation
This project owns one data preparation workflow and one AI task:
- **Data:** pair Dynamic World human annotations with Sentinel-2 L2A imagery
on the labels' grid. The independent `data/` repository owns preparation,
provenance, splits and exploratory analysis.
- **AI task:** semantic segmentation into nine Dynamic World land-cover classes.
Compare model accuracy and inference speed, then release the selected model
with its georeferenced prediction pipeline.
- **Method:** supervised learning. Encoder/decoder choices are experiments
within this task, configured in `configs/`.
Training runs through GeoSave's LightningCLI (`main.py`). Each project has one
AI task; additional methods for that task belong in `modules/<method>/`.
Three repos, one job each:
| Repo | Holds |
| --- | --- |
| [`fatmur/dynamicworld`](https://huggingface.co/fatmur/dynamicworld) (this one) | experiment code and configs |
| [`datasets/fatmur/dynamicworld`](https://huggingface.co/datasets/fatmur/dynamicworld) | label releases, image and label pairs, the scripts and notebook that make them |
| `fatmur/dynamicworld-<model>`, such as [`fatmur/dynamicworld-small-cnn`](https://huggingface.co/fatmur/dynamicworld-small-cnn) | one released model each: weights, pipeline, model card |
## Layout
```text
project.yaml AI task and data directory
main.py LightningCLI entry point
configs/ one self-contained file per experiment
βββ small_cnn_unet.yaml small CNN on RGB, CPU
βββ dinov3_s_dpt.yaml DINOv3 S/16 + DPT on RGB, GPU; not trained yet
modules/supervised/
βββ datasets.py SceneDataset: image GeoTIFF + label GeoTIFF -> Sample
βββ data.py Sample, DataModule: batches, crops and augments
βββ module.py Module: trains on crops, validates on whole scenes
scripts/
βββ publish.py checkpoint -> Hub repo; optional local export
data/ data repo: EDA, raw releases and prepared pairs
artifacts/ TensorBoard runs, configs and checkpoints
release/ optional local model exports
```
The task is plain semantic segmentation: a sample is one 510Γ510 px image
and its original annotation on the same grid, paired through the annotation catalogue.
```text
data/processed/scene.parquet ββΆ explicit split/source selection
ββ image_path + label_path ββΆ SceneDataset ββΆ DataModule ββΆ Module
```
A config records the data selection, label scheme and model settings. Two
settings are shared with the release, and `publish.py` copies both into it,
so inference prepares and chips a raster exactly as training and validation
did. The run config also freezes `label_scheme`: original annotation codes are
remapped only by `SceneDataset`, and publication uses the same class names and
colors rather than an independently selected target:
| Config | Used in training by | In the release |
| --- | --- | --- |
| `data.train.init_args.preprocessor` (GeoSave's `dense`) | `SceneDataset`, on every image | the pipeline's preprocessor |
| `model.chip_size`, `chip_stride`, `chip_mode`, `merge_window`, `chip_batch_size` | `Module.predict_chips`, in validation | the pipeline's `dense` predictor |
## Commands
```bash
hf download fatmur/dynamicworld --type dataset --local-dir data
python main.py fit --config configs/small_cnn_unet.yaml
python -m scripts.publish fatmur/dynamicworld-small-cnn \
artifacts/small_cnn_unet/version_0/checkpoints/<name>.ckpt
# Optional local copy alongside direct Hub publication:
# add --out release/dynamicworld-small-cnn
```
```python
import xarray as xr
import geosave as gs
from geosave.ml import load_pipeline
pipeline = load_pipeline("fatmur/dynamicworld-small-cnn")
image = gs.open_raster("data/processed/image/train/<scene>.tif")
product = pipeline.predict(xr.DataTree.from_dict({"image": image}))
```
The data repo's `eda.ipynb` explains the original tables, annotation sources,
voting rules and scene overlap. It assigns splits, copies labels unchanged and
writes `processed/label.parquet`. Ingestion discovers source STAC Items, acquires
each selected scene once and writes `processed/scene.parquet`, including paths,
biome metadata, geometry and diagnostics for pending, successful and failed scenes.
Training selects expert rows explicitly and remaps original codes only in memory.
The test dataset selects the supplied consensus composites. The notebook displays intermediate tables and uses GeoSave for raster plots.
After selecting a checkpoint using development validation, run final evaluation:
```bash
python main.py test --config configs/small_cnn_unet.yaml --ckpt_path <checkpoint>
```
This scores only the ingested test subset. Acquire the complete 409-scene cohort
before reporting a full benchmark result. Test metrics never select checkpoints.
## Run outputs and releases
TensorBoard owns each run directory, `artifacts/<model_name>/version_N/`.
Lightning saves `config.yaml`, `hparams.yaml`, event logs and `checkpoints/`
there. Leave `ModelCheckpoint.dirpath` unset so checkpoints follow the logger.
`last.ckpt` resumes training; the best-scoring checkpoint is selected by
`val_iou_macro`. The legacy top-level `checkpoints/last.ckpt` is retained as
an existing training result, but is not the destination of current configs.
`python -m scripts.publish` reconstructs the pipeline and calls the native
Hugging Face `push_to_hub` API. Each released model has its own Hub repository.
A local export is optional and belongs under `release/`, outside run artifacts.
## Experiment plan
Publish a size ladder of segmentation models and measure speed against accuracy.
| Stage | Runs | Varies |
| --- | --- | --- |
| 0 pipeline | small CNN + UNet, RGB (`small_cnn_unet.yaml`) | proves data β training β release |
| 1 baseline | DINOv3 S/16 (lvd1689m) + DPT, RGB (`dinov3_s_dpt.yaml`) | first pretrained encoder |
| 2 encoders | DINOv3 S/B/L lvd1689m and L sat493m (RGB); Prithvi-EO-2.0 300/600 (6 bands); Clay v1.5 L (10 bands) | encoder, bands |
| 3 ablations on the best | UNet vs DPT; augmentation none/flip/rotate; experts only vs + non-expert | one thing each |
A stage gets its config when it is run; only stages 0 and 1 have one now.
Training draws one random 256 px crop per scene and epoch. Validation scores
whole 510 px scenes, predicted chip by chip and merged with the release's
predictor settings.
### Evaluation scope and limits
- EDA prepares the full dataset and ingestion processes every prepared scene;
`data/README.md` records the earlier 300-scene study.
- All 409 published evaluation locations belong to test. Our seed-0 80/20
expert-location development split is a project choice, not a verified original
paper assignment. Overlapping held-out footprints are excluded from training.
- The global baseline trains on expert and non-expert labels across all biomes.
Val stays expert-only; test uses consensus. Training uses completed imagery,
so full-dataset training requires complete ingestion. Regional fine-tuning can
follow later. Our L2A inputs differ from the paper's L1C inputs.
- The earlier checkpoint and normalization statistics used a different cohort.
Current configs mark their statistics as historical. Recompute training-only
normalization and train a new run before claiming results for the new sample.
- Earlier models selected using the consensus cohort cannot retrospectively
claim it as unseen test data. Old per-split folders are retained as history;
current configs read only `scene.parquet`.
- Existing run configs without `label_scheme` need their actual training
taxonomy recorded explicitly before using the updated publisher.
## Sources
Human annotations: Dynamic World Project, National Geographic Society with
Google and the World Resources Institute, CC-BY-4.0.
[Annotations](https://doi.pangaea.de/10.1594/PANGAEA.933475) Β·
[Paper](https://doi.org/10.1038/s41597-022-01307-4).
Imagery: Copernicus Sentinel-2 data terms apply.
### Scene context and cloud masking
`Sample` includes `centroid` (latitude, longitude), `year`, and `day_of_year`
(starting at 1), read through `gs.to_tensor`. Augmentation and tensor chipping
retain the source scene's context. The model chain passes these fields to encoders
that need them, including Prithvi TL. Release raster chipping computes context
from each chip, including its own centroid.
The Dataset uses `scl_valid_mask` to set invalid target pixels to `ignore_index`.
SCL codes 0, 1, 3, 8, 9 and 10 are ignored; dark areas, vegetation, bare soil,
water, unclassified pixels and snow remain valid. SCL is not a model input band.
Input imagery must contain SCL and an acquisition date.
|