Skip to content

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:~tempestweb.native.onnx.OnnxModel handle.

Source code in tempestweb/vision/backend.py
class 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:
        model: The loaded :class:`~tempestweb.native.onnx.OnnxModel` handle.
    """

    def __init__(self, model: OnnxModel) -> None:
        """Wrap a loaded bridge session.

        Args:
            model: The :class:`~tempestweb.native.onnx.OnnxModel` from
                :func:`tempestweb.native.onnx.load`.
        """
        self.model: OnnxModel = model

    @classmethod
    async def create(
        cls, model_url: str, *, providers: list[str] | None = None
    ) -> NativeOnnxBackend:
        """Load an onnxruntime-web session and wrap it as a backend.

        Args:
            model_url: URL/path of the ``.onnx`` model (same-origin in the
                artifact, e.g. ``"./models/yolov8n.onnx"``).
            providers: Execution providers in preference order (defaults to
                ``["wasm"]`` on the JS side).

        Returns:
            The ready :class:`NativeOnnxBackend`.
        """
        model = await onnx_load(model_url, providers=providers)
        return cls(model)

    @property
    def input_names(self) -> list[str]:
        """Names of the model's inputs, in declaration order."""
        return list(self.model.input_names)

    @property
    def input_name(self) -> str:
        """Name of the first (and usually only) input."""
        return self.model.input_name

    @property
    def input_shapes(self) -> list[tuple[int | str, ...]]:
        """Declared input shapes. Empty — the bridge does not report shapes."""
        return []

    @property
    def input_shape(self) -> tuple[int | str, ...]:
        """Declared shape of the first input. Empty (see :pyattr:`input_shapes`)."""
        return ()

    @property
    def output_names(self) -> list[str]:
        """Names of the model's outputs, in declaration order."""
        return list(self.model.output_names)

    @property
    def output_shapes(self) -> list[tuple[int | str, ...]]:
        """Declared output shapes. Empty — tasks fall back to labels/runtime shape."""
        return []

    def run(
        self,
        feeds: dict[str, NDArray[np.generic]],
        *,
        output_names: list[str] | None = None,
    ) -> list[NDArray[np.generic]]:
        """Synchronous inference — unsupported over the async browser bridge.

        Args:
            feeds: Mapping of input name to array.
            output_names: Outputs to fetch (unused).

        Raises:
            RuntimeError: Always. The ``native.onnx`` bridge is asynchronous;
                use a task's ``predict`` / ``ort_async_predict`` instead.
        """
        raise RuntimeError(
            "NativeOnnxBackend has no synchronous run (the native.onnx bridge is "
            "async). Use `await task.predict(...)` or `task.ort_async_predict(...)`."
        )

    async def async_run(
        self,
        feeds: dict[str, NDArray[np.generic]],
        *,
        output_names: list[str] | None = None,
    ) -> list[NDArray[np.generic]]:
        """Run inference over the bridge, returning outputs in order.

        Args:
            feeds: Mapping of input name to NumPy array.
            output_names: Output names to fetch, in order. ``None`` returns all
                outputs in the model's declared order.

        Returns:
            One array per requested output, in order.
        """
        return await self._run(feeds, output_names)

    async def ort_async_run(
        self,
        feeds: dict[str, NDArray[np.generic]],
        *,
        output_names: list[str] | None = None,
    ) -> list[NDArray[np.generic]]:
        """High-concurrency async variant — delegates to :meth:`async_run`."""
        return await self._run(feeds, output_names)

    async def _run(
        self,
        feeds: dict[str, NDArray[np.generic]],
        output_names: list[str] | None,
    ) -> list[NDArray[np.generic]]:
        """Encode feeds, cross the bridge, decode outputs in the requested order.

        Args:
            feeds: Mapping of input name to NumPy array.
            output_names: Output names to fetch in order, or ``None`` for all.

        Returns:
            One decoded array per requested output.
        """
        tensor_feeds = {name: _ndarray_to_tensor(arr) for name, arr in feeds.items()}
        outputs = await onnx_run(self.model.session_id, tensor_feeds)
        names = output_names or self.output_names or list(outputs)
        return [_tensor_to_ndarray(outputs[name]) for name in names]

input_names property

input_names: list[str]

Names of the model's inputs, in declaration order.

input_name property

input_name: str

Name of the first (and usually only) input.

input_shapes property

input_shapes: list[tuple[int | str, ...]]

Declared input shapes. Empty — the bridge does not report shapes.

input_shape property

input_shape: tuple[int | str, ...]

Declared shape of the first input. Empty (see :pyattr:input_shapes).

output_names property

output_names: list[str]

Names of the model's outputs, in declaration order.

output_shapes property

output_shapes: list[tuple[int | str, ...]]

Declared output shapes. Empty — tasks fall back to labels/runtime shape.

create async classmethod

create(model_url: str, *, providers: list[str] | None = None) -> NativeOnnxBackend

Load an onnxruntime-web session and wrap it as a backend.

Parameters:

Name Type Description Default
model_url str

URL/path of the .onnx model (same-origin in the artifact, e.g. "./models/yolov8n.onnx").

required
providers list[str] | None

Execution providers in preference order (defaults to ["wasm"] on the JS side).

None

Returns:

Type Description
NativeOnnxBackend

The ready :class:NativeOnnxBackend.

Source code in tempestweb/vision/backend.py
@classmethod
async def create(
    cls, model_url: str, *, providers: list[str] | None = None
) -> NativeOnnxBackend:
    """Load an onnxruntime-web session and wrap it as a backend.

    Args:
        model_url: URL/path of the ``.onnx`` model (same-origin in the
            artifact, e.g. ``"./models/yolov8n.onnx"``).
        providers: Execution providers in preference order (defaults to
            ``["wasm"]`` on the JS side).

    Returns:
        The ready :class:`NativeOnnxBackend`.
    """
    model = await onnx_load(model_url, providers=providers)
    return cls(model)

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 native.onnx bridge is asynchronous; use a task's predict / ort_async_predict instead.

Source code in tempestweb/vision/backend.py
def run(
    self,
    feeds: dict[str, NDArray[np.generic]],
    *,
    output_names: list[str] | None = None,
) -> list[NDArray[np.generic]]:
    """Synchronous inference — unsupported over the async browser bridge.

    Args:
        feeds: Mapping of input name to array.
        output_names: Outputs to fetch (unused).

    Raises:
        RuntimeError: Always. The ``native.onnx`` bridge is asynchronous;
            use a task's ``predict`` / ``ort_async_predict`` instead.
    """
    raise RuntimeError(
        "NativeOnnxBackend has no synchronous run (the native.onnx bridge is "
        "async). Use `await task.predict(...)` or `task.ort_async_predict(...)`."
    )

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 all outputs in the model's declared order.

None

Returns:

Type Description
list[NDArray[generic]]

One array per requested output, in order.

Source code in tempestweb/vision/backend.py
async def async_run(
    self,
    feeds: dict[str, NDArray[np.generic]],
    *,
    output_names: list[str] | None = None,
) -> list[NDArray[np.generic]]:
    """Run inference over the bridge, returning outputs in order.

    Args:
        feeds: Mapping of input name to NumPy array.
        output_names: Output names to fetch, in order. ``None`` returns all
            outputs in the model's declared order.

    Returns:
        One array per requested output, in order.
    """
    return await self._run(feeds, output_names)

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
async def ort_async_run(
    self,
    feeds: dict[str, NDArray[np.generic]],
    *,
    output_names: list[str] | None = None,
) -> list[NDArray[np.generic]]:
    """High-concurrency async variant — delegates to :meth:`async_run`."""
    return await self._run(feeds, output_names)

BoundingBoxSchema

Bases: BaseModel

An axis-aligned box in pixel coordinates (top-left origin).

Source code in tempestweb/vision/schemas.py
class BoundingBoxSchema(BaseModel):
    """An axis-aligned box in pixel coordinates (top-left origin)."""

    x1: float = Field(description="Left edge (px).")
    y1: float = Field(description="Top edge (px).")
    x2: float = Field(description="Right edge (px).")
    y2: float = Field(description="Bottom edge (px).")

ClassificationSchema

Bases: BaseModel

A classification result: the top label plus the ranked scores.

Source code in tempestweb/vision/schemas.py
class ClassificationSchema(BaseModel):
    """A classification result: the top label plus the ranked scores."""

    class_id: int = Field(description="Top-1 class index.")
    class_name: str = Field(description="Top-1 label.")
    confidence: float = Field(description="Top-1 score in [0, 1].")
    probabilities: list[ClassProbabilitySchema] = Field(
        default_factory=list,
        description="Ranked class scores (top-k), highest first.",
    )

ClassProbabilitySchema

Bases: BaseModel

One class score from a classifier's ranked output.

Source code in tempestweb/vision/schemas.py
class ClassProbabilitySchema(BaseModel):
    """One class score from a classifier's ranked output."""

    class_id: int = Field(description="Integer class index.")
    class_name: str = Field(description="Human-readable label.")
    probability: float = Field(description="Score in [0, 1].")

DetectionSchema

Bases: BaseModel

A single detected object.

Source code in tempestweb/vision/schemas.py
class DetectionSchema(BaseModel):
    """A single detected object."""

    class_id: int = Field(description="Integer class index.")
    class_name: str = Field(description="Human-readable label.")
    confidence: float = Field(description="Detection score in [0, 1].")
    box: BoundingBoxSchema = Field(description="Object bounding box.")

SegmentationSchema

Bases: BaseModel

A single segmented instance (box + label; mask pixels omitted).

Source code in tempestweb/vision/schemas.py
class SegmentationSchema(BaseModel):
    """A single segmented instance (box + label; mask pixels omitted)."""

    class_id: int = Field(description="Integer class index.")
    class_name: str = Field(description="Human-readable label.")
    confidence: float = Field(description="Instance score in [0, 1].")
    box: BoundingBoxSchema = Field(description="Instance bounding box.")

Classifier

Bases: _VisionTask[Classifier]

Image classification over the native.onnx bridge (async).

Source code in tempestweb/vision/tasks.py
class Classifier(_VisionTask[_Classifier]):
    """Image classification over the ``native.onnx`` bridge (async)."""

    _factory = _Classifier

    @classmethod
    async def create(
        cls,
        model_url: str,
        *,
        providers: list[str] | None = None,
        **task_kwargs: Any,  # noqa: ANN401 - forwarded to ort-vision-sdk Classifier
    ) -> Classifier:
        """Load a classification model and return a ready :class:`Classifier`.

        Args:
            model_url: URL/path of the ``.onnx`` model.
            providers: onnxruntime-web execution providers.
            **task_kwargs: Forwarded to ``ort_vision_sdk.Classifier`` (``labels``,
                ``input_size``, …).

        Returns:
            The ready classifier.
        """
        return cls(await cls._build(model_url, providers=providers, **task_kwargs))

    async def predict(
        self,
        image: ImageInput,
        **kwargs: Any,  # noqa: ANN401 - forwarded to ort-vision-sdk predict
    ) -> list[ClassificationResults]:
        """Classify an image (async).

        Args:
            image: Image source (path, bytes, ``np.ndarray`` or ``PIL.Image``).
            **kwargs: Forwarded to ``ort-vision-sdk``.

        Returns:
            A 1-element list with the :class:`ClassificationResults`.
        """
        return await self.task.ort_async_predict(image, **kwargs)

create async classmethod

create(model_url: str, *, providers: list[str] | None = None, **task_kwargs: Any) -> Classifier

Load a classification model and return a ready :class:Classifier.

Parameters:

Name Type Description Default
model_url str

URL/path of the .onnx model.

required
providers list[str] | None

onnxruntime-web execution providers.

None
**task_kwargs Any

Forwarded to ort_vision_sdk.Classifier (labels, input_size, …).

{}

Returns:

Type Description
Classifier

The ready classifier.

Source code in tempestweb/vision/tasks.py
@classmethod
async def create(
    cls,
    model_url: str,
    *,
    providers: list[str] | None = None,
    **task_kwargs: Any,  # noqa: ANN401 - forwarded to ort-vision-sdk Classifier
) -> Classifier:
    """Load a classification model and return a ready :class:`Classifier`.

    Args:
        model_url: URL/path of the ``.onnx`` model.
        providers: onnxruntime-web execution providers.
        **task_kwargs: Forwarded to ``ort_vision_sdk.Classifier`` (``labels``,
            ``input_size``, …).

    Returns:
        The ready classifier.
    """
    return cls(await cls._build(model_url, providers=providers, **task_kwargs))

predict async

predict(image: ImageInput, **kwargs: Any) -> list[ClassificationResults]

Classify an image (async).

Parameters:

Name Type Description Default
image ImageInput

Image source (path, bytes, np.ndarray or PIL.Image).

required
**kwargs Any

Forwarded to ort-vision-sdk.

{}

Returns:

Type Description
list[ClassificationResults]

A 1-element list with the :class:ClassificationResults.

Source code in tempestweb/vision/tasks.py
async def predict(
    self,
    image: ImageInput,
    **kwargs: Any,  # noqa: ANN401 - forwarded to ort-vision-sdk predict
) -> list[ClassificationResults]:
    """Classify an image (async).

    Args:
        image: Image source (path, bytes, ``np.ndarray`` or ``PIL.Image``).
        **kwargs: Forwarded to ``ort-vision-sdk``.

    Returns:
        A 1-element list with the :class:`ClassificationResults`.
    """
    return await self.task.ort_async_predict(image, **kwargs)

Detector

Bases: _VisionTask[Detector]

Object detection over the native.onnx bridge (async).

Source code in tempestweb/vision/tasks.py
class Detector(_VisionTask[_Detector]):
    """Object detection over the ``native.onnx`` bridge (async)."""

    _factory = _Detector

    @classmethod
    async def create(
        cls,
        model_url: str,
        *,
        providers: list[str] | None = None,
        **task_kwargs: Any,  # noqa: ANN401 - forwarded to ort-vision-sdk Detector
    ) -> Detector:
        """Load a detection model and return a ready :class:`Detector`.

        Args:
            model_url: URL/path of the ``.onnx`` model.
            providers: onnxruntime-web execution providers.
            **task_kwargs: Forwarded to ``ort_vision_sdk.Detector`` (``labels``,
                ``input_size``, ``conf_threshold``, ``iou_threshold``, …).

        Returns:
            The ready detector.
        """
        return cls(await cls._build(model_url, providers=providers, **task_kwargs))

    async def predict(
        self,
        image: ImageInput,
        **kwargs: Any,  # noqa: ANN401 - forwarded to ort-vision-sdk predict
    ) -> list[DetectionResults]:
        """Detect objects in an image (async).

        Args:
            image: Image source (path, bytes, ``np.ndarray`` or ``PIL.Image``).
            **kwargs: Forwarded to ``ort-vision-sdk`` (``conf_threshold``,
                ``iou_threshold``, ``classes``).

        Returns:
            A 1-element list with the :class:`DetectionResults` envelope.
        """
        return await self.task.ort_async_predict(image, **kwargs)

create async classmethod

create(model_url: str, *, providers: list[str] | None = None, **task_kwargs: Any) -> Detector

Load a detection model and return a ready :class:Detector.

Parameters:

Name Type Description Default
model_url str

URL/path of the .onnx model.

required
providers list[str] | None

onnxruntime-web execution providers.

None
**task_kwargs Any

Forwarded to ort_vision_sdk.Detector (labels, input_size, conf_threshold, iou_threshold, …).

{}

Returns:

Type Description
Detector

The ready detector.

Source code in tempestweb/vision/tasks.py
@classmethod
async def create(
    cls,
    model_url: str,
    *,
    providers: list[str] | None = None,
    **task_kwargs: Any,  # noqa: ANN401 - forwarded to ort-vision-sdk Detector
) -> Detector:
    """Load a detection model and return a ready :class:`Detector`.

    Args:
        model_url: URL/path of the ``.onnx`` model.
        providers: onnxruntime-web execution providers.
        **task_kwargs: Forwarded to ``ort_vision_sdk.Detector`` (``labels``,
            ``input_size``, ``conf_threshold``, ``iou_threshold``, …).

    Returns:
        The ready detector.
    """
    return cls(await cls._build(model_url, providers=providers, **task_kwargs))

predict async

predict(image: ImageInput, **kwargs: Any) -> list[DetectionResults]

Detect objects in an image (async).

Parameters:

Name Type Description Default
image ImageInput

Image source (path, bytes, np.ndarray or PIL.Image).

required
**kwargs Any

Forwarded to ort-vision-sdk (conf_threshold, iou_threshold, classes).

{}

Returns:

Type Description
list[DetectionResults]

A 1-element list with the :class:DetectionResults envelope.

Source code in tempestweb/vision/tasks.py
async def predict(
    self,
    image: ImageInput,
    **kwargs: Any,  # noqa: ANN401 - forwarded to ort-vision-sdk predict
) -> list[DetectionResults]:
    """Detect objects in an image (async).

    Args:
        image: Image source (path, bytes, ``np.ndarray`` or ``PIL.Image``).
        **kwargs: Forwarded to ``ort-vision-sdk`` (``conf_threshold``,
            ``iou_threshold``, ``classes``).

    Returns:
        A 1-element list with the :class:`DetectionResults` envelope.
    """
    return await self.task.ort_async_predict(image, **kwargs)

Segmenter

Bases: _VisionTask[Segmenter]

Instance segmentation over the native.onnx bridge (async).

Source code in tempestweb/vision/tasks.py
class Segmenter(_VisionTask[_Segmenter]):
    """Instance segmentation over the ``native.onnx`` bridge (async)."""

    _factory = _Segmenter

    @classmethod
    async def create(
        cls,
        model_url: str,
        *,
        providers: list[str] | None = None,
        **task_kwargs: Any,  # noqa: ANN401 - forwarded to ort-vision-sdk Segmenter
    ) -> Segmenter:
        """Load a segmentation model and return a ready :class:`Segmenter`.

        Args:
            model_url: URL/path of the ``.onnx`` model.
            providers: onnxruntime-web execution providers.
            **task_kwargs: Forwarded to ``ort_vision_sdk.Segmenter`` (``labels``,
                ``input_size``, ``conf_threshold``, ``iou_threshold``, …).

        Returns:
            The ready segmenter.
        """
        return cls(await cls._build(model_url, providers=providers, **task_kwargs))

    async def predict(
        self,
        image: ImageInput,
        **kwargs: Any,  # noqa: ANN401 - forwarded to ort-vision-sdk predict
    ) -> list[SegmentationResults]:
        """Segment instances in an image (async).

        Args:
            image: Image source (path, bytes, ``np.ndarray`` or ``PIL.Image``).
            **kwargs: Forwarded to ``ort-vision-sdk`` (``conf_threshold``,
                ``iou_threshold``, …).

        Returns:
            A 1-element list with the :class:`SegmentationResults` envelope.
        """
        return await self.task.ort_async_predict(image, **kwargs)

create async classmethod

create(model_url: str, *, providers: list[str] | None = None, **task_kwargs: Any) -> Segmenter

Load a segmentation model and return a ready :class:Segmenter.

Parameters:

Name Type Description Default
model_url str

URL/path of the .onnx model.

required
providers list[str] | None

onnxruntime-web execution providers.

None
**task_kwargs Any

Forwarded to ort_vision_sdk.Segmenter (labels, input_size, conf_threshold, iou_threshold, …).

{}

Returns:

Type Description
Segmenter

The ready segmenter.

Source code in tempestweb/vision/tasks.py
@classmethod
async def create(
    cls,
    model_url: str,
    *,
    providers: list[str] | None = None,
    **task_kwargs: Any,  # noqa: ANN401 - forwarded to ort-vision-sdk Segmenter
) -> Segmenter:
    """Load a segmentation model and return a ready :class:`Segmenter`.

    Args:
        model_url: URL/path of the ``.onnx`` model.
        providers: onnxruntime-web execution providers.
        **task_kwargs: Forwarded to ``ort_vision_sdk.Segmenter`` (``labels``,
            ``input_size``, ``conf_threshold``, ``iou_threshold``, …).

    Returns:
        The ready segmenter.
    """
    return cls(await cls._build(model_url, providers=providers, **task_kwargs))

predict async

predict(image: ImageInput, **kwargs: Any) -> list[SegmentationResults]

Segment instances in an image (async).

Parameters:

Name Type Description Default
image ImageInput

Image source (path, bytes, np.ndarray or PIL.Image).

required
**kwargs Any

Forwarded to ort-vision-sdk (conf_threshold, iou_threshold, …).

{}

Returns:

Type Description
list[SegmentationResults]

A 1-element list with the :class:SegmentationResults envelope.

Source code in tempestweb/vision/tasks.py
async def predict(
    self,
    image: ImageInput,
    **kwargs: Any,  # noqa: ANN401 - forwarded to ort-vision-sdk predict
) -> list[SegmentationResults]:
    """Segment instances in an image (async).

    Args:
        image: Image source (path, bytes, ``np.ndarray`` or ``PIL.Image``).
        **kwargs: Forwarded to ``ort-vision-sdk`` (``conf_threshold``,
            ``iou_threshold``, …).

    Returns:
        A 1-element list with the :class:`SegmentationResults` envelope.
    """
    return await self.task.ort_async_predict(image, **kwargs)

to_classification_schema

to_classification_schema(results: ClassificationResults) -> ClassificationSchema

Map a classifier result to a single :class:ClassificationSchema.

Parameters:

Name Type Description Default
results ClassificationResults

One element of Classifier.predict's return list.

required

Returns:

Type Description
ClassificationSchema

The top-1 label plus the ranked scores.

Source code in tempestweb/vision/mapping.py
def to_classification_schema(results: ClassificationResults) -> ClassificationSchema:
    """Map a classifier result to a single :class:`ClassificationSchema`.

    Args:
        results: One element of ``Classifier.predict``'s return list.

    Returns:
        The top-1 label plus the ranked scores.
    """
    return ClassificationSchema(
        class_id=results.cls,
        class_name=results.name,
        confidence=results.conf,
        probabilities=[
            ClassProbabilitySchema(
                class_id=p.class_id,
                class_name=p.class_name,
                probability=p.probability,
            )
            for p in results.probabilities
        ],
    )

to_detection_schemas

to_detection_schemas(results: DetectionResults) -> list[DetectionSchema]

Map a detector result to a list of :class:DetectionSchema.

Parameters:

Name Type Description Default
results DetectionResults

One element of Detector.predict's return list.

required

Returns:

Type Description
list[DetectionSchema]

One entry per detected object ([] when nothing was detected).

Source code in tempestweb/vision/mapping.py
def to_detection_schemas(results: DetectionResults) -> list[DetectionSchema]:
    """Map a detector result to a list of :class:`DetectionSchema`.

    Args:
        results: One element of ``Detector.predict``'s return list.

    Returns:
        One entry per detected object (``[]`` when nothing was detected).
    """
    return [
        DetectionSchema(
            class_id=d.class_id,
            class_name=d.class_name,
            confidence=d.confidence,
            box=_box(d.bbox),
        )
        for d in results.detections
    ]

to_segmentation_schemas

to_segmentation_schemas(results: SegmentationResults) -> list[SegmentationSchema]

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 Segmenter.predict's return list.

required

Returns:

Type Description
list[SegmentationSchema]

One entry per segmented instance.

Source code in tempestweb/vision/mapping.py
def to_segmentation_schemas(results: SegmentationResults) -> list[SegmentationSchema]:
    """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.

    Args:
        results: One element of ``Segmenter.predict``'s return list.

    Returns:
        One entry per segmented instance.
    """
    return [
        SegmentationSchema(
            class_id=d.class_id,
            class_name=d.class_name,
            confidence=d.confidence,
            box=_box(d.bbox),
        )
        for d in results.detections
    ]