tensor-ee 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.
Files changed (91) hide show
  1. tensor_ee-0.1.0/LICENSE +21 -0
  2. tensor_ee-0.1.0/MANIFEST.in +2 -0
  3. tensor_ee-0.1.0/PKG-INFO +172 -0
  4. tensor_ee-0.1.0/README.md +131 -0
  5. tensor_ee-0.1.0/build_support.py +21 -0
  6. tensor_ee-0.1.0/pyproject.toml +52 -0
  7. tensor_ee-0.1.0/setup.cfg +4 -0
  8. tensor_ee-0.1.0/tensor_ee/__init__.py +28 -0
  9. tensor_ee-0.1.0/tensor_ee/_swin_parameters.py +304 -0
  10. tensor_ee-0.1.0/tensor_ee/blocks/__init__.py +0 -0
  11. tensor_ee-0.1.0/tensor_ee/blocks/raster/__init__.py +36 -0
  12. tensor_ee-0.1.0/tensor_ee/blocks/raster/activations.py +183 -0
  13. tensor_ee-0.1.0/tensor_ee/blocks/raster/conv.py +183 -0
  14. tensor_ee-0.1.0/tensor_ee/blocks/raster/merge.py +66 -0
  15. tensor_ee-0.1.0/tensor_ee/blocks/raster/outputs.py +211 -0
  16. tensor_ee-0.1.0/tensor_ee/blocks/raster/pooling.py +182 -0
  17. tensor_ee-0.1.0/tensor_ee/blocks/raster/resample.py +64 -0
  18. tensor_ee-0.1.0/tensor_ee/blocks/window/__init__.py +44 -0
  19. tensor_ee-0.1.0/tensor_ee/blocks/window/activations.py +54 -0
  20. tensor_ee-0.1.0/tensor_ee/blocks/window/attention.py +366 -0
  21. tensor_ee-0.1.0/tensor_ee/blocks/window/conv.py +323 -0
  22. tensor_ee-0.1.0/tensor_ee/blocks/window/linear.py +129 -0
  23. tensor_ee-0.1.0/tensor_ee/blocks/window/merge.py +67 -0
  24. tensor_ee-0.1.0/tensor_ee/blocks/window/normalization.py +197 -0
  25. tensor_ee-0.1.0/tensor_ee/blocks/window/patch.py +362 -0
  26. tensor_ee-0.1.0/tensor_ee/blocks/window/pooling.py +275 -0
  27. tensor_ee-0.1.0/tensor_ee/blocks/window/resample.py +286 -0
  28. tensor_ee-0.1.0/tensor_ee/blocks/window/segformer.py +718 -0
  29. tensor_ee-0.1.0/tensor_ee/blocks/window/swin.py +602 -0
  30. tensor_ee-0.1.0/tensor_ee/blocks/window/swin_upernet_config.py +361 -0
  31. tensor_ee-0.1.0/tensor_ee/blocks/window/upernet.py +1016 -0
  32. tensor_ee-0.1.0/tensor_ee/comparison.py +213 -0
  33. tensor_ee-0.1.0/tensor_ee/compatibility.py +180 -0
  34. tensor_ee-0.1.0/tensor_ee/compiler.py +356 -0
  35. tensor_ee-0.1.0/tensor_ee/converter/__init__.py +72 -0
  36. tensor_ee-0.1.0/tensor_ee/converter/build.py +120 -0
  37. tensor_ee-0.1.0/tensor_ee/converter/convert.py +388 -0
  38. tensor_ee-0.1.0/tensor_ee/converter/export.py +846 -0
  39. tensor_ee-0.1.0/tensor_ee/converter/graph.py +417 -0
  40. tensor_ee-0.1.0/tensor_ee/converter/operations.py +790 -0
  41. tensor_ee-0.1.0/tensor_ee/converter/plan.py +675 -0
  42. tensor_ee-0.1.0/tensor_ee/converter/recognizers.py +1273 -0
  43. tensor_ee-0.1.0/tensor_ee/converter/request.py +146 -0
  44. tensor_ee-0.1.0/tensor_ee/converter/run.py +950 -0
  45. tensor_ee-0.1.0/tensor_ee/core/__init__.py +8 -0
  46. tensor_ee-0.1.0/tensor_ee/core/errors.py +25 -0
  47. tensor_ee-0.1.0/tensor_ee/core/grid.py +323 -0
  48. tensor_ee-0.1.0/tensor_ee/core/metadata.py +398 -0
  49. tensor_ee-0.1.0/tensor_ee/core/ops.py +336 -0
  50. tensor_ee-0.1.0/tensor_ee/core/precision.py +133 -0
  51. tensor_ee-0.1.0/tensor_ee/core/tensor.py +129 -0
  52. tensor_ee-0.1.0/tensor_ee/examples/__init__.py +1 -0
  53. tensor_ee-0.1.0/tensor_ee/examples/nonwater.py +251 -0
  54. tensor_ee-0.1.0/tensor_ee/layouts/__init__.py +17 -0
  55. tensor_ee-0.1.0/tensor_ee/layouts/boundaries.py +103 -0
  56. tensor_ee-0.1.0/tensor_ee/layouts/raster.py +117 -0
  57. tensor_ee-0.1.0/tensor_ee/layouts/shift.py +226 -0
  58. tensor_ee-0.1.0/tensor_ee/layouts/window.py +201 -0
  59. tensor_ee-0.1.0/tensor_ee/models/__init__.py +16 -0
  60. tensor_ee-0.1.0/tensor_ee/models/fixtures.py +119 -0
  61. tensor_ee-0.1.0/tensor_ee/models/segformer_b0/__init__.py +9 -0
  62. tensor_ee-0.1.0/tensor_ee/models/segformer_b0/configuration.py +209 -0
  63. tensor_ee-0.1.0/tensor_ee/models/segformer_b0/decoder.py +130 -0
  64. tensor_ee-0.1.0/tensor_ee/models/segformer_b0/encoder.py +90 -0
  65. tensor_ee-0.1.0/tensor_ee/models/swin_t224/__init__.py +30 -0
  66. tensor_ee-0.1.0/tensor_ee/models/swin_t224/configuration.py +103 -0
  67. tensor_ee-0.1.0/tensor_ee/models/swin_t224/decoder.py +53 -0
  68. tensor_ee-0.1.0/tensor_ee/models/swin_t224/encoder.py +50 -0
  69. tensor_ee-0.1.0/tensor_ee/onnx_import.py +431 -0
  70. tensor_ee-0.1.0/tensor_ee/outputs.py +16 -0
  71. tensor_ee-0.1.0/tensor_ee/primitives.py +110 -0
  72. tensor_ee-0.1.0/tensor_ee/receptive_field.py +257 -0
  73. tensor_ee-0.1.0/tensor_ee/resnet_models.py +185 -0
  74. tensor_ee-0.1.0/tensor_ee/segwater_inference.py +235 -0
  75. tensor_ee-0.1.0/tensor_ee/segwater_preprocessing.py +182 -0
  76. tensor_ee-0.1.0/tensor_ee/segwater_pytorch.py +249 -0
  77. tensor_ee-0.1.0/tensor_ee/semantics.py +389 -0
  78. tensor_ee-0.1.0/tensor_ee/smp.py +155 -0
  79. tensor_ee-0.1.0/tensor_ee/swin.py +197 -0
  80. tensor_ee-0.1.0/tensor_ee/swin_workflow.py +470 -0
  81. tensor_ee-0.1.0/tensor_ee/tiling.py +287 -0
  82. tensor_ee-0.1.0/tensor_ee/weight_assets.py +371 -0
  83. tensor_ee-0.1.0/tensor_ee/weight_mapping.py +51 -0
  84. tensor_ee-0.1.0/tensor_ee/weights/__init__.py +14 -0
  85. tensor_ee-0.1.0/tensor_ee/weights/assets.py +160 -0
  86. tensor_ee-0.1.0/tensor_ee/weights/constants.py +156 -0
  87. tensor_ee-0.1.0/tensor_ee.egg-info/PKG-INFO +172 -0
  88. tensor_ee-0.1.0/tensor_ee.egg-info/SOURCES.txt +89 -0
  89. tensor_ee-0.1.0/tensor_ee.egg-info/dependency_links.txt +1 -0
  90. tensor_ee-0.1.0/tensor_ee.egg-info/requires.txt +23 -0
  91. tensor_ee-0.1.0/tensor_ee.egg-info/top_level.txt +1 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Noel Ivan Ulloa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ include build_support.py
2
+ prune tests
@@ -0,0 +1,172 @@
1
+ Metadata-Version: 2.4
2
+ Name: tensor-ee
3
+ Version: 0.1.0
4
+ Summary: Experimental building blocks for running pretrained PyTorch models natively in Google Earth Engine: a restricted CNN compiler (the SegWater U-Net; standard SMP Unet and UnetPlusPlus on ResNet and VGG encoders), a converter for supported attention models (SMP SegFormer-B0; SMP UPerNet with timm's Swin-T), and a planner and runner for staged exports.
5
+ Author: Noel Ivan Ulloa
6
+ License-Expression: MIT
7
+ Project-URL: Repository, https://github.com/noelEOS/tensor-ee
8
+ Project-URL: Issues, https://github.com/noelEOS/tensor-ee/issues
9
+ Project-URL: Documentation, https://github.com/noelEOS/tensor-ee/blob/main/docs/README.md
10
+ Project-URL: Changelog, https://github.com/noelEOS/tensor-ee/blob/main/CHANGELOG.md
11
+ Keywords: earth-engine,pytorch,geospatial,remote-sensing,neural-networks
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Classifier: Topic :: Scientific/Engineering :: GIS
20
+ Requires-Python: >=3.11
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: earthengine-api>=1.7.0
24
+ Requires-Dist: torch>=2.10
25
+ Requires-Dist: numpy>=1.26
26
+ Provides-Extra: test
27
+ Requires-Dist: pytest>=9.0.3; extra == "test"
28
+ Provides-Extra: resnet
29
+ Requires-Dist: torchvision>=0.20; extra == "resnet"
30
+ Provides-Extra: onnx
31
+ Requires-Dist: onnx>=1.22; extra == "onnx"
32
+ Requires-Dist: onnxruntime>=1.20; extra == "onnx"
33
+ Provides-Extra: segwater
34
+ Requires-Dist: segmentation-models-pytorch==0.5.0; extra == "segwater"
35
+ Provides-Extra: swin
36
+ Requires-Dist: segmentation-models-pytorch==0.5.0; extra == "swin"
37
+ Requires-Dist: timm==1.0.30; extra == "swin"
38
+ Provides-Extra: plot
39
+ Requires-Dist: matplotlib>=3.8; extra == "plot"
40
+ Dynamic: license-file
41
+
42
+ # TensorEE
43
+
44
+ [![Offline tests](https://github.com/noelEOS/tensor-ee/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/noelEOS/tensor-ee/actions/workflows/tests.yml)
45
+
46
+ **Run supported PyTorch models inside Google Earth Engine, without deploying a
47
+ model-serving endpoint.** TensorEE expresses neural-network inference as Earth Engine
48
+ image and array operations. Larger models can run in stages, saving intermediate
49
+ features as Earth Engine assets.
50
+
51
+ ![Earth Engine imagery passes to a deployed Vertex AI endpoint, or is evaluated directly with TensorEE's Earth Engine image and array operations](https://raw.githubusercontent.com/noelEOS/tensor-ee/main/docs/images/inference-location.svg)
52
+
53
+ Python builds the computation graph; Earth Engine evaluates the forward pass. Weights
54
+ are embedded constants or reads from EE table assets. Unsupported operations are refused,
55
+ not approximated. The [Vertex AI integration](https://developers.google.com/earth-engine/guides/ee-vertex-overview)
56
+ shown alongside it uses a separately deployed model endpoint.
57
+
58
+ ## A real example
59
+
60
+ ![Sentinel-1 radar imagery of Sun Moon Lake, with the water probability and mask computed by a trained U-Net inside Earth Engine](https://raw.githubusercontent.com/noelEOS/tensor-ee/main/docs/images/water_chip_224.png)
61
+
62
+ *A trained ResNet18 U-Net on one 224 × 224 Sentinel-1 chip: Sun Moon Lake, Taiwan,
63
+ 3 January 2024. Prediction, not ground truth. [Validation](https://github.com/noelEOS/tensor-ee/blob/main/docs/validation.md) ·
64
+ [Walkthrough](https://github.com/noelEOS/tensor-ee/blob/main/docs/water-chip.md). Contains modified Copernicus Sentinel data (2024).*
65
+
66
+ ## Get started
67
+
68
+ - **[Run the Code Editor demo](https://github.com/noelEOS/tensor-ee/blob/main/CODE_EDITOR.md).** No install or checkpoint. The trained
69
+ U-Net reads public weights; you need an Earth Engine account and a
70
+ [registered Cloud project](https://developers.google.com/earth-engine/guides/access)
71
+ where you can create an image asset. The demo exports one chip, billed to your project.
72
+ - **[Try the offline example](https://github.com/noelEOS/tensor-ee/blob/main/README.md#install).** Build a small CNN's graph locally, with no
73
+ credentials or cloud calls.
74
+ - **[Convert an attention model](https://github.com/noelEOS/tensor-ee/blob/main/docs/getting-started.md#5-convert-an-attention-model).**
75
+ Start with random weights, inspect the conversion report, then plan the stages.
76
+
77
+ ## What you can run
78
+
79
+ | Model or approach | Entry point | Availability |
80
+ |---|---|---|
81
+ | SegWater ResNet18 U-Net, 224 × 224 | [Code Editor demo](https://github.com/noelEOS/tensor-ee/blob/main/CODE_EDITOR.md); `compile_model` for CNNs | Trained EE weights are public; the Code Editor demo needs no checkpoint |
82
+ | Fixed Swin-T/UPerNet, 224 × 224 | [Three-stage workflow](https://github.com/noelEOS/tensor-ee/blob/main/docs/swin.md) | Trained EE weights are public; this workflow also needs a local checkpoint, not yet public |
83
+ | SMP SegFormer-B0 or UPerNet with timm's Swin encoder | [Attention converter](https://github.com/noelEOS/tensor-ee/blob/main/docs/converter.md) | Conversion examples use random weights; the report identifies settings outside the validated records |
84
+
85
+ You can also compose a model from the [block catalogue](https://github.com/noelEOS/tensor-ee/blob/main/docs/building-blocks.md).
86
+ It has 78 blocks: 16 in `tensor_ee/blocks/raster` and 62 in `tensor_ee/blocks/window`.
87
+ The [browser demo](https://github.com/noelEOS/tensor-ee/blob/main/DEMO.md) runs either trained model with a local checkpoint;
88
+ its `--offline` mode previews the interface without one.
89
+
90
+ ## Staged inference
91
+
92
+ Saving intermediate features lets a model run as several bounded EE graphs and avoids
93
+ recomputing earlier stages. In the fixed Swin workflow below, each step waits for its
94
+ predecessor's export to complete. The decoder reads both C4 and the earlier features.
95
+
96
+ ![Swin inference in three execution steps: weights are read from EE table assets, intermediate features are saved as EE image assets, and both feature paths feed the decoder. Active steps are blue; completed steps and saved assets turn green with checkmarks.](https://raw.githubusercontent.com/noelEOS/tensor-ee/main/docs/images/swin-inference.gif)
97
+
98
+ *Illustrative sequence, not execution timing. [Static diagram](https://raw.githubusercontent.com/noelEOS/tensor-ee/main/docs/images/swin-staged-inference.png).*
99
+
100
+ Weights live in EE table assets; saved features and predictions live in EE image assets.
101
+ The checkpoint, manifest and task state are local files. This workflow needs no GCS bucket.
102
+ The [Swin guide](https://github.com/noelEOS/tensor-ee/blob/main/docs/swin.md) details the three steps, including the validity summary
103
+ saved with C1–C3. Other models can use different cuts: the [converter planner](https://github.com/noelEOS/tensor-ee/blob/main/docs/converter.md#3-plan)
104
+ chooses stages under explicit limits.
105
+
106
+ ## Install
107
+
108
+ Python 3.11 or newer.
109
+
110
+ ```sh
111
+ python -m pip install tensor-ee
112
+ ```
113
+
114
+ Build a small CNN's graph offline, with no credentials or cloud calls:
115
+
116
+ ```sh
117
+ python -m tensor_ee.examples.nonwater --prepare
118
+ ```
119
+
120
+ Expect `"status": "offline_graph_only"` in the report.
121
+ [Getting started](https://github.com/noelEOS/tensor-ee/blob/main/docs/getting-started.md)
122
+ covers optional extras, PyTorch's download size and CPU-only installation, and the
123
+ steps for running in Earth Engine.
124
+
125
+ For the tests, tools, demos and checkout examples, install from source:
126
+
127
+ ```sh
128
+ git clone https://github.com/noelEOS/tensor-ee.git
129
+ cd tensor-ee
130
+ python -m venv .venv && source .venv/bin/activate
131
+ python -m pip install '.[test]'
132
+ python -m pytest -q tests/test_nonwater_example.py
133
+ ```
134
+
135
+ Expect `2 passed` from the example's tests.
136
+
137
+ ## Evidence and limits
138
+
139
+ - **Experimental, with restricted support.** Only the settings in the
140
+ [block catalogue](https://github.com/noelEOS/tensor-ee/blob/main/docs/building-blocks.md) have validation evidence. A conversion can
141
+ report settings outside those records; converting them does not validate them.
142
+ - **Numerical agreement is not model accuracy.** The [model evidence](https://github.com/noelEOS/tensor-ee/blob/main/docs/model.md)
143
+ records live comparisons with PyTorch and ONNX Runtime, offline graph identity,
144
+ and the inputs each result covers. The absolute logit target is 1e-4; segmentation
145
+ accuracy is not measured.
146
+ - **Known exception.** The U-Net's synthetic upper-left impulse chip has a largest
147
+ absolute logit difference of 1.6510487e-4, above the target; probabilities and the
148
+ water mask agree ([record](https://github.com/noelEOS/tensor-ee/blob/main/docs/history/cnn/SEGWATER_PYTORCH_RESULTS.md)).
149
+ - **EE limits still apply.** Inference uses EE computation and storage, with their costs
150
+ and quotas. The figures make no speed or cost comparison with Vertex AI.
151
+ - **Weights and training data.** Both trained models' EE weights are public under
152
+ [CC BY 4.0](https://github.com/noelEOS/tensor-ee/blob/main/WEIGHTS-LICENSE.md); their [manifests](https://github.com/noelEOS/tensor-ee/tree/main/data/manifests/) list the assets.
153
+ Checkpoint files are not yet public. Training used Sentinel-1 chips with water labels
154
+ derived from Sentinel-2; a fuller dataset description is not yet published
155
+ ([provenance](https://github.com/noelEOS/tensor-ee/blob/main/docs/model.md#training-data-and-provenance)).
156
+
157
+ ## Documentation
158
+
159
+ [Getting started](https://github.com/noelEOS/tensor-ee/blob/main/docs/getting-started.md) · [API guide](https://github.com/noelEOS/tensor-ee/blob/main/docs/api.md) ·
160
+ [Converter guide](https://github.com/noelEOS/tensor-ee/blob/main/docs/converter.md) · [Block catalogue](https://github.com/noelEOS/tensor-ee/blob/main/docs/building-blocks.md) ·
161
+ [All guides and evidence](https://github.com/noelEOS/tensor-ee/blob/main/docs/README.md) ·
162
+ [Changelog](https://github.com/noelEOS/tensor-ee/blob/main/CHANGELOG.md)
163
+
164
+ ## Licence, citation and attribution
165
+
166
+ Code and documentation: [MIT](https://github.com/noelEOS/tensor-ee/blob/main/LICENSE). Trained weights: [CC BY 4.0](https://github.com/noelEOS/tensor-ee/blob/main/WEIGHTS-LICENSE.md),
167
+ including the checkpoints when published. Satellite data and third-party libraries keep
168
+ their own terms. The Sentinel-1 examples contain modified Copernicus Sentinel data (2024).
169
+ To cite TensorEE, use [CITATION.cff](https://github.com/noelEOS/tensor-ee/blob/main/CITATION.cff) and record the commit used.
170
+
171
+ See [CONTRIBUTING](https://github.com/noelEOS/tensor-ee/blob/main/CONTRIBUTING.md) for contributions and [SECURITY.md](https://github.com/noelEOS/tensor-ee/blob/main/SECURITY.md) for
172
+ private vulnerability reports.
@@ -0,0 +1,131 @@
1
+ # TensorEE
2
+
3
+ [![Offline tests](https://github.com/noelEOS/tensor-ee/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/noelEOS/tensor-ee/actions/workflows/tests.yml)
4
+
5
+ **Run supported PyTorch models inside Google Earth Engine, without deploying a
6
+ model-serving endpoint.** TensorEE expresses neural-network inference as Earth Engine
7
+ image and array operations. Larger models can run in stages, saving intermediate
8
+ features as Earth Engine assets.
9
+
10
+ ![Earth Engine imagery passes to a deployed Vertex AI endpoint, or is evaluated directly with TensorEE's Earth Engine image and array operations](https://raw.githubusercontent.com/noelEOS/tensor-ee/main/docs/images/inference-location.svg)
11
+
12
+ Python builds the computation graph; Earth Engine evaluates the forward pass. Weights
13
+ are embedded constants or reads from EE table assets. Unsupported operations are refused,
14
+ not approximated. The [Vertex AI integration](https://developers.google.com/earth-engine/guides/ee-vertex-overview)
15
+ shown alongside it uses a separately deployed model endpoint.
16
+
17
+ ## A real example
18
+
19
+ ![Sentinel-1 radar imagery of Sun Moon Lake, with the water probability and mask computed by a trained U-Net inside Earth Engine](https://raw.githubusercontent.com/noelEOS/tensor-ee/main/docs/images/water_chip_224.png)
20
+
21
+ *A trained ResNet18 U-Net on one 224 × 224 Sentinel-1 chip: Sun Moon Lake, Taiwan,
22
+ 3 January 2024. Prediction, not ground truth. [Validation](https://github.com/noelEOS/tensor-ee/blob/main/docs/validation.md) ·
23
+ [Walkthrough](https://github.com/noelEOS/tensor-ee/blob/main/docs/water-chip.md). Contains modified Copernicus Sentinel data (2024).*
24
+
25
+ ## Get started
26
+
27
+ - **[Run the Code Editor demo](https://github.com/noelEOS/tensor-ee/blob/main/CODE_EDITOR.md).** No install or checkpoint. The trained
28
+ U-Net reads public weights; you need an Earth Engine account and a
29
+ [registered Cloud project](https://developers.google.com/earth-engine/guides/access)
30
+ where you can create an image asset. The demo exports one chip, billed to your project.
31
+ - **[Try the offline example](https://github.com/noelEOS/tensor-ee/blob/main/README.md#install).** Build a small CNN's graph locally, with no
32
+ credentials or cloud calls.
33
+ - **[Convert an attention model](https://github.com/noelEOS/tensor-ee/blob/main/docs/getting-started.md#5-convert-an-attention-model).**
34
+ Start with random weights, inspect the conversion report, then plan the stages.
35
+
36
+ ## What you can run
37
+
38
+ | Model or approach | Entry point | Availability |
39
+ |---|---|---|
40
+ | SegWater ResNet18 U-Net, 224 × 224 | [Code Editor demo](https://github.com/noelEOS/tensor-ee/blob/main/CODE_EDITOR.md); `compile_model` for CNNs | Trained EE weights are public; the Code Editor demo needs no checkpoint |
41
+ | Fixed Swin-T/UPerNet, 224 × 224 | [Three-stage workflow](https://github.com/noelEOS/tensor-ee/blob/main/docs/swin.md) | Trained EE weights are public; this workflow also needs a local checkpoint, not yet public |
42
+ | SMP SegFormer-B0 or UPerNet with timm's Swin encoder | [Attention converter](https://github.com/noelEOS/tensor-ee/blob/main/docs/converter.md) | Conversion examples use random weights; the report identifies settings outside the validated records |
43
+
44
+ You can also compose a model from the [block catalogue](https://github.com/noelEOS/tensor-ee/blob/main/docs/building-blocks.md).
45
+ It has 78 blocks: 16 in `tensor_ee/blocks/raster` and 62 in `tensor_ee/blocks/window`.
46
+ The [browser demo](https://github.com/noelEOS/tensor-ee/blob/main/DEMO.md) runs either trained model with a local checkpoint;
47
+ its `--offline` mode previews the interface without one.
48
+
49
+ ## Staged inference
50
+
51
+ Saving intermediate features lets a model run as several bounded EE graphs and avoids
52
+ recomputing earlier stages. In the fixed Swin workflow below, each step waits for its
53
+ predecessor's export to complete. The decoder reads both C4 and the earlier features.
54
+
55
+ ![Swin inference in three execution steps: weights are read from EE table assets, intermediate features are saved as EE image assets, and both feature paths feed the decoder. Active steps are blue; completed steps and saved assets turn green with checkmarks.](https://raw.githubusercontent.com/noelEOS/tensor-ee/main/docs/images/swin-inference.gif)
56
+
57
+ *Illustrative sequence, not execution timing. [Static diagram](https://raw.githubusercontent.com/noelEOS/tensor-ee/main/docs/images/swin-staged-inference.png).*
58
+
59
+ Weights live in EE table assets; saved features and predictions live in EE image assets.
60
+ The checkpoint, manifest and task state are local files. This workflow needs no GCS bucket.
61
+ The [Swin guide](https://github.com/noelEOS/tensor-ee/blob/main/docs/swin.md) details the three steps, including the validity summary
62
+ saved with C1–C3. Other models can use different cuts: the [converter planner](https://github.com/noelEOS/tensor-ee/blob/main/docs/converter.md#3-plan)
63
+ chooses stages under explicit limits.
64
+
65
+ ## Install
66
+
67
+ Python 3.11 or newer.
68
+
69
+ ```sh
70
+ python -m pip install tensor-ee
71
+ ```
72
+
73
+ Build a small CNN's graph offline, with no credentials or cloud calls:
74
+
75
+ ```sh
76
+ python -m tensor_ee.examples.nonwater --prepare
77
+ ```
78
+
79
+ Expect `"status": "offline_graph_only"` in the report.
80
+ [Getting started](https://github.com/noelEOS/tensor-ee/blob/main/docs/getting-started.md)
81
+ covers optional extras, PyTorch's download size and CPU-only installation, and the
82
+ steps for running in Earth Engine.
83
+
84
+ For the tests, tools, demos and checkout examples, install from source:
85
+
86
+ ```sh
87
+ git clone https://github.com/noelEOS/tensor-ee.git
88
+ cd tensor-ee
89
+ python -m venv .venv && source .venv/bin/activate
90
+ python -m pip install '.[test]'
91
+ python -m pytest -q tests/test_nonwater_example.py
92
+ ```
93
+
94
+ Expect `2 passed` from the example's tests.
95
+
96
+ ## Evidence and limits
97
+
98
+ - **Experimental, with restricted support.** Only the settings in the
99
+ [block catalogue](https://github.com/noelEOS/tensor-ee/blob/main/docs/building-blocks.md) have validation evidence. A conversion can
100
+ report settings outside those records; converting them does not validate them.
101
+ - **Numerical agreement is not model accuracy.** The [model evidence](https://github.com/noelEOS/tensor-ee/blob/main/docs/model.md)
102
+ records live comparisons with PyTorch and ONNX Runtime, offline graph identity,
103
+ and the inputs each result covers. The absolute logit target is 1e-4; segmentation
104
+ accuracy is not measured.
105
+ - **Known exception.** The U-Net's synthetic upper-left impulse chip has a largest
106
+ absolute logit difference of 1.6510487e-4, above the target; probabilities and the
107
+ water mask agree ([record](https://github.com/noelEOS/tensor-ee/blob/main/docs/history/cnn/SEGWATER_PYTORCH_RESULTS.md)).
108
+ - **EE limits still apply.** Inference uses EE computation and storage, with their costs
109
+ and quotas. The figures make no speed or cost comparison with Vertex AI.
110
+ - **Weights and training data.** Both trained models' EE weights are public under
111
+ [CC BY 4.0](https://github.com/noelEOS/tensor-ee/blob/main/WEIGHTS-LICENSE.md); their [manifests](https://github.com/noelEOS/tensor-ee/tree/main/data/manifests/) list the assets.
112
+ Checkpoint files are not yet public. Training used Sentinel-1 chips with water labels
113
+ derived from Sentinel-2; a fuller dataset description is not yet published
114
+ ([provenance](https://github.com/noelEOS/tensor-ee/blob/main/docs/model.md#training-data-and-provenance)).
115
+
116
+ ## Documentation
117
+
118
+ [Getting started](https://github.com/noelEOS/tensor-ee/blob/main/docs/getting-started.md) · [API guide](https://github.com/noelEOS/tensor-ee/blob/main/docs/api.md) ·
119
+ [Converter guide](https://github.com/noelEOS/tensor-ee/blob/main/docs/converter.md) · [Block catalogue](https://github.com/noelEOS/tensor-ee/blob/main/docs/building-blocks.md) ·
120
+ [All guides and evidence](https://github.com/noelEOS/tensor-ee/blob/main/docs/README.md) ·
121
+ [Changelog](https://github.com/noelEOS/tensor-ee/blob/main/CHANGELOG.md)
122
+
123
+ ## Licence, citation and attribution
124
+
125
+ Code and documentation: [MIT](https://github.com/noelEOS/tensor-ee/blob/main/LICENSE). Trained weights: [CC BY 4.0](https://github.com/noelEOS/tensor-ee/blob/main/WEIGHTS-LICENSE.md),
126
+ including the checkpoints when published. Satellite data and third-party libraries keep
127
+ their own terms. The Sentinel-1 examples contain modified Copernicus Sentinel data (2024).
128
+ To cite TensorEE, use [CITATION.cff](https://github.com/noelEOS/tensor-ee/blob/main/CITATION.cff) and record the commit used.
129
+
130
+ See [CONTRIBUTING](https://github.com/noelEOS/tensor-ee/blob/main/CONTRIBUTING.md) for contributions and [SECURITY.md](https://github.com/noelEOS/tensor-ee/blob/main/SECURITY.md) for
131
+ private vulnerability reports.
@@ -0,0 +1,21 @@
1
+ """Setuptools build step: the wheel ships the tensor_ee package only.
2
+
3
+ T01-T06 shipped a filtered research closure beside tensor_ee (``SWIN_MODULES``,
4
+ pinned to docs/evidence/t01-runtime-imports.json). Since L06 the runtime closure
5
+ of the library, the converter, the two reference models and the SegWater recipe
6
+ is tensor_ee plus third-party dependencies (docs/evidence/l06-runtime-imports.json),
7
+ and pyproject.toml finds ``tensor_ee*`` only. So nothing is filtered any more:
8
+ this step builds tensor_ee unchanged and refuses any other package, so that a
9
+ research folder cannot ship again by a change to the package list. This file is
10
+ build tooling, not runtime.
11
+ """
12
+ from setuptools.command.build_py import build_py
13
+
14
+ PACKAGE = "tensor_ee"
15
+
16
+
17
+ class RuntimeOnlyBuild(build_py):
18
+ def find_package_modules(self, package, package_dir):
19
+ if package != PACKAGE and not package.startswith(PACKAGE + "."):
20
+ raise ValueError(f"only the {PACKAGE} package ships in the wheel; refusing {package!r}")
21
+ return super().find_package_modules(package, package_dir)
@@ -0,0 +1,52 @@
1
+ [build-system]
2
+ requires = ["setuptools>=83"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "tensor-ee"
7
+ version = "0.1.0"
8
+ description = "Experimental building blocks for running pretrained PyTorch models natively in Google Earth Engine: a restricted CNN compiler (the SegWater U-Net; standard SMP Unet and UnetPlusPlus on ResNet and VGG encoders), a converter for supported attention models (SMP SegFormer-B0; SMP UPerNet with timm's Swin-T), and a planner and runner for staged exports."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ authors = [{name = "Noel Ivan Ulloa"}]
13
+ requires-python = ">=3.11"
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: Science/Research",
17
+ "Operating System :: OS Independent",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
22
+ "Topic :: Scientific/Engineering :: GIS",
23
+ ]
24
+ keywords = ["earth-engine", "pytorch", "geospatial", "remote-sensing", "neural-networks"]
25
+ dependencies = ["earthengine-api>=1.7.0", "torch>=2.10", "numpy>=1.26"]
26
+
27
+ [project.urls]
28
+ Repository = "https://github.com/noelEOS/tensor-ee"
29
+ Issues = "https://github.com/noelEOS/tensor-ee/issues"
30
+ Documentation = "https://github.com/noelEOS/tensor-ee/blob/main/docs/README.md"
31
+ Changelog = "https://github.com/noelEOS/tensor-ee/blob/main/CHANGELOG.md"
32
+
33
+ [project.optional-dependencies]
34
+ test = ["pytest>=9.0.3"]
35
+ resnet = ["torchvision>=0.20"]
36
+ onnx = ["onnx>=1.22", "onnxruntime>=1.20"]
37
+ segwater = ["segmentation-models-pytorch==0.5.0"]
38
+ swin = ["segmentation-models-pytorch==0.5.0", "timm==1.0.30"]
39
+ plot = ["matplotlib>=3.8"]
40
+
41
+ [tool.setuptools]
42
+ include-package-data = false
43
+
44
+ [tool.setuptools.cmdclass]
45
+ build_py = "build_support.RuntimeOnlyBuild"
46
+
47
+ [tool.setuptools.packages.find]
48
+ include = ["tensor_ee*"]
49
+
50
+ [tool.pytest.ini_options]
51
+ testpaths = ["tests"]
52
+ pythonpath = ["."]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,28 @@
1
+ """Experimental PyTorch-compatible building blocks for native Earth Engine."""
2
+
3
+ from importlib.metadata import PackageNotFoundError as _PackageNotFoundError, version as _distribution_version
4
+
5
+ try:
6
+ __version__ = _distribution_version("tensor-ee")
7
+ except _PackageNotFoundError:
8
+ __version__ = "0.1.0" # Source checkouts need no installed distribution metadata.
9
+
10
+ from .comparison import PixelTensor, compare_segmentation
11
+ from .compatibility import CompatibilityReport, check_compatibility
12
+ from .compiler import CompiledModel, Grid, Raster, UnsupportedOperation, WeightProvider, compile_model
13
+ from .primitives import (concatenate, conv2d, eval_dropout, from_image, gelu, leaky_relu, nearest_upsample,
14
+ pool2d, relu, residual_add, sigmoid, silu, softmax, tanh)
15
+ from .outputs import SegmentationOutputs, binary_threshold, segmentation_outputs
16
+ from .weight_assets import FeatureCollectionWeightProvider, effective_convolutions, export_weights
17
+ from .weight_mapping import MatchedWeightProvider
18
+
19
+ __all__ = [
20
+ "PixelTensor", "compare_segmentation",
21
+ "CompatibilityReport", "check_compatibility",
22
+ "CompiledModel", "Grid", "Raster", "UnsupportedOperation", "WeightProvider",
23
+ "compile_model", "from_image", "conv2d", "pool2d", "nearest_upsample",
24
+ "concatenate", "residual_add", "relu", "sigmoid", "leaky_relu", "silu", "gelu", "tanh", "eval_dropout", "softmax",
25
+ "SegmentationOutputs", "segmentation_outputs", "binary_threshold",
26
+ "FeatureCollectionWeightProvider", "MatchedWeightProvider",
27
+ "effective_convolutions", "export_weights",
28
+ ]