-
Notifications
You must be signed in to change notification settings - Fork 2
Feature/ramp #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AbdelrahmanKatkat
wants to merge
47
commits into
master
Choose a base branch
from
feature/ramp
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature/ramp #39
Changes from 22 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
b82ee01
feat(ramp): add Dockerfile and pipeline for EfficientNetB0 + U-Net se…
AbdelrahmanKatkat 65251b1
feat(ramp): enhance pipeline with STAC integration and hyperparameter…
AbdelrahmanKatkat 0c41a1a
feat(ramp): update Dockerfile and pipeline for improved functionality…
AbdelrahmanKatkat c01993e
feat(ramp): enhance pipeline with input resolution and model loading …
AbdelrahmanKatkat 0121689
Merge branch 'master' into feature/ramp
AbdelrahmanKatkat bbae718
Merge branch 'master' into feature/ramp
AbdelrahmanKatkat 394a826
refactor(ramp): update Dockerfile and pipeline for improved structure…
AbdelrahmanKatkat 98d3d85
refactor(ramp): improve model resolution logic and update STAC item s…
AbdelrahmanKatkat 0cdc85b
fix(ramp): update pretrained model source URLs in STAC item
AbdelrahmanKatkat b582bf0
refactor(ramp): streamline model resolution and enhance ZIP handling
AbdelrahmanKatkat 96ca4ed
refactor(ramp): clean up code formatting and improve readability in p…
AbdelrahmanKatkat a2195de
fix(ramp): enforce requirement for RAMP baseline weights and update S…
AbdelrahmanKatkat a88076f
refactor(ramp): enhance type hinting and improve model handling in pi…
AbdelrahmanKatkat 92b29b9
Merge branch 'master' into feature/ramp
AbdelrahmanKatkat 79314fd
chore(ci): update just version to 1.39.0 in workflows
AbdelrahmanKatkat 24b7e95
refactor(pipeline): streamline training directory creation and remove…
AbdelrahmanKatkat 4a2956c
feat(pipeline): add output materializers for model training and ONNX …
AbdelrahmanKatkat 1307685
feat(pipeline): support Keras model formats in model resolution and t…
AbdelrahmanKatkat 4cebc65
feat(tests): enhance model training tests to support Keras model seri…
AbdelrahmanKatkat 1a8f706
refactor(ramp): update Dockerfile for inference stages and modify ent…
AbdelrahmanKatkat 1c7afe5
feat(pipeline): enhance postprocessing function to validate CRS and s…
AbdelrahmanKatkat 73137db
refactor(ramp): update Dockerfile to use GPU base image and enhance t…
AbdelrahmanKatkat 23ac532
Merge branch 'master' into feature/ramp
AbdelrahmanKatkat 28243f0
Merge remote-tracking branch 'origin/master' into feature/ramp
kshitijrajsharma af807a1
Merge remote-tracking branch 'origin/master' into feature/ramp
kshitijrajsharma 95e0692
Merge remote-tracking branch 'origin/master' into feature/ramp
kshitijrajsharma 82d2158
Merge remote-tracking branch 'origin/master' into feature/ramp
kshitijrajsharma d03c412
Merge remote-tracking branch 'origin/master' into feature/ramp
kshitijrajsharma 153c6db
Merge branch 'master' into feature/ramp
AbdelrahmanKatkat 810cc79
Merge branch 'feature/ramp' of https://github.com/hotosm/fAIr-models …
AbdelrahmanKatkat 491a475
feat(pipeline): implement label resolution for GeoJSON/JSON files
AbdelrahmanKatkat 9c56e3d
refactor(pipeline): streamline label resolution and add model file pa…
AbdelrahmanKatkat 8c751d3
chore(config): update kind configuration and adjust STAC item parameters
AbdelrahmanKatkat 95e2632
Merge branch 'master' into feature/ramp
AbdelrahmanKatkat 8b3e527
chore(config): remove training and inference labels from kind configu…
AbdelrahmanKatkat fb9bde2
chore(pipeline): integrate MLflow context and enhance model evaluatio…
AbdelrahmanKatkat 323652a
fix(pipeline): update output materializer label in train_model function
AbdelrahmanKatkat 4b3cdad
feat(pipeline): enhance model loading and evaluation metrics
AbdelrahmanKatkat e9f4d48
refactor(pipeline): improve path resolution and model loading logic
AbdelrahmanKatkat 0c9780a
fix(ramp): update STAC item ID and name for consistency; change Docke…
AbdelrahmanKatkat e9189ca
refactor(ramp): remove unnecessary root user setting in Dockerfile
AbdelrahmanKatkat dc11407
Merge branch 'master' into feature/ramp
AbdelrahmanKatkat 7366dc9
docs(ramp): update README for model overview and usage instructions
AbdelrahmanKatkat b43f3c5
feat(pipeline): add sample_fraction parameter for chip selection in t…
AbdelrahmanKatkat 8abd477
Merge branch 'master' into feature/ramp
AbdelrahmanKatkat e8500e0
Merge branch 'master' into feature/ramp
AbdelrahmanKatkat 6e4d2d3
Merge branch 'master' into feature/ramp
AbdelrahmanKatkat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| # syntax=docker/dockerfile:1.7 | ||
|
|
||
| # Base image: ghcr.io/hotosm/fair-utilities-ramp:gpu-latest (override BASE_IMAGE for CPU builds). | ||
| # Build from the fAIr-models repo root: | ||
| # docker build -f models/ramp/Dockerfile --target test -t ramp:test . | ||
| # docker build -f models/ramp/Dockerfile --build-arg BASE_IMAGE=ghcr.io/hotosm/fair-utilities-ramp:gpu-latest --target test -t ramp:test . | ||
| # docker build -f models/ramp/Dockerfile --build-arg BASE_IMAGE=ghcr.io/hotosm/fair-utilities-ramp:cpu-latest --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:gpu-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 \ | ||
| NVIDIA_VISIBLE_DEVICES=all \ | ||
| NVIDIA_DRIVER_CAPABILITIES=compute,utility | ||
|
|
||
| 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 builder stage: distroless-ready venv with serving deps | ||
| # --------------------------------------------------------------------------- | ||
| FROM ghcr.io/astral-sh/uv:bookworm-slim AS inference-builder | ||
| ENV UV_PYTHON_INSTALL_DIR=/python UV_PYTHON_PREFERENCE=only-managed | ||
| RUN uv python install 3.13 | ||
| WORKDIR /app | ||
| COPY pyproject.toml README.md fair_zenml_patch.pth /tmp/fair-src/ | ||
| COPY fair /tmp/fair-src/fair | ||
| RUN --mount=type=cache,target=/root/.cache/uv \ | ||
| export SETUPTOOLS_SCM_PRETEND_VERSION=0.0.0 && \ | ||
| uv venv && uv pip install \ | ||
| /tmp/fair-src[serve] \ | ||
| rasterio \ | ||
| pyproj \ | ||
| numpy \ | ||
| Pillow \ | ||
| onnx \ | ||
| onnxruntime | ||
| COPY models/ramp/pipeline.py /app/models/ramp/pipeline.py | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Inference stage: distroless runtime for live serving | ||
| # --------------------------------------------------------------------------- | ||
| FROM gcr.io/distroless/python3-debian12:nonroot AS inference | ||
| WORKDIR /app | ||
| COPY --from=inference-builder /python /python | ||
| COPY --from=inference-builder /app/.venv /app/.venv | ||
| COPY --from=inference-builder /app/models /app/models | ||
| ENV PATH="/app/.venv/bin:$PATH" PYTHONPATH=/app \ | ||
| ZENML_CONFIG_PATH=/tmp/zenml | ||
| EXPOSE 8080 | ||
| ENTRYPOINT ["/app/.venv/bin/python", "-m", "uvicorn"] | ||
| CMD ["fair.serve.base:create_app", "--factory", "--host", "0.0.0.0", "--port", "8080"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
AbdelrahmanKatkat marked this conversation as resolved.
Outdated
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.