# geogfm.inference
Course Roadmap Mapping
This weekβs work in the broader GFM plan.
Week | Stage | Focus | You will build (geogfm) | Library tools | Outcome |
---|---|---|---|---|---|
9 | Stage 3: Apply & Deploy | Deployment & Inference | inference/{tiling.py, sliding_window.py} |
numpy , rasterio windows |
Sliding-window inference on a small scene |
Weekly goals
- Implement sliding-window/tiling inference utilities
- Stitch predictions; sanity-check outputs
- Outline API/UI deployment considerations
Session Outline (and Tangled Code)
- Concepts β Components mapping
- Sliding-window and tiling utilities β
inference/*.py
- Sliding-window and tiling utilities β
Package inits
1) Sliding-window helpers
from __future__ import annotations
import numpy as np
from typing import Iterator, Tuple
= np.ndarray
Array
def window_slices(height: int, width: int, patch_size: int, stride: int) -> Iterator[Tuple[slice, slice]]:
for r in range(0, height - patch_size + 1, stride):
for c in range(0, width - patch_size + 1, stride):
yield slice(r, r + patch_size), slice(c, c + patch_size)
2) Tiling inference (naive)
from __future__ import annotations
import numpy as np
from typing import Callable
from geogfm.inference.sliding_window import window_slices
= np.ndarray
Array
def apply_tiled(model_apply: Callable[[Array], Array], image: Array, patch_size: int, stride: int) -> Array:
"""Apply a function over tiles and stitch back naively (no overlaps blending)."""
= image.shape
bands, height, width = np.zeros_like(image)
output for rs, cs in window_slices(height, width, patch_size, stride):
= model_apply(image[:, rs, cs]) # (C, P, P)
pred = pred
output[:, rs, cs] return output