vagheshpatel commited on
Commit
04359c8
·
verified ·
1 Parent(s): b9ab682

Update native RC1 samples and supported device documentation

Browse files
Files changed (5) hide show
  1. README.md +72 -20
  2. config.json +11 -3
  3. dlstreamer_sample.py +66 -0
  4. export_and_quantize.sh +119 -12
  5. openvino_sample.py +51 -0
README.md CHANGED
@@ -8,6 +8,7 @@ tags:
8
  - intel
9
  - yolo
10
  - yolo26
 
11
  - crowd-detection
12
  - person-counting
13
  - edge-ai
@@ -22,8 +23,8 @@ language:
22
  | Property | Value |
23
  |---|---|
24
  | **Category** | Object Detection (Crowd / Person Counting) |
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 |
@@ -42,16 +43,35 @@ Typical Metro deployments include:
42
  - **Crowd Build-up Alerts** -- trigger notifications when person counts cross a threshold.
43
  - **Public Safety Analytics** -- support situational awareness in transit hubs and venues.
44
 
45
- Available variants: `yolo26n`, `yolo26s`, `yolo26m`, `yolo26l`, `yolo26x`.
46
  Smaller variants (`yolo26n`, `yolo26s`) are recommended for high-FPS edge deployment; larger variants improve recall in dense crowds.
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  ---
49
 
50
  ## Prerequisites
51
 
 
 
 
 
52
  - Python 3.11+
53
  - [Install OpenVINO](https://docs.openvino.ai/2026/get-started/install-openvino.html) (latest version)
54
- - [Install Intel DLStreamer](https://docs.openedgeplatform.intel.com/2026.0/edge-ai-libraries/dlstreamer/get_started/install/install_guide_ubuntu.html)
55
 
56
  Create and activate a Python virtual environment before running the scripts:
57
 
@@ -79,25 +99,27 @@ chmod +x export_and_quantize.sh
79
 
80
  This exports the default **yolo26n** model in **FP16** precision.
81
 
82
- #### Optional: Select a Different Variant or Precision
83
 
84
  ```bash
85
- ./export_and_quantize.sh yolo26n FP32 # full-precision
86
- ./export_and_quantize.sh yolo26n INT8 # quantized
87
- ./export_and_quantize.sh yolo26s # larger variant, default FP16
 
 
88
  ```
89
 
90
- Replace `yolo26n` with any variant (`yolo26s`, `yolo26m`, `yolo26l`, `yolo26x`).
91
  The second argument selects the precision (`FP32`, `FP16`, `INT8`); the default is **FP16**.
92
 
93
  The script performs the following steps:
94
 
95
- 1. Installs dependencies (`openvino`, `ultralytics`; adds `nncf` for INT8).
96
  2. Downloads a sample test image (`test.jpg`) and a sample test video (`test_video.mp4`).
97
  3. Downloads the PyTorch weights and exports to OpenVINO IR.
98
  4. *(INT8 only)* Quantizes the model using NNCF post-training quantization.
99
 
100
- Output files:
101
 
102
  - `yolo26n_openvino_model/` -- FP32 or FP16 OpenVINO IR model directory.
103
  - `yolo26n_crowd_int8.xml` / `yolo26n_crowd_int8.bin` -- INT8 quantized model *(only when `INT8` is selected)*.
@@ -119,17 +141,28 @@ Output files:
119
  The sample below runs YOLO26 inference, filters to the `person` class, and
120
  reports the crowd count for a single image.
121
 
 
 
 
122
  ```python
 
 
 
 
 
 
123
  import cv2
124
  import numpy as np
125
  import openvino as ov
126
 
127
  PERSON_CLASS_ID = 0
128
  CONF_THRESHOLD = 0.4
129
- INPUT_SIZE = 640
 
 
130
 
131
  core = ov.Core()
132
- model = core.read_model("yolo26n_openvino_model/yolo26n.xml")
133
  compiled = core.compile_model(model, "CPU") # or "GPU", "NPU"
134
 
135
  image = cv2.imread("test.jpg")
@@ -140,7 +173,8 @@ blob = cv2.resize(image, (INPUT_SIZE, INPUT_SIZE))
140
  blob = cv2.cvtColor(blob, cv2.COLOR_BGR2RGB).astype(np.float32) / 255.0
141
  blob = blob.transpose(2, 0, 1)[np.newaxis, ...] # NCHW
142
 
143
- # YOLO26 end-to-end output: [1, 300, 6] = [x1, y1, x2, y2, confidence, class_id]
 
144
  # No NMS is needed -- YOLO26 is natively end-to-end.
145
  output = compiled([blob])[compiled.output(0)][0]
146
  mask = (output[:, 4] >= CONF_THRESHOLD) & (output[:, 5].astype(int) == PERSON_CLASS_ID)
@@ -163,6 +197,7 @@ cv2.putText(
163
  )
164
  cv2.imwrite("output_openvino.jpg", image)
165
  ```
 
166
 
167
  ### Try It on a Sample Image
168
 
@@ -195,10 +230,12 @@ frame.
195
 
196
  > **Notes on running this sample:**
197
  >
198
- > - Use the FP16 IR (`yolo26n_openvino_model/yolo26n.xml`).
199
- > On DLStreamer 2026.0.0, `gvadetect` cannot auto-derive a YOLO post-processor
200
- > from the INT8 model produced by the bundled script.
201
- > To use the INT8 model, supply a matching `model-proc` JSON.
 
 
202
  > - Class names are read automatically from the model's embedded
203
  > `metadata.yaml` by DLStreamer 2026.0+ -- no external `labels-file` is
204
  > required.
@@ -214,7 +251,16 @@ frame.
214
  > /opt/intel/dlstreamer/gstreamer/lib/python3/dist-packages:${PYTHONPATH:-}
215
  > ```
216
 
 
 
 
217
  ```python
 
 
 
 
 
 
218
  import gi
219
 
220
  gi.require_version("Gst", "1.0")
@@ -225,12 +271,15 @@ Gst.init([])
225
 
226
  INPUT_VIDEO = "test_video.mp4"
227
 
 
 
 
228
  # For CPU: change device=GPU to device=CPU.
229
  # For NPU: change device=GPU to device=NPU (batch-size=1, nireq=4 recommended).
230
  pipeline_str = (
231
  f"filesrc location={INPUT_VIDEO} ! decodebin3 ! "
232
  "videoconvert ! "
233
- "gvadetect model=yolo26n_openvino_model/yolo26n.xml "
234
  "device=GPU "
235
  "threshold=0.4 ! queue ! "
236
  "gvawatermark displ-cfg=show-roi=person ! "
@@ -273,6 +322,7 @@ bus.timed_pop_filtered(
273
  )
274
  pipeline.set_state(Gst.State.NULL)
275
  ```
 
276
 
277
  #### Expected Output
278
 
@@ -293,8 +343,10 @@ Licensed under the MIT License. See [LICENSE](LICENSE) for details.
293
  ## References
294
 
295
  - [YOLO26 Documentation](https://docs.ultralytics.com/models/yolo26/)
 
 
296
  - [OpenVINO YOLO26 Notebook](https://github.com/openvinotoolkit/openvino_notebooks/blob/latest/notebooks/yolov26-optimization/yolov26-object-detection.ipynb)
297
  - [COCO Dataset](https://cocodataset.org/)
298
  - [OpenVINO Documentation](https://docs.openvino.ai/)
299
  - [NNCF Post-Training Quantization](https://docs.openvino.ai/latest/nncf_ptq_introduction.html)
300
- - [Intel DLStreamer](https://docs.openedgeplatform.intel.com/2026.0/edge-ai-libraries/dlstreamer/index.html)
 
8
  - intel
9
  - yolo
10
  - yolo26
11
+ - detr
12
  - crowd-detection
13
  - person-counting
14
  - edge-ai
 
23
  | Property | Value |
24
  |---|---|
25
  | **Category** | Object Detection (Crowd / Person Counting) |
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 |
 
43
  - **Crowd Build-up Alerts** -- trigger notifications when person counts cross a threshold.
44
  - **Public Safety Analytics** -- support situational awareness in transit hubs and venues.
45
 
46
+ Available variants: `yolo26n`, `yolo26s`, `yolo26m`, `yolo26l`.
47
  Smaller variants (`yolo26n`, `yolo26s`) are recommended for high-FPS edge deployment; larger variants improve recall in dense crowds.
48
 
49
+ ### Model Selection
50
+
51
+ [DETR](https://huggingface.co/facebook/detr-resnet-50) (DEtection TRansformer) is available as an alternative to YOLO26.
52
+ DETR is a transformer-based, NMS-free detector trained on COCO and released under the Apache-2.0 license.
53
+ 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.
54
+ The same OpenVINO and DLStreamer samples run either model; select one with the `MODEL` constant at the top of each sample.
55
+
56
+ | Model | Variants | Input Size | Output | License |
57
+ |---|---|---|---|---|
58
+ | YOLO26 (default) | `yolo26n`, `yolo26s`, `yolo26m`, `yolo26l` | 640 x 640 | `[1, 300, 6]` | AGPL-3.0 |
59
+ | DETR | `detr-resnet-50` | 800 x 800 | `[1, 100, 6]` | Apache-2.0 |
60
+
61
+ Choose YOLO26 for maximum throughput on edge devices.
62
+ Choose DETR when a permissively licensed transformer detector is preferred; it is heavier and runs at a lower frame rate.
63
+
64
  ---
65
 
66
  ## Prerequisites
67
 
68
+ 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**).
69
+ Use the [native RC1 setup](../README.md#native-rc1-runtime) before running these samples; this is a development stack, not a stable release.
70
+ See the [device validation matrix](../DEVICE_SUPPORT_MATRIX.md) for measured CPU, GPU, and NPU results.
71
+
72
  - Python 3.11+
73
  - [Install OpenVINO](https://docs.openvino.ai/2026/get-started/install-openvino.html) (latest version)
74
+ - [Install Intel DLStreamer](https://docs.openedgeplatform.intel.com/dev/edge-ai-libraries/dlstreamer/get_started/install/install_guide_ubuntu.html)
75
 
76
  Create and activate a Python virtual environment before running the scripts:
77
 
 
99
 
100
  This exports the default **yolo26n** model in **FP16** precision.
101
 
102
+ #### Optional: Select a Different Model, Variant, or Precision
103
 
104
  ```bash
105
+ ./export_and_quantize.sh yolo26n FP32 # full-precision
106
+ ./export_and_quantize.sh yolo26n INT8 # quantized
107
+ ./export_and_quantize.sh yolo26s # larger variant, default FP16
108
+ ./export_and_quantize.sh detr-resnet-50 # DETR alternative, default FP16
109
+ ./export_and_quantize.sh detr-resnet-50 INT8 # DETR quantized
110
  ```
111
 
112
+ The first argument selects the model: any YOLO26 variant (`yolo26n`, `yolo26s`, `yolo26m`, `yolo26l`) or DETR (`detr-resnet-50`).
113
  The second argument selects the precision (`FP32`, `FP16`, `INT8`); the default is **FP16**.
114
 
115
  The script performs the following steps:
116
 
117
+ 1. Installs dependencies (`openvino`, `ultralytics` for YOLO26 or `transformers`, `torch` for DETR; adds `nncf` for INT8).
118
  2. Downloads a sample test image (`test.jpg`) and a sample test video (`test_video.mp4`).
119
  3. Downloads the PyTorch weights and exports to OpenVINO IR.
120
  4. *(INT8 only)* Quantizes the model using NNCF post-training quantization.
121
 
122
+ Output files (replace `yolo26n` with the selected model, for example `detr-resnet-50`):
123
 
124
  - `yolo26n_openvino_model/` -- FP32 or FP16 OpenVINO IR model directory.
125
  - `yolo26n_crowd_int8.xml` / `yolo26n_crowd_int8.bin` -- INT8 quantized model *(only when `INT8` is selected)*.
 
141
  The sample below runs YOLO26 inference, filters to the `person` class, and
142
  reports the crowd count for a single image.
143
 
144
+ The full sample is in [openvino_sample.py](openvino_sample.py); run it with `python3 openvino_sample.py` or copy the code below.
145
+
146
+ <!-- sample: openvino_sample.py -->
147
  ```python
148
+ # SPDX-License-Identifier: MIT
149
+ # Copyright (C) Intel Corporation
150
+ #
151
+ # Crowd Detection: OpenVINO Runtime sample.
152
+ # See README.md for prerequisites and inputs. Run: python3 openvino_sample.py
153
+
154
  import cv2
155
  import numpy as np
156
  import openvino as ov
157
 
158
  PERSON_CLASS_ID = 0
159
  CONF_THRESHOLD = 0.4
160
+ # Select the model: "yolo26n" (default) or "detr-resnet-50".
161
+ MODEL = "yolo26n"
162
+ INPUT_SIZE = 800 if MODEL.startswith("detr") else 640
163
 
164
  core = ov.Core()
165
+ model = core.read_model(f"{MODEL}_openvino_model/{MODEL}.xml")
166
  compiled = core.compile_model(model, "CPU") # or "GPU", "NPU"
167
 
168
  image = cv2.imread("test.jpg")
 
173
  blob = cv2.cvtColor(blob, cv2.COLOR_BGR2RGB).astype(np.float32) / 255.0
174
  blob = blob.transpose(2, 0, 1)[np.newaxis, ...] # NCHW
175
 
176
+ # End-to-end output: [1, N, 6] = [x1, y1, x2, y2, confidence, class_id]
177
+ # (N = 300 for YOLO26, 100 for DETR)
178
  # No NMS is needed -- YOLO26 is natively end-to-end.
179
  output = compiled([blob])[compiled.output(0)][0]
180
  mask = (output[:, 4] >= CONF_THRESHOLD) & (output[:, 5].astype(int) == PERSON_CLASS_ID)
 
197
  )
198
  cv2.imwrite("output_openvino.jpg", image)
199
  ```
200
+ <!-- /sample -->
201
 
202
  ### Try It on a Sample Image
203
 
 
230
 
231
  > **Notes on running this sample:**
232
  >
233
+ > - Use the FP16 IR (`yolo26n_openvino_model/yolo26n.xml` or `detr-resnet-50_openvino_model/detr-resnet-50.xml`).
234
+ > The DETR IR carries the same `model_info` metadata as YOLO26, so `gvadetect` uses the same YOLO26 post-processor for both models.
235
+ > `gvadetect` selects the YOLO26 post-processor from the `metadata.yaml` file stored next to the model.
236
+ > To use the INT8 model, place it in a directory together with that file, for example
237
+ > `mkdir int8 && cp yolo26n_crowd_int8.* yolo26n_openvino_model/metadata.yaml int8/`,
238
+ > and set `model=int8/yolo26n_crowd_int8.xml`.
239
  > - Class names are read automatically from the model's embedded
240
  > `metadata.yaml` by DLStreamer 2026.0+ -- no external `labels-file` is
241
  > required.
 
251
  > /opt/intel/dlstreamer/gstreamer/lib/python3/dist-packages:${PYTHONPATH:-}
252
  > ```
253
 
254
+ The full sample is in [dlstreamer_sample.py](dlstreamer_sample.py); run it with `python3 dlstreamer_sample.py` or copy the code below.
255
+
256
+ <!-- sample: dlstreamer_sample.py -->
257
  ```python
258
+ # SPDX-License-Identifier: MIT
259
+ # Copyright (C) Intel Corporation
260
+ #
261
+ # Crowd Detection: DLStreamer pipeline sample.
262
+ # See README.md for prerequisites and inputs. Run: python3 dlstreamer_sample.py
263
+
264
  import gi
265
 
266
  gi.require_version("Gst", "1.0")
 
271
 
272
  INPUT_VIDEO = "test_video.mp4"
273
 
274
+ # Select the model: "yolo26n" (default) or "detr-resnet-50".
275
+ MODEL = "yolo26n"
276
+
277
  # For CPU: change device=GPU to device=CPU.
278
  # For NPU: change device=GPU to device=NPU (batch-size=1, nireq=4 recommended).
279
  pipeline_str = (
280
  f"filesrc location={INPUT_VIDEO} ! decodebin3 ! "
281
  "videoconvert ! "
282
+ f"gvadetect model={MODEL}_openvino_model/{MODEL}.xml "
283
  "device=GPU "
284
  "threshold=0.4 ! queue ! "
285
  "gvawatermark displ-cfg=show-roi=person ! "
 
322
  )
323
  pipeline.set_state(Gst.State.NULL)
324
  ```
325
+ <!-- /sample -->
326
 
327
  #### Expected Output
328
 
 
343
  ## References
344
 
345
  - [YOLO26 Documentation](https://docs.ultralytics.com/models/yolo26/)
346
+ - [DETR Model Card (facebook/detr-resnet-50)](https://huggingface.co/facebook/detr-resnet-50)
347
+ - [End-to-End Object Detection with Transformers (DETR paper)](https://arxiv.org/abs/2005.12872)
348
  - [OpenVINO YOLO26 Notebook](https://github.com/openvinotoolkit/openvino_notebooks/blob/latest/notebooks/yolov26-optimization/yolov26-object-detection.ipynb)
349
  - [COCO Dataset](https://cocodataset.org/)
350
  - [OpenVINO Documentation](https://docs.openvino.ai/)
351
  - [NNCF Post-Training Quantization](https://docs.openvino.ai/latest/nncf_ptq_introduction.html)
352
+ - [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 (Crowd / Person Counting)",
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/crowd-detection",
21
- "description": "Crowd detection use case using YOLO26 for person counting"
 
 
 
 
 
 
 
 
22
  }
 
3
  "library_name": "openvino",
4
  "pipeline_tag": "object-detection",
5
  "category": "Object Detection (Crowd / Person Counting)",
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": "`person` (COCO class 0)",
20
  "hf_repo_id": "Intel/crowd-detection",
21
+ "description": "Crowd detection use case using YOLO26 (default) or DETR for person counting",
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,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (C) Intel Corporation
3
+ #
4
+ # Crowd 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 displ-cfg=show-roi=person ! "
29
+ "videoconvert ! video/x-raw,format=I420 ! "
30
+ "openh264enc ! h264parse ! "
31
+ "mp4mux ! filesink name=sink location=output_dlstreamer.mp4"
32
+ )
33
+ pipeline = Gst.parse_launch(pipeline_str)
34
+
35
+ sink = pipeline.get_by_name("sink")
36
+ sink_pad = sink.get_static_pad("sink")
37
+
38
+
39
+ def on_buffer(pad, info):
40
+ buf = info.get_buffer()
41
+ rmeta = GstAnalytics.buffer_get_analytics_relation_meta(buf)
42
+ if rmeta is None:
43
+ return Gst.PadProbeReturn.OK
44
+ crowd_count = 0
45
+ idx = 1
46
+ while True:
47
+ ok, od = rmeta.get_od_mtd(idx)
48
+ if not ok:
49
+ break
50
+ if GLib.quark_to_string(od.get_obj_type()) == "person":
51
+ crowd_count += 1
52
+ idx += 1
53
+ if crowd_count:
54
+ print(f"Crowd count: {crowd_count}", flush=True)
55
+ return Gst.PadProbeReturn.OK
56
+
57
+
58
+ sink_pad.add_probe(Gst.PadProbeType.BUFFER, on_buffer)
59
+
60
+ pipeline.set_state(Gst.State.PLAYING)
61
+ bus = pipeline.get_bus()
62
+ bus.timed_pop_filtered(
63
+ Gst.CLOCK_TIME_NONE,
64
+ Gst.MessageType.EOS | Gst.MessageType.ERROR,
65
+ )
66
+ 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 for crowd detection 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}_crowd_int8.xml')
 
2
  # SPDX-License-Identifier: MIT
3
  # Copyright (C) Intel Corporation
4
  #
5
+ # Export a YOLO26 or DETR person detector for crowd detection 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}_crowd_int8.xml')
openvino_sample.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (C) Intel Corporation
3
+ #
4
+ # Crowd 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
+ PERSON_CLASS_ID = 0
12
+ CONF_THRESHOLD = 0.4
13
+ # Select the model: "yolo26n" (default) or "detr-resnet-50".
14
+ MODEL = "yolo26n"
15
+ INPUT_SIZE = 800 if MODEL.startswith("detr") else 640
16
+
17
+ core = ov.Core()
18
+ model = core.read_model(f"{MODEL}_openvino_model/{MODEL}.xml")
19
+ compiled = core.compile_model(model, "CPU") # or "GPU", "NPU"
20
+
21
+ image = cv2.imread("test.jpg")
22
+ h0, w0 = image.shape[:2]
23
+
24
+ # Preprocess: letterbox-free resize for simplicity.
25
+ blob = cv2.resize(image, (INPUT_SIZE, INPUT_SIZE))
26
+ blob = cv2.cvtColor(blob, cv2.COLOR_BGR2RGB).astype(np.float32) / 255.0
27
+ blob = blob.transpose(2, 0, 1)[np.newaxis, ...] # NCHW
28
+
29
+ # End-to-end output: [1, N, 6] = [x1, y1, x2, y2, confidence, class_id]
30
+ # (N = 300 for YOLO26, 100 for DETR)
31
+ # No NMS is needed -- YOLO26 is natively end-to-end.
32
+ output = compiled([blob])[compiled.output(0)][0]
33
+ mask = (output[:, 4] >= CONF_THRESHOLD) & (output[:, 5].astype(int) == PERSON_CLASS_ID)
34
+ dets = output[mask]
35
+
36
+ sx, sy = w0 / INPUT_SIZE, h0 / INPUT_SIZE
37
+ crowd_count = len(dets)
38
+ print(f"Detected persons: {crowd_count}")
39
+
40
+ for det in dets:
41
+ x1 = int(det[0] * sx)
42
+ y1 = int(det[1] * sy)
43
+ x2 = int(det[2] * sx)
44
+ y2 = int(det[3] * sy)
45
+ cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2)
46
+
47
+ cv2.putText(
48
+ image, f"Crowd count: {crowd_count}", (10, 30),
49
+ cv2.FONT_HERSHEY_SIMPLEX, 1.0, (0, 255, 0), 2,
50
+ )
51
+ cv2.imwrite("output_openvino.jpg", image)