Download code/tt_visionpilot/server/app.py from changh95/auto_steer-p150: direct link, hf CLI and curl.
- Browser
- Download file 3.27 kB
-
https://huggingface.co/changh95/auto_steer-p150/resolve/main/code/tt_visionpilot/server/app.py
- Command line
-
hf download hf://changh95/auto_steer-p150/code/tt_visionpilot/server/app.py
-
curl -L -o app.py https://huggingface.co/changh95/auto_steer-p150/resolve/main/code/tt_visionpilot/server/app.py
3.27 kB
| # 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) | |