stac-model 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,207 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the
13
+ copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other
16
+ entities that control, are controlled by, or are under common control with
17
+ that entity. For the purposes of this definition, "control" means (i) the
18
+ power, direct or indirect, to cause the direction or management of such
19
+ entity, whether by contract or otherwise, or (ii) ownership of
20
+ fifty percent (50%) or more of the outstanding shares, or (iii) beneficial
21
+ ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
24
+ permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation source,
28
+ and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical transformation
31
+ or translation of a Source form, including but not limited to compiled
32
+ object code, generated documentation, and conversions to
33
+ other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or Object
36
+ form, made available under the License, as indicated by a copyright notice
37
+ that is included in or attached to the work (an example is provided in the
38
+ Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object form,
41
+ that is based on (or derived from) the Work and for which the editorial
42
+ revisions, annotations, elaborations, or other modifications represent,
43
+ as a whole, an original work of authorship. For the purposes of this
44
+ License, Derivative Works shall not include works that remain separable
45
+ from, or merely link (or bind by name) to the interfaces of, the Work and
46
+ Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including the original
49
+ version of the Work and any modifications or additions to that Work or
50
+ Derivative Works thereof, that is intentionally submitted to Licensor for
51
+ inclusion in the Work by the copyright owner or by an individual or
52
+ Legal Entity authorized to submit on behalf of the copyright owner.
53
+ For the purposes of this definition, "submitted" means any form of
54
+ electronic, verbal, or written communication sent to the Licensor or its
55
+ representatives, including but not limited to communication on electronic
56
+ mailing lists, source code control systems, and issue tracking systems
57
+ that are managed by, or on behalf of, the Licensor for the purpose of
58
+ discussing and improving the Work, but excluding communication that is
59
+ conspicuously marked or otherwise designated in writing by the copyright
60
+ owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity on
63
+ behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License.
67
+
68
+ Subject to the terms and conditions of this License, each Contributor
69
+ hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
70
+ royalty-free, irrevocable copyright license to reproduce, prepare
71
+ Derivative Works of, publicly display, publicly perform, sublicense,
72
+ and distribute the Work and such Derivative Works in
73
+ Source or Object form.
74
+
75
+ 3. Grant of Patent License.
76
+
77
+ Subject to the terms and conditions of this License, each Contributor
78
+ hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
79
+ royalty-free, irrevocable (except as stated in this section) patent
80
+ license to make, have made, use, offer to sell, sell, import, and
81
+ otherwise transfer the Work, where such license applies only to those
82
+ patent claims licensable by such Contributor that are necessarily
83
+ infringed by their Contribution(s) alone or by combination of their
84
+ Contribution(s) with the Work to which such Contribution(s) was submitted.
85
+ If You institute patent litigation against any entity (including a
86
+ cross-claim or counterclaim in a lawsuit) alleging that the Work or a
87
+ Contribution incorporated within the Work constitutes direct or
88
+ contributory patent infringement, then any patent licenses granted to
89
+ You under this License for that Work shall terminate as of the date such
90
+ litigation is filed.
91
+
92
+ 4. Redistribution.
93
+
94
+ You may reproduce and distribute copies of the Work or Derivative Works
95
+ thereof in any medium, with or without modifications, and in Source or
96
+ Object form, provided that You meet the following conditions:
97
+
98
+ 1. You must give any other recipients of the Work or Derivative Works a
99
+ copy of this License; and
100
+
101
+ 2. You must cause any modified files to carry prominent notices stating
102
+ that You changed the files; and
103
+
104
+ 3. You must retain, in the Source form of any Derivative Works that You
105
+ distribute, all copyright, patent, trademark, and attribution notices from
106
+ the Source form of the Work, excluding those notices that do not pertain
107
+ to any part of the Derivative Works; and
108
+
109
+ 4. If the Work includes a "NOTICE" text file as part of its distribution,
110
+ then any Derivative Works that You distribute must include a readable copy
111
+ of the attribution notices contained within such NOTICE file, excluding
112
+ those notices that do not pertain to any part of the Derivative Works,
113
+ in at least one of the following places: within a NOTICE text file
114
+ distributed as part of the Derivative Works; within the Source form or
115
+ documentation, if provided along with the Derivative Works; or, within a
116
+ display generated by the Derivative Works, if and wherever such
117
+ third-party notices normally appear. The contents of the NOTICE file are
118
+ for informational purposes only and do not modify the License.
119
+ You may add Your own attribution notices within Derivative Works that You
120
+ distribute, alongside or as an addendum to the NOTICE text from the Work,
121
+ provided that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and may
125
+ provide additional or different license terms and conditions for use,
126
+ reproduction, or distribution of Your modifications, or for any such
127
+ Derivative Works as a whole, provided Your use, reproduction, and
128
+ distribution of the Work otherwise complies with the conditions
129
+ stated in this License.
130
+
131
+ 5. Submission of Contributions.
132
+
133
+ Unless You explicitly state otherwise, any Contribution intentionally
134
+ submitted for inclusion in the Work by You to the Licensor shall be under
135
+ the terms and conditions of this License, without any additional
136
+ terms or conditions. Notwithstanding the above, nothing herein shall
137
+ supersede or modify the terms of any separate license agreement you may
138
+ have executed with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks.
141
+
142
+ This License does not grant permission to use the trade names, trademarks,
143
+ service marks, or product names of the Licensor, except as required for
144
+ reasonable and customary use in describing the origin of the Work and
145
+ reproducing the content of the NOTICE file.
146
+
147
+ 7. Disclaimer of Warranty.
148
+
149
+ Unless required by applicable law or agreed to in writing, Licensor
150
+ provides the Work (and each Contributor provides its Contributions)
151
+ on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
152
+ either express or implied, including, without limitation, any warranties
153
+ or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS
154
+ FOR A PARTICULAR PURPOSE. You are solely responsible for determining the
155
+ appropriateness of using or redistributing the Work and assume any risks
156
+ associated with Your exercise of permissions under this License.
157
+
158
+ 8. Limitation of Liability.
159
+
160
+ In no event and under no legal theory, whether in tort
161
+ (including negligence), contract, or otherwise, unless required by
162
+ applicable law (such as deliberate and grossly negligent acts) or agreed
163
+ to in writing, shall any Contributor be liable to You for damages,
164
+ including any direct, indirect, special, incidental, or consequential
165
+ damages of any character arising as a result of this License or out of
166
+ the use or inability to use the Work (including but not limited to damages
167
+ for loss of goodwill, work stoppage, computer failure or malfunction,
168
+ or any and all other commercial damages or losses), even if such
169
+ Contributor has been advised of the possibility of such damages.
170
+
171
+ 9. Accepting Warranty or Additional Liability.
172
+
173
+ While redistributing the Work or Derivative Works thereof, You may choose
174
+ to offer, and charge a fee for, acceptance of support, warranty,
175
+ indemnity, or other liability obligations and/or rights consistent with
176
+ this License. However, in accepting such obligations, You may act only
177
+ on Your own behalf and on Your sole responsibility, not on behalf of any
178
+ other Contributor, and only if You agree to indemnify, defend, and hold
179
+ each Contributor harmless for any liability incurred by, or claims
180
+ asserted against, such Contributor by reason of your accepting any such
181
+ warranty or additional liability.
182
+
183
+ END OF TERMS AND CONDITIONS
184
+
185
+ APPENDIX: How to apply the Apache License to your work
186
+
187
+ To apply the Apache License to your work, attach the following boilerplate
188
+ notice, with the fields enclosed by brackets "[]" replaced with your own
189
+ identifying information. (Don't include the brackets!) The text should be
190
+ enclosed in the appropriate comment syntax for the file format. We also
191
+ recommend that a file or class name and description of purpose be included
192
+ on the same "printed page" as the copyright notice for easier
193
+ identification within third-party archives.
194
+
195
+ Copyright 2023 Ryan Avery
196
+
197
+ Licensed under the Apache License, Version 2.0 (the "License");
198
+ you may not use this file except in compliance with the License.
199
+ You may obtain a copy of the License at
200
+
201
+ http://www.apache.org/licenses/LICENSE-2.0
202
+
203
+ Unless required by applicable law or agreed to in writing, software
204
+ distributed under the License is distributed on an "AS IS" BASIS,
205
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
206
+ or implied. See the License for the specific language governing
207
+ permissions and limitations under the License.
@@ -0,0 +1,189 @@
1
+ Metadata-Version: 2.1
2
+ Name: stac-model
3
+ Version: 0.1.0
4
+ Summary: A PydanticV2 validation and serialization libary for the STAC ML Model Extension
5
+ Home-page: https://github.com/rbavery/stac-model
6
+ License: Apache Software License 2.0
7
+ Author: Ryan Avery
8
+ Author-email: ryan@wherobots.com
9
+ Requires-Python: >=3.10,<4.0
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: License :: Other/Proprietary License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Dist: numpy (>=1.26.2,<2.0.0)
21
+ Requires-Dist: pydantic (>=2.3.0,<2.4.0)
22
+ Requires-Dist: pydantic-core (>=2,<3)
23
+ Requires-Dist: rich (>=12.6.0,<13.0.0)
24
+ Requires-Dist: typer[all] (>=0.7.0,<0.8.0)
25
+ Project-URL: Repository, https://github.com/rbavery/stac-model
26
+ Description-Content-Type: text/markdown
27
+
28
+ # stac-model
29
+
30
+ <div align="center">
31
+
32
+ [![Python support][bp1]][bp2]
33
+ [![PyPI Release][bp3]][bp2]
34
+ [![Repository][bscm1]][bp4]
35
+ [![Releases][bscm2]][bp5]
36
+ [![Docs][bdoc1]][bdoc2]
37
+
38
+ [![Contributions Welcome][bp8]][bp9]
39
+
40
+ [![Poetry][bp11]][bp12]
41
+ [![Pre-commit][bp15]][bp16]
42
+ [![Semantic versions][blic3]][bp5]
43
+ [![Pipelines][bscm6]][bscm7]
44
+
45
+ _A PydanticV2 validation and serialization library for the STAC ML Model Extension_
46
+
47
+ </div>
48
+
49
+ ## Installation
50
+
51
+ ```bash
52
+ pip install -U stac-model
53
+ ```
54
+
55
+ or install with `Poetry`:
56
+
57
+ ```bash
58
+ poetry add stac-model
59
+ ```
60
+ Then you can run
61
+
62
+ ```bash
63
+ stac-model --help
64
+ ```
65
+
66
+ or with `Poetry`:
67
+
68
+ ```bash
69
+ poetry run stac-model --help
70
+ ```
71
+
72
+ ## Creating an example metadata json
73
+
74
+ ```
75
+ poetry run stac-model
76
+ ```
77
+
78
+ This will make an example example.json metadata file for an example model.
79
+
80
+ Currently this looks like
81
+
82
+ ```
83
+ {
84
+ "signatures": {
85
+ "inputs": [
86
+ {
87
+ "name": "input_tensor",
88
+ "dtype": "float32",
89
+ "shape": [
90
+ -1,
91
+ 13,
92
+ 64,
93
+ 64
94
+ ]
95
+ }
96
+ ],
97
+ "outputs": [
98
+ {
99
+ "name": "output_tensor",
100
+ "dtype": "float32",
101
+ "shape": [
102
+ -1,
103
+ 10
104
+ ]
105
+ }
106
+ ],
107
+ "params": null
108
+ },
109
+ "artifact": {
110
+ "path": "s3://example/s3/uri/model.pt",
111
+ "additional_files": null
112
+ },
113
+ "id": "3fa03dceb4004b6e8a9e8591e4b3a99d",
114
+ "class_map": {
115
+ "class_to_label_id": {
116
+ "Annual Crop": 0,
117
+ "Forest": 1,
118
+ "Herbaceous Vegetation": 2,
119
+ "Highway": 3,
120
+ "Industrial Buildings": 4,
121
+ "Pasture": 5,
122
+ "Permanent Crop": 6,
123
+ "Residential Buildings": 7,
124
+ "River": 8,
125
+ "SeaLake": 9
126
+ }
127
+ },
128
+ "runtime_config": null,
129
+ "name": "eurosat",
130
+ "ml_model_type": null,
131
+ "ml_model_processor_type": "cpu",
132
+ "ml_model_learning_approach": null,
133
+ "ml_model_prediction_type": null,
134
+ "ml_model_architecture": null
135
+ }
136
+ ```
137
+
138
+ ## :chart_with_upwards_trend: Releases
139
+
140
+ You can see the list of available releases on the [GitHub Releases][r1] page.
141
+
142
+
143
+ [![License][blic1]][blic2]
144
+
145
+ This project is licenced under the terms of the `Apache Software License 2.0` licence. See [LICENCE][blic2] for more details.
146
+
147
+
148
+ ## Credits [![Python project templated from galactipy.][bp6]][bp7]
149
+
150
+ This project was generated with [`galactipy`][bp7].
151
+
152
+ <!-- Anchors -->
153
+
154
+ [bp1]: https://img.shields.io/pypi/pyversions/stac-model?style=for-the-badge
155
+ [bp2]: https://pypi.org/project/stac-model/
156
+ [bp3]: https://img.shields.io/pypi/v/stac-model?style=for-the-badge&logo=pypi&color=3775a9
157
+ [bp4]: https://github.com/stac-extensions/stac-model
158
+ [bp5]: https://github.com/stac-extensions/stac-model/releases
159
+ [bp6]: https://img.shields.io/badge/made%20with-galactipy%20%F0%9F%8C%8C-179287?style=for-the-badge&labelColor=193A3E
160
+ [bp7]: https://kutt.it/7fYqQl
161
+ [bp8]: https://img.shields.io/static/v1.svg?label=Contributions&message=Welcome&color=0059b3&style=for-the-badge
162
+ [bp9]: https://github.com/stac-extensions/stac-model/blob/main/CONTRIBUTING.md
163
+ [bp11]: https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json&style=for-the-badge
164
+ [bp12]: https://python-poetry.org/
165
+
166
+ [bp15]: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=for-the-badge
167
+ [bp16]: https://github.com/stac-extensions/stac-model/blob/main/.pre-commit-config.yaml
168
+
169
+ [blic1]: https://img.shields.io/github/license/stac-extensions/stac-model?style=for-the-badge
170
+ [blic2]: https://github.com/stac-extensions/stac-model/blob/main/LICENCE
171
+ [blic3]: https://img.shields.io/badge/%F0%9F%93%A6-semantic%20versions-4053D6?style=for-the-badge
172
+
173
+ [r1]: https://github.com/stac-extensions/stac-model/releases
174
+
175
+ [bscm1]: https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white
176
+ [bscm2]: https://img.shields.io/github/v/release/stac-extensions/stac-model?style=for-the-badge&logo=semantic-release&color=347d39
177
+ [bscm6]: https://img.shields.io/github/actions/workflow/status/stac-extensions/stac-model/build.yml?style=for-the-badge&logo=github
178
+ [bscm7]: https://github.com/stac-extensions/stac-model/actions/workflows/build.yml
179
+
180
+ [hub1]: https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuring-dependabot-version-updates#enabling-dependabot-version-updates
181
+ [hub2]: https://github.com/marketplace/actions/close-stale-issues
182
+ [hub5]: https://github.com/stac-extensions/stac-model/blob/main/.github/workflows/build.yml
183
+ [hub6]: https://docs.github.com/en/code-security/dependabot
184
+ [hub8]: https://github.com/stac-extensions/stac-model/blob/main/.github/release-drafter.yml
185
+ [hub9]: https://github.com/stac-extensions/stac-model/blob/main/.github/.stale.yml
186
+
187
+ [bdoc1]: https://img.shields.io/badge/docs-github%20pages-0a507a?style=for-the-badge
188
+ [bdoc2]: https://stac-extensions.github.io/stac-model
189
+
@@ -0,0 +1,161 @@
1
+ # stac-model
2
+
3
+ <div align="center">
4
+
5
+ [![Python support][bp1]][bp2]
6
+ [![PyPI Release][bp3]][bp2]
7
+ [![Repository][bscm1]][bp4]
8
+ [![Releases][bscm2]][bp5]
9
+ [![Docs][bdoc1]][bdoc2]
10
+
11
+ [![Contributions Welcome][bp8]][bp9]
12
+
13
+ [![Poetry][bp11]][bp12]
14
+ [![Pre-commit][bp15]][bp16]
15
+ [![Semantic versions][blic3]][bp5]
16
+ [![Pipelines][bscm6]][bscm7]
17
+
18
+ _A PydanticV2 validation and serialization library for the STAC ML Model Extension_
19
+
20
+ </div>
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ pip install -U stac-model
26
+ ```
27
+
28
+ or install with `Poetry`:
29
+
30
+ ```bash
31
+ poetry add stac-model
32
+ ```
33
+ Then you can run
34
+
35
+ ```bash
36
+ stac-model --help
37
+ ```
38
+
39
+ or with `Poetry`:
40
+
41
+ ```bash
42
+ poetry run stac-model --help
43
+ ```
44
+
45
+ ## Creating an example metadata json
46
+
47
+ ```
48
+ poetry run stac-model
49
+ ```
50
+
51
+ This will make an example example.json metadata file for an example model.
52
+
53
+ Currently this looks like
54
+
55
+ ```
56
+ {
57
+ "signatures": {
58
+ "inputs": [
59
+ {
60
+ "name": "input_tensor",
61
+ "dtype": "float32",
62
+ "shape": [
63
+ -1,
64
+ 13,
65
+ 64,
66
+ 64
67
+ ]
68
+ }
69
+ ],
70
+ "outputs": [
71
+ {
72
+ "name": "output_tensor",
73
+ "dtype": "float32",
74
+ "shape": [
75
+ -1,
76
+ 10
77
+ ]
78
+ }
79
+ ],
80
+ "params": null
81
+ },
82
+ "artifact": {
83
+ "path": "s3://example/s3/uri/model.pt",
84
+ "additional_files": null
85
+ },
86
+ "id": "3fa03dceb4004b6e8a9e8591e4b3a99d",
87
+ "class_map": {
88
+ "class_to_label_id": {
89
+ "Annual Crop": 0,
90
+ "Forest": 1,
91
+ "Herbaceous Vegetation": 2,
92
+ "Highway": 3,
93
+ "Industrial Buildings": 4,
94
+ "Pasture": 5,
95
+ "Permanent Crop": 6,
96
+ "Residential Buildings": 7,
97
+ "River": 8,
98
+ "SeaLake": 9
99
+ }
100
+ },
101
+ "runtime_config": null,
102
+ "name": "eurosat",
103
+ "ml_model_type": null,
104
+ "ml_model_processor_type": "cpu",
105
+ "ml_model_learning_approach": null,
106
+ "ml_model_prediction_type": null,
107
+ "ml_model_architecture": null
108
+ }
109
+ ```
110
+
111
+ ## :chart_with_upwards_trend: Releases
112
+
113
+ You can see the list of available releases on the [GitHub Releases][r1] page.
114
+
115
+
116
+ [![License][blic1]][blic2]
117
+
118
+ This project is licenced under the terms of the `Apache Software License 2.0` licence. See [LICENCE][blic2] for more details.
119
+
120
+
121
+ ## Credits [![Python project templated from galactipy.][bp6]][bp7]
122
+
123
+ This project was generated with [`galactipy`][bp7].
124
+
125
+ <!-- Anchors -->
126
+
127
+ [bp1]: https://img.shields.io/pypi/pyversions/stac-model?style=for-the-badge
128
+ [bp2]: https://pypi.org/project/stac-model/
129
+ [bp3]: https://img.shields.io/pypi/v/stac-model?style=for-the-badge&logo=pypi&color=3775a9
130
+ [bp4]: https://github.com/stac-extensions/stac-model
131
+ [bp5]: https://github.com/stac-extensions/stac-model/releases
132
+ [bp6]: https://img.shields.io/badge/made%20with-galactipy%20%F0%9F%8C%8C-179287?style=for-the-badge&labelColor=193A3E
133
+ [bp7]: https://kutt.it/7fYqQl
134
+ [bp8]: https://img.shields.io/static/v1.svg?label=Contributions&message=Welcome&color=0059b3&style=for-the-badge
135
+ [bp9]: https://github.com/stac-extensions/stac-model/blob/main/CONTRIBUTING.md
136
+ [bp11]: https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json&style=for-the-badge
137
+ [bp12]: https://python-poetry.org/
138
+
139
+ [bp15]: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=for-the-badge
140
+ [bp16]: https://github.com/stac-extensions/stac-model/blob/main/.pre-commit-config.yaml
141
+
142
+ [blic1]: https://img.shields.io/github/license/stac-extensions/stac-model?style=for-the-badge
143
+ [blic2]: https://github.com/stac-extensions/stac-model/blob/main/LICENCE
144
+ [blic3]: https://img.shields.io/badge/%F0%9F%93%A6-semantic%20versions-4053D6?style=for-the-badge
145
+
146
+ [r1]: https://github.com/stac-extensions/stac-model/releases
147
+
148
+ [bscm1]: https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white
149
+ [bscm2]: https://img.shields.io/github/v/release/stac-extensions/stac-model?style=for-the-badge&logo=semantic-release&color=347d39
150
+ [bscm6]: https://img.shields.io/github/actions/workflow/status/stac-extensions/stac-model/build.yml?style=for-the-badge&logo=github
151
+ [bscm7]: https://github.com/stac-extensions/stac-model/actions/workflows/build.yml
152
+
153
+ [hub1]: https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuring-dependabot-version-updates#enabling-dependabot-version-updates
154
+ [hub2]: https://github.com/marketplace/actions/close-stale-issues
155
+ [hub5]: https://github.com/stac-extensions/stac-model/blob/main/.github/workflows/build.yml
156
+ [hub6]: https://docs.github.com/en/code-security/dependabot
157
+ [hub8]: https://github.com/stac-extensions/stac-model/blob/main/.github/release-drafter.yml
158
+ [hub9]: https://github.com/stac-extensions/stac-model/blob/main/.github/.stale.yml
159
+
160
+ [bdoc1]: https://img.shields.io/badge/docs-github%20pages-0a507a?style=for-the-badge
161
+ [bdoc2]: https://stac-extensions.github.io/stac-model
@@ -0,0 +1,201 @@
1
+
2
+ # Poetry pyproject.toml: https://python-poetry.org/docs/pyproject/
3
+ [build-system]
4
+ requires = ["poetry_core>=1.0.0"]
5
+ build-backend = "poetry.core.masonry.api"
6
+
7
+
8
+ [tool.poetry]
9
+ name = "stac-model"
10
+ version = "0.1.0"
11
+ description = "A PydanticV2 validation and serialization libary for the STAC ML Model Extension"
12
+ readme = "README.md"
13
+ authors = ["Ryan Avery <ryan@wherobots.com>"]
14
+ license = "Apache Software License 2.0"
15
+ repository = "https://github.com/rbavery/stac-model"
16
+ homepage = "https://github.com/rbavery/stac-model"
17
+ packages = [
18
+ {include = "stac_model"}
19
+ ]
20
+
21
+
22
+ # Keywords description https://python-poetry.org/docs/pyproject/#keywords
23
+ keywords = [] # UPDATEME with relevant keywords
24
+
25
+
26
+ # Pypi classifiers: https://pypi.org/classifiers/
27
+ classifiers = [ # UPDATEME with additional classifiers; remove last classifier to allow publishing on PyPI
28
+ "Development Status :: 3 - Alpha",
29
+ "Intended Audience :: Developers",
30
+ "Operating System :: OS Independent",
31
+ "Topic :: Software Development :: Libraries :: Python Modules",
32
+ "License :: OSI Approved :: Apache Software License",
33
+ "Programming Language :: Python :: 3",
34
+ "Programming Language :: Python :: 3.10",
35
+ "Programming Language :: Python :: 3.11",
36
+ ]
37
+
38
+
39
+ [tool.poetry.scripts]
40
+ # Entry points for the package https://python-poetry.org/docs/pyproject/#scripts
41
+ "stac-model" = "stac_model.__main__:app"
42
+
43
+
44
+ [tool.poetry.dependencies]
45
+ python = "^3.10"
46
+
47
+ typer = {extras = ["all"], version = "^0.7.0"}
48
+ rich = "^12.6.0"
49
+ pydantic = "~2.3.0" # bug in post 2.3 https://github.com/pydantic/pydantic/issues/7720
50
+ pydantic-core = "~2"
51
+ numpy = "^1.26.2"
52
+
53
+
54
+ [tool.poetry.group.dev.dependencies]
55
+ mypy = "^1.0.0"
56
+ mypy-extensions = "^0.4.3"
57
+ pre-commit = "^2.21.0"
58
+ bandit = "^1.7.5"
59
+ safety = "^2.3.4"
60
+
61
+
62
+ pydocstyle = {extras = ["toml"], version = "^6.2.0"}
63
+ pydoclint = "^0.3.0"
64
+
65
+ pytest = "^7.2.1"
66
+ pytest-html = "^3.2.0"
67
+ pytest-cov = "^4.1.0"
68
+ pytest-mock = "^3.10.0"
69
+ pytest-timeout = "^2.2.0"
70
+ pytest-benchmark = "^4.0.0"
71
+ pytest-sugar = "^0.9.7"
72
+ pytest-click = "^1.1.0"
73
+ pytest-pikachu = "^1.0.0"
74
+ coverage = "^7.3.0"
75
+ ruff = "^0.1.7"
76
+
77
+ [tool.ruff]
78
+ exclude = [
79
+ ".git",
80
+ "__pycache__",
81
+ ".mypy_cache",
82
+ ".tox",
83
+ ".venv",
84
+ "_build",
85
+ "buck-out",
86
+ "build",
87
+ "dist",
88
+ "env",
89
+ "venv"
90
+ ]
91
+
92
+
93
+ [tool.mypy]
94
+ # https://github.com/python/mypy
95
+ # https://mypy.readthedocs.io/en/latest/config_file.html#using-a-pyproject-toml-file
96
+ python_version = "3.10"
97
+ pretty = true
98
+ show_traceback = true
99
+ color_output = true
100
+
101
+ allow_redefinition = false
102
+ check_untyped_defs = true
103
+ disallow_any_generics = true
104
+ disallow_incomplete_defs = true
105
+ ignore_missing_imports = true
106
+ implicit_reexport = false
107
+ no_implicit_optional = true
108
+ show_column_numbers = true
109
+ show_error_codes = true
110
+ show_error_context = true
111
+ strict_equality = true
112
+ strict_optional = true
113
+ warn_no_return = true
114
+ warn_redundant_casts = true
115
+ warn_return_any = true
116
+ warn_unreachable = true
117
+ warn_unused_configs = true
118
+ warn_unused_ignores = true
119
+
120
+ plugins = [
121
+ "pydantic.mypy"
122
+ ]
123
+
124
+
125
+ [tool.pydantic-mypy]
126
+ init_forbid_extra = true
127
+ init_typed = true
128
+ warn_required_dynamic_aliases = true
129
+
130
+ [tool.pydocstyle]
131
+ # https://github.com/PyCQA/pydocstyle
132
+ # http://www.pydocstyle.org/en/stable/usage.html#available-options
133
+ convention = "google"
134
+
135
+
136
+ [tool.pydoclint]
137
+ # https://github.com/jsh9/pydoclint
138
+ # https://jsh9.github.io/pydoclint/how_to_config.html
139
+ style = "google"
140
+ exclude = '''
141
+ /(
142
+ \.git
143
+ | \.hg
144
+ | \.mypy_cache
145
+ | \.tox
146
+ | \.venv
147
+ | __pycache__
148
+ | _build
149
+ | buck-out
150
+ | build
151
+ | dist
152
+ | env
153
+ | venv
154
+ )/
155
+ '''
156
+
157
+
158
+ [tool.pytest.ini_options]
159
+ # https://github.com/pytest-dev/pytest
160
+ # https://docs.pytest.org/en/6.2.x/customize.html#pyproject-toml
161
+ # Directories that are not visited by pytest collector:
162
+ norecursedirs =[
163
+ "hooks",
164
+ "*.egg",
165
+ ".eggs",
166
+ "dist",
167
+ "build",
168
+ "docs",
169
+ ".tox",
170
+ ".git",
171
+ "__pycache__"
172
+ ]
173
+ doctest_optionflags = ["NUMBER", "NORMALIZE_WHITESPACE", "IGNORE_EXCEPTION_DETAIL"]
174
+ timeout = 1000
175
+
176
+ # Extra options:
177
+ addopts = [
178
+ "--strict-markers",
179
+ "--tb=short",
180
+ "--doctest-modules",
181
+ "--doctest-continue-on-failure",
182
+ "--pikachu"
183
+ ]
184
+
185
+
186
+ [tool.coverage.run]
187
+ source = ["tests"]
188
+ branch = true
189
+
190
+
191
+ [tool.coverage.report]
192
+ exclude_also = [
193
+ "def main",
194
+ "if __name__ == .__main__.:"
195
+ ]
196
+ fail_under = 50
197
+ show_missing = true
198
+
199
+
200
+ [tool.coverage.paths]
201
+ source = ["stac_model"]
@@ -0,0 +1,8 @@
1
+ """A PydanticV2 validation and serialization library for the STAC ML Model Extension"""
2
+
3
+ from importlib import metadata
4
+
5
+ try:
6
+ __version__ = metadata.version("stac-model")
7
+ except metadata.PackageNotFoundError:
8
+ __version__ = "unknown"
@@ -0,0 +1,69 @@
1
+ import typer
2
+ from rich.console import Console
3
+
4
+ from stac_model import __version__
5
+ from stac_model.schema import *
6
+
7
+
8
+ app = typer.Typer(
9
+ name="stac-model",
10
+ help="A PydanticV2 validation and serialization libary for the STAC ML Model Extension",
11
+ add_completion=False,
12
+ )
13
+ console = Console()
14
+
15
+
16
+ def version_callback(print_version: bool) -> None:
17
+ """Print the version of the package."""
18
+ if print_version:
19
+ console.print(f"[yellow]stac-model[/] version: [bold blue]{__version__}[/]")
20
+ raise typer.Exit()
21
+
22
+
23
+ @app.command(name="")
24
+ def main(
25
+ print_version: bool = typer.Option(
26
+ None,
27
+ "-v",
28
+ "--version",
29
+ callback=version_callback,
30
+ is_eager=True,
31
+ help="Prints the version of the stac-model package.",
32
+ ),
33
+ ) -> None:
34
+ """Generate example spec."""
35
+
36
+ input_sig = TensorSignature(
37
+ name="input_tensor", dtype="float32", shape=(-1, 13, 64, 64)
38
+ )
39
+ output_sig = TensorSignature(name="output_tensor", dtype="float32", shape=(-1, 10))
40
+ model_sig = ModelSignature(inputs=[input_sig], outputs=[output_sig])
41
+ model_artifact = ModelArtifact(path="s3://example/s3/uri/model.pt")
42
+ class_map = ClassMap(
43
+ class_to_label_id={
44
+ "Annual Crop": 0,
45
+ "Forest": 1,
46
+ "Herbaceous Vegetation": 2,
47
+ "Highway": 3,
48
+ "Industrial Buildings": 4,
49
+ "Pasture": 5,
50
+ "Permanent Crop": 6,
51
+ "Residential Buildings": 7,
52
+ "River": 8,
53
+ "SeaLake": 9,
54
+ }
55
+ )
56
+ meta = ModelMetadata(
57
+ name="eurosat",
58
+ class_map=class_map,
59
+ signatures=model_sig,
60
+ artifact=model_artifact,
61
+ ml_model_processor_type="cpu",
62
+ )
63
+ json_str = meta.model_dump_json(indent=2)
64
+ with open("example.json", "w") as file:
65
+ file.write(json_str)
66
+ print(meta)
67
+
68
+ if __name__ == "__main__":
69
+ app()
@@ -0,0 +1,192 @@
1
+ from pydantic import (
2
+ BaseModel,
3
+ Field,
4
+ FilePath,
5
+ field_validator,
6
+ field_serializer,
7
+ AnyUrl,
8
+ ConfigDict,
9
+ )
10
+ from typing import Optional
11
+ import re
12
+ from typing import List, Tuple, Dict, Optional, Literal, Any
13
+ import numpy as np
14
+ from uuid import uuid4
15
+ # import numpy.typing as npt
16
+
17
+
18
+ class TensorSignature(BaseModel):
19
+ """Tensor metadata, including the dtype (int8, float32, etc) and the tensor shape."""
20
+
21
+ name: Optional[str] = None
22
+ # TODO there's a couple of issues blocking numpy typing with
23
+ # pydantic or I'm not familiar enough with custom validators
24
+ # https://github.com/numpy/numpy/issues/25206
25
+ # dtype: npt.DTypeLike = Field(...)
26
+ dtype: str = Field(...)
27
+ shape: Tuple[int, ...] | List[int] = Field(...)
28
+ model_config = ConfigDict(arbitrary_types_allowed=True)
29
+
30
+ # TODO can't take numpy types for now until new pydant 2.6
31
+ # # NotImplementedError: Cannot check isinstance when validating from json, use a JsonOrPython validator instead.
32
+ # @field_serializer('dtype')
33
+ # def serialize_ndtype(self, dtype: np.dtype) -> str:
34
+ # return dtype.name
35
+ # @field_validator('dtype', mode="before")
36
+ # @classmethod
37
+ # def convert_dtype(cls, v):
38
+ # if isinstance(v, str):
39
+ # v = np.dtype(v)
40
+ # elif not isinstance(v, np.dtype):
41
+ # raise ValueError(f'Expected np.dtype, received {type(v).__name__}')
42
+ # return v
43
+
44
+ # @field_validator('shape')
45
+ # @classmethod
46
+ # def validate_shape(cls, v):
47
+ # if not isinstance(v, (tuple, list)):
48
+ # raise ValueError(f'Expected tuple or list for shape, received {type(v).__name__}')
49
+ # return list(v)
50
+
51
+
52
+ class ModelSignature(BaseModel):
53
+ """The name of the input tensor and accompanying tensor metadata."""
54
+
55
+ inputs: List[TensorSignature]
56
+ outputs: List[TensorSignature]
57
+ params: Optional[
58
+ Dict[str, int | float | str]
59
+ ] = None # Or any other type that 'params' might take
60
+
61
+ class Config:
62
+ arbitrary_types_allowed = True
63
+
64
+ @property
65
+ def inputs_length(self) -> int:
66
+ return len(self.inputs)
67
+
68
+ @property
69
+ def outputs_length(self) -> int:
70
+ return len(self.outputs)
71
+
72
+
73
+ class RuntimeConfig(BaseModel):
74
+ """TODO decide how to handle model runtime configurations. dependencies and hyperparams"""
75
+
76
+ environment: str
77
+
78
+
79
+ class S3Path(AnyUrl):
80
+ allowed_schemes = {"s3"}
81
+ user_required = False
82
+ max_length = 1023
83
+ min_length = 8
84
+
85
+ @field_validator("url")
86
+ @classmethod
87
+ def validate_s3_url(cls, v):
88
+ if not v.startswith("s3://"):
89
+ raise ValueError("S3 path must start with s3://")
90
+ if len(v) < cls.min_length:
91
+ raise ValueError("S3 path is too short")
92
+ if len(v) > cls.max_length:
93
+ raise ValueError("S3 path is too long")
94
+ return v
95
+
96
+ @field_validator("host")
97
+ @classmethod
98
+ def validate_bucket_name(cls, v):
99
+ if not v:
100
+ raise ValueError("Bucket name cannot be empty")
101
+ if not 3 <= len(v) <= 63:
102
+ raise ValueError("Bucket name must be between 3 and 63 characters")
103
+ if not re.match(r"^[a-z0-9.\-]+$", v):
104
+ raise ValueError(
105
+ "Bucket name can only contain lowercase letters, numbers, dots, and hyphens"
106
+ )
107
+ if v.startswith("-") or v.endswith("-"):
108
+ raise ValueError("Bucket name cannot start or end with a hyphen")
109
+ if ".." in v:
110
+ raise ValueError("Bucket name cannot have consecutive periods")
111
+ return v
112
+
113
+ @field_validator("path")
114
+ @classmethod
115
+ def validate_key(cls, v):
116
+ if "//" in v:
117
+ raise ValueError("Key must not contain double slashes")
118
+ if "\\" in v:
119
+ raise ValueError("Backslashes are not standard in S3 paths")
120
+ if "\t" in v or "\n" in v:
121
+ raise ValueError("Key cannot contain tab or newline characters")
122
+ return v.strip("/")
123
+
124
+
125
+ class ModelArtifact(BaseModel):
126
+ """Information about the model location and other additional file locations."""
127
+
128
+ path: S3Path | FilePath | str = Field(...)
129
+ additional_files: Optional[Dict[str, FilePath]] = None
130
+
131
+ class Config:
132
+ arbitrary_types_allowed = True
133
+
134
+ @field_validator("path")
135
+ @classmethod
136
+ def check_path_type(cls, v):
137
+ if isinstance(v, str):
138
+ if v.startswith("s3://"):
139
+ v = S3Path(url=v)
140
+ else:
141
+ v = FilePath(f=v)
142
+ else:
143
+ raise ValueError(
144
+ f"Expected str, S3Path, or FilePath input, received {type(v).__name__}"
145
+ )
146
+ return v
147
+
148
+
149
+ class ClassMap(BaseModel):
150
+ class_to_label_id: Dict[str, int]
151
+
152
+ # Property to reverse the mapping
153
+ @property
154
+ def label_id_to_class(self) -> Dict[int, str]:
155
+ # Reverse the mapping
156
+ return {v: k for k, v in self.class_to_label_id.items()}
157
+
158
+ def get_class(self, class_id: int) -> str:
159
+ """Get class name from class id."""
160
+ if class_id not in self.label_id_to_class:
161
+ raise ValueError(f"Class ID '{class_id}' not found")
162
+ return self.label_id_to_class[class_id]
163
+
164
+ def get_label_id(self, class_name: str) -> int:
165
+ """Get class id from class name."""
166
+ if class_name not in self.class_to_label_id:
167
+ raise ValueError(f"Class name '{class_name}' not found")
168
+ return self.class_to_label_id[class_name]
169
+
170
+
171
+ class ModelMetadata(BaseModel):
172
+ signatures: ModelSignature
173
+ artifact: ModelArtifact
174
+ id: str = Field(default_factory=lambda: uuid4().hex)
175
+ class_map: ClassMap
176
+
177
+ # Runtime configurations required to run the model.
178
+ # TODO requirements.txt , conda.yml, or lock files for each should be supported in future.
179
+ runtime_config: Optional[RuntimeConfig] = None
180
+
181
+ # the name of the model
182
+ name: str
183
+ ml_model_type: Optional[str] = None
184
+ ml_model_processor_type: Optional[Literal["cpu", "gpu", "tpu", "mps"]] = None
185
+ ml_model_learning_approach: Optional[str] = None
186
+ ml_model_prediction_type: Optional[
187
+ Literal["object-detection", "classification", "segmentation", "regression"]
188
+ ] = None
189
+ ml_model_architecture: Optional[str] = None
190
+
191
+ class Config:
192
+ arbitrary_types_allowed = True