Skip to main content

A modular video object detection toolkit with a clean det-v1 JSON schema, pluggable backends, and optional model export.

Project description

detect

A modular video object detection toolkit with a clean det-v1 JSON schema, pluggable backends, and optional model export.

Current backend:

  • Ultralytics YOLO (bbox / pose / segmentation)

By default, detect does not write any files. You opt-in to saving JSON, frames, or annotated video via flags.


det-v1 output (returned + optionally saved)

detect always produces a canonical JSON payload in-memory with:

  • schema_version: always "det-v1"
  • video: input metadata (path, fps, frame_count, width, height)
  • detector: detector settings used for the run (name, weights, classes, conf/imgsz/device/half)
  • frames: per-frame detections
    • bbox detection: bbox = [x1, y1, x2, y2]
    • pose detection: keypoints = [[x, y, score], ...]
    • segmentation: segments = [[[x, y], ...], ...] (polygons)

Minimal schema example

{
  "schema_version": "det-v1",
  "video": {
    "path": "in.mp4",
    "fps": 30.0,
    "frame_count": 120,
    "width": 1920,
    "height": 1080
  },
  "detector": {
    "name": "yolo_bbox",
    "weights": "yolo26n",
    "classes": null,
    "conf_thresh": 0.25,
    "imgsz": 640,
    "device": "cpu",
    "half": false
  },
  "frames": [
    {
      "frame": 0,
      "file": "000000.jpg",
      "detections": [
        {
          "det_ind": 0,
          "bbox": [100.0, 50.0, 320.0, 240.0],
          "score": 0.91,
          "class_id": 0,
          "class_name": "person"
        }
      ]
    }
  ]
}

Returned vs saved

  • Returned (always): the full det-v1 payload is available as DetectResult.payload (Python) or printed to stdout (CLI).
  • Saved (opt-in): nothing is written unless you enable artifacts:
    • --json saves detections.json
    • --frames saves frames under frames/
    • --save-video saves an annotated video

When no artifacts are enabled, no output directory/run folder is created.


Install with pip (PyPI)

Use this if you want to install and use the tool without cloning the repo.

Install

pip install detect-lib

Optional dependencies (pip extras)

Export helpers (ONNX + ONNXRuntime):

pip install "detect-lib[export]"

TensorFlow export paths (heavy):

pip install "detect-lib[tf]"

OpenVINO export:

pip install "detect-lib[openvino]"

CoreML export (macOS):

pip install "detect-lib[coreml]"

CLI usage (pip)

Global help:

python -m detect.cli.detect_video -h
python -m detect.cli.export_model -h

List detectors:

python -c "import detect; print(detect.available_detectors())"

List models (registry + installed):

python -m detect.cli.detect_video --list-models
python -m detect.cli.export_model --list-models

Basic command (detection):

python -m detect.cli.detect_video \
  --video <in.mp4> \
  --detector yolo_bbox \
  --weights yolo26n

Basic command (export):

python -m detect.cli.export_model \
  --weights yolo26n \
  --formats onnx \
  --out-dir models/exports --run-name y26_onnx

Python usage (import)

You can use detect as a library after installing detect-lib with pip.

Quick sanity check

python -c "import detect; print(detect.available_detectors())"

Run detection from a Python file

Create run_detect.py:

from detect import detect_video

res = detect_video(
    video="in.mp4",
    detector="yolo_bbox",
    weights="yolo26n",
)

payload = res.payload
print(payload["schema_version"], len(payload["frames"]))
print(res.paths)  # populated only if you enable saving artifacts

Run:

python run_detect.py

Run model export from a Python file

Requires export extras based on the type of export needed (e.g., pip install "detect-lib[export]").

Create run_export.py:

from detect import export_model

res = export_model(
    weights="yolo26n",
    formats=["onnx"],
    imgsz=640,
    out_dir="models/exports",
    run_name="y26_onnx_py",
)

print("run_dir:", res["run_dir"])
print("artifacts:")
for p in res["artifacts"]:
    print(" -", p)

Run it:

python run_export.py

Install from GitHub (uv)

Use this if you are developing locally or want reproducible project environments.

Install uv:
https://docs.astral.sh/uv/getting-started/installation/#standalone-installer

Verify:

uv --version

Install dependencies

git clone https://github.com/Surya-Rayala/VideoPipeline-detection.git
cd VideoPipeline-detection
uv sync

Optional dependencies (uv extras)

uv sync --extra export
uv sync --extra tf
uv sync --extra openvino
uv sync --extra coreml

CLI usage (uv)

Global help:

uv run python -m detect.cli.detect_video -h
uv run python -m detect.cli.export_model -h

List detectors:

uv run python -c "import detect; print(detect.available_detectors())"

List models (registry + installed):

uv run python -m detect.cli.detect_video --list-models
uv run python -m detect.cli.export_model --list-models

Basic command (detection):

uv run python -m detect.cli.detect_video \
  --video <in.mp4> \
  --detector yolo_bbox \
  --weights yolo26n

Basic command (export):

uv run python -m detect.cli.export_model \
  --weights yolo26n \
  --formats onnx \
  --out-dir models/exports --run-name y26_onnx

TensorRT / engine export and run notes (important)

Exporting engine (TensorRT) typically requires an NVIDIA GPU + CUDA + TensorRT installed and version-compatible.

Export TensorRT engine:

uv run python -m detect.cli.export_model \
  --weights yolo26n \
  --formats engine \
  --device 0 \
  --out-dir models/exports --run-name y26_trt

Run / sanity-check the exported engine using this package (produces det-v1 output):

uv run python -m detect.cli.detect_video \
  --video in.mp4 \
  --detector yolo_bbox \
  --weights models/exports/y26_trt/yolo26n.engine \
  --device 0

Optionally save artifacts (JSON + annotated video):

uv run python -m detect.cli.detect_video \
  --video in.mp4 \
  --detector yolo_bbox \
  --weights models/exports/y26_trt/yolo26n.engine \
  --device 0 \
  --json \
  --save-video annotated_engine.mp4 \
  --out-dir out --run-name y26_trt_check

CLI arguments

Detection: detect.cli.detect_video

Required

  • --video <path>: Path to the input video file.
  • --detector <name>: Detector type (yolo_bbox, yolo_pose, or yolo_seg).
  • --weights <id|path|url>: Registry key, local weights path, or URL to weights.

Detection options

  • --classes <ids>: Filter to specific class IDs (comma/semicolon-separated), or omit for all classes.
  • --conf-thresh <float>: Confidence threshold for detections (default 0.25).
  • --imgsz <int>: Inference image size used by the backend (default 640).
  • --device <str>: Device selector (e.g., auto, cpu, mps, 0).
  • --half: Enable FP16 inference where supported.

Artifact saving (opt-in)

  • --json: Save detections.json under the run directory.
  • --frames: Save extracted frames as images under the run directory.
  • --save-video <name.mp4>: Save an annotated video under the run directory.
  • --display: Show live visualization window while running (press q to quit).

Output control

  • --out-dir <dir>: Output root directory used only if saving artifacts (default out).
  • --run-name <name>: Run folder name inside out-dir (auto-derived if omitted).

Model registry / downloads

  • --models-dir <dir>: Directory where models are stored/downloaded (default models).
  • --no-download: Disable automatic download for registry keys/URLs.

Misc

  • --no-progress: Disable progress bar output.
  • --list-models: Print registry + installed models then exit.

Export: detect.cli.export_model

Required

  • --weights <id|path|url>: Registry key, local weights path, or URL to weights.

Export options

  • --formats <list>: Comma/semicolon-separated export formats (default onnx).
  • --imgsz <int|H,W>: Export image size as an int or H,W pair (default 640).
  • --device <str>: Export device selector (e.g., cpu, mps, 0).
  • --half: Enable FP16 export where supported.
  • --int8: Enable INT8 quantization (format/toolchain-dependent).
  • --data <yaml>: Dataset YAML for INT8 calibration (when required).
  • --fraction <float>: Fraction of dataset used for calibration (default 1.0).
  • --dynamic: Enable dynamic shapes where supported.
  • --batch <int>: Export batch size (default 1).
  • --opset <int>: ONNX opset version (ONNX only).
  • --simplify: Simplify the ONNX graph (ONNX only).
  • --workspace <int>: TensorRT workspace size in GB (TensorRT only).
  • --nms: Add NMS to exported model when supported by format/backend.

Output control

  • --out-dir <dir>: Output root directory for exports (default models/exports).
  • --run-name <name>: Export run folder name inside out-dir.

Model registry / downloads

  • --models-dir <dir>: Directory where models are stored/downloaded (default models).
  • --no-download: Disable automatic download for registry keys/URLs.

Misc

  • --list-models: Print registry + installed models then exit.

License

MIT License. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

detect_lib-0.1.3.tar.gz (26.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

detect_lib-0.1.3-py3-none-any.whl (28.5 kB view details)

Uploaded Python 3

File details

Details for the file detect_lib-0.1.3.tar.gz.

File metadata

  • Download URL: detect_lib-0.1.3.tar.gz
  • Upload date:
  • Size: 26.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for detect_lib-0.1.3.tar.gz
Algorithm Hash digest
SHA256 c435acb3c1035ef8e22a7e43d8e003d9d21d2d7656e613f890af7b99514d1102
MD5 ed0dcc7222d84999eb620cf514d5b85e
BLAKE2b-256 8ca0b68d56f64e6e34f4bd24cbf513e954f7ec62106d0cab039a97284c136850

See more details on using hashes here.

File details

Details for the file detect_lib-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: detect_lib-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 28.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for detect_lib-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8dd605a5da1e5cc50aa5ce94a3d06911d3b45980a173b9664b4dee21fc2d337a
MD5 8d2331298c2a0e185904f1f7ec30803e
BLAKE2b-256 19e12c894ec8ceb9bf285e8d92e2d845e5a6b17208bd12f354127b840790b46b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page