File size: 3,270 Bytes
7d7fddc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | # SPDX-License-Identifier: Apache-2.0
"""ASGI serving app of one VisionPilot network on one Tenstorrent Blackhole p150: the HTTP contract of the Autoware
collection (vendored ``ttaw.server.app``) bound to one class of :mod:`tt_visionpilot.api`.
VP_NETWORK=autosteer python -m uvicorn --host 0.0.0.0 --port 20000 --lifespan on tt_visionpilot.server.app:app
``VP_NETWORK`` (``autosteer`` | ``autospeed`` | ``autodrive``) picks the network; each Hugging Face package pins it in
its ``serve.env``. Routes: ``GET /``, ``/health`` and ``/v1/health``, ``/info``, ``/v1/models`` (stub),
``POST /predict``; errors 400 / 422 / 503 / 500. AutoDrive's request adds ``homography`` (9 numbers, VisionPilot's
``C``: raw pixel -> warped 1024 x 512) to the common envelope; AutoSteer / AutoSpeed take one image.
"""
import os
from typing import Any, Dict, List, Optional
from .. import __version__
from ..api import MODELS
from ..ttaw.server.app import PredictRequest, ServerSpec, create_app, parse_mesh_shape # noqa: F401
NETWORK = os.environ.get("VP_NETWORK", "autosteer")
if NETWORK not in MODELS:
raise RuntimeError(f"VP_NETWORK={NETWORK!r}: expected one of {sorted(MODELS)}")
MODEL = MODELS[NETWORK]
TASKS = {
"autosteer": ("ego path prediction (VisionPilot AutoSteer 2.0)",
"one front camera frame (52-55 deg horizontal FOV, 1-2 MP; top-cropped to 2:1 and resized to "
"1024x512 as VisionPilot does) in; xp and h_vector (64 each, the network outputs) out"),
"autospeed": ("closest in-path object detection (VisionPilot AutoSpeed 2.0)",
"one front camera frame (as AutoSteer) in; 2-D boxes with the class of the highest score, after "
"VisionPilot's threshold and NMS, in network and input pixels, out"),
"autodrive": ("distance to the closest in-path object, road curvature and its presence (VisionPilot AutoDrive)",
"two consecutive front frames (prev, curr), warped by the camera homography to 1024x512 (or the "
"homography in the request) in; normalised distance, raw curvature, presence probability out"),
}
__all__ = ["SPEC", "app", "NETWORK", "parse_mesh_shape"]
class AutoDriveRequest(PredictRequest):
homography: Optional[List[float]] = None
def decode_extra(req: Any, kwargs: Dict[str, Any], max_bytes: int) -> None:
value = getattr(req, "homography", None)
if value is not None:
kwargs["homography"] = value
SPEC = ServerSpec(
model_name=MODEL.MODEL_NAME,
env_prefix=MODEL.ENV_PREFIX,
model_cls=MODEL,
task=TASKS[NETWORK][0],
default_weights=MODEL.DEFAULT_REPO,
owner="changh95",
io=TASKS[NETWORK][1],
autoware={"package": "none (VisionPilot is a standalone ROS 2 / C++ stack: autowarefoundation/vision_pilot)"},
source={"repo": f"https://huggingface.co/changh95/{MODEL.MODEL_NAME}", "license": "Apache-2.0"},
version=__version__,
description=f"{MODEL.MODEL_NAME}: the published VisionPilot ONNX network on one Tenstorrent Blackhole p150. "
"Not an OpenAI-compatible API.",
request_model=AutoDriveRequest if NETWORK == "autodrive" else PredictRequest,
decode_extra=decode_extra if NETWORK == "autodrive" else None,
)
app = create_app(SPEC)
|