vagheshpatel commited on
Commit
af84571
·
verified ·
1 Parent(s): 485fb6e

Update native RC1 samples and supported device documentation

Browse files
Files changed (5) hide show
  1. README.md +67 -16
  2. config.json +11 -3
  3. dlstreamer_sample.py +68 -0
  4. export_and_quantize.sh +119 -11
  5. openvino_sample.py +81 -0
README.md CHANGED
@@ -8,6 +8,7 @@ tags:
8
  - intel
9
  - yolo
10
  - yolo26
 
11
  - delivery
12
  - package-verification
13
  - edge-ai
@@ -22,8 +23,8 @@ language:
22
  | Property | Value |
23
  |---|---|
24
  | **Category** | Object Detection (Package and Parcel Detection) |
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 |
@@ -54,18 +55,37 @@ Typical Metro deployments include:
54
  - **Package Counting** -- count parcels on a conveyor or at a drop-off zone.
55
  - **Theft Prevention** -- alert when a package disappears from a monitored area.
56
 
57
- Available variants: `yolo26n`, `yolo26s`, `yolo26m`, `yolo26l`, `yolo26x`.
58
  Smaller variants (`yolo26n`, `yolo26s`) are recommended for high-FPS edge
59
  deployment; larger variants improve recall for distant or partially occluded
60
  packages.
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  ---
63
 
64
  ## Prerequisites
65
 
 
 
 
 
66
  - Python 3.11+
67
  - [Install OpenVINO](https://docs.openvino.ai/2026/get-started/install-openvino.html) (latest version)
68
- - [Install Intel DLStreamer](https://docs.openedgeplatform.intel.com/2026.0/edge-ai-libraries/dlstreamer/get_started/install/install_guide_ubuntu.html) (latest version)
69
 
70
  Create and activate a Python virtual environment before running the scripts:
71
 
@@ -93,22 +113,25 @@ chmod +x export_and_quantize.sh
93
 
94
  This exports the default **yolo26n** model in **FP16** precision.
95
 
96
- #### Optional: Select a Different Variant or Precision
97
 
98
  ```bash
99
- ./export_and_quantize.sh yolo26n FP32 # full-precision
100
- ./export_and_quantize.sh yolo26n INT8 # quantized
101
- ./export_and_quantize.sh yolo26s # larger variant, default FP16
 
 
102
  ```
103
 
 
104
  The script performs the following steps:
105
 
106
- 1. Installs dependencies (`openvino`, `ultralytics`; adds `nncf` for INT8).
107
  2. Downloads a sample test image (`test.jpg`) and a sample test video (`test_video.mp4`).
108
  3. Downloads the PyTorch weights and exports to OpenVINO IR.
109
  4. *(INT8 only)* Quantizes the model using NNCF post-training quantization.
110
 
111
- Output files:
112
 
113
  - `yolo26n_openvino_model/` -- FP32 or FP16 OpenVINO IR model directory.
114
  - `yolo26n_package_int8.xml` / `.bin` -- INT8 quantized model *(only when `INT8` is selected)*.
@@ -132,7 +155,16 @@ inference so the input matches how DLStreamer's `gvadetect` preprocesses.
132
  YOLO26 is end-to-end (NMS-free), so no manual non-maximum suppression is needed.
133
  Change the `device` string to run on CPU, GPU, or NPU.
134
 
 
 
 
135
  ```python
 
 
 
 
 
 
136
  import cv2
137
  import numpy as np
138
  import openvino as ov
@@ -142,11 +174,13 @@ PACKAGE_CLASS_IDS = {24, 26, 28} # backpack, handbag, suitcase
142
  PACKAGE_LABEL = "package"
143
  BOX_COLOR = (0, 200, 0)
144
  CONF_THRESHOLD = 0.25
145
- INPUT_SIZE = 640
 
 
146
  INPUT_VIDEO = "test_video.mp4"
147
 
148
  core = ov.Core()
149
- model = core.read_model("yolo26n_openvino_model/yolo26n.xml")
150
 
151
  # Change device to "GPU" or "NPU" to run on integrated GPU or NPU.
152
  compiled = core.compile_model(model, "CPU")
@@ -182,7 +216,8 @@ while True:
182
  blob = cv2.cvtColor(padded, cv2.COLOR_BGR2RGB).astype(np.float32) / 255.0
183
  blob = blob.transpose(2, 0, 1)[np.newaxis, ...] # NCHW
184
 
185
- # YOLO26 end-to-end output: [1, 300, 6] = [x1, y1, x2, y2, confidence, class_id]
 
186
  output = compiled([blob])[compiled.output(0)][0]
187
  mask = (output[:, 4] >= CONF_THRESHOLD) & np.isin(
188
  output[:, 5].astype(int), list(PACKAGE_CLASS_IDS))
@@ -206,6 +241,7 @@ while True:
206
  cap.release()
207
  writer.release()
208
  ```
 
209
 
210
  **Device targets:**
211
 
@@ -226,7 +262,7 @@ The pipeline below runs the FP16 YOLO26 detector on the sample video via
226
 
227
  > **Notes on running this sample:**
228
  >
229
- > - Use the FP16 IR (`yolo26n_openvino_model/yolo26n.xml`) together with the
230
  > `coco_package_labels.txt` label map produced by `export_and_quantize.sh`.
231
  > It relabels the COCO `backpack`/`handbag`/`suitcase` classes to `package`,
232
  > so `gvadetect` emits a single `package` class and `gvawatermark` renders a
@@ -240,7 +276,16 @@ The pipeline below runs the FP16 YOLO26 detector on the sample video via
240
  > /opt/intel/dlstreamer/gstreamer/lib/python3/dist-packages:${PYTHONPATH:-}
241
  > ```
242
 
 
 
 
243
  ```python
 
 
 
 
 
 
244
  import gi
245
 
246
  gi.require_version("Gst", "1.0")
@@ -252,12 +297,15 @@ Gst.init([])
252
  INPUT_VIDEO = "test_video.mp4"
253
  PACKAGE_LABELS = {"package"}
254
 
 
 
 
255
  # For CPU: change device=GPU to device=CPU.
256
  # For NPU: change device=GPU to device=NPU (batch-size=1, nireq=4 recommended).
257
  pipeline_str = (
258
  f"filesrc location={INPUT_VIDEO} ! decodebin3 ! "
259
  "videoconvert ! "
260
- "gvadetect model=yolo26n_openvino_model/yolo26n.xml "
261
  "labels-file=coco_package_labels.txt "
262
  "device=GPU "
263
  "threshold=0.25 ! queue ! "
@@ -301,6 +349,7 @@ bus.timed_pop_filtered(
301
  )
302
  pipeline.set_state(Gst.State.NULL)
303
  ```
 
304
 
305
  **Device targets:**
306
 
@@ -321,5 +370,7 @@ Licensed under the MIT License. See [LICENSE](LICENSE) for details.
321
  ## References
322
 
323
  - [YOLO26 Documentation](https://docs.ultralytics.com/models/yolo26/)
 
 
324
  - [OpenVINO Documentation](https://docs.openvino.ai/)
325
- - [Intel DLStreamer](https://docs.openedgeplatform.intel.com/2026.0/edge-ai-libraries/dlstreamer/index.html)
 
8
  - intel
9
  - yolo
10
  - yolo26
11
+ - detr
12
  - delivery
13
  - package-verification
14
  - edge-ai
 
23
  | Property | Value |
24
  |---|---|
25
  | **Category** | Object Detection (Package and Parcel Detection) |
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 |
 
55
  - **Package Counting** -- count parcels on a conveyor or at a drop-off zone.
56
  - **Theft Prevention** -- alert when a package disappears from a monitored area.
57
 
58
+ Available variants: `yolo26n`, `yolo26s`, `yolo26m`, `yolo26l`.
59
  Smaller variants (`yolo26n`, `yolo26s`) are recommended for high-FPS edge
60
  deployment; larger variants improve recall for distant or partially occluded
61
  packages.
62
 
63
+ ### Model Selection
64
+
65
+ [DETR](https://huggingface.co/facebook/detr-resnet-50) (DEtection TRansformer) is available as an alternative to YOLO26.
66
+ DETR is a transformer-based, NMS-free detector trained on COCO and released under the Apache-2.0 license.
67
+ 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.
68
+ The same OpenVINO and DLStreamer samples run either model; select one with the `MODEL` constant at the top of each sample.
69
+
70
+ | Model | Variants | Input Size | Output | License |
71
+ |---|---|---|---|---|
72
+ | YOLO26 (default) | `yolo26n`, `yolo26s`, `yolo26m`, `yolo26l` | 640 x 640 | `[1, 300, 6]` | AGPL-3.0 |
73
+ | DETR | `detr-resnet-50` | 800 x 800 | `[1, 100, 6]` | Apache-2.0 |
74
+
75
+ Choose YOLO26 for maximum throughput on edge devices.
76
+ Choose DETR when a permissively licensed transformer detector is preferred; it is heavier and runs at a lower frame rate.
77
+
78
  ---
79
 
80
  ## Prerequisites
81
 
82
+ 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**).
83
+ Use the [native RC1 setup](../README.md#native-rc1-runtime) before running these samples; this is a development stack, not a stable release.
84
+ See the [device validation matrix](../DEVICE_SUPPORT_MATRIX.md) for measured CPU, GPU, and NPU results.
85
+
86
  - Python 3.11+
87
  - [Install OpenVINO](https://docs.openvino.ai/2026/get-started/install-openvino.html) (latest version)
88
+ - [Install Intel DLStreamer](https://docs.openedgeplatform.intel.com/dev/edge-ai-libraries/dlstreamer/get_started/install/install_guide_ubuntu.html) (latest version)
89
 
90
  Create and activate a Python virtual environment before running the scripts:
91
 
 
113
 
114
  This exports the default **yolo26n** model in **FP16** precision.
115
 
116
+ #### Optional: Select a Different Model, Variant, or Precision
117
 
118
  ```bash
119
+ ./export_and_quantize.sh yolo26n FP32 # full-precision
120
+ ./export_and_quantize.sh yolo26n INT8 # quantized
121
+ ./export_and_quantize.sh yolo26s # larger variant, default FP16
122
+ ./export_and_quantize.sh detr-resnet-50 # DETR alternative, default FP16
123
+ ./export_and_quantize.sh detr-resnet-50 INT8 # DETR quantized
124
  ```
125
 
126
+ The first argument selects the model: any YOLO26 variant (`yolo26n`, `yolo26s`, `yolo26m`, `yolo26l`) or DETR (`detr-resnet-50`).
127
  The script performs the following steps:
128
 
129
+ 1. Installs dependencies (`openvino`, `ultralytics` for YOLO26 or `transformers`, `torch` for DETR; adds `nncf` for INT8).
130
  2. Downloads a sample test image (`test.jpg`) and a sample test video (`test_video.mp4`).
131
  3. Downloads the PyTorch weights and exports to OpenVINO IR.
132
  4. *(INT8 only)* Quantizes the model using NNCF post-training quantization.
133
 
134
+ Output files (replace `yolo26n` with the selected model, for example `detr-resnet-50`):
135
 
136
  - `yolo26n_openvino_model/` -- FP32 or FP16 OpenVINO IR model directory.
137
  - `yolo26n_package_int8.xml` / `.bin` -- INT8 quantized model *(only when `INT8` is selected)*.
 
155
  YOLO26 is end-to-end (NMS-free), so no manual non-maximum suppression is needed.
156
  Change the `device` string to run on CPU, GPU, or NPU.
157
 
158
+ The full sample is in [openvino_sample.py](openvino_sample.py); run it with `python3 openvino_sample.py` or copy the code below.
159
+
160
+ <!-- sample: openvino_sample.py -->
161
  ```python
162
+ # SPDX-License-Identifier: MIT
163
+ # Copyright (C) Intel Corporation
164
+ #
165
+ # Delivery/Package Verification: OpenVINO Runtime sample.
166
+ # See README.md for prerequisites and inputs. Run: python3 openvino_sample.py
167
+
168
  import cv2
169
  import numpy as np
170
  import openvino as ov
 
174
  PACKAGE_LABEL = "package"
175
  BOX_COLOR = (0, 200, 0)
176
  CONF_THRESHOLD = 0.25
177
+ # Select the model: "yolo26n" (default) or "detr-resnet-50".
178
+ MODEL = "yolo26n"
179
+ INPUT_SIZE = 800 if MODEL.startswith("detr") else 640
180
  INPUT_VIDEO = "test_video.mp4"
181
 
182
  core = ov.Core()
183
+ model = core.read_model(f"{MODEL}_openvino_model/{MODEL}.xml")
184
 
185
  # Change device to "GPU" or "NPU" to run on integrated GPU or NPU.
186
  compiled = core.compile_model(model, "CPU")
 
216
  blob = cv2.cvtColor(padded, cv2.COLOR_BGR2RGB).astype(np.float32) / 255.0
217
  blob = blob.transpose(2, 0, 1)[np.newaxis, ...] # NCHW
218
 
219
+ # End-to-end output: [1, N, 6] = [x1, y1, x2, y2, confidence, class_id]
220
+ # (N = 300 for YOLO26, 100 for DETR)
221
  output = compiled([blob])[compiled.output(0)][0]
222
  mask = (output[:, 4] >= CONF_THRESHOLD) & np.isin(
223
  output[:, 5].astype(int), list(PACKAGE_CLASS_IDS))
 
241
  cap.release()
242
  writer.release()
243
  ```
244
+ <!-- /sample -->
245
 
246
  **Device targets:**
247
 
 
262
 
263
  > **Notes on running this sample:**
264
  >
265
+ > - Use the FP16 IR (`yolo26n_openvino_model/yolo26n.xml` or `detr-resnet-50_openvino_model/detr-resnet-50.xml`) together with the
266
  > `coco_package_labels.txt` label map produced by `export_and_quantize.sh`.
267
  > It relabels the COCO `backpack`/`handbag`/`suitcase` classes to `package`,
268
  > so `gvadetect` emits a single `package` class and `gvawatermark` renders a
 
276
  > /opt/intel/dlstreamer/gstreamer/lib/python3/dist-packages:${PYTHONPATH:-}
277
  > ```
278
 
279
+ The full sample is in [dlstreamer_sample.py](dlstreamer_sample.py); run it with `python3 dlstreamer_sample.py` or copy the code below.
280
+
281
+ <!-- sample: dlstreamer_sample.py -->
282
  ```python
283
+ # SPDX-License-Identifier: MIT
284
+ # Copyright (C) Intel Corporation
285
+ #
286
+ # Delivery/Package Verification: DLStreamer pipeline sample.
287
+ # See README.md for prerequisites and inputs. Run: python3 dlstreamer_sample.py
288
+
289
  import gi
290
 
291
  gi.require_version("Gst", "1.0")
 
297
  INPUT_VIDEO = "test_video.mp4"
298
  PACKAGE_LABELS = {"package"}
299
 
300
+ # Select the model: "yolo26n" (default) or "detr-resnet-50".
301
+ MODEL = "yolo26n"
302
+
303
  # For CPU: change device=GPU to device=CPU.
304
  # For NPU: change device=GPU to device=NPU (batch-size=1, nireq=4 recommended).
305
  pipeline_str = (
306
  f"filesrc location={INPUT_VIDEO} ! decodebin3 ! "
307
  "videoconvert ! "
308
+ f"gvadetect model={MODEL}_openvino_model/{MODEL}.xml "
309
  "labels-file=coco_package_labels.txt "
310
  "device=GPU "
311
  "threshold=0.25 ! queue ! "
 
349
  )
350
  pipeline.set_state(Gst.State.NULL)
351
  ```
352
+ <!-- /sample -->
353
 
354
  **Device targets:**
355
 
 
370
  ## References
371
 
372
  - [YOLO26 Documentation](https://docs.ultralytics.com/models/yolo26/)
373
+ - [DETR Model Card (facebook/detr-resnet-50)](https://huggingface.co/facebook/detr-resnet-50)
374
+ - [End-to-End Object Detection with Transformers (DETR paper)](https://arxiv.org/abs/2005.12872)
375
  - [OpenVINO Documentation](https://docs.openvino.ai/)
376
+ - [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 (Package and Parcel 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": "`package` (COCO `backpack`/`handbag`/`suitcase`, relabeled)",
20
  "hf_repo_id": "Intel/delivery-package-verification",
21
- "description": "Delivery/package verification use case using YOLO26 to detect packages and parcels (COCO backpack/handbag/suitcase relabeled as package)"
 
 
 
 
 
 
 
 
22
  }
 
3
  "library_name": "openvino",
4
  "pipeline_tag": "object-detection",
5
  "category": "Object Detection (Package and Parcel Detection)",
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": "`package` (COCO `backpack`/`handbag`/`suitcase`, relabeled)",
20
  "hf_repo_id": "Intel/delivery-package-verification",
21
+ "description": "Delivery/package verification use case using YOLO26 (default) or DETR to detect packages and parcels (COCO backpack/handbag/suitcase relabeled as package)",
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,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (C) Intel Corporation
3
+ #
4
+ # Delivery/Package Verification: 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
+ PACKAGE_LABELS = {"package"}
17
+
18
+ # Select the model: "yolo26n" (default) or "detr-resnet-50".
19
+ MODEL = "yolo26n"
20
+
21
+ # For CPU: change device=GPU to device=CPU.
22
+ # For NPU: change device=GPU to device=NPU (batch-size=1, nireq=4 recommended).
23
+ pipeline_str = (
24
+ f"filesrc location={INPUT_VIDEO} ! decodebin3 ! "
25
+ "videoconvert ! "
26
+ f"gvadetect model={MODEL}_openvino_model/{MODEL}.xml "
27
+ "labels-file=coco_package_labels.txt "
28
+ "device=GPU "
29
+ "threshold=0.25 ! queue ! "
30
+ "gvawatermark displ-cfg=show-roi=package ! "
31
+ "videoconvert ! video/x-raw,format=I420 ! "
32
+ "openh264enc bitrate=4000000 ! h264parse ! "
33
+ "mp4mux ! filesink name=sink location=output_dlstreamer.mp4"
34
+ )
35
+ pipeline = Gst.parse_launch(pipeline_str)
36
+
37
+
38
+ def on_buffer(pad, info):
39
+ buf = info.get_buffer()
40
+ rmeta = GstAnalytics.buffer_get_analytics_relation_meta(buf)
41
+ if rmeta is None:
42
+ return Gst.PadProbeReturn.OK
43
+ packages = []
44
+ idx = 1
45
+ while True:
46
+ ok, od = rmeta.get_od_mtd(idx)
47
+ if not ok:
48
+ break
49
+ label = GLib.quark_to_string(od.get_obj_type())
50
+ if label in PACKAGE_LABELS:
51
+ packages.append(label)
52
+ idx += 1
53
+ if packages:
54
+ print(f"Packages detected: {len(packages)} ({', '.join(packages)})",
55
+ flush=True)
56
+ return Gst.PadProbeReturn.OK
57
+
58
+
59
+ sink = pipeline.get_by_name("sink")
60
+ sink.get_static_pad("sink").add_probe(Gst.PadProbeType.BUFFER, on_buffer)
61
+
62
+ pipeline.set_state(Gst.State.PLAYING)
63
+ bus = pipeline.get_bus()
64
+ bus.timed_pop_filtered(
65
+ Gst.CLOCK_TIME_NONE,
66
+ Gst.MessageType.EOS | Gst.MessageType.ERROR,
67
+ )
68
+ pipeline.set_state(Gst.State.NULL)
export_and_quantize.sh CHANGED
@@ -2,10 +2,20 @@
2
  # SPDX-License-Identifier: MIT
3
  # Copyright (C) Intel Corporation
4
  #
5
- # Export a YOLO26 detector to OpenVINO IR for the delivery-package-verification
6
  # use case (COCO backpack/handbag/suitcase relabeled to "package" at runtime).
7
  # Usage: ./export_and_quantize.sh [MODEL_VARIANT] [PRECISION]
8
  # Example: ./export_and_quantize.sh yolo26n FP16
 
 
 
 
 
 
 
 
 
 
9
 
10
  set -euo pipefail
11
 
@@ -18,12 +28,20 @@ if [[ "${PRECISION}" != "FP32" && "${PRECISION}" != "FP16" && "${PRECISION}" !=
18
  exit 1
19
  fi
20
 
21
- echo "--- Installing dependencies ---"
22
- if [[ "${PRECISION}" == "INT8" ]]; then
23
- pip install -qU openvino nncf ultralytics
24
- else
25
- pip install -qU openvino ultralytics
26
- fi
 
 
 
 
 
 
 
 
27
 
28
  # Ask for approval before downloading models and sample files
29
  echo ""
@@ -48,6 +66,17 @@ else
48
  echo "WARNING: HuggingFace tracking ping failed (offline?); continuing." >&2
49
  fi
50
  echo ""
 
 
 
 
 
 
 
 
 
 
 
51
  echo "--- Downloading sample test image ---"
52
  if [[ ! -f test.jpg ]]; then
53
  wget -q -O test.jpg https://ultralytics.com/images/bus.jpg
@@ -73,14 +102,92 @@ else
73
  EXPORT_LABEL="FP16"
74
  fi
75
 
76
- echo "--- Exporting ${MODEL_NAME} to OpenVINO IR (${EXPORT_LABEL}) ---"
77
- python3 -c "
 
78
  from ultralytics import YOLO
79
 
80
  model = YOLO('${MODEL_NAME}.pt')
81
- model.export(format='openvino', half=${HALF_FLAG}, dynamic=False, imgsz=640)
82
  print('Export complete: ${MODEL_NAME}_openvino_model/')
83
  "
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
  echo "--- Writing package label map (relabels backpack/handbag/suitcase -> package) ---"
86
  python3 - "${MODEL_NAME}" <<'PY'
@@ -111,7 +218,7 @@ core = ov.Core()
111
  model = core.read_model('${MODEL_NAME}_openvino_model/${MODEL_NAME}.xml')
112
 
113
  img = cv2.imread('test.jpg')
114
- img = cv2.resize(img, (640, 640))
115
  img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB).astype(np.float32) / 255.0
116
  img = img.transpose(2, 0, 1)[np.newaxis, ...]
117
 
@@ -125,6 +232,7 @@ quantized = nncf.quantize(
125
  calibration_dataset,
126
  preset=nncf.QuantizationPreset.MIXED,
127
  subset_size=300,
 
128
  )
129
 
130
  ov.save_model(quantized, '${MODEL_NAME}_package_int8.xml')
 
2
  # SPDX-License-Identifier: MIT
3
  # Copyright (C) Intel Corporation
4
  #
5
+ # Export a YOLO26 or DETR detector to OpenVINO IR for the delivery-package-verification
6
  # use case (COCO backpack/handbag/suitcase relabeled to "package" at runtime).
7
  # Usage: ./export_and_quantize.sh [MODEL_VARIANT] [PRECISION]
8
  # Example: ./export_and_quantize.sh yolo26n FP16
9
+ # Example: ./export_and_quantize.sh detr-resnet-50 FP16
10
+ #
11
+ # Supported model variants:
12
+ # yolo26n, yolo26s, yolo26m, yolo26l -- Ultralytics YOLO26 (default)
13
+ # detr-resnet-50 -- Facebook DETR (Hugging Face)
14
+ #
15
+ # DETR is exported end-to-end: ImageNet normalization, softmax,
16
+ # box decoding, and the COCO-91 to COCO-80 class remap are embedded in the
17
+ # graph, so the IR produces the same [1, N, 6] output layout and class ids as
18
+ # YOLO26 and runs with the same OpenVINO and DLStreamer samples.
19
 
20
  set -euo pipefail
21
 
 
28
  exit 1
29
  fi
30
 
31
+ case "${MODEL_NAME}" in
32
+ yolo26n|yolo26s|yolo26m|yolo26l)
33
+ MODEL_FAMILY="yolo"
34
+ INPUT_SIZE=640
35
+ ;;
36
+ detr-resnet-50)
37
+ MODEL_FAMILY="detr"
38
+ INPUT_SIZE=800
39
+ ;;
40
+ *)
41
+ echo "ERROR: unsupported model '${MODEL_NAME}'. Choose yolo26[n|s|m|l] or detr-resnet-50." >&2
42
+ exit 1
43
+ ;;
44
+ esac
45
 
46
  # Ask for approval before downloading models and sample files
47
  echo ""
 
66
  echo "WARNING: HuggingFace tracking ping failed (offline?); continuing." >&2
67
  fi
68
  echo ""
69
+ echo "--- Installing dependencies ---"
70
+ if [[ "${MODEL_FAMILY}" == "detr" ]]; then
71
+ DEPS=(openvino transformers torch pyyaml opencv-python)
72
+ else
73
+ DEPS=(openvino ultralytics)
74
+ fi
75
+ if [[ "${PRECISION}" == "INT8" ]]; then
76
+ DEPS+=(nncf)
77
+ fi
78
+ pip install -qU "${DEPS[@]}"
79
+
80
  echo "--- Downloading sample test image ---"
81
  if [[ ! -f test.jpg ]]; then
82
  wget -q -O test.jpg https://ultralytics.com/images/bus.jpg
 
102
  EXPORT_LABEL="FP16"
103
  fi
104
 
105
+ if [[ "${MODEL_FAMILY}" == "yolo" ]]; then
106
+ echo "--- Exporting ${MODEL_NAME} to OpenVINO IR (${EXPORT_LABEL}) ---"
107
+ python3 -c "
108
  from ultralytics import YOLO
109
 
110
  model = YOLO('${MODEL_NAME}.pt')
111
+ model.export(format='openvino', half=${HALF_FLAG}, dynamic=False, imgsz=${INPUT_SIZE}, nms=False)
112
  print('Export complete: ${MODEL_NAME}_openvino_model/')
113
  "
114
+ else
115
+ echo "--- Exporting facebook/${MODEL_NAME} to OpenVINO IR (${EXPORT_LABEL}) ---"
116
+ python3 - "${MODEL_NAME}" "${HALF_FLAG}" "${INPUT_SIZE}" <<'PYEXPORT'
117
+ import sys
118
+ from pathlib import Path
119
+
120
+ import openvino as ov
121
+ import torch
122
+ import yaml
123
+ from transformers import DetrForObjectDetection
124
+
125
+ model_name, half_flag, size = sys.argv[1], sys.argv[2] == "True", int(sys.argv[3])
126
+ model_id = f"facebook/{model_name}"
127
+
128
+ # The "no_timm" revision uses the transformers ResNet backbone (no timm dependency).
129
+ detr = DetrForObjectDetection.from_pretrained(model_id, revision="no_timm").eval()
130
+ id2label = detr.config.id2label
131
+ # DETR predicts 91 COCO category ids (with "N/A" gaps) plus a no-object class.
132
+ # Keep the 80 real categories so class ids match YOLO26 (person = 0).
133
+ coco80 = [k for k in sorted(id2label) if id2label[k] != "N/A"]
134
+ assert len(coco80) == 80, f"unexpected label map with {len(coco80)} classes"
135
+
136
+
137
+ class DetrEndToEnd(torch.nn.Module):
138
+ """Input: RGB [0, 1] NCHW. Output: [1, 100, 6] = [x1, y1, x2, y2, conf, class_id] in input pixels."""
139
+
140
+ def __init__(self, model: torch.nn.Module) -> None:
141
+ super().__init__()
142
+ self.model = model
143
+ self.register_buffer("mean", torch.tensor([0.485, 0.456, 0.406]).view(1, 3, 1, 1))
144
+ self.register_buffer("std", torch.tensor([0.229, 0.224, 0.225]).view(1, 3, 1, 1))
145
+ self.register_buffer("coco80", torch.tensor(coco80))
146
+
147
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
148
+ out = self.model(pixel_values=(x - self.mean) / self.std, return_dict=True)
149
+ probs = out.logits.softmax(-1).index_select(-1, self.coco80)
150
+ conf, cls = probs.max(-1)
151
+ cx, cy, w, h = (out.pred_boxes * size).unbind(-1)
152
+ return torch.stack([cx - w / 2, cy - h / 2, cx + w / 2, cy + h / 2, conf, cls.float()], -1)
153
+
154
+
155
+ ov_model = ov.convert_model(
156
+ DetrEndToEnd(detr), example_input=torch.zeros(1, 3, size, size), input=[1, 3, size, size]
157
+ )
158
+ ov_model.outputs[0].get_tensor().set_names({"output0"})
159
+
160
+ names = {i: id2label[k] for i, k in enumerate(coco80)}
161
+ # DLStreamer reads preprocessing and the post-processor type from model_info.
162
+ model_info = {
163
+ "model_type": "YOLO",
164
+ "labels": " ".join(n.replace(" ", "_") for n in names.values()),
165
+ "resize_type": "standard",
166
+ "reverse_input_channels": "YES",
167
+ "scale_values": "255",
168
+ "iou_threshold": "0.7",
169
+ }
170
+ for key, value in model_info.items():
171
+ ov_model.set_rt_info(value, ["model_info", key])
172
+
173
+ out_dir = Path(f"{model_name}_openvino_model")
174
+ out_dir.mkdir(exist_ok=True)
175
+ ov.save_model(ov_model, out_dir / f"{model_name}.xml", compress_to_fp16=half_flag)
176
+ metadata = {
177
+ "description": f"{model_id} exported end-to-end with YOLO26-compatible output",
178
+ "license": "Apache-2.0",
179
+ "task": "detect",
180
+ "batch": 1,
181
+ "imgsz": [size, size],
182
+ "names": names,
183
+ "channels": 3,
184
+ "end2end": True,
185
+ }
186
+ with open(out_dir / "metadata.yaml", "w", encoding="utf-8") as f:
187
+ yaml.safe_dump(metadata, f, sort_keys=False)
188
+ print(f"Export complete: {out_dir}/")
189
+ PYEXPORT
190
+ fi
191
 
192
  echo "--- Writing package label map (relabels backpack/handbag/suitcase -> package) ---"
193
  python3 - "${MODEL_NAME}" <<'PY'
 
218
  model = core.read_model('${MODEL_NAME}_openvino_model/${MODEL_NAME}.xml')
219
 
220
  img = cv2.imread('test.jpg')
221
+ img = cv2.resize(img, (${INPUT_SIZE}, ${INPUT_SIZE}))
222
  img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB).astype(np.float32) / 255.0
223
  img = img.transpose(2, 0, 1)[np.newaxis, ...]
224
 
 
232
  calibration_dataset,
233
  preset=nncf.QuantizationPreset.MIXED,
234
  subset_size=300,
235
+ model_type=nncf.ModelType.TRANSFORMER if '${MODEL_FAMILY}' == 'detr' else None,
236
  )
237
 
238
  ov.save_model(quantized, '${MODEL_NAME}_package_int8.xml')
openvino_sample.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (C) Intel Corporation
3
+ #
4
+ # Delivery/Package Verification: 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
+ # COCO classes used as delivery-package proxies; all shown as "package".
12
+ PACKAGE_CLASS_IDS = {24, 26, 28} # backpack, handbag, suitcase
13
+ PACKAGE_LABEL = "package"
14
+ BOX_COLOR = (0, 200, 0)
15
+ CONF_THRESHOLD = 0.25
16
+ # Select the model: "yolo26n" (default) or "detr-resnet-50".
17
+ MODEL = "yolo26n"
18
+ INPUT_SIZE = 800 if MODEL.startswith("detr") else 640
19
+ INPUT_VIDEO = "test_video.mp4"
20
+
21
+ core = ov.Core()
22
+ model = core.read_model(f"{MODEL}_openvino_model/{MODEL}.xml")
23
+
24
+ # Change device to "GPU" or "NPU" to run on integrated GPU or NPU.
25
+ compiled = core.compile_model(model, "CPU")
26
+
27
+
28
+ def letterbox(image, size=INPUT_SIZE):
29
+ """Resize keeping aspect ratio and pad to a square (matches gvadetect)."""
30
+ h, w = image.shape[:2]
31
+ ratio = min(size / h, size / w)
32
+ nw, nh = int(round(w * ratio)), int(round(h * ratio))
33
+ resized = cv2.resize(image, (nw, nh))
34
+ canvas = np.full((size, size, 3), 114, dtype=np.uint8)
35
+ pad_x, pad_y = (size - nw) // 2, (size - nh) // 2
36
+ canvas[pad_y:pad_y + nh, pad_x:pad_x + nw] = resized
37
+ return canvas, ratio, pad_x, pad_y
38
+
39
+
40
+ cap = cv2.VideoCapture(INPUT_VIDEO)
41
+ fps = cap.get(cv2.CAP_PROP_FPS) or 30.0
42
+ width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
43
+ height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
44
+ writer = cv2.VideoWriter(
45
+ "output_openvino.mp4", cv2.VideoWriter_fourcc(*"mp4v"), fps, (width, height))
46
+
47
+ frame_idx = 0
48
+ while True:
49
+ ok, frame = cap.read()
50
+ if not ok:
51
+ break
52
+ frame_idx += 1
53
+
54
+ padded, ratio, pad_x, pad_y = letterbox(frame, INPUT_SIZE)
55
+ blob = cv2.cvtColor(padded, cv2.COLOR_BGR2RGB).astype(np.float32) / 255.0
56
+ blob = blob.transpose(2, 0, 1)[np.newaxis, ...] # NCHW
57
+
58
+ # End-to-end output: [1, N, 6] = [x1, y1, x2, y2, confidence, class_id]
59
+ # (N = 300 for YOLO26, 100 for DETR)
60
+ output = compiled([blob])[compiled.output(0)][0]
61
+ mask = (output[:, 4] >= CONF_THRESHOLD) & np.isin(
62
+ output[:, 5].astype(int), list(PACKAGE_CLASS_IDS))
63
+ dets = output[mask]
64
+
65
+ for det in dets:
66
+ # Undo the letterbox padding and scaling to map boxes back to the frame.
67
+ x1 = int((det[0] - pad_x) / ratio)
68
+ y1 = int((det[1] - pad_y) / ratio)
69
+ x2 = int((det[2] - pad_x) / ratio)
70
+ y2 = int((det[3] - pad_y) / ratio)
71
+ conf = float(det[4])
72
+ label = f"{PACKAGE_LABEL} {conf:.2f}"
73
+ cv2.rectangle(frame, (x1, y1), (x2, y2), BOX_COLOR, 2)
74
+ cv2.putText(frame, label, (x1, y1 - 5),
75
+ cv2.FONT_HERSHEY_SIMPLEX, 0.6, BOX_COLOR, 2)
76
+
77
+ writer.write(frame)
78
+ print(f"Frame {frame_idx}: Packages detected: {len(dets)}", flush=True)
79
+
80
+ cap.release()
81
+ writer.release()