Vision API is a containerized FastAPI service for object detection, depth maps, retained camera frames, and event callbacks. It is designed to run locally, expose a small debug UI, and optionally discover TensorRT-compiled GroundingDINO engines built by the companion model-build container.
- Vision API Runtime: FastAPI service with model load/unload endpoints, image inference, stream ingestion, retained frames, and a browser debug UI.
- Camera Capture Flow: Create short camera codes, open a browser capture page, and retain frames that can be queried or attached to detection streams.
- Detection Streams: Register streams with labels, stop conditions, callbacks, and WebSocket events for frame-by-frame detection results.
- Depth and Geometry: Depth backends can enrich results with relative or metric depth, distance estimates, and bearing angles.
- Containerized Runtime: Docker Compose runs the API service on port
8000with runtime assets mounted undercomponent/vision/assets/. - Optional TensorRT Builder: The
gdinoonnxprofile builds GroundingDINO ONNX/TensorRT artifacts for the vision service to discover.
- Backend API
- FastAPI and Uvicorn for the HTTP, WebSocket, and browser-facing routes.
- Pydantic for request validation and structured API payloads.
asynciofor stream state, callbacks, and retained-frame coordination.
- Vision Models
- PyTorch and Transformers for Hugging Face model execution.
- GroundingDINO for open-vocabulary object detection.
- ZoeDepth and Depth Anything V2 style backends for depth estimation.
- Optional TensorRT support for compiled GroundingDINO engines.
- Image and Runtime Handling
- Pillow and OpenCV headless for image decoding, resizing, annotation, and temporary JPEG output.
- Runtime assets, model caches, generated images, and compiled engines are
stored outside git under
component/vision/assets/.
- Deployment
- Docker and Docker Compose for the API, optional model-build container, and optional Cloudflare tunnel.
uvfor Python dependency installation inside the service images.
- One API for images and streams Vision API can process one-off image
requests through
/api/applyor keep stream state and retained frames under/api/streams. - Camera-code capture pages The API can create a temporary capture code and
serve a browser page at
/{code}. Frames posted by that page are retained and can also feed active streams. - Explicit model lifecycle Models are listed, loaded, unloaded, and queried through API endpoints, which makes VRAM use easier to control on local GPU machines.
- Runtime model discovery Compiled GroundingDINO TensorRT artifacts are
discovered from
component/vision/assets/models/compiled/gdinoonnx/, so the API can use newly built engines after a restart. - Separate builder profile The ONNX/TensorRT build environment is isolated
behind the
model-buildCompose profile, keeping normal API startup focused on the runtime service.
- Docker and Docker Compose
- An NVIDIA GPU runtime if you want GPU-backed model execution
- Optional Hugging Face token if you need authenticated model downloads
- Optional Cloudflare tunnel token if you want to expose the service through
the
tunnelprofile
-
Clone the repository
git clone https://github.com/Ryustiel/DetectiPublic cd DetectiPublic -
Configure environment files
Copy the examples in
environ/to matching.envfiles when you need to override defaults:environ/vision.env: API runtime settings, public URLs, and optional Hugging Face token.environ/gdinoonnx.env: optional GroundingDINO ONNX/TensorRT build settings.environ/tunnel.env: Cloudflare tunnel token.
-
Build and run the API container
docker compose up --build vision
The debug UI and API are available at
http://localhost:8000.
Useful routes:
GET /GET /healthGET /api/modelsGET /api/models/statusPOST /api/models/{model_id}/loadPOST /api/models/{model_id}/unloadPOST /api/applyGET /api/streamsPOST /api/streamsPATCH /api/streams/{stream_id}DELETE /api/streams/{stream_id}POST /api/streams/{stream_id}/framesPOST /api/streams/{stream_id}/urlWS /api/streams/eventsWS /api/streams/{stream_id}/eventsGET /api/camera-codesPOST /api/camera-codesDELETE /api/camera-codes/{code}GET /api/camera-codes/{code}/frames/queryGET /api/camera-codes/{code}/frames/raw
The Vision API diagrams live in
docs/VISION/VISION_API_COMMUNICATION_SCHEMA.md.
They link the Mermaid sources with SVG and PNG renders for the runtime, stream,
camera, and apply flows.
The TensorRT builder is optional and is not needed to boot the API container. Build or rebuild the GroundingDINO ONNX/TensorRT artifacts with:
docker compose --profile model-build run --rm --build gdinoonnx bash /app/src/build_gdino.shArtifacts are written to
component/vision/assets/models/compiled/gdinoonnx/. Restart a TensorRT-enabled
vision image after a new build so the API can rediscover the compiled backend.
The default API image skips the TensorRT Python bindings so normal container
startup does not depend on the TensorRT wheel stack. To include those bindings
in the vision image, build with:
VISION_EXTRAS=tensorrt docker compose build vision.
|-- docker-compose.yaml # Orchestrates the API, builder, and tunnel services.
|-- environ/ # Optional environment files and examples.
| |-- vision.env.example # Runtime settings for the vision API.
| |-- gdinoonnx.env.example # TensorRT builder configuration.
| `-- tunnel.env.example # Cloudflare tunnel configuration.
|-- component/
| |-- vision/ # FastAPI runtime service.
| | |-- Dockerfile
| | |-- pyproject.toml
| | `-- src/
| | |-- service.py # API entry point.
| | |-- processor/ # Detection, depth, and angle logic.
| | `-- templates/ # Debug UI and camera capture page.
| `-- gdinoonnx/ # Optional GroundingDINO ONNX/TensorRT builder.
| |-- Dockerfile
| |-- pyproject.toml
| `-- src/ # Bootstrap, checkpoint, patch, and build scripts.
`-- pyproject.toml # Local development workspace metadata.
Model weights, compiled engines, generated images, temporary files, and cloned
upstream wrappers are intentionally excluded from git. They live under
component/vision/assets/ at runtime.
MIT License. See LICENSE.