Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b82ee01
feat(ramp): add Dockerfile and pipeline for EfficientNetB0 + U-Net se…
AbdelrahmanKatkat Mar 1, 2026
65251b1
feat(ramp): enhance pipeline with STAC integration and hyperparameter…
AbdelrahmanKatkat Mar 2, 2026
0c41a1a
feat(ramp): update Dockerfile and pipeline for improved functionality…
AbdelrahmanKatkat Apr 7, 2026
c01993e
feat(ramp): enhance pipeline with input resolution and model loading …
AbdelrahmanKatkat Apr 14, 2026
0121689
Merge branch 'master' into feature/ramp
AbdelrahmanKatkat Apr 14, 2026
bbae718
Merge branch 'master' into feature/ramp
AbdelrahmanKatkat Apr 21, 2026
394a826
refactor(ramp): update Dockerfile and pipeline for improved structure…
AbdelrahmanKatkat Apr 21, 2026
98d3d85
refactor(ramp): improve model resolution logic and update STAC item s…
AbdelrahmanKatkat Apr 22, 2026
0cdc85b
fix(ramp): update pretrained model source URLs in STAC item
AbdelrahmanKatkat Apr 23, 2026
b582bf0
refactor(ramp): streamline model resolution and enhance ZIP handling
AbdelrahmanKatkat Apr 28, 2026
96ca4ed
refactor(ramp): clean up code formatting and improve readability in p…
AbdelrahmanKatkat Apr 28, 2026
a2195de
fix(ramp): enforce requirement for RAMP baseline weights and update S…
AbdelrahmanKatkat Apr 29, 2026
a88076f
refactor(ramp): enhance type hinting and improve model handling in pi…
AbdelrahmanKatkat Apr 30, 2026
92b29b9
Merge branch 'master' into feature/ramp
AbdelrahmanKatkat May 4, 2026
79314fd
chore(ci): update just version to 1.39.0 in workflows
AbdelrahmanKatkat May 5, 2026
24b7e95
refactor(pipeline): streamline training directory creation and remove…
AbdelrahmanKatkat May 5, 2026
4a2956c
feat(pipeline): add output materializers for model training and ONNX …
AbdelrahmanKatkat May 5, 2026
1307685
feat(pipeline): support Keras model formats in model resolution and t…
AbdelrahmanKatkat May 6, 2026
4cebc65
feat(tests): enhance model training tests to support Keras model seri…
AbdelrahmanKatkat May 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/k8s-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jobs:
enable-cache: true

- uses: extractions/setup-just@v2
with:
just-version: "1.39.0"

- uses: helm/kind-action@v1
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/validate-stac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ jobs:
enable-cache: true
- name: Install just
uses: extractions/setup-just@v2
with:
just-version: "1.39.0"
- name: Install dependencies
run: uv sync --group dev
- name: Validate STAC items
Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,19 @@ implementation.md

# data
data/sample/predict/predictions
data/sample/ramp_work
data/sample/yolo_work
stac_catalog

# hatch-vcs generated version file
fair/_version.py


# runs
runs/

# weights
yolov8s_v2-seg.pt
# dev infra
infra/dev/.port-forward.pids
infra/dev/.pf-logs/
Expand Down
86 changes: 86 additions & 0 deletions models/ramp/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# syntax=docker/dockerfile:1.7

# Base image: ghcr.io/hotosm/fair-utilities-ramp:cpu-latest (or :gpu-latest via BASE_IMAGE build arg).
# Build from the fAIr-models repo root:
# docker build -f models/ramp/Dockerfile --target test -t ramp:test .
# docker build -f models/ramp/Dockerfile --target runtime -t ramp:runtime .
# docker build -f models/ramp/Dockerfile --target inference -t ramp:inference .
ARG BASE_IMAGE=ghcr.io/hotosm/fair-utilities-ramp:cpu-latest

# ---------------------------------------------------------------------------
# Builder stage: install model-pack deps into the base image venv
# ---------------------------------------------------------------------------
FROM ${BASE_IMAGE} AS builder

ENV UV_LINK_MODE=copy

COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /usr/local/bin/

WORKDIR /workspace

COPY pyproject.toml README.md fair_zenml_patch.pth /tmp/fair-src/
COPY fair /tmp/fair-src/fair

# The fair-utilities-ramp image already provides hot_fair_utilities, ramp-fair,
# segmentation_models, and TensorFlow under /app/.venv. Add the fAIr model-pack
# deps (fair itself, STAC validation, fairpredictor, onnx tooling) into that
# same venv so training, tests, and inference share one interpreter.
RUN --mount=type=cache,target=/root/.cache/uv \
SETUPTOOLS_SCM_PRETEND_VERSION=0.0.0 \
uv pip install --python /app/.venv/bin/python \
"pystac[validation]>=1.14.3" \
"universal-pathlib" \
"fairpredictor>=0.5.1" \
"onnx>=1.16" \
"tf2onnx>=1.16" \
/tmp/fair-src[k8s]

# ---------------------------------------------------------------------------
# Runtime stage: production image (no test deps)
# ---------------------------------------------------------------------------
FROM ${BASE_IMAGE} AS runtime

WORKDIR /workspace

ENV PATH="/app/.venv/bin:$PATH" \
MPLBACKEND=Agg \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
RAMP_HOME=/app \
SM_FRAMEWORK=tf.keras

COPY --from=builder /app/.venv /app/.venv

COPY models/ramp models/ramp
COPY models/conftest.py models/conftest.py
COPY models/test_integration.py models/test_integration.py

ENTRYPOINT ["/app/.venv/bin/python"]

# ---------------------------------------------------------------------------
# Test stage: add pytest + ZenML server deps for step & integration tests
# ---------------------------------------------------------------------------
FROM runtime AS test

COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
COPY --from=builder /tmp/fair-src /tmp/fair-src

RUN --mount=type=cache,target=/root/.cache/uv \
SETUPTOOLS_SCM_PRETEND_VERSION=0.0.0 \
uv pip install --python /app/.venv/bin/python /tmp/fair-src[test]

# ---------------------------------------------------------------------------
# Inference stage: runtime + serving deps for the smoke test / live API
# ---------------------------------------------------------------------------
FROM runtime AS inference

COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
COPY --from=builder /tmp/fair-src /tmp/fair-src

RUN --mount=type=cache,target=/root/.cache/uv \
SETUPTOOLS_SCM_PRETEND_VERSION=0.0.0 \
uv pip install --python /app/.venv/bin/python /tmp/fair-src[serve]

ENV PYTHONPATH=/workspace
EXPOSE 8080
CMD ["/app/.venv/bin/uvicorn", "fair.serve.base:create_app", "--factory", "--host", "0.0.0.0", "--port", "8080"]
60 changes: 60 additions & 0 deletions models/ramp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# RAMP EfficientNetB0 + U-Net Building Segmentation

Semantic segmentation model for building footprint extraction from RGB aerial imagery, derived from the RAMP (Replicable AI for Microplanning) project.

## Architecture

- **Model**: EfficientNetB0 encoder + U-Net decoder (`EffUnet`)
- **Framework**: TensorFlow 2.15 / `tf.keras` (via `segmentation_models` with `SM_FRAMEWORK=tf.keras`)
- **Task**: Semantic segmentation (sparse categorical crossentropy)
- **Input**: RGB chips (256x256, float32, channels-last)
- **Classes**: 4 (background=0, building=1, boundary=2, contact=3)

The boundary (class 2) and contact (class 3) channels help the model cleanly separate adjacent buildings at inference time, even when they share a wall. The `predict()` helper collapses the 4-class softmax to a binary building mask before vectorization.

## Pretrained Source

Baseline RAMP weights (TensorFlow SavedModel) hosted by HOTOSM:

- Checkpoint: `https://api-prod.fair.hotosm.org/api/v1/workspace/download/ramp/baseline.zip`
- ONNX model: `https://api-prod.fair.hotosm.org/api/v1/workspace/download/ramp/ramp-v1.onnx`

## Pipeline

Training pipeline steps (ZenML) defined in `pipeline.py`:

- `split_dataset` - preprocesses chips + labels into 4-class multimasks and produces a seeded random train/validation split via `hot_fair_utilities.split_training_2_validation`
- `train_model` - fine-tunes RAMP on the split, returning the best SavedModel serialized as a zipped byte stream
- `evaluate_model` - computes `fair:accuracy`, `fair:mean_iou` (building IoU), `fair:precision`, and `fair:recall` on the validation split
- `export_onnx` - converts the trained SavedModel to an ONNX byte stream via `tf2onnx`

Inference is served through `fair.serve.base`, which calls the module-level `predict(session, input_images, params) -> FeatureCollection`: each chip is preprocessed, run through an `onnxruntime` session, decoded to a binary building mask, and vectorized to georeferenced polygons.

## Base Image

Training, test, and inference Docker stages all build on
`ghcr.io/hotosm/fair-utilities-ramp:cpu-latest` (or `:gpu-latest` via the
`BASE_IMAGE` build arg), which provides TensorFlow, GDAL, `hot_fair_utilities`
RAMP extras, and the RAMP runtime under `/app/.venv`.

```bash
# Build targets
docker build -f models/ramp/Dockerfile --target runtime -t ramp:runtime .
docker build -f models/ramp/Dockerfile --target test -t ramp:test .
docker build -f models/ramp/Dockerfile --target inference -t ramp:inference .
```

## Limitations and Bias

- Training data and baseline weights are derived from the RAMP corpus (primarily humanitarian-mapping contexts); performance on dense urban scenes with complex roof structures may be lower than on sparser rural settlements.
- The model is sensitive to imagery with strong color casts, motion blur, or significant off-nadir angle; preprocess inputs to approximately nadir RGB at the target zoom before inference.
- Binary building output from `predict()` discards the boundary/contact auxiliary classes after decoding; downstream polygonization may still merge neighbouring buildings that share a footprint edge.

## Citation

RAMP - Replicable AI for Microplanning. Upstream source: https://github.com/radiantearth/ramp-code

## License

- Model weights and code: Apache-2.0
- Training data: ODbL-1.0 (OpenStreetMap-derived labels)
Loading
Loading