tensorplate-python 0.1.3__py3-none-any.whl
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.
- tensorplate/__init__.py +71 -0
- tensorplate/client.py +278 -0
- tensorplate/conventions.py +29 -0
- tensorplate/errors.py +87 -0
- tensorplate/postprocess.py +142 -0
- tensorplate/preprocess.py +165 -0
- tensorplate/py.typed +0 -0
- tensorplate/serving.py +291 -0
- tensorplate/tensors.py +250 -0
- tensorplate/vision.py +121 -0
- tensorplate_python-0.1.3.dist-info/METADATA +83 -0
- tensorplate_python-0.1.3.dist-info/RECORD +15 -0
- tensorplate_python-0.1.3.dist-info/WHEEL +5 -0
- tensorplate_python-0.1.3.dist-info/licenses/LICENSE +203 -0
- tensorplate_python-0.1.3.dist-info/top_level.txt +1 -0
tensorplate/tensors.py
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"""Tensor value objects and v0.1 serving-envelope tensor marshalling.
|
|
2
|
+
|
|
3
|
+
Tensors travel over the wire as base64-encoded raw bytes plus a small
|
|
4
|
+
metadata block (``dtype``, ``shape``, ``layout``, ``byte_offset``,
|
|
5
|
+
``byte_size``). These value objects own that marshalling so the client
|
|
6
|
+
and the vision helpers share one representation. ``numpy`` is an optional
|
|
7
|
+
dependency: array access imports it lazily and fails with a clear message
|
|
8
|
+
when it is absent.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import base64
|
|
14
|
+
import math
|
|
15
|
+
from dataclasses import dataclass
|
|
16
|
+
from enum import Enum
|
|
17
|
+
from typing import TYPE_CHECKING, Literal
|
|
18
|
+
|
|
19
|
+
from tensorplate.errors import ProtocolError
|
|
20
|
+
|
|
21
|
+
if TYPE_CHECKING:
|
|
22
|
+
import numpy as np
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class DType(str, Enum):
|
|
26
|
+
"""Supported v0.1 envelope tensor dtypes."""
|
|
27
|
+
|
|
28
|
+
FLOAT32 = "float32"
|
|
29
|
+
FLOAT16 = "float16"
|
|
30
|
+
BFLOAT16 = "bfloat16"
|
|
31
|
+
INT64 = "int64"
|
|
32
|
+
INT32 = "int32"
|
|
33
|
+
INT16 = "int16"
|
|
34
|
+
INT8 = "int8"
|
|
35
|
+
UINT8 = "uint8"
|
|
36
|
+
BOOL = "bool"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class Layout(str, Enum):
|
|
40
|
+
"""Memory layout of the raw tensor bytes."""
|
|
41
|
+
|
|
42
|
+
ROW_MAJOR = "row_major"
|
|
43
|
+
COL_MAJOR = "col_major"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
#: Bytes per element for each dtype.
|
|
47
|
+
_ITEMSIZE: dict[DType, int] = {
|
|
48
|
+
DType.FLOAT32: 4,
|
|
49
|
+
DType.FLOAT16: 2,
|
|
50
|
+
DType.BFLOAT16: 2,
|
|
51
|
+
DType.INT64: 8,
|
|
52
|
+
DType.INT32: 4,
|
|
53
|
+
DType.INT16: 2,
|
|
54
|
+
DType.INT8: 1,
|
|
55
|
+
DType.UINT8: 1,
|
|
56
|
+
DType.BOOL: 1,
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
#: dtypes with a native numpy mapping. ``bfloat16`` is intentionally
|
|
60
|
+
#: absent: numpy has no native bfloat16, so array access for it raises.
|
|
61
|
+
_NUMPY_NAME: dict[DType, str] = {
|
|
62
|
+
DType.FLOAT32: "float32",
|
|
63
|
+
DType.FLOAT16: "float16",
|
|
64
|
+
DType.INT64: "int64",
|
|
65
|
+
DType.INT32: "int32",
|
|
66
|
+
DType.INT16: "int16",
|
|
67
|
+
DType.INT8: "int8",
|
|
68
|
+
DType.UINT8: "uint8",
|
|
69
|
+
DType.BOOL: "bool",
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
_NUMPY_NAME_TO_DTYPE: dict[str, DType] = {name: dt for dt, name in _NUMPY_NAME.items()}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def itemsize(dtype: DType) -> int:
|
|
76
|
+
"""Return the number of bytes per element for ``dtype``."""
|
|
77
|
+
return _ITEMSIZE[dtype]
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@dataclass(frozen=True)
|
|
81
|
+
class TensorInput:
|
|
82
|
+
"""A single named input tensor ready to marshal into the v0.1 envelope."""
|
|
83
|
+
|
|
84
|
+
name: str
|
|
85
|
+
dtype: DType
|
|
86
|
+
shape: tuple[int, ...]
|
|
87
|
+
data: bytes
|
|
88
|
+
layout: Layout = Layout.ROW_MAJOR
|
|
89
|
+
|
|
90
|
+
def __post_init__(self) -> None:
|
|
91
|
+
if not self.name:
|
|
92
|
+
raise ValueError("tensor input name must be non-empty")
|
|
93
|
+
if not self.shape:
|
|
94
|
+
raise ValueError(f"tensor input {self.name!r} must have at least one dimension")
|
|
95
|
+
if any(dim < 1 for dim in self.shape):
|
|
96
|
+
raise ValueError(
|
|
97
|
+
f"tensor input {self.name!r} has a non-positive dimension: {self.shape}"
|
|
98
|
+
)
|
|
99
|
+
expected = _ITEMSIZE[self.dtype] * math.prod(self.shape)
|
|
100
|
+
if len(self.data) != expected:
|
|
101
|
+
raise ValueError(
|
|
102
|
+
f"tensor input {self.name!r}: data is {len(self.data)} bytes, expected {expected} "
|
|
103
|
+
f"for dtype {self.dtype.value} shape {self.shape}"
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
def to_named_input(self) -> dict[str, object]:
|
|
107
|
+
"""Serialize to a v0.1 ``NamedInput`` envelope object."""
|
|
108
|
+
return {
|
|
109
|
+
"name": self.name,
|
|
110
|
+
"tensor": {
|
|
111
|
+
"dtype": self.dtype.value,
|
|
112
|
+
"layout": self.layout.value,
|
|
113
|
+
"shape": list(self.shape),
|
|
114
|
+
"byte_offset": 0,
|
|
115
|
+
"byte_size": len(self.data),
|
|
116
|
+
},
|
|
117
|
+
"payload_b64": base64.b64encode(self.data).decode("ascii"),
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@classmethod
|
|
121
|
+
def from_numpy(
|
|
122
|
+
cls,
|
|
123
|
+
name: str,
|
|
124
|
+
array: np.ndarray,
|
|
125
|
+
*,
|
|
126
|
+
dtype: DType | None = None,
|
|
127
|
+
layout: Layout = Layout.ROW_MAJOR,
|
|
128
|
+
) -> TensorInput:
|
|
129
|
+
"""Build a ``TensorInput`` from a numpy array (numpy required)."""
|
|
130
|
+
resolved = dtype if dtype is not None else _NUMPY_NAME_TO_DTYPE.get(str(array.dtype))
|
|
131
|
+
if resolved is None:
|
|
132
|
+
raise ValueError(
|
|
133
|
+
f"numpy dtype {array.dtype!r} has no v0.1 envelope mapping; "
|
|
134
|
+
"pass `dtype=` explicitly"
|
|
135
|
+
)
|
|
136
|
+
order: Literal["C", "F"] = "C" if layout is Layout.ROW_MAJOR else "F"
|
|
137
|
+
data = array.astype(_NUMPY_NAME[resolved], copy=False).tobytes(order=order)
|
|
138
|
+
return cls(
|
|
139
|
+
name=name,
|
|
140
|
+
dtype=resolved,
|
|
141
|
+
shape=tuple(int(dim) for dim in array.shape),
|
|
142
|
+
data=data,
|
|
143
|
+
layout=layout,
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
@dataclass(frozen=True)
|
|
148
|
+
class TensorOutput:
|
|
149
|
+
"""A single named output tensor parsed from a v0.1 success envelope."""
|
|
150
|
+
|
|
151
|
+
name: str
|
|
152
|
+
dtype: DType
|
|
153
|
+
shape: tuple[int, ...]
|
|
154
|
+
data: bytes
|
|
155
|
+
layout: Layout = Layout.ROW_MAJOR
|
|
156
|
+
semantic_tag: str | None = None
|
|
157
|
+
|
|
158
|
+
@classmethod
|
|
159
|
+
def from_named_output(cls, obj: object) -> TensorOutput:
|
|
160
|
+
"""Parse a v0.1 ``NamedOutput`` envelope object."""
|
|
161
|
+
if not isinstance(obj, dict):
|
|
162
|
+
raise ProtocolError("serving output entry is not a JSON object")
|
|
163
|
+
name = obj.get("name")
|
|
164
|
+
if not isinstance(name, str) or not name:
|
|
165
|
+
raise ProtocolError("serving output is missing a non-empty 'name'")
|
|
166
|
+
tensor = obj.get("tensor")
|
|
167
|
+
if not isinstance(tensor, dict):
|
|
168
|
+
raise ProtocolError(f"serving output {name!r} is missing its 'tensor' metadata")
|
|
169
|
+
dtype_value = tensor.get("dtype")
|
|
170
|
+
try:
|
|
171
|
+
dtype = DType(dtype_value)
|
|
172
|
+
except ValueError as exc:
|
|
173
|
+
raise ProtocolError(
|
|
174
|
+
f"serving output {name!r} has unknown dtype {dtype_value!r}"
|
|
175
|
+
) from exc
|
|
176
|
+
layout_value = tensor.get("layout", Layout.ROW_MAJOR.value)
|
|
177
|
+
try:
|
|
178
|
+
layout = Layout(layout_value)
|
|
179
|
+
except ValueError as exc:
|
|
180
|
+
raise ProtocolError(
|
|
181
|
+
f"serving output {name!r} has unknown layout {layout_value!r}"
|
|
182
|
+
) from exc
|
|
183
|
+
shape_raw = tensor.get("shape")
|
|
184
|
+
if (
|
|
185
|
+
not isinstance(shape_raw, list)
|
|
186
|
+
or not shape_raw
|
|
187
|
+
or not all(
|
|
188
|
+
isinstance(dim, int) and not isinstance(dim, bool) and dim >= 1 for dim in shape_raw
|
|
189
|
+
)
|
|
190
|
+
):
|
|
191
|
+
raise ProtocolError(f"serving output {name!r} has an invalid 'shape'")
|
|
192
|
+
shape = tuple(int(dim) for dim in shape_raw)
|
|
193
|
+
expected_size = _ITEMSIZE[dtype] * math.prod(shape)
|
|
194
|
+
payload_b64 = obj.get("payload_b64")
|
|
195
|
+
if not isinstance(payload_b64, str):
|
|
196
|
+
raise ProtocolError(f"serving output {name!r} is missing 'payload_b64'")
|
|
197
|
+
try:
|
|
198
|
+
raw = base64.b64decode(payload_b64, validate=True)
|
|
199
|
+
except ValueError as exc:
|
|
200
|
+
raise ProtocolError(f"serving output {name!r} has an invalid base64 payload") from exc
|
|
201
|
+
offset_obj = tensor.get("byte_offset", 0)
|
|
202
|
+
if not isinstance(offset_obj, int) or isinstance(offset_obj, bool) or offset_obj < 0:
|
|
203
|
+
raise ProtocolError(f"serving output {name!r} has an invalid 'byte_offset'")
|
|
204
|
+
offset = offset_obj
|
|
205
|
+
if "byte_size" in tensor:
|
|
206
|
+
size_obj = tensor.get("byte_size")
|
|
207
|
+
if not isinstance(size_obj, int) or isinstance(size_obj, bool) or size_obj < 0:
|
|
208
|
+
raise ProtocolError(f"serving output {name!r} has an invalid 'byte_size'")
|
|
209
|
+
size = expected_size if size_obj == 0 else size_obj
|
|
210
|
+
else:
|
|
211
|
+
size = expected_size
|
|
212
|
+
if size < expected_size:
|
|
213
|
+
raise ProtocolError(
|
|
214
|
+
f"serving output {name!r} byte_size is {size}, expected {expected_size} "
|
|
215
|
+
f"for dtype {dtype.value} shape {shape}"
|
|
216
|
+
)
|
|
217
|
+
end = offset + size
|
|
218
|
+
if len(raw) < end:
|
|
219
|
+
raise ProtocolError(f"serving output {name!r} payload is {len(raw)} bytes, need {end}")
|
|
220
|
+
data = raw[offset : offset + expected_size]
|
|
221
|
+
semantic_tag = obj.get("semantic_tag")
|
|
222
|
+
return cls(
|
|
223
|
+
name=name,
|
|
224
|
+
dtype=dtype,
|
|
225
|
+
shape=shape,
|
|
226
|
+
data=data,
|
|
227
|
+
layout=layout,
|
|
228
|
+
semantic_tag=semantic_tag if isinstance(semantic_tag, str) else None,
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
def to_numpy(self) -> np.ndarray:
|
|
232
|
+
"""Return the tensor as a numpy array (numpy required).
|
|
233
|
+
|
|
234
|
+
Raises ``ValueError`` for dtypes with no native numpy mapping
|
|
235
|
+
(``bfloat16``); use :attr:`data` for the raw bytes in that case.
|
|
236
|
+
"""
|
|
237
|
+
numpy_name = _NUMPY_NAME.get(self.dtype)
|
|
238
|
+
if numpy_name is None:
|
|
239
|
+
raise ValueError(
|
|
240
|
+
f"dtype {self.dtype.value!r} has no native numpy mapping; read `.data` instead"
|
|
241
|
+
)
|
|
242
|
+
try:
|
|
243
|
+
import numpy
|
|
244
|
+
except ModuleNotFoundError as exc: # pragma: no cover - exercised only without numpy
|
|
245
|
+
raise RuntimeError(
|
|
246
|
+
"tensor array access requires numpy; install `tensorplate-python[numpy]`"
|
|
247
|
+
) from exc
|
|
248
|
+
array = numpy.frombuffer(self.data, dtype=numpy_name)
|
|
249
|
+
order: Literal["C", "F"] = "C" if self.layout is Layout.ROW_MAJOR else "F"
|
|
250
|
+
return array.reshape(self.shape, order=order)
|
tensorplate/vision.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"""High-level vision detection client built on the serving client."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Sequence
|
|
6
|
+
from dataclasses import replace
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import TYPE_CHECKING
|
|
9
|
+
|
|
10
|
+
from tensorplate.client import DEFAULT_TIMEOUT_S
|
|
11
|
+
from tensorplate.conventions import YOLO_V8_SINGLE_OUTPUT, detections
|
|
12
|
+
from tensorplate.errors import ProtocolError
|
|
13
|
+
from tensorplate.postprocess import Detection, decode_detections
|
|
14
|
+
from tensorplate.preprocess import PreprocessConfig, preprocess
|
|
15
|
+
from tensorplate.serving import InferResult, ServingClient
|
|
16
|
+
from tensorplate.tensors import TensorOutput
|
|
17
|
+
|
|
18
|
+
if TYPE_CHECKING:
|
|
19
|
+
import numpy as np
|
|
20
|
+
|
|
21
|
+
_DETECTION_TAGS = frozenset({detections.boxes, detections.scores, detections.classes})
|
|
22
|
+
_DEFAULT_INPUT_NAME = "images"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class VisionClient:
|
|
26
|
+
"""High-level object-detection client over a deployed detector.
|
|
27
|
+
|
|
28
|
+
Composes client-side preprocessing, ``ServingClient.infer``, and YOLO
|
|
29
|
+
postprocessing into a single :meth:`detect` call. Synchronous in
|
|
30
|
+
v0.1.3. Pass an existing :class:`ServingClient` via ``client``, or let
|
|
31
|
+
the constructor resolve one with the same precedence as the CLI.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
def __init__(
|
|
35
|
+
self,
|
|
36
|
+
serving_url: str | None = None,
|
|
37
|
+
*,
|
|
38
|
+
profile: str | None = None,
|
|
39
|
+
config_path: str | None = None,
|
|
40
|
+
timeout: float = DEFAULT_TIMEOUT_S,
|
|
41
|
+
discover: bool = True,
|
|
42
|
+
client: ServingClient | None = None,
|
|
43
|
+
) -> None:
|
|
44
|
+
self._serving = client or ServingClient(
|
|
45
|
+
serving_url,
|
|
46
|
+
profile=profile,
|
|
47
|
+
config_path=config_path,
|
|
48
|
+
timeout=timeout,
|
|
49
|
+
discover=discover,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def serving(self) -> ServingClient:
|
|
54
|
+
"""The underlying serving client."""
|
|
55
|
+
return self._serving
|
|
56
|
+
|
|
57
|
+
def detect(
|
|
58
|
+
self,
|
|
59
|
+
image: str | bytes | Path | np.ndarray,
|
|
60
|
+
*,
|
|
61
|
+
endpoint: str,
|
|
62
|
+
input_name: str = _DEFAULT_INPUT_NAME,
|
|
63
|
+
output_name: str | None = None,
|
|
64
|
+
score_threshold: float = 0.25,
|
|
65
|
+
nms_threshold: float = 0.45,
|
|
66
|
+
labels: Sequence[str] | None = None,
|
|
67
|
+
transposed: bool = False,
|
|
68
|
+
contract: str = YOLO_V8_SINGLE_OUTPUT,
|
|
69
|
+
preprocess_config: PreprocessConfig | None = None,
|
|
70
|
+
) -> list[Detection]:
|
|
71
|
+
"""Detect objects in ``image`` using the deployed model at ``endpoint``.
|
|
72
|
+
|
|
73
|
+
Preprocesses the image, runs one synchronous inference, and decodes
|
|
74
|
+
the detector output into source-pixel :class:`Detection` results.
|
|
75
|
+
Requires the ``tensorplate-python[vision]`` extra. The detection
|
|
76
|
+
output tensor is chosen explicitly (``output_name``), or — for a
|
|
77
|
+
single-output response — automatically, or by a ``detections.*``
|
|
78
|
+
``semantic_tag``; an ambiguous response fails clearly.
|
|
79
|
+
"""
|
|
80
|
+
if preprocess_config is not None:
|
|
81
|
+
config = (
|
|
82
|
+
preprocess_config
|
|
83
|
+
if input_name == _DEFAULT_INPUT_NAME
|
|
84
|
+
else replace(preprocess_config, input_name=input_name)
|
|
85
|
+
)
|
|
86
|
+
else:
|
|
87
|
+
config = PreprocessConfig(input_name=input_name)
|
|
88
|
+
tensor, transform = preprocess(image, config)
|
|
89
|
+
result = self._serving.infer(endpoint, [tensor])
|
|
90
|
+
output = _select_detection_output(result, output_name)
|
|
91
|
+
return decode_detections(
|
|
92
|
+
output,
|
|
93
|
+
transform,
|
|
94
|
+
score_threshold=score_threshold,
|
|
95
|
+
nms_threshold=nms_threshold,
|
|
96
|
+
labels=labels,
|
|
97
|
+
transposed=transposed,
|
|
98
|
+
contract=contract,
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def _select_detection_output(result: InferResult, output_name: str | None) -> TensorOutput:
|
|
103
|
+
if output_name is not None:
|
|
104
|
+
for output in result.outputs:
|
|
105
|
+
if output.name == output_name:
|
|
106
|
+
return output
|
|
107
|
+
available = [output.name for output in result.outputs]
|
|
108
|
+
raise ProtocolError(
|
|
109
|
+
f"serving response has no output named {output_name!r}; available: {available}"
|
|
110
|
+
)
|
|
111
|
+
if len(result.outputs) == 1:
|
|
112
|
+
return result.outputs[0]
|
|
113
|
+
tagged = [output for output in result.outputs if output.semantic_tag in _DETECTION_TAGS]
|
|
114
|
+
if len(tagged) == 1:
|
|
115
|
+
return tagged[0]
|
|
116
|
+
available = [output.name for output in result.outputs]
|
|
117
|
+
raise ProtocolError(
|
|
118
|
+
f"serving response has {len(result.outputs)} outputs; pass output_name to choose the "
|
|
119
|
+
f"detection tensor (available: {available}), or tag exactly one output with a "
|
|
120
|
+
"detections.* semantic_tag"
|
|
121
|
+
)
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tensorplate-python
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: First-party Python SDK for calling deployed TensorPlate detection and vision serving models.
|
|
5
|
+
Author: TensorPlate Contributors
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/tensorplate/tensorplate
|
|
8
|
+
Project-URL: Repository, https://github.com/tensorplate/tensorplate
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Provides-Extra: numpy
|
|
22
|
+
Requires-Dist: numpy>=1.22; extra == "numpy"
|
|
23
|
+
Provides-Extra: vision
|
|
24
|
+
Requires-Dist: numpy>=1.22; extra == "vision"
|
|
25
|
+
Requires-Dist: pillow>=9.1; extra == "vision"
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
28
|
+
Requires-Dist: ruff>=0.6; extra == "dev"
|
|
29
|
+
Requires-Dist: mypy>=1.10; extra == "dev"
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# `sdk/python/`
|
|
33
|
+
|
|
34
|
+
`tensorplate-python` — the first-party Python SDK for calling deployed
|
|
35
|
+
TensorPlate detection and vision serving models over the v0.1 `/infer`
|
|
36
|
+
HTTP envelope.
|
|
37
|
+
|
|
38
|
+
The import package is `tensorplate`:
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
import tensorplate
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Install
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install tensorplate-python # core client
|
|
48
|
+
pip install "tensorplate-python[vision]" # + numpy & Pillow for VisionClient.detect
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The wheel + sdist are also attached to each signed GitHub Release for
|
|
52
|
+
checksum-verified or air-gapped installs. See the
|
|
53
|
+
[SDK quickstart](../../docs/sdk/python.md#install) for that flow and the
|
|
54
|
+
`[numpy]` / `[vision]` extras.
|
|
55
|
+
|
|
56
|
+
## Ownership
|
|
57
|
+
|
|
58
|
+
- **Layer:** client / user space (no runtime or serving-worker code)
|
|
59
|
+
- **Language:** Python (3.10+)
|
|
60
|
+
- **Distribution:** `tensorplate-python` (PEP 621 `pyproject.toml`)
|
|
61
|
+
- **Import package:** `tensorplate`
|
|
62
|
+
|
|
63
|
+
## Documentation
|
|
64
|
+
|
|
65
|
+
- [Quickstart and API reference](../../docs/sdk/python.md) —
|
|
66
|
+
`ServingClient`, `VisionClient`, `Detection`, tensors, and errors.
|
|
67
|
+
- [Detection workflow](../../docs/sdk/detection.md) — preprocessing, the
|
|
68
|
+
`yolo_v8_single_output` contract, and postprocessing.
|
|
69
|
+
- [Endpoint resolution](../../docs/sdk/endpoint-resolution.md) — CLI-parity
|
|
70
|
+
precedence and URL canonicalization.
|
|
71
|
+
- [Examples](../../examples/vision_detection_sdk/) — single-image and
|
|
72
|
+
user-space camera samples.
|
|
73
|
+
|
|
74
|
+
## Scope
|
|
75
|
+
|
|
76
|
+
The SDK is a client-side library: it calls already-deployed models and
|
|
77
|
+
does not change runtime serving. In-runtime camera/video ingest, a
|
|
78
|
+
DeepStream sink, and a streaming session API are out of scope and are
|
|
79
|
+
not provided here.
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
Apache-2.0. See [`LICENSE`](LICENSE).
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
tensorplate/__init__.py,sha256=cPJYqsMBR-PjWtfqN1N1yA2alUrVv32RwaSSTPQ1UUs,1961
|
|
2
|
+
tensorplate/client.py,sha256=SwgFZYnxXO1Ff3ruBSIAdCMzbyReGixlXOvjYK6Oj5M,10506
|
|
3
|
+
tensorplate/conventions.py,sha256=rysRZVfesQ6vRLrlTxiWbRBK4zbazvv-9njmBVKdJJo,1109
|
|
4
|
+
tensorplate/errors.py,sha256=oZSYgG1T8TtLaw4jFwW806KzfDzke_5GB6Omlkvx8Uw,2718
|
|
5
|
+
tensorplate/postprocess.py,sha256=GusFErKCJdUERoDUDvdrPbMkt0wtEFkXL5R3_c5O_JA,5186
|
|
6
|
+
tensorplate/preprocess.py,sha256=ItUWijW3jKzel3ESLhnjg5ag6BoNXQhytpa_2o08fKk,6019
|
|
7
|
+
tensorplate/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
tensorplate/serving.py,sha256=d4OYe4JdcPFJWTwTzbi3xgbftFxgfSEHDiubc7C_eAc,10287
|
|
9
|
+
tensorplate/tensors.py,sha256=KvI3zYkAfNuquBKb9xDT-Mt4W8HudMECt02aHbMKm6Y,8939
|
|
10
|
+
tensorplate/vision.py,sha256=KwbVfPqtqdbIGSzEKqbkif9-KZj6U0zUZ81MrQDPPhw,4531
|
|
11
|
+
tensorplate_python-0.1.3.dist-info/licenses/LICENSE,sha256=ZxVIDHiEBfOHLu3QJTeSSO8fYRNUlInHP9ESK3DZmEE,11389
|
|
12
|
+
tensorplate_python-0.1.3.dist-info/METADATA,sha256=vS3F-CXLjd5BCrwYKRsUkzbzkyZZtNPp9d3Oy62JX3c,2905
|
|
13
|
+
tensorplate_python-0.1.3.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
14
|
+
tensorplate_python-0.1.3.dist-info/top_level.txt,sha256=FFVk-zeOOH6pSd9Hd9gzDD7WSJpbZ23RazVSCssIXnM,12
|
|
15
|
+
tensorplate_python-0.1.3.dist-info/RECORD,,
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
Copyright 2026 TensorPlate Inc
|
|
2
|
+
|
|
3
|
+
Apache License
|
|
4
|
+
Version 2.0, January 2004
|
|
5
|
+
http://www.apache.org/licenses/
|
|
6
|
+
|
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
|
+
|
|
9
|
+
1. Definitions.
|
|
10
|
+
|
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
12
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
13
|
+
|
|
14
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
15
|
+
the copyright owner that is granting the License.
|
|
16
|
+
|
|
17
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
18
|
+
other entities that control, are controlled by, or are under common
|
|
19
|
+
control with that entity. For the purposes of this definition,
|
|
20
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
21
|
+
direction or management of such entity, whether by contract or
|
|
22
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
23
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
24
|
+
|
|
25
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
26
|
+
exercising permissions granted by this License.
|
|
27
|
+
|
|
28
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
29
|
+
including but not limited to software source code, documentation
|
|
30
|
+
source, and configuration files.
|
|
31
|
+
|
|
32
|
+
"Object" form shall mean any form resulting from mechanical
|
|
33
|
+
transformation or translation of a Source form, including but
|
|
34
|
+
not limited to compiled object code, generated documentation,
|
|
35
|
+
and conversions to other media types.
|
|
36
|
+
|
|
37
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
38
|
+
Object form, made available under the License, as indicated by a
|
|
39
|
+
copyright notice that is included in or attached to the work
|
|
40
|
+
(an example is provided in the Appendix below).
|
|
41
|
+
|
|
42
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
43
|
+
form, that is based on (or derived from) the Work and for which the
|
|
44
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
45
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
46
|
+
of this License, Derivative Works shall not include works that remain
|
|
47
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
48
|
+
the Work and Derivative Works thereof.
|
|
49
|
+
|
|
50
|
+
"Contribution" shall mean any work of authorship, including
|
|
51
|
+
the original version of the Work and any modifications or additions
|
|
52
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
53
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
54
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
55
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
56
|
+
means any form of electronic, verbal, or written communication sent
|
|
57
|
+
to the Licensor or its representatives, including but not limited to
|
|
58
|
+
communication on electronic mailing lists, source code control systems,
|
|
59
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
60
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
61
|
+
excluding communication that is conspicuously marked or otherwise
|
|
62
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
63
|
+
|
|
64
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
65
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
66
|
+
subsequently incorporated within the Work.
|
|
67
|
+
|
|
68
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
69
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
70
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
71
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
72
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
73
|
+
Work and such Derivative Works in Source or Object form.
|
|
74
|
+
|
|
75
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
76
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
77
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
78
|
+
(except as stated in this section) patent license to make, have made,
|
|
79
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
80
|
+
where such license applies only to those patent claims licensable
|
|
81
|
+
by such Contributor that are necessarily infringed by their
|
|
82
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
83
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
84
|
+
institute patent litigation against any entity (including a
|
|
85
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
86
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
87
|
+
or contributory patent infringement, then any patent licenses
|
|
88
|
+
granted to You under this License for that Work shall terminate
|
|
89
|
+
as of the date such litigation is filed.
|
|
90
|
+
|
|
91
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
92
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
93
|
+
modifications, and in Source or Object form, provided that You
|
|
94
|
+
meet the following conditions:
|
|
95
|
+
|
|
96
|
+
(a) You must give any other recipients of the Work or
|
|
97
|
+
Derivative Works a copy of this License; and
|
|
98
|
+
|
|
99
|
+
(b) You must cause any modified files to carry prominent notices
|
|
100
|
+
stating that You changed the files; and
|
|
101
|
+
|
|
102
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
103
|
+
that You distribute, all copyright, patent, trademark, and
|
|
104
|
+
attribution notices from the Source form of the Work,
|
|
105
|
+
excluding those notices that do not pertain to any part of
|
|
106
|
+
the Derivative Works; and
|
|
107
|
+
|
|
108
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
109
|
+
distribution, then any Derivative Works that You distribute must
|
|
110
|
+
include a readable copy of the attribution notices contained
|
|
111
|
+
within such NOTICE file, excluding those notices that do not
|
|
112
|
+
pertain to any part of the Derivative Works, in at least one
|
|
113
|
+
of the following places: within a NOTICE text file distributed
|
|
114
|
+
as part of the Derivative Works; within the Source form or
|
|
115
|
+
documentation, if provided along with the Derivative Works; or,
|
|
116
|
+
within a display generated by the Derivative Works, if and
|
|
117
|
+
wherever such third-party notices normally appear. The contents
|
|
118
|
+
of the NOTICE file are for informational purposes only and
|
|
119
|
+
do not modify the License. You may add Your own attribution
|
|
120
|
+
notices within Derivative Works that You distribute, alongside
|
|
121
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
122
|
+
that such additional attribution notices cannot be construed
|
|
123
|
+
as modifying the License.
|
|
124
|
+
|
|
125
|
+
You may add Your own copyright statement to Your modifications and
|
|
126
|
+
may provide additional or different license terms and conditions
|
|
127
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
128
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
129
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
130
|
+
the conditions stated in this License.
|
|
131
|
+
|
|
132
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
133
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
134
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
135
|
+
this License, without any additional terms or conditions.
|
|
136
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
137
|
+
the terms of any separate license agreement you may have executed
|
|
138
|
+
with Licensor regarding such Contributions.
|
|
139
|
+
|
|
140
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
141
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
142
|
+
except as required for reasonable and customary use in describing the
|
|
143
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
144
|
+
|
|
145
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
146
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
147
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
148
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
149
|
+
implied, including, without limitation, any warranties or conditions
|
|
150
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
151
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
152
|
+
appropriateness of using or redistributing the Work and assume any
|
|
153
|
+
risks associated with Your exercise of permissions under this License.
|
|
154
|
+
|
|
155
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
156
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
157
|
+
unless required by applicable law (such as deliberate and grossly
|
|
158
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
159
|
+
liable to You for damages, including any direct, indirect, special,
|
|
160
|
+
incidental, or consequential damages of any character arising as a
|
|
161
|
+
result of this License or out of the use or inability to use the
|
|
162
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
163
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
164
|
+
other commercial damages or losses), even if such Contributor
|
|
165
|
+
has been advised of the possibility of such damages.
|
|
166
|
+
|
|
167
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
168
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
169
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
170
|
+
or other liability obligations and/or rights consistent with this
|
|
171
|
+
License. However, in accepting such obligations, You may act only
|
|
172
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
173
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
174
|
+
defend, and hold each Contributor harmless for any liability
|
|
175
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
176
|
+
of your accepting any such warranty or additional liability.
|
|
177
|
+
|
|
178
|
+
END OF TERMS AND CONDITIONS
|
|
179
|
+
|
|
180
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
181
|
+
|
|
182
|
+
To apply the Apache License to your work, attach the following
|
|
183
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
184
|
+
replaced with your own identifying information. (Don't include
|
|
185
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
186
|
+
comment syntax for the file format. We also recommend that a
|
|
187
|
+
file or class name and description of purpose be included on the
|
|
188
|
+
same "printed page" as the copyright notice for easier
|
|
189
|
+
identification within third-party archives.
|
|
190
|
+
|
|
191
|
+
Copyright [yyyy] [name of copyright owner]
|
|
192
|
+
|
|
193
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
194
|
+
you may not use this file except in compliance with the License.
|
|
195
|
+
You may obtain a copy of the License at
|
|
196
|
+
|
|
197
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
198
|
+
|
|
199
|
+
Unless required by applicable law or agreed to in writing, software
|
|
200
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
201
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
202
|
+
See the License for the specific language governing permissions and
|
|
203
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tensorplate
|