Skip to content
This repository was archived by the owner on Jul 14, 2025. It is now read-only.

Commit 1f579a0

Browse files
authored
Add inference metadata [WIP] (#3)
* Add inferencing asset fields * Include model asset in JSON schema & examples * Use Compose file instead of Docker image asset * Rename Inferencing Images -> Inferencing Runtimes * Add rel type for Docker image links * Clarify media and relation types
1 parent 7edd955 commit 1f579a0

File tree

4 files changed

+90
-20
lines changed

4 files changed

+90
-20
lines changed

README.md

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,57 @@ these models for the following types of use-cases:
5959
| ml-model:prediction_type | string | **REQUIRED.** The type of prediction that the model makes. It is STRONGLY RECOMMENDED that you use one of the values described below, but other values are allowed. |
6060
| ml-model:architecture | string | **REQUIRED.** Identifies the architecture employed by the model (e.g. RCNN, U-Net, etc.). This may be any string identifier, but publishers are encouraged to use well-known identifiers whenever possible. |
6161

62+
## Asset Objects
63+
64+
### Roles
65+
66+
| Role Name | Description |
67+
| ------------------------ | ----------- |
68+
| ml-model:inference-runtime | Represents a file containing instructions for running a containerized version of the model to generate inferences. See the [Inference Runtimes](#inference-runtimes) section below for details on related fields. |
69+
70+
### Inference Runtimes
71+
72+
An Asset with the `ml-model:inference-runtime` role represents a file containing instructions for running a containerized version of the model to
73+
generate inferences. Currently, only [Compose files](https://github.com/compose-spec/compose-spec/blob/master/spec.md#compose-file) are supported,
74+
but support is planned for other formats, including [Common Workflow Language (CWL)](https://www.commonwl.org/) and [Workflow Description Language
75+
(WDL)](https://openwdl.org/).
76+
77+
The `"type"` field should be used to indicate the format of this asset. Assets in the Compose format should have a `"type"` value of
78+
`"text/x-yaml; application=compose"`.
79+
80+
While the Compose file defines nearly all of the parameters required to run the containerized model image, we still need a way to define which host
81+
directory containing input data should be mounted to the container and to which host directory the output predictions should be written. The Compose
82+
file MUST define volume mounts for input and output data using the Compose
83+
[Interpolation syntax](https://github.com/compose-spec/compose-spec/blob/master/spec.md#interpolation). The input data volume MUST be defined by an
84+
`INPUT_VOLUME` variable and the output data volume MUST be defined by an `OUTPUT_DATA` variable.
85+
86+
For example, the following Compose file snippet would mount the host input directory to `/var/data/input` in the container and would mount the host
87+
output data directory to `/var/data/output` in the host container. In this contrived example, the script to run the model takes 2 arguments: the
88+
location to the input data directory and the location to the output data directory.
89+
90+
```yaml
91+
services:
92+
...
93+
model_runtime:
94+
...
95+
volumes:
96+
- "${INPUT_DATA}:/var/data/input"
97+
- "${OUTPUT_DATA}:/var/data/output"
98+
command: "run-model.sh /var/data/input /var/data/output"
99+
```
100+
101+
A user would then set the `INPUT_DATA` and `OUTPUT_DATA` environment variables when running the model. An example using `docker-compose` might look
102+
like the following:
103+
104+
```console
105+
$ INPUT_DATA=/local/path/to/model/inputs; \
106+
OUTPUT_DATA=/local/path/to/model/outputs; \
107+
docker-compose up -f path/to/inference-runtime.yml
108+
```
109+
110+
It is RECOMMENDED that model publishers use the Asset `description` field to describe any other requirements or constraints for running the model
111+
container.
112+
62113
### Additional Field Information
63114

64115
#### ml-model:learning_approach
@@ -82,6 +133,15 @@ for a given [Learning Approach](#ml-modellearning_approach).
82133
- `"segmentation"`
83134
- `"regression"`
84135

136+
## Relation types
137+
138+
The following types should be used as applicable `rel` types in the
139+
[Link Object](https://github.com/radiantearth/stac-spec/tree/master/item-spec/item-spec.md#link-object).
140+
141+
| Type | Description |
142+
| ---------------------------- | ----------- |
143+
| ml-model:image | Links with this relation type refer to Docker images built using the model. The `href` value for links of this type should contain a fully-qualified URI for the image as would be required for a command like `docker pull`. These URIs should be of the form `<registry_domain>/<user_or_organization_name>/<image_name>:<tag>`. Links with this relation type should have a `"type"` value of `"docker-image"` to indicate a Docker image. |
144+
85145
## Interpretation of STAC Fields
86146

87147
The semantics of ML model metadata can sometimes differ significantly from the use-cases for which STAC was originally intended (Earth observation
@@ -108,15 +168,6 @@ It is RECOMMENDED that following STAC Extensions be used in conjunction with the
108168
- [Scientific Citation Extension](https://github.com/stac-extensions/scientific): This extension should be used to describe how the model should
109169
cited in publications, as well as to reference any existing publications associated with the model.
110170

111-
## Relation types
112-
113-
The following types should be used as applicable `rel` types in the
114-
[Link Object](https://github.com/radiantearth/stac-spec/tree/master/item-spec/item-spec.md#link-object).
115-
116-
| Type | Description |
117-
| ------------------- | ----------- |
118-
| TBD | More detail to come... |
119-
120171
## Contributing
121172

122173
All contributions are subject to the

examples/dummy/inferencing.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
services:
2+
model-inference:
3+
image: docker.io/someusername/some_model_image:1
4+
volumes:
5+
- "${INPUT_VOLUME}:/var/data/input"
6+
- "${OUTPUT_VOLUME}:/var/data/output"
7+
entrypoint: bash /app/scripts/run-model.sh
8+

examples/dummy/item.json

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"https://stac-extensions.github.io/ml-model/v1.0.0/schema.json"
55
],
66
"type": "Feature",
7-
"id": "item",
7+
"id": "model-item",
88
"bbox": [
99
34.18,
1010
0.47,
@@ -74,16 +74,27 @@
7474
"href": "./collection.json",
7575
"type": "application/json",
7676
"title": "Containing Collection"
77+
},
78+
{
79+
"rel": "ml-model:image",
80+
"href": "registry.hub.docker.com/my-user/my-model:v1",
81+
"type": "docker-image",
82+
"title": "My Model (v1)"
7783
}
7884
],
7985
"assets": {
8086
"model": {
81-
"href": "https://github.com/m-mohr/gmlmc-hackathon-tree-detection/blob/main/epoch_019.ckpt",
82-
"type": "application/x.ckpt",
83-
"title": "Model checkpoint file",
87+
"href": "./inferencing.yml",
88+
"type": "text/x-yaml; application=compose",
89+
"title": "Model inferencing runtime",
8490
"roles": [
85-
"model"
91+
"ml-model:inference-runtime"
8692
]
93+
},
94+
"other": {
95+
"href": "https://some-domain.com/another/thing.json",
96+
"type": "application/json",
97+
"title": "Some other asset"
8798
}
8899
}
89100
}

json-schema/schema.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232
]
3333
},
3434
{
35-
"$ref": "#/definitions/fields"
35+
"$ref": "#/definitions/common_fields"
3636
}
3737
]
3838
},
3939
"assets": {
4040
"$comment": "This validates the fields in Item Assets, but does not require them.",
4141
"type": "object",
4242
"additionalProperties": {
43-
"$ref": "#/definitions/fields"
43+
"$ref": "#/definitions/common_fields"
4444
}
4545
}
4646
}
@@ -82,7 +82,7 @@
8282
"$ref": "#/definitions/require_any_field"
8383
},
8484
{
85-
"$ref": "#/definitions/fields"
85+
"$ref": "#/definitions/common_fields"
8686
}
8787
]
8888
}
@@ -107,7 +107,7 @@
107107
"$ref": "#/definitions/require_any_field"
108108
},
109109
{
110-
"$ref": "#/definitions/fields"
110+
"$ref": "#/definitions/common_fields"
111111
}
112112
]
113113
}
@@ -165,8 +165,8 @@
165165
}
166166
]
167167
},
168-
"fields": {
169-
"$comment": "Add your new fields here. Don't require them here, do that above in the corresponding schema.",
168+
"common_fields": {
169+
"$comment": "Add your new Item fields here. Don't require them here, do that above in the corresponding schema.",
170170
"type": "object",
171171
"properties": {
172172
"ml-model:learning_approach": {

0 commit comments

Comments
 (0)