Skip to content

Feature/ramp - #39

Open
AbdelrahmanKatkat wants to merge 47 commits into
developfrom
feature/ramp
Open

Feature/ramp#39
AbdelrahmanKatkat wants to merge 47 commits into
developfrom
feature/ramp

Conversation

@AbdelrahmanKatkat

@AbdelrahmanKatkat AbdelrahmanKatkat commented Apr 14, 2026

Copy link
Copy Markdown

What does this PR do?

Adds / documents RAMP building-footprint segmentation (models/ramp): a 4‑class semantic building segmentation model (background, building, boundary, contact) built on an EfficientNetB0 encoder + U‑Net decoder. The fAIr serving path returns building GeoJSON polygons in EPSG:4326 derived from the predicted mask.


Summary

Field Value
Task Building footprint extraction
Input 3‑band RGB chips (OAM tiles / GeoTIFF)
Output GeoJSON FeatureCollection of Polygon features in EPSG:4326, each with class and confidence
Model type Semantic segmentation (4‑class mask → polygons)
Coverage Global baseline + per‑area fine‑tuning on user-labelled chips
Use cases Fast semantic mask baseline, coarse building inventory, AOI-specific fine-tuning experiments
License Apache‑2.0

When to pick this model

  • You want a fast semantic building segmentation baseline that can be fine-tuned on small AOIs.
  • You can tolerate that dense/touching roofs may be merged because the model is semantic, not instance.

Intended use

Direct inference on OpenAerialMap tiles, and optional fine‑tuning on small downstream labelled sets (~100–200 chips) when local imagery differs from the baseline distribution.

Typical workflow

  1. Provide a TMS URL + bounding box (or a directory of georeferenced RGB chips).
  2. Run inference via the serving container (POST /predict) or the inference pipeline.
  3. Receive EPSG:4326 polygons suitable for OSM / vector stores.

How to use

Live inference

POST /predict expects:

{
  "model_uri":  "https://huggingface.co/hotosm/ramp/resolve/83c77a7e5feb3af62e3604d7bb96c6c6e9ff1a96/ramp-v1.onnx",
  "image_uri":  "https://tiles.openaerialmap.org/.../{z}/{x}/{y}",
  "bbox":       [west, south, east, north],
  "zoom":       18,
  "params":     {"confidence_threshold": 0.5, "min_class_value": 1}
}

The server downloads tiles for the bbox, runs ONNX inference, and returns a GeoJSON FeatureCollection. Each feature has properties.class = 1 and properties.confidence.


Inference parameters

Catalog defaults from models/ramp/stac-item.json:

Parameter Default Meaning
confidence_threshold 0.5 Current serve path uses this as per-feature confidence
min_class_value 1 Building class id when collapsing the 4‑class mask to binary

Inputs and outputs

Input contract

A directory of RGB chips (.tif / .tiff / .png). The platform downloader (geomltoolkits.downloader.tms) produces this automatically from a TMS URL + bbox.

Output contract

A GeoJSON FeatureCollection in EPSG:4326. Each feature:

{
  "type": "Feature",
  "properties": {"class": 1, "confidence": 0.5},
  "geometry":   {"type": "Polygon", "coordinates": [...]}
}

Architecture

Component Description
Encoder EfficientNetB0
Decoder U‑Net
Head 4‑class sparse categorical mask: bg / building / boundary / contact
Instance separation Not native (semantic). Boundary/contact are present in labels but not currently used in serving decode.

Training labels (multimasks)

RAMP training uses polygon-derived multimasks with explicit separation channels:

Parameter Value Meaning
boundary_width 3 px thickness of boundary ring
contact_spacing 8 px spacing for “contact” points between neighboring buildings

Evaluation (Banepa, Nepal — polymetrics)

Truth: 2720 OSM building polygons (data/sample/test/osm/labels.geojson)
Metric: object-level matching (Hungarian) with IoU thresholds

Banepa @ IoU 0.5

Output Source artifact TP / FP / FN Precision Recall F1@0.5
Zero-shot (base) ci-artifacts/github_result_ramp/ramp-predictions-base.geojson 376 / 2419 / 2344 0.135 0.138 0.136
Per-area tuned (local ONNX serve output) ci-artifacts/ramp-predictions.geojson 95 / 2654 / 2625 0.035 0.035 0.035
Baseline fairpredictor (TFLite + merged-mask postprocess) ci-artifacts/ramp-predictions-fairpredictor.geojson 250 / 2145 / 2470 0.104 0.092 0.098

Banepa @ IoU 0.25

Output TP / FP / FN Precision Recall F1@0.25
Zero-shot (base) 1220 / 1575 / 1500 0.436 0.449 0.442
Per-area tuned (local ONNX serve output) 1275 / 1474 / 1445 0.464 0.469 0.466
Baseline fairpredictor 1064 / 1331 / 1656 0.444 0.391 0.416

Notes

  • RAMP often produces visually plausible roof blobs that land in the IoU 0.25–0.5 band
  • Because this is semantic segmentation, touching buildings can merge into one polygon (penalized heavily by object-level scoring).

Where it works best

  • VHR RGB imagery (~30–50 cm GSD) where roof boundaries are visible.
  • AOIs where a semantic mask baseline is acceptable and downstream cleanup is possible.

Where to use caution

  • Dense urban with touching roofs: semantic blobs merge instances → F1@0.5 drops.
  • If strict instance performance matters, use an instance model or add boundary/contact-aware splitting.

License & citation

  • Apache‑2.0
  • Upstream citation link in STAC: https://github.com/devglobalpartners/ramp-code

AbdelrahmanKatkat and others added 7 commits March 1, 2026 23:54
…mantic segmentation model

- Introduced Dockerfile for building the RAMP model environment with GPU and CPU support.
- Added pipeline.py for defining the ZenML pipeline, including preprocessing, training, inference, and postprocessing steps.
- Created README.md to document the model architecture, usage, and data layout.
- Implemented stac-item.json for STAC catalog integration.
- Included smoke tests to validate the Docker runtime and model functionality.
- Updated .gitignore to exclude new data directories.
… loading

- Updated pipeline.py to load hyperparameters from STAC Item JSON, streamlining model configuration.
- Modified training_pipeline to accept a path to the STAC Item, allowing for flexible hyperparameter management.
- Revised README.md to reflect changes in hyperparameter handling and usage of STAC Item.
- Enhanced stac-item.json with additional metadata and structure for better integration.
- Removed outdated CODE_EXPLAINED.md and README.md from tests directory to clean up documentation.
… and compatibility

- Refactored Dockerfile to streamline the build process, using a base image from GHCR for both CPU and GPU.
- Enhanced pipeline.py to support new model weight loading mechanisms and improved error handling for model paths.
- Updated README.md to reflect changes in framework version and model usage, including new data directory structure.
- Revised stac-item.json to include updated model weights source and additional metadata for better integration.
- Improved smoke tests to validate the new pipeline functionality and ensure compatibility with the latest TensorFlow/Keras versions.
- Added per-file ignores in Ruff for specific linting rules in pipeline.py.
…improvements

- Added functions to resolve local and remote input directories and files, improving flexibility in handling model paths.
- Implemented a zip extraction utility for loading models from compressed files.
- Updated `resolve_model_href` to support both local and remote SavedModel directories, enhancing compatibility with various model formats.
- Modified smoke tests to validate the new `split_dataset` functionality alongside training wrappers, ensuring robust model training and validation.
… and dependencies

- Refactored Dockerfile to separate build, runtime, test, and inference stages for better clarity and efficiency.
- Updated `pyproject.toml` to remove unnecessary lint ignores.
- Enhanced `pipeline.py` with improved model resolution and added support for lazy imports.
- Revised README.md for clarity on architecture and usage.
- Added test fixtures for a toy dataset and implemented step tests for the RAMP pipeline.
- Updated STAC item schema to version 1.1.0 and included additional metadata properties.
@codecov

codecov Bot commented Apr 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.27%. Comparing base (186a987) to head (6e4d2d3).

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #39   +/-   ##
=======================================
  Coverage   97.27%   97.27%           
=======================================
  Files          44       44           
  Lines        3892     3893    +1     
=======================================
+ Hits         3786     3787    +1     
  Misses        106      106           
Flag Coverage Δ
fair 96.21% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…ources

- Refactored model resolution logic in `pipeline.py` for clarity and efficiency.
- Updated `pretrained_source` and `checkpoint` URLs in `stac-item.json` to point to Hugging Face.
- Adjusted metadata properties in `stac-item.json` for consistency and accuracy.
- Simplified the `resolve_model_href` function to focus on .onnx and .zip formats.
- Improved error handling for unsupported model formats and missing files.
- Updated ZIP extraction logic to ensure proper directory creation and cache management.
- Removed deprecated code and comments for better readability.
…ipeline.py

- Consolidated multi-line string definitions into single lines for consistency.
- Removed unnecessary blank lines to enhance code clarity.
- Streamlined parameter retrieval in several functions for better readability.
…TAC item references

- Removed the default baseline URL in `pipeline.py` and raised a ValueError if weights are not provided.
- Updated `pretrained_source` and `checkpoint` URLs in `stac-item.json` to point to the new Hugging Face location.
- Adjusted the `create_toy_data` function to ensure it uses a GeoJSON file for labels, aligning with the expectations in `pipeline.py`.
…peline.py

- Updated type hints for several functions to use Optional and Union for better clarity.
- Introduced a new function `_normalize_to_savedmodel_dir` to streamline model path normalization.
- Improved error handling and readability in model resolution and checkpoint restoration logic.
- Consolidated ZIP handling and model loading processes for better maintainability.
… unused cache function; update hyperparameters specification in stac-item.json
Comment thread models/ramp/README.md Outdated
Comment thread models/ramp/README.md Outdated
kshitijrajsharma and others added 21 commits May 17, 2026 00:17
Added a new function `_resolve_labels_geojson` to handle the resolution of dataset labels, supporting both direct file paths and directories containing a single labels file. Updated `_materialize_training_input` to utilize the new label resolution function, enhancing input handling for training datasets.
…th handling

Refactored the `_resolve_labels_geojson` function to simplify label resolution for GeoJSON/JSON files, removing redundant file path checks. Introduced a new helper function `_resolve_model_file_path` to handle the resolution of model file paths from various sources, improving code organization and maintainability. Updated the STAC item JSON to reflect a new citation URL.
Added new labels for training and inference to the kind configuration. Updated the default values for training epochs and batch size in the STAC item JSON, reflecting a more suitable configuration for model training.
…ration

Deleted the training and inference labels from the kind configuration file to streamline the setup and reduce unnecessary complexity.
…n logging

Added MLflow training context to the model training process for better tracking. Enhanced model evaluation by logging evaluation results for both zero metrics and computed metrics, improving observability of model performance.
Changed the output materializer label from "trained_model" to "trained_model_artifact" in the train_model function to better reflect the returned artifact type.
Updated the model loading process to support both `.keras` and `.h5` formats, improving flexibility. Adjusted evaluation metrics to remove the "fair:" prefix for consistency. Additionally, modified the STAC item JSON to reduce training epochs and batch size for better initial training performance.
Renamed and refactored functions for clarity and consistency in handling local and remote paths. Updated the model loading process to exclusively support ZIP files containing SavedModel directories, enhancing error handling and simplifying the extraction logic. Adjusted related function calls to reflect these changes, improving overall code maintainability.
…rfile user to root

Modified the STAC item JSON to change the ID and name from "ramp-v1" to "ramp" for better alignment with naming conventions. Updated the Dockerfile to set the user to root, ensuring the k8s ZenML orchestrator can access the in-cluster service account token without authentication issues.
Eliminated the USER root directive from the Dockerfile, as it was no longer needed for the k8s ZenML orchestrator to access the in-cluster service account token. This change simplifies the Dockerfile and enhances security by avoiding unnecessary root privileges.
Enhanced the README.md to provide a clearer overview of the RAMP EfficientNetB0 + U-Net model, including detailed architecture, input/output specifications, pretrained artifacts, and usage instructions for inference and fine-tuning. Added limitations and citation information for better context and usability.
…raining

Introduced a new `sample_fraction` parameter to control the fraction of chip files used during training across multiple models. This allows for faster smoke and CI runs by enabling stride sampling. Updated relevant model pipelines and STAC item JSON files to reflect this change, ensuring consistency in model configurations. Additionally, added unit tests for the new functionality to validate its behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants