Skip to content

Commit

Permalink
combine stac_model and pystac metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
rbavery committed Feb 28, 2024
1 parent 3178b27 commit 2b62d7b
Show file tree
Hide file tree
Showing 6 changed files with 330 additions and 8 deletions.
4 changes: 4 additions & 0 deletions best-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

This document makes a number of recommendations for creating real world ML Model Extensions. None of them are required to meet the core specification, but following these practices will improve the documentation of your model and make life easier for client tooling and users. They come about from practical experience of implementors and introduce a bit more 'constraint' for those who are creating STAC objects representing their models or creating tools to work with STAC.

## Using STAC Common Metadata Fields for the ML Model Extension

We recommend using the `start_datetime` and `end_datetime`, `geometry`, and `bbox` to represent the recommended context of data the model was trained with and for which the model should have appropriate domain knowledge for inference. For example, we can consider a model which is trained on imagery from all over the world and is robust enough to be applied to any time period. In this case, the common metadata to use with the model would include the bbox of "the world" `[-90, -180, 90, 180]` and the start_datetime and end_datetime range could be generic values like `["1900-01-01", null]`.

## Recommended Extensions to Compose with the ML Model Extension

### Processing Extension
Expand Down
50 changes: 49 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ typer = {extras = ["all"], version = "^0.9.0"}
rich = "^13.7.0"
pydantic = "2.3" # bug in post 2.3 https://github.com/pydantic/pydantic/issues/7720
pydantic-core = "^2"
numpy = "^1.26.2"
# fastapi="^0.108.0"
pystac = "^1.9.0"


[tool.poetry.group.dev.dependencies]
Expand Down
4 changes: 2 additions & 2 deletions stac_model/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Asset,
ClassObject,
InputArray,
MLModel,
MLModelExtension,
ModelInput,
ModelOutput,
ResultArray,
Expand Down Expand Up @@ -112,7 +112,7 @@ def eurosat_resnet():
output_shape=[-1, 10],
result_array=[result_array],
)
ml_model_meta = MLModel(
ml_model_meta = MLModelExtension(
mlm_name="Resnet-18 Sentinel-2 ALL MOCO",
mlm_task="classification",
mlm_framework="pytorch",
Expand Down
39 changes: 39 additions & 0 deletions stac_model/geometry_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from typing import List, Literal, Union

from pydantic import (
BaseModel,
)


class Geometry(BaseModel):
type: str
coordinates: List


class GeoJSONPoint(Geometry):
type: Literal["Point"]
coordinates: List[float]


class GeoJSONMultiPoint(Geometry):
type: Literal["MultiPoint"]
coordinates: List[List[float]]


class GeoJSONPolygon(Geometry):
type: Literal["Polygon"]
coordinates: List[List[List[float]]]


class GeoJSONMultiPolygon(Geometry):
type: Literal["MultiPolygon"]
coordinates: List[List[List[List[float]]]]


AnyGeometry = Union[
Geometry,
GeoJSONPoint,
GeoJSONMultiPoint,
GeoJSONPolygon,
GeoJSONMultiPolygon,
]
Loading

0 comments on commit 2b62d7b

Please sign in to comment.