Sync catalog updates from GitHub (ec63768)
Browse files- README.md +61 -19
- export_and_quantize.sh +124 -11
README.md
CHANGED
|
@@ -8,6 +8,7 @@ tags:
|
|
| 8 |
- intel
|
| 9 |
- yolo
|
| 10 |
- yolo26
|
|
|
|
| 11 |
- motion-tracking
|
| 12 |
- multi-object-tracking
|
| 13 |
- edge-ai
|
|
@@ -22,8 +23,8 @@ language:
|
|
| 22 |
| Property | Value |
|
| 23 |
|---|---|
|
| 24 |
| **Category** | Object Detection + Multi-Object Tracking |
|
| 25 |
-
| **Base Model** | [YOLO26](https://docs.ultralytics.com/models/yolo26/) (Ultralytics) + DLStreamer `gvatrack` (Kalman filter tracker) |
|
| 26 |
-
| **Source Framework** | PyTorch (Ultralytics) |
|
| 27 |
| **Supported Precisions** | FP32, FP16, INT8 (mixed-precision) |
|
| 28 |
| **Inference Engine** | OpenVINO |
|
| 29 |
| **Hardware** | CPU, GPU, NPU |
|
|
@@ -49,19 +50,38 @@ Typical Metro deployments include:
|
|
| 49 |
- **Traffic Flow Analytics** -- track vehicles through intersections for signal timing optimization.
|
| 50 |
- **Incident Replay** -- reconstruct object paths for post-event forensic review.
|
| 51 |
|
| 52 |
-
Available YOLO26 variants: `yolo26n`, `yolo26s`, `yolo26m`, `yolo26l`
|
| 53 |
Smaller variants (`yolo26n`, `yolo26s`) are recommended for high-FPS edge deployment.
|
| 54 |
The default tracker is `short-term-imageless` (Kalman filter-based, no image data required).
|
| 55 |
DLStreamer also supports `tracking-type=deep-sort` for more robust re-identification using a feature extraction model (e.g., mars-small128).
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
---
|
| 58 |
|
| 59 |
## Prerequisites
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
- Python 3.11+
|
| 62 |
- `ffmpeg` (`sudo apt install ffmpeg`) -- used by both samples to encode output video
|
| 63 |
- [Install OpenVINO](https://docs.openvino.ai/2026/get-started/install-openvino.html) (latest version)
|
| 64 |
-
- [Install Intel DLStreamer](https://docs.openedgeplatform.intel.com/
|
| 65 |
|
| 66 |
Create and activate a Python virtual environment before running the scripts:
|
| 67 |
|
|
@@ -83,31 +103,34 @@ source .venv/bin/activate
|
|
| 83 |
Run the provided script to download, export to OpenVINO IR, and optionally quantize:
|
| 84 |
|
| 85 |
```bash
|
|
|
|
| 86 |
chmod +x export_and_quantize.sh
|
| 87 |
./export_and_quantize.sh
|
| 88 |
```
|
| 89 |
|
| 90 |
This exports the default **yolo26n** model in **FP16** precision.
|
| 91 |
|
| 92 |
-
#### Optional: Select a Different Variant or Precision
|
| 93 |
|
| 94 |
```bash
|
| 95 |
-
./export_and_quantize.sh yolo26n FP32
|
| 96 |
-
./export_and_quantize.sh yolo26n INT8
|
| 97 |
-
./export_and_quantize.sh yolo26s
|
|
|
|
|
|
|
| 98 |
```
|
| 99 |
|
| 100 |
-
|
| 101 |
The second argument selects the precision (`FP32`, `FP16`, `INT8`); the default is **FP16**.
|
| 102 |
|
| 103 |
The script performs the following steps:
|
| 104 |
|
| 105 |
-
1. Installs dependencies (`openvino`, `ultralytics`; adds `nncf` for INT8).
|
| 106 |
2. Downloads the sample test video (`test_video.mp4`) and a sample test image (`test.jpg`).
|
| 107 |
3. Downloads the PyTorch weights and exports to OpenVINO IR.
|
| 108 |
4. *(INT8 only)* Quantizes the model using NNCF post-training quantization.
|
| 109 |
|
| 110 |
-
Output files:
|
| 111 |
|
| 112 |
- `yolo26n_openvino_model/` -- FP32 or FP16 OpenVINO IR model directory.
|
| 113 |
- `yolo26n_tracking_int8.xml` / `yolo26n_tracking_int8.bin` -- INT8 quantized model *(only when `INT8` is selected)*.
|
|
@@ -135,7 +158,7 @@ polylines are drawn with OpenCV, and the result is muxed to `output_dlstreamer.m
|
|
| 135 |
|
| 136 |
> **Notes on running this sample:**
|
| 137 |
>
|
| 138 |
-
> - Use the FP16 IR (`yolo26n_openvino_model/yolo26n.xml`). Class names are
|
| 139 |
> read automatically from the model's embedded `metadata.yaml` by
|
| 140 |
> DLStreamer 2026.0+ -- no external `labels-file` is required.
|
| 141 |
> - Export `PYTHONPATH` so the DLStreamer Python module is importable:
|
|
@@ -147,7 +170,16 @@ polylines are drawn with OpenCV, and the result is muxed to `output_dlstreamer.m
|
|
| 147 |
> /opt/intel/dlstreamer/gstreamer/lib/python3/dist-packages:${PYTHONPATH:-}
|
| 148 |
> ```
|
| 149 |
|
|
|
|
|
|
|
|
|
|
| 150 |
```python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
import subprocess
|
| 152 |
from collections import defaultdict
|
| 153 |
|
|
@@ -156,23 +188,28 @@ import gi
|
|
| 156 |
|
| 157 |
gi.require_version("Gst", "1.0")
|
| 158 |
gi.require_version("GstAnalytics", "1.0")
|
| 159 |
-
|
|
|
|
| 160 |
|
| 161 |
Gst.init([])
|
| 162 |
|
| 163 |
# Import cv2 after Gst.init to avoid GStreamer re-initialization conflicts.
|
| 164 |
import cv2
|
| 165 |
|
|
|
|
|
|
|
|
|
|
| 166 |
# For CPU: change device=GPU to device=CPU.
|
| 167 |
# For NPU: change device=GPU to device=NPU (batch-size=1, nireq=4 recommended).
|
| 168 |
pipeline_str = (
|
| 169 |
"filesrc location=test_video.mp4 ! decodebin3 ! "
|
| 170 |
"videoconvert ! "
|
| 171 |
-
"gvadetect model=
|
| 172 |
"device=GPU "
|
| 173 |
"threshold=0.4 ! queue ! "
|
| 174 |
"gvatrack tracking-type=short-term-imageless ! queue ! "
|
| 175 |
-
"gvawatermark !
|
|
|
|
| 176 |
)
|
| 177 |
pipeline = Gst.parse_launch(pipeline_str)
|
| 178 |
appsink = pipeline.get_by_name("sink")
|
|
@@ -244,8 +281,10 @@ while True:
|
|
| 244 |
success, map_info = buf.map(Gst.MapFlags.READ)
|
| 245 |
if not success:
|
| 246 |
continue
|
|
|
|
|
|
|
| 247 |
arr = np.ndarray((height, width, 3), dtype=np.uint8,
|
| 248 |
-
buffer=map_info.data).copy()
|
| 249 |
buf.unmap(map_info)
|
| 250 |
|
| 251 |
# Draw per-track trajectory polylines on the frame copy.
|
|
@@ -267,6 +306,7 @@ if proc:
|
|
| 267 |
proc.wait()
|
| 268 |
print("Wrote output_dlstreamer.mp4", flush=True)
|
| 269 |
```
|
|
|
|
| 270 |
|
| 271 |
#### Expected Output
|
| 272 |
|
|
@@ -287,9 +327,11 @@ Licensed under the MIT License. See [LICENSE](LICENSE) for details.
|
|
| 287 |
## References
|
| 288 |
|
| 289 |
- [YOLO26 Documentation](https://docs.ultralytics.com/models/yolo26/)
|
|
|
|
|
|
|
| 290 |
- [Ultralytics Multi-Object Tracking](https://docs.ultralytics.com/modes/track/)
|
| 291 |
-
- [Intel DLStreamer gvatrack](https://docs.openedgeplatform.intel.com/
|
| 292 |
-
- [DLStreamer Object Tracking Guide](https://docs.openedgeplatform.intel.com/
|
| 293 |
- [OpenVINO Documentation](https://docs.openvino.ai/)
|
| 294 |
- [NNCF Post-Training Quantization](https://docs.openvino.ai/latest/nncf_ptq_introduction.html)
|
| 295 |
-
- [Intel DLStreamer](https://docs.openedgeplatform.intel.com/
|
|
|
|
| 8 |
- intel
|
| 9 |
- yolo
|
| 10 |
- yolo26
|
| 11 |
+
- detr
|
| 12 |
- motion-tracking
|
| 13 |
- multi-object-tracking
|
| 14 |
- edge-ai
|
|
|
|
| 23 |
| Property | Value |
|
| 24 |
|---|---|
|
| 25 |
| **Category** | Object Detection + Multi-Object Tracking |
|
| 26 |
+
| **Base Model** | [YOLO26](https://docs.ultralytics.com/models/yolo26/) (Ultralytics, default) or [DETR](https://huggingface.co/facebook/detr-resnet-50) (Facebook, alternative) + DLStreamer `gvatrack` (Kalman filter tracker) |
|
| 27 |
+
| **Source Framework** | PyTorch (Ultralytics, Hugging Face Transformers) |
|
| 28 |
| **Supported Precisions** | FP32, FP16, INT8 (mixed-precision) |
|
| 29 |
| **Inference Engine** | OpenVINO |
|
| 30 |
| **Hardware** | CPU, GPU, NPU |
|
|
|
|
| 50 |
- **Traffic Flow Analytics** -- track vehicles through intersections for signal timing optimization.
|
| 51 |
- **Incident Replay** -- reconstruct object paths for post-event forensic review.
|
| 52 |
|
| 53 |
+
Available YOLO26 variants: `yolo26n`, `yolo26s`, `yolo26m`, `yolo26l`.
|
| 54 |
Smaller variants (`yolo26n`, `yolo26s`) are recommended for high-FPS edge deployment.
|
| 55 |
The default tracker is `short-term-imageless` (Kalman filter-based, no image data required).
|
| 56 |
DLStreamer also supports `tracking-type=deep-sort` for more robust re-identification using a feature extraction model (e.g., mars-small128).
|
| 57 |
|
| 58 |
+
### Model Selection
|
| 59 |
+
|
| 60 |
+
[DETR](https://huggingface.co/facebook/detr-resnet-50) (DEtection TRansformer) is available as an alternative to YOLO26.
|
| 61 |
+
DETR is a transformer-based, NMS-free detector trained on COCO and released under the Apache-2.0 license.
|
| 62 |
+
The export script embeds DETR normalization, box decoding, and the class remap into the OpenVINO IR, so the DETR model produces the same output layout and class ids as YOLO26.
|
| 63 |
+
The same DLStreamer sample run either model; select one with the `MODEL` constant at the top of the sample.
|
| 64 |
+
|
| 65 |
+
| Model | Variants | Input Size | Output | License |
|
| 66 |
+
|---|---|---|---|---|
|
| 67 |
+
| YOLO26 (default) | `yolo26n`, `yolo26s`, `yolo26m`, `yolo26l` | 640 x 640 | `[1, 300, 6]` | AGPL-3.0 |
|
| 68 |
+
| DETR | `detr-resnet-50` | 800 x 800 | `[1, 100, 6]` | Apache-2.0 |
|
| 69 |
+
|
| 70 |
+
Choose YOLO26 for maximum throughput on edge devices.
|
| 71 |
+
Choose DETR when a permissively licensed transformer detector is preferred; it is heavier and runs at a lower frame rate.
|
| 72 |
+
|
| 73 |
---
|
| 74 |
|
| 75 |
## Prerequisites
|
| 76 |
|
| 77 |
+
Target stack: Intel DLStreamer **2026.3.0 RC1** with the matching OpenVINO GenAI bundle **2026.5.0.0.dev20261030** (OpenVINO Runtime **2026.5.0.dev20261030**).
|
| 78 |
+
Use the [native RC1 setup](../README.md#native-rc1-runtime) before running these samples; this is a development stack, not a stable release.
|
| 79 |
+
See the [device validation matrix](../DEVICE_SUPPORT_MATRIX.md) for measured CPU, GPU, and NPU results.
|
| 80 |
+
|
| 81 |
- Python 3.11+
|
| 82 |
- `ffmpeg` (`sudo apt install ffmpeg`) -- used by both samples to encode output video
|
| 83 |
- [Install OpenVINO](https://docs.openvino.ai/2026/get-started/install-openvino.html) (latest version)
|
| 84 |
+
- [Install Intel DLStreamer](https://docs.openedgeplatform.intel.com/dev/edge-ai-libraries/dlstreamer/get_started/install/install_guide_ubuntu.html) (latest version)
|
| 85 |
|
| 86 |
Create and activate a Python virtual environment before running the scripts:
|
| 87 |
|
|
|
|
| 103 |
Run the provided script to download, export to OpenVINO IR, and optionally quantize:
|
| 104 |
|
| 105 |
```bash
|
| 106 |
+
wget https://huggingface.co/Intel/motion-tracking/resolve/main/export_and_quantize.sh
|
| 107 |
chmod +x export_and_quantize.sh
|
| 108 |
./export_and_quantize.sh
|
| 109 |
```
|
| 110 |
|
| 111 |
This exports the default **yolo26n** model in **FP16** precision.
|
| 112 |
|
| 113 |
+
#### Optional: Select a Different Model, Variant, or Precision
|
| 114 |
|
| 115 |
```bash
|
| 116 |
+
./export_and_quantize.sh yolo26n FP32 # full-precision
|
| 117 |
+
./export_and_quantize.sh yolo26n INT8 # quantized
|
| 118 |
+
./export_and_quantize.sh yolo26s # larger variant, default FP16
|
| 119 |
+
./export_and_quantize.sh detr-resnet-50 # DETR alternative, default FP16
|
| 120 |
+
./export_and_quantize.sh detr-resnet-50 INT8 # DETR quantized
|
| 121 |
```
|
| 122 |
|
| 123 |
+
The first argument selects the model: any YOLO26 variant (`yolo26n`, `yolo26s`, `yolo26m`, `yolo26l`) or DETR (`detr-resnet-50`).
|
| 124 |
The second argument selects the precision (`FP32`, `FP16`, `INT8`); the default is **FP16**.
|
| 125 |
|
| 126 |
The script performs the following steps:
|
| 127 |
|
| 128 |
+
1. Installs dependencies (`openvino`, `ultralytics` for YOLO26 or `transformers`, `torch` for DETR; adds `nncf` for INT8).
|
| 129 |
2. Downloads the sample test video (`test_video.mp4`) and a sample test image (`test.jpg`).
|
| 130 |
3. Downloads the PyTorch weights and exports to OpenVINO IR.
|
| 131 |
4. *(INT8 only)* Quantizes the model using NNCF post-training quantization.
|
| 132 |
|
| 133 |
+
Output files (replace `yolo26n` with the selected model, for example `detr-resnet-50`):
|
| 134 |
|
| 135 |
- `yolo26n_openvino_model/` -- FP32 or FP16 OpenVINO IR model directory.
|
| 136 |
- `yolo26n_tracking_int8.xml` / `yolo26n_tracking_int8.bin` -- INT8 quantized model *(only when `INT8` is selected)*.
|
|
|
|
| 158 |
|
| 159 |
> **Notes on running this sample:**
|
| 160 |
>
|
| 161 |
+
> - Use the FP16 IR (`yolo26n_openvino_model/yolo26n.xml` or `detr-resnet-50_openvino_model/detr-resnet-50.xml`). Class names are
|
| 162 |
> read automatically from the model's embedded `metadata.yaml` by
|
| 163 |
> DLStreamer 2026.0+ -- no external `labels-file` is required.
|
| 164 |
> - Export `PYTHONPATH` so the DLStreamer Python module is importable:
|
|
|
|
| 170 |
> /opt/intel/dlstreamer/gstreamer/lib/python3/dist-packages:${PYTHONPATH:-}
|
| 171 |
> ```
|
| 172 |
|
| 173 |
+
The full sample is in [dlstreamer_sample.py](dlstreamer_sample.py); run it with `python3 dlstreamer_sample.py` or copy the code below.
|
| 174 |
+
|
| 175 |
+
<!-- sample: dlstreamer_sample.py -->
|
| 176 |
```python
|
| 177 |
+
# SPDX-License-Identifier: MIT
|
| 178 |
+
# Copyright (C) Intel Corporation
|
| 179 |
+
#
|
| 180 |
+
# Motion Tracking: DLStreamer pipeline sample.
|
| 181 |
+
# See README.md for prerequisites and inputs. Run: python3 dlstreamer_sample.py
|
| 182 |
+
|
| 183 |
import subprocess
|
| 184 |
from collections import defaultdict
|
| 185 |
|
|
|
|
| 188 |
|
| 189 |
gi.require_version("Gst", "1.0")
|
| 190 |
gi.require_version("GstAnalytics", "1.0")
|
| 191 |
+
gi.require_version("GstVideo", "1.0")
|
| 192 |
+
from gi.repository import Gst, GLib, GstAnalytics, GstVideo
|
| 193 |
|
| 194 |
Gst.init([])
|
| 195 |
|
| 196 |
# Import cv2 after Gst.init to avoid GStreamer re-initialization conflicts.
|
| 197 |
import cv2
|
| 198 |
|
| 199 |
+
# Select the model: "yolo26n" (default) or "detr-resnet-50".
|
| 200 |
+
MODEL = "yolo26n"
|
| 201 |
+
|
| 202 |
# For CPU: change device=GPU to device=CPU.
|
| 203 |
# For NPU: change device=GPU to device=NPU (batch-size=1, nireq=4 recommended).
|
| 204 |
pipeline_str = (
|
| 205 |
"filesrc location=test_video.mp4 ! decodebin3 ! "
|
| 206 |
"videoconvert ! "
|
| 207 |
+
f"gvadetect model={MODEL}_openvino_model/{MODEL}.xml "
|
| 208 |
"device=GPU "
|
| 209 |
"threshold=0.4 ! queue ! "
|
| 210 |
"gvatrack tracking-type=short-term-imageless ! queue ! "
|
| 211 |
+
"gvawatermark ! videoconvert ! video/x-raw,format=BGR ! "
|
| 212 |
+
"appsink name=sink emit-signals=false sync=false"
|
| 213 |
)
|
| 214 |
pipeline = Gst.parse_launch(pipeline_str)
|
| 215 |
appsink = pipeline.get_by_name("sink")
|
|
|
|
| 281 |
success, map_info = buf.map(Gst.MapFlags.READ)
|
| 282 |
if not success:
|
| 283 |
continue
|
| 284 |
+
video_info = GstVideo.VideoInfo.new_from_caps(caps)
|
| 285 |
+
stride = video_info.stride[0]
|
| 286 |
arr = np.ndarray((height, width, 3), dtype=np.uint8,
|
| 287 |
+
buffer=map_info.data, strides=(stride, 3, 1)).copy()
|
| 288 |
buf.unmap(map_info)
|
| 289 |
|
| 290 |
# Draw per-track trajectory polylines on the frame copy.
|
|
|
|
| 306 |
proc.wait()
|
| 307 |
print("Wrote output_dlstreamer.mp4", flush=True)
|
| 308 |
```
|
| 309 |
+
<!-- /sample -->
|
| 310 |
|
| 311 |
#### Expected Output
|
| 312 |
|
|
|
|
| 327 |
## References
|
| 328 |
|
| 329 |
- [YOLO26 Documentation](https://docs.ultralytics.com/models/yolo26/)
|
| 330 |
+
- [DETR Model Card (facebook/detr-resnet-50)](https://huggingface.co/facebook/detr-resnet-50)
|
| 331 |
+
- [End-to-End Object Detection with Transformers (DETR paper)](https://arxiv.org/abs/2005.12872)
|
| 332 |
- [Ultralytics Multi-Object Tracking](https://docs.ultralytics.com/modes/track/)
|
| 333 |
+
- [Intel DLStreamer gvatrack](https://docs.openedgeplatform.intel.com/dev/edge-ai-libraries/dlstreamer/elements/gvatrack.html)
|
| 334 |
+
- [DLStreamer Object Tracking Guide](https://docs.openedgeplatform.intel.com/dev/edge-ai-libraries/dlstreamer/dev_guide/object_tracking.html)
|
| 335 |
- [OpenVINO Documentation](https://docs.openvino.ai/)
|
| 336 |
- [NNCF Post-Training Quantization](https://docs.openvino.ai/latest/nncf_ptq_introduction.html)
|
| 337 |
+
- [Intel DLStreamer](https://docs.openedgeplatform.intel.com/dev/edge-ai-libraries/dlstreamer/index.html)
|
export_and_quantize.sh
CHANGED
|
@@ -2,11 +2,21 @@
|
|
| 2 |
# SPDX-License-Identifier: MIT
|
| 3 |
# Copyright (C) Intel Corporation
|
| 4 |
#
|
| 5 |
-
# Export a YOLO26 detector for motion tracking to OpenVINO IR.
|
| 6 |
# The tracker itself (BoT-SORT / ByteTrack) runs at inference time via
|
| 7 |
# Ultralytics or DLStreamer gvatrack; no separate model export is needed.
|
| 8 |
# Usage: ./export_and_quantize.sh [MODEL_VARIANT] [PRECISION]
|
| 9 |
# Example: ./export_and_quantize.sh yolo26n FP16
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
#
|
| 11 |
# Supported precisions:
|
| 12 |
# FP32 -- Full-precision floating-point weights
|
|
@@ -31,12 +41,20 @@ if [[ "${PRECISION}" != "FP32" && "${PRECISION}" != "FP16" && "${PRECISION}" !=
|
|
| 31 |
exit 1
|
| 32 |
fi
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
# Ask for approval before downloading models and sample files
|
| 42 |
echo ""
|
|
@@ -61,6 +79,17 @@ else
|
|
| 61 |
echo "WARNING: HuggingFace tracking ping failed (offline?); continuing." >&2
|
| 62 |
fi
|
| 63 |
echo ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
echo "--- Downloading sample test video ---"
|
| 65 |
if [[ ! -f test_video.mp4 ]]; then
|
| 66 |
wget -q -O test_video.mp4 \
|
|
@@ -86,14 +115,97 @@ else
|
|
| 86 |
EXPORT_LABEL="FP16"
|
| 87 |
fi
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
|
|
|
| 91 |
from ultralytics import YOLO
|
| 92 |
|
| 93 |
model = YOLO('${MODEL_NAME}.pt')
|
| 94 |
-
model.export(format='openvino', half=${HALF_FLAG}, dynamic=False, imgsz=
|
| 95 |
print('Export complete: ${MODEL_NAME}_openvino_model/')
|
| 96 |
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
if [[ "${PRECISION}" == "INT8" ]]; then
|
| 99 |
echo "--- Quantizing to INT8 with NNCF ---"
|
|
@@ -114,7 +226,7 @@ while len(frames) < 300:
|
|
| 114 |
if not ret:
|
| 115 |
cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
|
| 116 |
continue
|
| 117 |
-
img = cv2.resize(frame, (
|
| 118 |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB).astype(np.float32) / 255.0
|
| 119 |
img = img.transpose(2, 0, 1)[np.newaxis, ...]
|
| 120 |
frames.append(img)
|
|
@@ -130,6 +242,7 @@ quantized = nncf.quantize(
|
|
| 130 |
calibration_dataset,
|
| 131 |
preset=nncf.QuantizationPreset.MIXED,
|
| 132 |
subset_size=300,
|
|
|
|
| 133 |
)
|
| 134 |
|
| 135 |
ov.save_model(quantized, '${MODEL_NAME}_tracking_int8.xml')
|
|
|
|
| 2 |
# SPDX-License-Identifier: MIT
|
| 3 |
# Copyright (C) Intel Corporation
|
| 4 |
#
|
| 5 |
+
# Export a YOLO26 or DETR detector for motion tracking to OpenVINO IR.
|
| 6 |
# The tracker itself (BoT-SORT / ByteTrack) runs at inference time via
|
| 7 |
# Ultralytics or DLStreamer gvatrack; no separate model export is needed.
|
| 8 |
# Usage: ./export_and_quantize.sh [MODEL_VARIANT] [PRECISION]
|
| 9 |
# Example: ./export_and_quantize.sh yolo26n FP16
|
| 10 |
+
# Example: ./export_and_quantize.sh detr-resnet-50 FP16
|
| 11 |
+
#
|
| 12 |
+
# Supported model variants:
|
| 13 |
+
# yolo26n, yolo26s, yolo26m, yolo26l -- Ultralytics YOLO26 (default)
|
| 14 |
+
# detr-resnet-50 -- Facebook DETR (Hugging Face)
|
| 15 |
+
#
|
| 16 |
+
# DETR is exported end-to-end: ImageNet normalization, softmax,
|
| 17 |
+
# box decoding, and the COCO-91 to COCO-80 class remap are embedded in the
|
| 18 |
+
# graph, so the IR produces the same [1, N, 6] output layout and class ids as
|
| 19 |
+
# YOLO26 and runs with the same OpenVINO and DLStreamer samples.
|
| 20 |
#
|
| 21 |
# Supported precisions:
|
| 22 |
# FP32 -- Full-precision floating-point weights
|
|
|
|
| 41 |
exit 1
|
| 42 |
fi
|
| 43 |
|
| 44 |
+
case "${MODEL_NAME}" in
|
| 45 |
+
yolo26n|yolo26s|yolo26m|yolo26l)
|
| 46 |
+
MODEL_FAMILY="yolo"
|
| 47 |
+
INPUT_SIZE=640
|
| 48 |
+
;;
|
| 49 |
+
detr-resnet-50)
|
| 50 |
+
MODEL_FAMILY="detr"
|
| 51 |
+
INPUT_SIZE=800
|
| 52 |
+
;;
|
| 53 |
+
*)
|
| 54 |
+
echo "ERROR: unsupported model '${MODEL_NAME}'. Choose yolo26[n|s|m|l] or detr-resnet-50." >&2
|
| 55 |
+
exit 1
|
| 56 |
+
;;
|
| 57 |
+
esac
|
| 58 |
|
| 59 |
# Ask for approval before downloading models and sample files
|
| 60 |
echo ""
|
|
|
|
| 79 |
echo "WARNING: HuggingFace tracking ping failed (offline?); continuing." >&2
|
| 80 |
fi
|
| 81 |
echo ""
|
| 82 |
+
echo "--- Installing dependencies ---"
|
| 83 |
+
if [[ "${MODEL_FAMILY}" == "detr" ]]; then
|
| 84 |
+
DEPS=(openvino transformers torch pyyaml opencv-python)
|
| 85 |
+
else
|
| 86 |
+
DEPS=(openvino ultralytics)
|
| 87 |
+
fi
|
| 88 |
+
if [[ "${PRECISION}" == "INT8" ]]; then
|
| 89 |
+
DEPS+=(nncf)
|
| 90 |
+
fi
|
| 91 |
+
pip install -qU "${DEPS[@]}"
|
| 92 |
+
|
| 93 |
echo "--- Downloading sample test video ---"
|
| 94 |
if [[ ! -f test_video.mp4 ]]; then
|
| 95 |
wget -q -O test_video.mp4 \
|
|
|
|
| 115 |
EXPORT_LABEL="FP16"
|
| 116 |
fi
|
| 117 |
|
| 118 |
+
if [[ "${MODEL_FAMILY}" == "yolo" ]]; then
|
| 119 |
+
echo "--- Exporting ${MODEL_NAME} to OpenVINO IR (${EXPORT_LABEL}) ---"
|
| 120 |
+
python3 -c "
|
| 121 |
from ultralytics import YOLO
|
| 122 |
|
| 123 |
model = YOLO('${MODEL_NAME}.pt')
|
| 124 |
+
model.export(format='openvino', half=${HALF_FLAG}, dynamic=False, imgsz=${INPUT_SIZE}, nms=False)
|
| 125 |
print('Export complete: ${MODEL_NAME}_openvino_model/')
|
| 126 |
"
|
| 127 |
+
else
|
| 128 |
+
echo "--- Exporting facebook/${MODEL_NAME} to OpenVINO IR (${EXPORT_LABEL}) ---"
|
| 129 |
+
python3 - "${MODEL_NAME}" "${HALF_FLAG}" "${INPUT_SIZE}" <<'PYEXPORT'
|
| 130 |
+
import sys
|
| 131 |
+
from pathlib import Path
|
| 132 |
+
|
| 133 |
+
import openvino as ov
|
| 134 |
+
import torch
|
| 135 |
+
import yaml
|
| 136 |
+
from transformers import DetrConfig, DetrForObjectDetection
|
| 137 |
+
|
| 138 |
+
model_name, half_flag, size = sys.argv[1], sys.argv[2] == "True", int(sys.argv[3])
|
| 139 |
+
model_id = f"facebook/{model_name}"
|
| 140 |
+
|
| 141 |
+
# The "no_timm" revision uses the transformers ResNet backbone (no timm dependency).
|
| 142 |
+
config_dict, _ = DetrConfig.get_config_dict(model_id, revision="no_timm")
|
| 143 |
+
# Older no_timm configs serialize the standard non-dilated backbone as null.
|
| 144 |
+
if config_dict.get("dilation") is None:
|
| 145 |
+
config_dict["dilation"] = False
|
| 146 |
+
config = DetrConfig.from_dict(config_dict)
|
| 147 |
+
detr = DetrForObjectDetection.from_pretrained(model_id, revision="no_timm", config=config).eval()
|
| 148 |
+
id2label = detr.config.id2label
|
| 149 |
+
# DETR predicts 91 COCO category ids (with "N/A" gaps) plus a no-object class.
|
| 150 |
+
# Keep the 80 real categories so class ids match YOLO26 (person = 0).
|
| 151 |
+
coco80 = [k for k in sorted(id2label) if id2label[k] != "N/A"]
|
| 152 |
+
assert len(coco80) == 80, f"unexpected label map with {len(coco80)} classes"
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
class DetrEndToEnd(torch.nn.Module):
|
| 156 |
+
"""Input: RGB [0, 1] NCHW. Output: [1, 100, 6] = [x1, y1, x2, y2, conf, class_id] in input pixels."""
|
| 157 |
+
|
| 158 |
+
def __init__(self, model: torch.nn.Module) -> None:
|
| 159 |
+
super().__init__()
|
| 160 |
+
self.model = model
|
| 161 |
+
self.register_buffer("mean", torch.tensor([0.485, 0.456, 0.406]).view(1, 3, 1, 1))
|
| 162 |
+
self.register_buffer("std", torch.tensor([0.229, 0.224, 0.225]).view(1, 3, 1, 1))
|
| 163 |
+
self.register_buffer("coco80", torch.tensor(coco80))
|
| 164 |
+
|
| 165 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 166 |
+
out = self.model(pixel_values=(x - self.mean) / self.std, return_dict=True)
|
| 167 |
+
probs = out.logits.softmax(-1).index_select(-1, self.coco80)
|
| 168 |
+
conf, cls = probs.max(-1)
|
| 169 |
+
cx, cy, w, h = (out.pred_boxes * size).unbind(-1)
|
| 170 |
+
return torch.stack([cx - w / 2, cy - h / 2, cx + w / 2, cy + h / 2, conf, cls.float()], -1)
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
ov_model = ov.convert_model(
|
| 174 |
+
DetrEndToEnd(detr), example_input=torch.zeros(1, 3, size, size), input=[1, 3, size, size]
|
| 175 |
+
)
|
| 176 |
+
ov_model.outputs[0].get_tensor().set_names({"output0"})
|
| 177 |
+
|
| 178 |
+
names = {i: id2label[k] for i, k in enumerate(coco80)}
|
| 179 |
+
# DLStreamer reads preprocessing and the post-processor type from model_info.
|
| 180 |
+
model_info = {
|
| 181 |
+
"model_type": "YOLO",
|
| 182 |
+
"labels": " ".join(n.replace(" ", "_") for n in names.values()),
|
| 183 |
+
"resize_type": "standard",
|
| 184 |
+
"reverse_input_channels": "YES",
|
| 185 |
+
"scale_values": "255",
|
| 186 |
+
"iou_threshold": "0.7",
|
| 187 |
+
}
|
| 188 |
+
for key, value in model_info.items():
|
| 189 |
+
ov_model.set_rt_info(value, ["model_info", key])
|
| 190 |
+
|
| 191 |
+
out_dir = Path(f"{model_name}_openvino_model")
|
| 192 |
+
out_dir.mkdir(exist_ok=True)
|
| 193 |
+
ov.save_model(ov_model, out_dir / f"{model_name}.xml", compress_to_fp16=half_flag)
|
| 194 |
+
metadata = {
|
| 195 |
+
"description": f"{model_id} exported end-to-end with YOLO26-compatible output",
|
| 196 |
+
"license": "Apache-2.0",
|
| 197 |
+
"task": "detect",
|
| 198 |
+
"batch": 1,
|
| 199 |
+
"imgsz": [size, size],
|
| 200 |
+
"names": names,
|
| 201 |
+
"channels": 3,
|
| 202 |
+
"end2end": True,
|
| 203 |
+
}
|
| 204 |
+
with open(out_dir / "metadata.yaml", "w", encoding="utf-8") as f:
|
| 205 |
+
yaml.safe_dump(metadata, f, sort_keys=False)
|
| 206 |
+
print(f"Export complete: {out_dir}/")
|
| 207 |
+
PYEXPORT
|
| 208 |
+
fi
|
| 209 |
|
| 210 |
if [[ "${PRECISION}" == "INT8" ]]; then
|
| 211 |
echo "--- Quantizing to INT8 with NNCF ---"
|
|
|
|
| 226 |
if not ret:
|
| 227 |
cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
|
| 228 |
continue
|
| 229 |
+
img = cv2.resize(frame, (${INPUT_SIZE}, ${INPUT_SIZE}))
|
| 230 |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB).astype(np.float32) / 255.0
|
| 231 |
img = img.transpose(2, 0, 1)[np.newaxis, ...]
|
| 232 |
frames.append(img)
|
|
|
|
| 242 |
calibration_dataset,
|
| 243 |
preset=nncf.QuantizationPreset.MIXED,
|
| 244 |
subset_size=300,
|
| 245 |
+
model_type=nncf.ModelType.TRANSFORMER if '${MODEL_FAMILY}' == 'detr' else None,
|
| 246 |
)
|
| 247 |
|
| 248 |
ov.save_model(quantized, '${MODEL_NAME}_tracking_int8.xml')
|