Skip to main content

Fast object-level (polygon) metrics for geospatial ML: precision, recall, F1, IoU, mAP, shape stats.

Project description

polymetrics

Fast object-level (polygon) accuracy metrics for geospatial ML. Compare two GeoJSONs and get precision, recall, F1, IoU, mAP, and polygon-shape statistics in one call.

uvx polymetrics truth.geojson pred.geojson
from polymetrics import evaluate

result = evaluate("truth.geojson", "pred.geojson", iou_threshold=0.5)
print(result.precision, result.recall, result.f1, result.mean_iou)
result.to_geojson("annotated.geojson")

What it computes

Metric Definition
precision, recall, f1 Standard object-level scores after one-to-one Hungarian matching on IoU
mean_iou Mean IoU across matched (TP) pairs
map_50 Mean Average Precision at IoU=0.5, 101-point AP integration (COCO-style)
map_50_95 Mean of mAP at IoU thresholds 0.5, 0.55, ..., 0.95
avg_vertices Mean exterior vertex count across predicted polygons
orthogonality Mean fraction of edges within 5° of each polygon's MBR dominant axis

How it differs from pixel metrics

Pixel IoU pools every pixel and asks "what fraction did you get right?". Object IoU asks "did you find each building, and how well-shaped is each one?" which is what users actually see on a map. Both are useful for different reasons; this library only does object-level.

CRS handling

Inputs are always reprojected to EPSG:3857 before any geometric computation. If the prediction and truth GeoJSONs declare different source CRSs, a warning is emitted and both are projected. A missing CRS is treated as EPSG:4326 (the GeoJSON 2008 default).

Matching algorithm

Hungarian bipartite assignment (scipy.optimize.linear_sum_assignment) on a -IoU cost matrix, with gdf.sindex (STRtree) pruning to skip non-overlapping pairs. Each prediction matches at most one truth; pairs below iou_threshold are dropped (the prediction becomes FP, the truth FN).

mAP

mAP requires each prediction feature to carry a score or confidence property in [0, 1]. If neither is present, mAP is reported as null and a warning is emitted; the other metrics still compute.

Install

uv pip install polymetrics

CLI

polymetrics truth.geojson pred.geojson [options]

positional arguments:
  truth                 ground-truth GeoJSON
  pred                  prediction GeoJSON

options:
  --iou FLOAT           IoU threshold for TP (default: 0.5)
  --no-map              skip mAP computation
  --out PATH            write annotated GeoJSON (TP/FP/FN per feature)
  --json                emit metrics as JSON on stdout

License

Apache-2.0.

Project details


Download files

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

Source Distribution

polymetrics-0.1.0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

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

polymetrics-0.1.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file polymetrics-0.1.0.tar.gz.

File metadata

  • Download URL: polymetrics-0.1.0.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","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 polymetrics-0.1.0.tar.gz
Algorithm Hash digest
SHA256 36332a701bc87aa5f730f67c3c61762317d3c6f5b15ba5eba849640c27b87f4f
MD5 7e7c9137239e1d7116e849dd786453a1
BLAKE2b-256 6fb2324da0d8025460de163ae50883f9a09a17db26972b657f931465a9338681

See more details on using hashes here.

File details

Details for the file polymetrics-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: polymetrics-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","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 polymetrics-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dd52457354291e884a89b4918ba0c0248e66a1d04a8b0578330dcb6f8dd4a335
MD5 6a0d03373c0a6e4cbc53cf52ab798dab
BLAKE2b-256 5a657eec5d4d350080a72b49fd0373dd2d497622ea6f0adc3e2521e0468e9c30

See more details on using hashes here.

Supported by

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