tempestweb.vision¶
Classification, detection and segmentation over ONNX, with the same API as ort-vision-sdk. Requires the [vision] extra. Loading the model and running inference are long operations — move them off the handler with tempestweb.runtime.spawn.
Guide with examples: Computer vision (ONNX).
tempestweb.vision ¶
Computer-vision task classes for tempestweb apps (the [vision] extra).
Classification, detection and instance segmentation with the same input/output
contract as ort-vision-sdk and tempest-fastapi-sdk's vision layer — but
running the model over tempestweb's native.onnx bridge (onnxruntime-web) so
it works in the browser, where the onnxruntime Python wheel does not exist.
The task classes reuse ort-vision-sdk's preprocessing, postprocessing and
result objects unchanged; only the model run crosses the async bridge, so
construction and prediction are await-ed:
from tempestweb.vision import Detector, to_detection_schemas
det = await Detector.create("./models/yolov8n.onnx", labels="coco")
result = (await det.predict("./images/street.jpg"))[0]
for d in result:
print(d.name, d.conf, d.box.xyxy) # Ultralytics-style views
payload = to_detection_schemas(result) # JSON for a fastapi-sdk backend
Requires the vision extra: pip install "tempestweb[vision]" (pulls
ort-vision-sdk + numpy).
NativeOnnxBackend ¶
An ort-vision-sdk backend that runs the model over native.onnx.
Satisfies ort_vision_sdk.InferenceBackend. Build it with the async
:meth:create factory (loading crosses the bridge), then inject it into a
task: Detector("", backend=backend). The synchronous :meth:run is
unsupported in the browser — use the async predict path.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
OnnxModel
|
The loaded :class: |
Source code in tempestweb/vision/backend.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
input_shapes
property
¶
Declared input shapes. Empty — the bridge does not report shapes.
input_shape
property
¶
Declared shape of the first input. Empty (see :pyattr:input_shapes).
output_shapes
property
¶
Declared output shapes. Empty — tasks fall back to labels/runtime shape.
create
async
classmethod
¶
Load an onnxruntime-web session and wrap it as a backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_url
|
str
|
URL/path of the |
required |
providers
|
list[str] | None
|
Execution providers in preference order (defaults to
|
None
|
Returns:
| Type | Description |
|---|---|
NativeOnnxBackend
|
The ready :class: |
Source code in tempestweb/vision/backend.py
run ¶
run(feeds: dict[str, NDArray[generic]], *, output_names: list[str] | None = None) -> list[NDArray[np.generic]]
Synchronous inference — unsupported over the async browser bridge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feeds
|
dict[str, NDArray[generic]]
|
Mapping of input name to array. |
required |
output_names
|
list[str] | None
|
Outputs to fetch (unused). |
None
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
Always. The |
Source code in tempestweb/vision/backend.py
async_run
async
¶
async_run(feeds: dict[str, NDArray[generic]], *, output_names: list[str] | None = None) -> list[NDArray[np.generic]]
Run inference over the bridge, returning outputs in order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feeds
|
dict[str, NDArray[generic]]
|
Mapping of input name to NumPy array. |
required |
output_names
|
list[str] | None
|
Output names to fetch, in order. |
None
|
Returns:
| Type | Description |
|---|---|
list[NDArray[generic]]
|
One array per requested output, in order. |
Source code in tempestweb/vision/backend.py
ort_async_run
async
¶
ort_async_run(feeds: dict[str, NDArray[generic]], *, output_names: list[str] | None = None) -> list[NDArray[np.generic]]
High-concurrency async variant — delegates to :meth:async_run.
Source code in tempestweb/vision/backend.py
BoundingBoxSchema ¶
Bases: BaseModel
An axis-aligned box in pixel coordinates (top-left origin).
Source code in tempestweb/vision/schemas.py
ClassificationSchema ¶
Bases: BaseModel
A classification result: the top label plus the ranked scores.
Source code in tempestweb/vision/schemas.py
ClassProbabilitySchema ¶
Bases: BaseModel
One class score from a classifier's ranked output.
Source code in tempestweb/vision/schemas.py
DetectionSchema ¶
Bases: BaseModel
A single detected object.
Source code in tempestweb/vision/schemas.py
SegmentationSchema ¶
Bases: BaseModel
A single segmented instance (box + label; mask pixels omitted).
Source code in tempestweb/vision/schemas.py
Classifier ¶
Bases: _VisionTask[Classifier]
Image classification over the native.onnx bridge (async).
Source code in tempestweb/vision/tasks.py
create
async
classmethod
¶
Load a classification model and return a ready :class:Classifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_url
|
str
|
URL/path of the |
required |
providers
|
list[str] | None
|
onnxruntime-web execution providers. |
None
|
**task_kwargs
|
Any
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Classifier
|
The ready classifier. |
Source code in tempestweb/vision/tasks.py
predict
async
¶
Classify an image (async).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ImageInput
|
Image source (path, bytes, |
required |
**kwargs
|
Any
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
list[ClassificationResults]
|
A 1-element list with the :class: |
Source code in tempestweb/vision/tasks.py
Detector ¶
Bases: _VisionTask[Detector]
Object detection over the native.onnx bridge (async).
Source code in tempestweb/vision/tasks.py
create
async
classmethod
¶
Load a detection model and return a ready :class:Detector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_url
|
str
|
URL/path of the |
required |
providers
|
list[str] | None
|
onnxruntime-web execution providers. |
None
|
**task_kwargs
|
Any
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Detector
|
The ready detector. |
Source code in tempestweb/vision/tasks.py
predict
async
¶
Detect objects in an image (async).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ImageInput
|
Image source (path, bytes, |
required |
**kwargs
|
Any
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
list[DetectionResults]
|
A 1-element list with the :class: |
Source code in tempestweb/vision/tasks.py
Segmenter ¶
Bases: _VisionTask[Segmenter]
Instance segmentation over the native.onnx bridge (async).
Source code in tempestweb/vision/tasks.py
create
async
classmethod
¶
Load a segmentation model and return a ready :class:Segmenter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_url
|
str
|
URL/path of the |
required |
providers
|
list[str] | None
|
onnxruntime-web execution providers. |
None
|
**task_kwargs
|
Any
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Segmenter
|
The ready segmenter. |
Source code in tempestweb/vision/tasks.py
predict
async
¶
Segment instances in an image (async).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ImageInput
|
Image source (path, bytes, |
required |
**kwargs
|
Any
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
list[SegmentationResults]
|
A 1-element list with the :class: |
Source code in tempestweb/vision/tasks.py
to_classification_schema ¶
Map a classifier result to a single :class:ClassificationSchema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
ClassificationResults
|
One element of |
required |
Returns:
| Type | Description |
|---|---|
ClassificationSchema
|
The top-1 label plus the ranked scores. |
Source code in tempestweb/vision/mapping.py
to_detection_schemas ¶
Map a detector result to a list of :class:DetectionSchema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
DetectionResults
|
One element of |
required |
Returns:
| Type | Description |
|---|---|
list[DetectionSchema]
|
One entry per detected object ( |
Source code in tempestweb/vision/mapping.py
to_segmentation_schemas ¶
Map a segmenter result to a list of :class:SegmentationSchema.
Mask pixels are omitted (see :class:SegmentationSchema); only the box +
label of each instance are returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
SegmentationResults
|
One element of |
required |
Returns:
| Type | Description |
|---|---|
list[SegmentationSchema]
|
One entry per segmented instance. |