vagheshpatel commited on
Commit
8af681b
·
verified ·
1 Parent(s): d4418fd

Update native RC1 samples and supported device documentation

Browse files
Files changed (5) hide show
  1. README.md +76 -23
  2. config.json +11 -3
  3. dlstreamer_sample.py +64 -0
  4. export_and_quantize.sh +119 -12
  5. openvino_sample.py +52 -0
README.md CHANGED
@@ -8,6 +8,7 @@ tags:
8
  - intel
9
  - yolo
10
  - yolo26
 
11
  - person-detection
12
  - edge-ai
13
  - metro
@@ -21,8 +22,8 @@ language:
21
  | Property | Value |
22
  |---|---|
23
  | **Category** | Object Detection (Person Detection) |
24
- | **Base Model** | [YOLO26](https://docs.ultralytics.com/models/yolo26/) (Ultralytics) |
25
- | **Source Framework** | PyTorch (Ultralytics) |
26
  | **Supported Precisions** | FP32, FP16, INT8 (mixed-precision) |
27
  | **Inference Engine** | OpenVINO |
28
  | **Hardware** | CPU, GPU, NPU |
@@ -43,16 +44,35 @@ Typical Metro deployments include:
43
  - **Access Control** -- detect unauthorized presence in restricted zones.
44
  - **Public Safety** -- support situational awareness in transit hubs and venues.
45
 
46
- Available variants: `yolo26n`, `yolo26s`, `yolo26m`, `yolo26l`, `yolo26x`.
47
  Smaller variants (`yolo26n`, `yolo26s`) are recommended for high-FPS edge deployment; larger variants improve recall in dense scenes.
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  ---
50
 
51
  ## Prerequisites
52
 
 
 
 
 
53
  - Python 3.11+
54
  - [Install OpenVINO](https://docs.openvino.ai/2026/get-started/install-openvino.html) (latest version)
55
- - [Install Intel DLStreamer](https://docs.openedgeplatform.intel.com/2026.0/edge-ai-libraries/dlstreamer/get_started/install/install_guide_ubuntu.html) (latest version)
56
 
57
  Create and activate a Python virtual environment before running the scripts:
58
 
@@ -80,25 +100,27 @@ chmod +x export_and_quantize.sh
80
 
81
  This exports the default **yolo26n** model in **FP16** precision.
82
 
83
- #### Optional: Select a Different Variant or Precision
84
 
85
  ```bash
86
- ./export_and_quantize.sh yolo26n FP32 # full-precision
87
- ./export_and_quantize.sh yolo26n INT8 # quantized
88
- ./export_and_quantize.sh yolo26s # larger variant, default FP16
 
 
89
  ```
90
 
91
- Replace `yolo26n` with any variant (`yolo26s`, `yolo26m`, `yolo26l`, `yolo26x`).
92
  The second argument selects the precision (`FP32`, `FP16`, `INT8`); the default is **FP16**.
93
 
94
  The script performs the following steps:
95
 
96
- 1. Installs dependencies (`openvino`, `ultralytics`; adds `nncf` for INT8).
97
  2. Downloads a sample test image (`test.jpg`) and a sample test video (`test_video.mp4`).
98
  3. Downloads the PyTorch weights and exports to OpenVINO IR.
99
  4. *(INT8 only)* Quantizes the model using NNCF post-training quantization.
100
 
101
- Output files:
102
 
103
  - `yolo26n_openvino_model/` -- FP32 or FP16 OpenVINO IR model directory.
104
  - `yolo26n_person_int8.xml` / `yolo26n_person_int8.bin` -- INT8 quantized model *(only when `INT8` is selected)*.
@@ -117,21 +139,34 @@ Output files:
117
 
118
  ### OpenVINO Sample
119
 
120
- The sample below runs YOLO26 inference, filters to the `person` class, and reports the person count for a single image.
121
- YOLO26 is end-to-end (NMS-free), so no manual non-maximum suppression is needed.
 
122
  Change the `device` string to run on CPU, GPU, or NPU.
123
 
 
 
 
124
  ```python
 
 
 
 
 
 
125
  import cv2
126
  import numpy as np
127
  import openvino as ov
128
 
 
 
 
129
  PERSON_CLASS_ID = 0
130
  CONF_THRESHOLD = 0.4
131
- INPUT_SIZE = 640
132
 
133
  core = ov.Core()
134
- model = core.read_model("yolo26n_openvino_model/yolo26n.xml")
135
 
136
  # Change device to "GPU" or "NPU" to run on integrated GPU or NPU.
137
  compiled = core.compile_model(model, "CPU")
@@ -143,7 +178,8 @@ blob = cv2.resize(image, (INPUT_SIZE, INPUT_SIZE))
143
  blob = cv2.cvtColor(blob, cv2.COLOR_BGR2RGB).astype(np.float32) / 255.0
144
  blob = blob.transpose(2, 0, 1)[np.newaxis, ...] # NCHW
145
 
146
- # YOLO26 end-to-end output: [1, 300, 6] = [x1, y1, x2, y2, confidence, class_id]
 
147
  output = compiled([blob])[compiled.output(0)][0]
148
  mask = (output[:, 4] >= CONF_THRESHOLD) & (output[:, 5].astype(int) == PERSON_CLASS_ID)
149
  dets = output[mask]
@@ -165,6 +201,7 @@ cv2.putText(
165
  )
166
  cv2.imwrite("output_openvino.jpg", image)
167
  ```
 
168
 
169
  **Device targets:**
170
 
@@ -192,7 +229,7 @@ Detected persons: 2
192
 
193
  ### DLStreamer Sample
194
 
195
- The pipeline below runs the FP16 YOLO26 detector on the sample video via
196
  `gvadetect`, filters detections to the `person` class in a buffer probe using
197
  the GStreamer Analytics metadata API (`GstAnalytics`), overlays bounding boxes,
198
  saves the annotated result to `output_dlstreamer.mp4`, and prints the person count per
@@ -200,10 +237,12 @@ frame.
200
 
201
  > **Notes on running this sample:**
202
  >
203
- > - Use the FP16 IR (`yolo26n_openvino_model/yolo26n.xml`).
204
- > On DLStreamer 2026.1, `gvadetect` cannot auto-derive a YOLO post-processor
205
- > from the INT8 model produced by the bundled script.
206
- > To use the INT8 model, supply a matching `model-proc` JSON.
 
 
207
  > - Class names are read automatically from the model's embedded
208
  > `metadata.yaml` by DLStreamer 2026.0+ -- no external `labels-file` is
209
  > required.
@@ -216,7 +255,16 @@ frame.
216
  > /opt/intel/dlstreamer/gstreamer/lib/python3/dist-packages:${PYTHONPATH:-}
217
  > ```
218
 
 
 
 
219
  ```python
 
 
 
 
 
 
220
  import gi
221
 
222
  gi.require_version("Gst", "1.0")
@@ -226,13 +274,15 @@ from gi.repository import Gst, GLib, GstAnalytics
226
  Gst.init([])
227
 
228
  INPUT_VIDEO = "test_video.mp4"
 
 
229
 
230
  # For CPU: change device=GPU to device=CPU.
231
  # For NPU: change device=GPU to device=NPU (batch-size=1, nireq=4 recommended).
232
  pipeline_str = (
233
  f"filesrc location={INPUT_VIDEO} ! decodebin3 ! "
234
  "videoconvert ! "
235
- "gvadetect model=yolo26n_openvino_model/yolo26n.xml "
236
  "device=GPU "
237
  "threshold=0.4 ! queue ! "
238
  "gvawatermark displ-cfg=show-roi=person ! "
@@ -274,6 +324,7 @@ bus.timed_pop_filtered(
274
  )
275
  pipeline.set_state(Gst.State.NULL)
276
  ```
 
277
 
278
  #### Expected Output
279
 
@@ -294,8 +345,10 @@ Licensed under the MIT License. See [LICENSE](LICENSE) for details.
294
  ## References
295
 
296
  - [YOLO26 Documentation](https://docs.ultralytics.com/models/yolo26/)
 
 
297
  - [OpenVINO YOLO26 Notebook](https://github.com/openvinotoolkit/openvino_notebooks/blob/latest/notebooks/yolov26-optimization/yolov26-object-detection.ipynb)
298
  - [COCO Dataset](https://cocodataset.org/)
299
  - [OpenVINO Documentation](https://docs.openvino.ai/)
300
  - [NNCF Post-Training Quantization](https://docs.openvino.ai/latest/nncf_ptq_introduction.html)
301
- - [Intel DLStreamer](https://docs.openedgeplatform.intel.com/2026.0/edge-ai-libraries/dlstreamer/index.html)
 
8
  - intel
9
  - yolo
10
  - yolo26
11
+ - detr
12
  - person-detection
13
  - edge-ai
14
  - metro
 
22
  | Property | Value |
23
  |---|---|
24
  | **Category** | Object Detection (Person Detection) |
25
+ | **Base Model** | [YOLO26](https://docs.ultralytics.com/models/yolo26/) (Ultralytics, default) or [DETR](https://huggingface.co/facebook/detr-resnet-50) (Facebook, alternative) |
26
+ | **Source Framework** | PyTorch (Ultralytics, Hugging Face Transformers) |
27
  | **Supported Precisions** | FP32, FP16, INT8 (mixed-precision) |
28
  | **Inference Engine** | OpenVINO |
29
  | **Hardware** | CPU, GPU, NPU |
 
44
  - **Access Control** -- detect unauthorized presence in restricted zones.
45
  - **Public Safety** -- support situational awareness in transit hubs and venues.
46
 
47
+ Available variants: `yolo26n`, `yolo26s`, `yolo26m`, `yolo26l`.
48
  Smaller variants (`yolo26n`, `yolo26s`) are recommended for high-FPS edge deployment; larger variants improve recall in dense scenes.
49
 
50
+ ### Model Selection
51
+
52
+ [DETR](https://huggingface.co/facebook/detr-resnet-50) (DEtection TRansformer) is available as an alternative to YOLO26.
53
+ DETR is a transformer-based, NMS-free detector trained on COCO and released under the Apache-2.0 license.
54
+ 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.
55
+ The same OpenVINO and DLStreamer samples run either model; select one with the `MODEL` constant at the top of each sample.
56
+
57
+ | Model | Variants | Input Size | Output | License |
58
+ |---|---|---|---|---|
59
+ | YOLO26 (default) | `yolo26n`, `yolo26s`, `yolo26m`, `yolo26l` | 640 x 640 | `[1, 300, 6]` | AGPL-3.0 |
60
+ | DETR | `detr-resnet-50` | 800 x 800 | `[1, 100, 6]` | Apache-2.0 |
61
+
62
+ Choose YOLO26 for maximum throughput on edge devices.
63
+ Choose DETR when a permissively licensed transformer detector is preferred; it is heavier and runs at a lower frame rate.
64
+
65
  ---
66
 
67
  ## Prerequisites
68
 
69
+ 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**).
70
+ Use the [native RC1 setup](../README.md#native-rc1-runtime) before running these samples; this is a development stack, not a stable release.
71
+ See the [device validation matrix](../DEVICE_SUPPORT_MATRIX.md) for measured CPU, GPU, and NPU results.
72
+
73
  - Python 3.11+
74
  - [Install OpenVINO](https://docs.openvino.ai/2026/get-started/install-openvino.html) (latest version)
75
+ - [Install Intel DLStreamer](https://docs.openedgeplatform.intel.com/dev/edge-ai-libraries/dlstreamer/get_started/install/install_guide_ubuntu.html) (latest version)
76
 
77
  Create and activate a Python virtual environment before running the scripts:
78
 
 
100
 
101
  This exports the default **yolo26n** model in **FP16** precision.
102
 
103
+ #### Optional: Select a Different Model, Variant, or Precision
104
 
105
  ```bash
106
+ ./export_and_quantize.sh yolo26n FP32 # full-precision
107
+ ./export_and_quantize.sh yolo26n INT8 # quantized
108
+ ./export_and_quantize.sh yolo26s # larger variant, default FP16
109
+ ./export_and_quantize.sh detr-resnet-50 # DETR alternative, default FP16
110
+ ./export_and_quantize.sh detr-resnet-50 INT8 # DETR quantized
111
  ```
112
 
113
+ The first argument selects the model: any YOLO26 variant (`yolo26n`, `yolo26s`, `yolo26m`, `yolo26l`) or DETR (`detr-resnet-50`).
114
  The second argument selects the precision (`FP32`, `FP16`, `INT8`); the default is **FP16**.
115
 
116
  The script performs the following steps:
117
 
118
+ 1. Installs dependencies (`openvino`, `ultralytics` for YOLO26 or `transformers`, `torch` for DETR; adds `nncf` for INT8).
119
  2. Downloads a sample test image (`test.jpg`) and a sample test video (`test_video.mp4`).
120
  3. Downloads the PyTorch weights and exports to OpenVINO IR.
121
  4. *(INT8 only)* Quantizes the model using NNCF post-training quantization.
122
 
123
+ Output files (replace `yolo26n` with the selected model, for example `detr-resnet-50`):
124
 
125
  - `yolo26n_openvino_model/` -- FP32 or FP16 OpenVINO IR model directory.
126
  - `yolo26n_person_int8.xml` / `yolo26n_person_int8.bin` -- INT8 quantized model *(only when `INT8` is selected)*.
 
139
 
140
  ### OpenVINO Sample
141
 
142
+ The sample below runs YOLO26 or DETR inference, filters to the `person` class, and reports the person count for a single image.
143
+ Both models are end-to-end (NMS-free), so no manual non-maximum suppression is needed.
144
+ Set `MODEL` to the model exported by `export_and_quantize.sh`.
145
  Change the `device` string to run on CPU, GPU, or NPU.
146
 
147
+ The full sample is in [openvino_sample.py](openvino_sample.py); run it with `python3 openvino_sample.py` or copy the code below.
148
+
149
+ <!-- sample: openvino_sample.py -->
150
  ```python
151
+ # SPDX-License-Identifier: MIT
152
+ # Copyright (C) Intel Corporation
153
+ #
154
+ # Person detection with YOLO26 or DETR using OpenVINO Runtime.
155
+ # Run: python3 openvino_sample.py (expects test.jpg and the exported model).
156
+
157
  import cv2
158
  import numpy as np
159
  import openvino as ov
160
 
161
+ # Select the model: "yolo26n" (default) or "detr-resnet-50".
162
+ MODEL = "yolo26n"
163
+
164
  PERSON_CLASS_ID = 0
165
  CONF_THRESHOLD = 0.4
166
+ INPUT_SIZE = 800 if MODEL.startswith("detr") else 640
167
 
168
  core = ov.Core()
169
+ model = core.read_model(f"{MODEL}_openvino_model/{MODEL}.xml")
170
 
171
  # Change device to "GPU" or "NPU" to run on integrated GPU or NPU.
172
  compiled = core.compile_model(model, "CPU")
 
178
  blob = cv2.cvtColor(blob, cv2.COLOR_BGR2RGB).astype(np.float32) / 255.0
179
  blob = blob.transpose(2, 0, 1)[np.newaxis, ...] # NCHW
180
 
181
+ # End-to-end output: [1, N, 6] = [x1, y1, x2, y2, confidence, class_id]
182
+ # (N = 300 for YOLO26, 100 for DETR)
183
  output = compiled([blob])[compiled.output(0)][0]
184
  mask = (output[:, 4] >= CONF_THRESHOLD) & (output[:, 5].astype(int) == PERSON_CLASS_ID)
185
  dets = output[mask]
 
201
  )
202
  cv2.imwrite("output_openvino.jpg", image)
203
  ```
204
+ <!-- /sample -->
205
 
206
  **Device targets:**
207
 
 
229
 
230
  ### DLStreamer Sample
231
 
232
+ The pipeline below runs the FP16 YOLO26 or DETR detector (selected with `MODEL`) on the sample video via
233
  `gvadetect`, filters detections to the `person` class in a buffer probe using
234
  the GStreamer Analytics metadata API (`GstAnalytics`), overlays bounding boxes,
235
  saves the annotated result to `output_dlstreamer.mp4`, and prints the person count per
 
237
 
238
  > **Notes on running this sample:**
239
  >
240
+ > - Use the FP16 IR (`yolo26n_openvino_model/yolo26n.xml` or `detr-resnet-50_openvino_model/detr-resnet-50.xml`).
241
+ > The DETR IR carries the same `model_info` metadata as YOLO26, so `gvadetect` uses the same YOLO26 post-processor for both models.
242
+ > `gvadetect` selects the YOLO26 post-processor from the `metadata.yaml` file stored next to the model.
243
+ > To use the INT8 model, place it in a directory together with that file, for example
244
+ > `mkdir int8 && cp yolo26n_person_int8.* yolo26n_openvino_model/metadata.yaml int8/`,
245
+ > and set `model=int8/yolo26n_person_int8.xml`.
246
  > - Class names are read automatically from the model's embedded
247
  > `metadata.yaml` by DLStreamer 2026.0+ -- no external `labels-file` is
248
  > required.
 
255
  > /opt/intel/dlstreamer/gstreamer/lib/python3/dist-packages:${PYTHONPATH:-}
256
  > ```
257
 
258
+ The full sample is in [dlstreamer_sample.py](dlstreamer_sample.py); run it with `python3 dlstreamer_sample.py` or copy the code below.
259
+
260
+ <!-- sample: dlstreamer_sample.py -->
261
  ```python
262
+ # SPDX-License-Identifier: MIT
263
+ # Copyright (C) Intel Corporation
264
+ #
265
+ # Person detection with YOLO26 or DETR using a DLStreamer pipeline.
266
+ # Run: python3 dlstreamer_sample.py (expects test_video.mp4 and the exported model).
267
+
268
  import gi
269
 
270
  gi.require_version("Gst", "1.0")
 
274
  Gst.init([])
275
 
276
  INPUT_VIDEO = "test_video.mp4"
277
+ # Select the model: "yolo26n" (default) or "detr-resnet-50".
278
+ MODEL = "yolo26n"
279
 
280
  # For CPU: change device=GPU to device=CPU.
281
  # For NPU: change device=GPU to device=NPU (batch-size=1, nireq=4 recommended).
282
  pipeline_str = (
283
  f"filesrc location={INPUT_VIDEO} ! decodebin3 ! "
284
  "videoconvert ! "
285
+ f"gvadetect model={MODEL}_openvino_model/{MODEL}.xml "
286
  "device=GPU "
287
  "threshold=0.4 ! queue ! "
288
  "gvawatermark displ-cfg=show-roi=person ! "
 
324
  )
325
  pipeline.set_state(Gst.State.NULL)
326
  ```
327
+ <!-- /sample -->
328
 
329
  #### Expected Output
330
 
 
345
  ## References
346
 
347
  - [YOLO26 Documentation](https://docs.ultralytics.com/models/yolo26/)
348
+ - [DETR Model Card (facebook/detr-resnet-50)](https://huggingface.co/facebook/detr-resnet-50)
349
+ - [End-to-End Object Detection with Transformers (DETR paper)](https://arxiv.org/abs/2005.12872)
350
  - [OpenVINO YOLO26 Notebook](https://github.com/openvinotoolkit/openvino_notebooks/blob/latest/notebooks/yolov26-optimization/yolov26-object-detection.ipynb)
351
  - [COCO Dataset](https://cocodataset.org/)
352
  - [OpenVINO Documentation](https://docs.openvino.ai/)
353
  - [NNCF Post-Training Quantization](https://docs.openvino.ai/latest/nncf_ptq_introduction.html)
354
+ - [Intel DLStreamer](https://docs.openedgeplatform.intel.com/dev/edge-ai-libraries/dlstreamer/index.html)
config.json CHANGED
@@ -3,8 +3,8 @@
3
  "library_name": "openvino",
4
  "pipeline_tag": "object-detection",
5
  "category": "Object Detection (Person Detection)",
6
- "base_model": "YOLO26 (Ultralytics)",
7
- "source_framework": "PyTorch (Ultralytics)",
8
  "supported_precisions": [
9
  "FP32",
10
  "FP16",
@@ -18,5 +18,13 @@
18
  ],
19
  "detected_classes": "`person` (COCO class 0)",
20
  "hf_repo_id": "Intel/person-detection",
21
- "description": "Person detection use case using YOLO26 INT8 filtered to the person class"
 
 
 
 
 
 
 
 
22
  }
 
3
  "library_name": "openvino",
4
  "pipeline_tag": "object-detection",
5
  "category": "Object Detection (Person Detection)",
6
+ "base_model": "YOLO26 (Ultralytics, default); DETR facebook/detr-resnet-50 (alternative)",
7
+ "source_framework": "PyTorch (Ultralytics, Hugging Face Transformers)",
8
  "supported_precisions": [
9
  "FP32",
10
  "FP16",
 
18
  ],
19
  "detected_classes": "`person` (COCO class 0)",
20
  "hf_repo_id": "Intel/person-detection",
21
+ "description": "Person detection use case using YOLO26 (default) or DETR, filtered to the person class",
22
+ "selectable_models": [
23
+ "yolo26n",
24
+ "yolo26s",
25
+ "yolo26m",
26
+ "yolo26l",
27
+ "detr-resnet-50"
28
+ ],
29
+ "default_model": "yolo26n"
30
  }
dlstreamer_sample.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (C) Intel Corporation
3
+ #
4
+ # Person detection with YOLO26 or DETR using a DLStreamer pipeline.
5
+ # Run: python3 dlstreamer_sample.py (expects test_video.mp4 and the exported model).
6
+
7
+ import gi
8
+
9
+ gi.require_version("Gst", "1.0")
10
+ gi.require_version("GstAnalytics", "1.0")
11
+ from gi.repository import Gst, GLib, GstAnalytics
12
+
13
+ Gst.init([])
14
+
15
+ INPUT_VIDEO = "test_video.mp4"
16
+ # Select the model: "yolo26n" (default) or "detr-resnet-50".
17
+ MODEL = "yolo26n"
18
+
19
+ # For CPU: change device=GPU to device=CPU.
20
+ # For NPU: change device=GPU to device=NPU (batch-size=1, nireq=4 recommended).
21
+ pipeline_str = (
22
+ f"filesrc location={INPUT_VIDEO} ! decodebin3 ! "
23
+ "videoconvert ! "
24
+ f"gvadetect model={MODEL}_openvino_model/{MODEL}.xml "
25
+ "device=GPU "
26
+ "threshold=0.4 ! queue ! "
27
+ "gvawatermark displ-cfg=show-roi=person ! "
28
+ "videoconvert ! video/x-raw,format=I420 ! "
29
+ "openh264enc ! h264parse ! "
30
+ "mp4mux ! filesink name=sink location=output_dlstreamer.mp4"
31
+ )
32
+ pipeline = Gst.parse_launch(pipeline_str)
33
+
34
+
35
+ def on_buffer(pad, info):
36
+ buf = info.get_buffer()
37
+ rmeta = GstAnalytics.buffer_get_analytics_relation_meta(buf)
38
+ if rmeta is None:
39
+ return Gst.PadProbeReturn.OK
40
+ person_count = 0
41
+ idx = 1
42
+ while True:
43
+ ok, od = rmeta.get_od_mtd(idx)
44
+ if not ok:
45
+ break
46
+ if GLib.quark_to_string(od.get_obj_type()) == "person":
47
+ person_count += 1
48
+ idx += 1
49
+ if person_count:
50
+ print(f"Person count: {person_count}", flush=True)
51
+ return Gst.PadProbeReturn.OK
52
+
53
+
54
+ sink = pipeline.get_by_name("sink")
55
+ sink_pad = sink.get_static_pad("sink")
56
+ sink_pad.add_probe(Gst.PadProbeType.BUFFER, on_buffer)
57
+
58
+ pipeline.set_state(Gst.State.PLAYING)
59
+ bus = pipeline.get_bus()
60
+ bus.timed_pop_filtered(
61
+ Gst.CLOCK_TIME_NONE,
62
+ Gst.MessageType.EOS | Gst.MessageType.ERROR,
63
+ )
64
+ pipeline.set_state(Gst.State.NULL)
export_and_quantize.sh CHANGED
@@ -2,9 +2,19 @@
2
  # SPDX-License-Identifier: MIT
3
  # Copyright (C) Intel Corporation
4
  #
5
- # Export a YOLO26 person detector to OpenVINO IR.
6
  # Usage: ./export_and_quantize.sh [MODEL_VARIANT] [PRECISION]
7
  # Example: ./export_and_quantize.sh yolo26n FP16
 
 
 
 
 
 
 
 
 
 
8
  #
9
  # Supported precisions:
10
  # FP32 -- Full-precision floating-point weights
@@ -29,17 +39,25 @@ if [[ "${PRECISION}" != "FP32" && "${PRECISION}" != "FP16" && "${PRECISION}" !=
29
  exit 1
30
  fi
31
 
32
- echo "--- Installing dependencies ---"
33
- if [[ "${PRECISION}" == "INT8" ]]; then
34
- pip install -qU openvino nncf ultralytics
35
- else
36
- pip install -qU openvino ultralytics
37
- fi
 
 
 
 
 
 
 
 
38
 
39
  # Ask for approval before downloading models and sample files
40
  echo ""
41
  echo "This script will download:"
42
- echo " - YOLO26 model weights (if not cached locally)"
43
  echo " - Sample test image and video files"
44
  echo ""
45
  read -p "Continue with downloads? (yes/no): " APPROVAL
@@ -60,6 +78,16 @@ else
60
  echo "WARNING: HuggingFace tracking ping failed (offline?); continuing." >&2
61
  fi
62
  echo ""
 
 
 
 
 
 
 
 
 
 
63
 
64
  echo "--- Downloading sample test image ---"
65
  if [[ ! -f test.jpg ]]; then
@@ -86,14 +114,92 @@ else
86
  EXPORT_LABEL="FP16"
87
  fi
88
 
89
- echo "--- Exporting ${MODEL_NAME} to OpenVINO IR (${EXPORT_LABEL}) ---"
90
- python3 -c "
 
91
  from ultralytics import YOLO
92
 
93
  model = YOLO('${MODEL_NAME}.pt')
94
- model.export(format='openvino', half=${HALF_FLAG}, dynamic=False, imgsz=640)
95
  print('Export complete: ${MODEL_NAME}_openvino_model/')
96
  "
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
 
98
  if [[ "${PRECISION}" == "INT8" ]]; then
99
  echo "--- Quantizing to INT8 with NNCF ---"
@@ -108,7 +214,7 @@ model = core.read_model('${MODEL_NAME}_openvino_model/${MODEL_NAME}.xml')
108
 
109
  # Use the downloaded test image for calibration instead of random noise.
110
  img = cv2.imread('test.jpg')
111
- img = cv2.resize(img, (640, 640))
112
  img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB).astype(np.float32) / 255.0
113
  img = img.transpose(2, 0, 1)[np.newaxis, ...] # NCHW
114
 
@@ -122,6 +228,7 @@ quantized = nncf.quantize(
122
  calibration_dataset,
123
  preset=nncf.QuantizationPreset.MIXED,
124
  subset_size=300,
 
125
  )
126
 
127
  ov.save_model(quantized, '${MODEL_NAME}_person_int8.xml')
 
2
  # SPDX-License-Identifier: MIT
3
  # Copyright (C) Intel Corporation
4
  #
5
+ # Export a person detector (YOLO26 or DETR) to OpenVINO IR.
6
  # Usage: ./export_and_quantize.sh [MODEL_VARIANT] [PRECISION]
7
  # Example: ./export_and_quantize.sh yolo26n FP16
8
+ # Example: ./export_and_quantize.sh detr-resnet-50 FP16
9
+ #
10
+ # Supported model variants:
11
+ # yolo26n, yolo26s, yolo26m, yolo26l -- Ultralytics YOLO26 (default)
12
+ # detr-resnet-50 -- Facebook DETR (Hugging Face)
13
+ #
14
+ # DETR is exported end-to-end: ImageNet normalization, softmax,
15
+ # box decoding, and the COCO-91 to COCO-80 class remap are embedded in the
16
+ # graph, so the IR produces the same [1, N, 6] output layout and class ids as
17
+ # YOLO26 and runs with the same OpenVINO and DLStreamer samples.
18
  #
19
  # Supported precisions:
20
  # FP32 -- Full-precision floating-point weights
 
39
  exit 1
40
  fi
41
 
42
+ case "${MODEL_NAME}" in
43
+ yolo26n|yolo26s|yolo26m|yolo26l)
44
+ MODEL_FAMILY="yolo"
45
+ INPUT_SIZE=640
46
+ ;;
47
+ detr-resnet-50)
48
+ MODEL_FAMILY="detr"
49
+ INPUT_SIZE=800
50
+ ;;
51
+ *)
52
+ echo "ERROR: unsupported model '${MODEL_NAME}'. Choose yolo26[n|s|m|l] or detr-resnet-50." >&2
53
+ exit 1
54
+ ;;
55
+ esac
56
 
57
  # Ask for approval before downloading models and sample files
58
  echo ""
59
  echo "This script will download:"
60
+ echo " - ${MODEL_NAME} model weights (if not cached locally)"
61
  echo " - Sample test image and video files"
62
  echo ""
63
  read -p "Continue with downloads? (yes/no): " APPROVAL
 
78
  echo "WARNING: HuggingFace tracking ping failed (offline?); continuing." >&2
79
  fi
80
  echo ""
81
+ echo "--- Installing dependencies ---"
82
+ if [[ "${MODEL_FAMILY}" == "detr" ]]; then
83
+ DEPS=(openvino transformers torch pyyaml opencv-python)
84
+ else
85
+ DEPS=(openvino ultralytics)
86
+ fi
87
+ if [[ "${PRECISION}" == "INT8" ]]; then
88
+ DEPS+=(nncf)
89
+ fi
90
+ pip install -qU "${DEPS[@]}"
91
 
92
  echo "--- Downloading sample test image ---"
93
  if [[ ! -f test.jpg ]]; then
 
114
  EXPORT_LABEL="FP16"
115
  fi
116
 
117
+ if [[ "${MODEL_FAMILY}" == "yolo" ]]; then
118
+ echo "--- Exporting ${MODEL_NAME} to OpenVINO IR (${EXPORT_LABEL}) ---"
119
+ python3 -c "
120
  from ultralytics import YOLO
121
 
122
  model = YOLO('${MODEL_NAME}.pt')
123
+ model.export(format='openvino', half=${HALF_FLAG}, dynamic=False, imgsz=${INPUT_SIZE}, nms=False)
124
  print('Export complete: ${MODEL_NAME}_openvino_model/')
125
  "
126
+ else
127
+ echo "--- Exporting facebook/${MODEL_NAME} to OpenVINO IR (${EXPORT_LABEL}) ---"
128
+ python3 - "${MODEL_NAME}" "${HALF_FLAG}" "${INPUT_SIZE}" <<'PYEXPORT'
129
+ import sys
130
+ from pathlib import Path
131
+
132
+ import openvino as ov
133
+ import torch
134
+ import yaml
135
+ from transformers import DetrForObjectDetection
136
+
137
+ model_name, half_flag, size = sys.argv[1], sys.argv[2] == "True", int(sys.argv[3])
138
+ model_id = f"facebook/{model_name}"
139
+
140
+ # The "no_timm" revision uses the transformers ResNet backbone (no timm dependency).
141
+ detr = DetrForObjectDetection.from_pretrained(model_id, revision="no_timm").eval()
142
+ id2label = detr.config.id2label
143
+ # DETR predicts 91 COCO category ids (with "N/A" gaps) plus a no-object class.
144
+ # Keep the 80 real categories so class ids match YOLO26 (person = 0).
145
+ coco80 = [k for k in sorted(id2label) if id2label[k] != "N/A"]
146
+ assert len(coco80) == 80, f"unexpected label map with {len(coco80)} classes"
147
+
148
+
149
+ class DetrEndToEnd(torch.nn.Module):
150
+ """Input: RGB [0, 1] NCHW. Output: [1, 100, 6] = [x1, y1, x2, y2, conf, class_id] in input pixels."""
151
+
152
+ def __init__(self, model: torch.nn.Module) -> None:
153
+ super().__init__()
154
+ self.model = model
155
+ self.register_buffer("mean", torch.tensor([0.485, 0.456, 0.406]).view(1, 3, 1, 1))
156
+ self.register_buffer("std", torch.tensor([0.229, 0.224, 0.225]).view(1, 3, 1, 1))
157
+ self.register_buffer("coco80", torch.tensor(coco80))
158
+
159
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
160
+ out = self.model(pixel_values=(x - self.mean) / self.std, return_dict=True)
161
+ probs = out.logits.softmax(-1).index_select(-1, self.coco80)
162
+ conf, cls = probs.max(-1)
163
+ cx, cy, w, h = (out.pred_boxes * size).unbind(-1)
164
+ return torch.stack([cx - w / 2, cy - h / 2, cx + w / 2, cy + h / 2, conf, cls.float()], -1)
165
+
166
+
167
+ ov_model = ov.convert_model(
168
+ DetrEndToEnd(detr), example_input=torch.zeros(1, 3, size, size), input=[1, 3, size, size]
169
+ )
170
+ ov_model.outputs[0].get_tensor().set_names({"output0"})
171
+
172
+ names = {i: id2label[k] for i, k in enumerate(coco80)}
173
+ # DLStreamer reads preprocessing and the post-processor type from model_info.
174
+ model_info = {
175
+ "model_type": "YOLO",
176
+ "labels": " ".join(n.replace(" ", "_") for n in names.values()),
177
+ "resize_type": "standard",
178
+ "reverse_input_channels": "YES",
179
+ "scale_values": "255",
180
+ "iou_threshold": "0.7",
181
+ }
182
+ for key, value in model_info.items():
183
+ ov_model.set_rt_info(value, ["model_info", key])
184
+
185
+ out_dir = Path(f"{model_name}_openvino_model")
186
+ out_dir.mkdir(exist_ok=True)
187
+ ov.save_model(ov_model, out_dir / f"{model_name}.xml", compress_to_fp16=half_flag)
188
+ metadata = {
189
+ "description": f"{model_id} exported end-to-end with YOLO26-compatible output",
190
+ "license": "Apache-2.0",
191
+ "task": "detect",
192
+ "batch": 1,
193
+ "imgsz": [size, size],
194
+ "names": names,
195
+ "channels": 3,
196
+ "end2end": True,
197
+ }
198
+ with open(out_dir / "metadata.yaml", "w", encoding="utf-8") as f:
199
+ yaml.safe_dump(metadata, f, sort_keys=False)
200
+ print(f"Export complete: {out_dir}/")
201
+ PYEXPORT
202
+ fi
203
 
204
  if [[ "${PRECISION}" == "INT8" ]]; then
205
  echo "--- Quantizing to INT8 with NNCF ---"
 
214
 
215
  # Use the downloaded test image for calibration instead of random noise.
216
  img = cv2.imread('test.jpg')
217
+ img = cv2.resize(img, (${INPUT_SIZE}, ${INPUT_SIZE}))
218
  img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB).astype(np.float32) / 255.0
219
  img = img.transpose(2, 0, 1)[np.newaxis, ...] # NCHW
220
 
 
228
  calibration_dataset,
229
  preset=nncf.QuantizationPreset.MIXED,
230
  subset_size=300,
231
+ model_type=nncf.ModelType.TRANSFORMER if '${MODEL_FAMILY}' == 'detr' else None,
232
  )
233
 
234
  ov.save_model(quantized, '${MODEL_NAME}_person_int8.xml')
openvino_sample.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (C) Intel Corporation
3
+ #
4
+ # Person detection with YOLO26 or DETR using OpenVINO Runtime.
5
+ # Run: python3 openvino_sample.py (expects test.jpg and the exported model).
6
+
7
+ import cv2
8
+ import numpy as np
9
+ import openvino as ov
10
+
11
+ # Select the model: "yolo26n" (default) or "detr-resnet-50".
12
+ MODEL = "yolo26n"
13
+
14
+ PERSON_CLASS_ID = 0
15
+ CONF_THRESHOLD = 0.4
16
+ INPUT_SIZE = 800 if MODEL.startswith("detr") else 640
17
+
18
+ core = ov.Core()
19
+ model = core.read_model(f"{MODEL}_openvino_model/{MODEL}.xml")
20
+
21
+ # Change device to "GPU" or "NPU" to run on integrated GPU or NPU.
22
+ compiled = core.compile_model(model, "CPU")
23
+
24
+ image = cv2.imread("test.jpg")
25
+ h0, w0 = image.shape[:2]
26
+
27
+ blob = cv2.resize(image, (INPUT_SIZE, INPUT_SIZE))
28
+ blob = cv2.cvtColor(blob, cv2.COLOR_BGR2RGB).astype(np.float32) / 255.0
29
+ blob = blob.transpose(2, 0, 1)[np.newaxis, ...] # NCHW
30
+
31
+ # End-to-end output: [1, N, 6] = [x1, y1, x2, y2, confidence, class_id]
32
+ # (N = 300 for YOLO26, 100 for DETR)
33
+ output = compiled([blob])[compiled.output(0)][0]
34
+ mask = (output[:, 4] >= CONF_THRESHOLD) & (output[:, 5].astype(int) == PERSON_CLASS_ID)
35
+ dets = output[mask]
36
+
37
+ sx, sy = w0 / INPUT_SIZE, h0 / INPUT_SIZE
38
+ person_count = len(dets)
39
+ print(f"Detected persons: {person_count}")
40
+
41
+ for det in dets:
42
+ x1 = int(det[0] * sx)
43
+ y1 = int(det[1] * sy)
44
+ x2 = int(det[2] * sx)
45
+ y2 = int(det[3] * sy)
46
+ cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2)
47
+
48
+ cv2.putText(
49
+ image, f"Persons: {person_count}", (10, 30),
50
+ cv2.FONT_HERSHEY_SIMPLEX, 1.0, (0, 255, 0), 2,
51
+ )
52
+ cv2.imwrite("output_openvino.jpg", image)