Skip to main content

fAIr Predictor

Run fAIr model predictions anywhere. Works on CPU, compatible with serverless functions.

Requires Python >= 3.10.

Installation

# core (RAMP / TFLite models)
uv add fairpredictor
# or
pip install fairpredictor

# with YOLO / ONNX support
uv add "fairpredictor[pytorch]"
pip install "fairpredictor[pytorch]"

# with TensorFlow support
uv add "fairpredictor[tensorflow]"
pip install "fairpredictor[tensorflow]"

# everything
uv add "fairpredictor[all]"
pip install "fairpredictor[all]"

Python usage

import asyncio

from predictor import DEFAULT_OAM_TMS_MOSAIC, DEFAULT_RAMP_MODEL, DEFAULT_YOLO_MODEL, predict

bbox = [100.56228021333352, 13.685230854641182, 100.56383321235313, 13.685961853747969]
zoom_level = 20

# RAMP (TFLite) prediction
result = asyncio.run(
    predict(
        model_path=DEFAULT_RAMP_MODEL,
        zoom_level=zoom_level,
        tms_url=DEFAULT_OAM_TMS_MOSAIC,
        bbox=bbox,
        confidence=0.5,
        tolerance=0.5,
        area_threshold=3,
        orthogonalize=True,
    )
)
print(result)

# YOLO (ONNX) prediction
result = asyncio.run(
    predict(
        model_path=DEFAULT_YOLO_MODEL,
        zoom_level=zoom_level,
        tms_url=DEFAULT_OAM_TMS_MOSAIC,
        bbox=bbox,
    )
)
print(result)

predict() parameters

Parameter Type Default Description
model_path str required URL or local path to model (.tflite, .onnx, .pt, .h5)
zoom_level int required Tile zoom level (18-22)
tms_url str OAM mosaic TMS URL template {z}/{x}/{y}
bbox list[float] None [min_lon, min_lat, max_lon, max_lat]
geojson dict|str None GeoJSON polygon as alternative to bbox
confidence float 0.5 Confidence threshold 0-1
tolerance float 0.5 Polygon simplification tolerance
area_threshold float 3 Minimum polygon area
orthogonalize bool True Apply orthogonalization
ortho_skew_tolerance_deg int 15 Orthogonalization skew tolerance (0-45)
ortho_max_angle_change_deg int 15 Maximum angle change for orthogonalization (0-45)
get_predictions_as_points bool True Include centroid points in output
make_geoms_valid bool True Validate and fix output polygons
task str "segmentation" Task type (segmentation only for now)
output_path str None Directory to save outputs; auto-generated if not set
debug bool False Save intermediate rasters for debugging

Either bbox or geojson must be provided.

Development

# Install all dependency groups
just install

# Run linting + type checking + tests
just check

# Lint only
just lint

# Tests only
just test

Load testing

Always obtain permission from the server admin before load testing.

uv run locust -f locust.py

Set HOST to the base URL of the predictor API.

Docker

Build

docker build -t fairpredictor .

Run

docker run --rm -p 8000:8000 fairpredictor

API

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc

Example request

{
  "bbox": [100.56228021333352, 13.685230854641182, 100.56383321235313, 13.685961853747969],
  "checkpoint": "https://api-prod.fair.hotosm.org/api/v1/workspace/download/ramp/baseline.tflite",
  "zoom_level": 20,
  "source": "https://apps.kontur.io/raster-tiler/oam/mosaic/{z}/{x}/{y}.png",
  "confidence": 50,
  "tolerance": 0.5,
  "area_threshold": 2,
  "orthogonalize": true,
  "task": "segmentation"
}

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fairpredictor-0.5.1.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fairpredictor-0.5.1-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file fairpredictor-0.5.1.tar.gz.

File metadata

  • Download URL: fairpredictor-0.5.1.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fairpredictor-0.5.1.tar.gz
Algorithm Hash digest
SHA256 cf0f40a04a7ce52fbd67efa0524d522e8688d7d31cd3130c4b092e42af1427fe
MD5 bb6b5983fbbbf4ba629f11fa658b5fd5
BLAKE2b-256 3986123eeb34bd823be2a2f642570ce59e717be74ced6bec91d87219b8278385

See more details on using hashes here.

File details

Details for the file fairpredictor-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: fairpredictor-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fairpredictor-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bbf182df0b80761c8868154ab836c7865a106aff141a835f0f9c6649f87c1556
MD5 e5db910dc66ff963fc934bc61dde28b8
BLAKE2b-256 a6f5aa3d07731c2172aae928a9e82892e4d0cbc8808f8ea460a7bc866eb45df7

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.5.1 This release

2 files

0.3.15

2 files

0.3.14

2 files

0.3.12

2 files

0.3.11

2 files

0.3.10

2 files

0.3.9

2 files

0.3.8

2 files

0.3.7

2 files

0.3.6

2 files

0.3.5

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

1 file

0.3.0

1 file

0.1.12

2 files

0.1.11

2 files

0.1.10

2 files

0.1.9

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.0.39

2 files

0.0.38

2 files

0.0.37

2 files

0.0.36

2 files

0.0.35

2 files

0.0.34

2 files

0.0.33

2 files

0.0.32

2 files

0.0.31

1 file

0.0.30

1 file

0.0.29

1 file

0.0.28

1 file

0.0.27

1 file

0.0.26

1 file

0.0.25

1 file

0.0.24

1 file

0.0.23

1 file

0.0.22

1 file

0.0.21

1 file

0.0.20

1 file

0.0.19

1 file

0.0.18

1 file

0.0.17

1 file

0.0.16

1 file

0.0.15

1 file

0.0.14

1 file

0.0.13

1 file

0.0.12

1 file

0.0.11

1 file

0.0.10

1 file

0.0.9

1 file

0.0.8

1 file

0.0.7

1 file

0.0.6

1 file

0.0.5

1 file

0.0.4

1 file

0.0.3

1 file

0.0.2

1 file

0.0.1

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page