vagheshpatel commited on
Commit
4b9584f
·
verified ·
1 Parent(s): 35c04ff

Update native RC1 samples and supported device documentation

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