Sync crowd-detection from metro-analytics-catalog
Browse files- LICENSE +4 -4
- README.md +76 -84
- export_and_quantize.sh +50 -13
LICENSE
CHANGED
|
@@ -29,17 +29,17 @@ MIT License.
|
|
| 29 |
THE SOFTWARE.
|
| 30 |
|
| 31 |
|
| 32 |
-
|
| 33 |
------------
|
| 34 |
|
| 35 |
-
The
|
| 36 |
Ultralytics and licensed under the GNU Affero General Public License v3.0
|
| 37 |
(AGPL-3.0).
|
| 38 |
|
| 39 |
Source: https://github.com/ultralytics/ultralytics
|
| 40 |
License: https://github.com/ultralytics/ultralytics/blob/main/LICENSE
|
| 41 |
-
Docs: https://docs.ultralytics.com/models/
|
| 42 |
|
| 43 |
Users must comply with the AGPL-3.0 license terms when using, modifying,
|
| 44 |
-
or distributing the
|
| 45 |
For commercial licensing options, see https://www.ultralytics.com/license.
|
|
|
|
| 29 |
THE SOFTWARE.
|
| 30 |
|
| 31 |
|
| 32 |
+
YOLO26 Model
|
| 33 |
------------
|
| 34 |
|
| 35 |
+
The YOLO26 model weights and the Ultralytics framework are developed by
|
| 36 |
Ultralytics and licensed under the GNU Affero General Public License v3.0
|
| 37 |
(AGPL-3.0).
|
| 38 |
|
| 39 |
Source: https://github.com/ultralytics/ultralytics
|
| 40 |
License: https://github.com/ultralytics/ultralytics/blob/main/LICENSE
|
| 41 |
+
Docs: https://docs.ultralytics.com/models/yolo26/
|
| 42 |
|
| 43 |
Users must comply with the AGPL-3.0 license terms when using, modifying,
|
| 44 |
+
or distributing the YOLO26 model weights or Ultralytics software.
|
| 45 |
For commercial licensing options, see https://www.ultralytics.com/license.
|
README.md
CHANGED
|
@@ -1,14 +1,12 @@
|
|
| 1 |
-
# Crowd Detection
|
| 2 |
|
| 3 |
-
> **
|
| 4 |
-
>
|
| 5 |
-
> **Validated with:** OpenVINO 2026.0.0, NNCF 3.0.0, Ultralytics 8.3.0, Python 3.11+
|
| 6 |
|
| 7 |
| Property | Value |
|
| 8 |
|---|---|
|
| 9 |
| **Category** | Object Detection (Crowd / Person Counting) |
|
| 10 |
| **Source Framework** | PyTorch (Ultralytics) |
|
| 11 |
-
| **Supported Precisions** | FP16, FP16-INT8 |
|
| 12 |
| **Inference Engine** | OpenVINO |
|
| 13 |
| **Hardware** | CPU, GPU, NPU |
|
| 14 |
| **Detected Class** | `person` (COCO class 0) |
|
|
@@ -18,7 +16,7 @@
|
|
| 18 |
## Overview
|
| 19 |
|
| 20 |
Crowd Detection is a Metro Analytics use case that detects and counts people in video streams to estimate occupancy and identify crowd build-up.
|
| 21 |
-
It is built on [
|
| 22 |
Typical Metro deployments include:
|
| 23 |
|
| 24 |
- **Platform Occupancy** -- count waiting passengers on station platforms.
|
|
@@ -26,15 +24,23 @@ Typical Metro deployments include:
|
|
| 26 |
- **Crowd Build-up Alerts** -- trigger notifications when person counts cross a threshold.
|
| 27 |
- **Public Safety Analytics** -- support situational awareness in transit hubs and venues.
|
| 28 |
|
| 29 |
-
Available variants: `
|
| 30 |
-
Smaller variants (`
|
| 31 |
|
| 32 |
---
|
| 33 |
|
| 34 |
## Prerequisites
|
| 35 |
|
|
|
|
| 36 |
- [Install OpenVINO 2026.0.0](https://docs.openvino.ai/2026/get-started/install-openvino.html)
|
| 37 |
-
- [Install Intel DLStreamer](https://
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
---
|
| 40 |
|
|
@@ -42,26 +48,37 @@ Smaller variants (`yolo11n`, `yolo11s`) are recommended for high-FPS edge deploy
|
|
| 42 |
|
| 43 |
### Download and Quantize Model
|
| 44 |
|
| 45 |
-
Run the provided script to download, export to OpenVINO IR
|
| 46 |
|
| 47 |
```bash
|
| 48 |
chmod +x export_and_quantize.sh
|
| 49 |
-
./export_and_quantize.sh
|
|
|
|
|
|
|
| 50 |
```
|
| 51 |
|
| 52 |
-
Replace `
|
|
|
|
| 53 |
|
| 54 |
The script performs the following steps:
|
| 55 |
|
| 56 |
-
1. Installs dependencies (`openvino`, `
|
| 57 |
-
2. Downloads
|
| 58 |
-
3.
|
| 59 |
-
4.
|
| 60 |
|
| 61 |
Output files:
|
| 62 |
|
| 63 |
-
- `
|
| 64 |
-
- `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
> **Note:** For production accuracy, replace the random calibration tensors in
|
| 67 |
> `export_and_quantize.sh` with a representative sample of frames from the
|
|
@@ -69,7 +86,7 @@ Output files:
|
|
| 69 |
|
| 70 |
### OpenVINO Sample
|
| 71 |
|
| 72 |
-
The sample below runs
|
| 73 |
non-maximum suppression, and reports the crowd count for a single image.
|
| 74 |
|
| 75 |
```python
|
|
@@ -79,11 +96,10 @@ import openvino as ov
|
|
| 79 |
|
| 80 |
PERSON_CLASS_ID = 0
|
| 81 |
CONF_THRESHOLD = 0.4
|
| 82 |
-
IOU_THRESHOLD = 0.5
|
| 83 |
INPUT_SIZE = 640
|
| 84 |
|
| 85 |
core = ov.Core()
|
| 86 |
-
model = core.read_model("
|
| 87 |
compiled = core.compile_model(model, "CPU") # or "GPU", "NPU"
|
| 88 |
|
| 89 |
image = cv2.imread("test.jpg")
|
|
@@ -94,87 +110,60 @@ blob = cv2.resize(image, (INPUT_SIZE, INPUT_SIZE))
|
|
| 94 |
blob = cv2.cvtColor(blob, cv2.COLOR_BGR2RGB).astype(np.float32) / 255.0
|
| 95 |
blob = blob.transpose(2, 0, 1)[np.newaxis, ...] # NCHW
|
| 96 |
|
| 97 |
-
#
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
class_scores = preds[:, 4:]
|
| 103 |
-
class_ids = class_scores.argmax(axis=1)
|
| 104 |
-
confidences = class_scores.max(axis=1)
|
| 105 |
-
|
| 106 |
-
mask = (class_ids == PERSON_CLASS_ID) & (confidences >= CONF_THRESHOLD)
|
| 107 |
-
boxes_xywh = boxes_xywh[mask]
|
| 108 |
-
confidences = confidences[mask]
|
| 109 |
|
| 110 |
-
# Convert xywh (center) to xyxy in original image coordinates.
|
| 111 |
sx, sy = w0 / INPUT_SIZE, h0 / INPUT_SIZE
|
| 112 |
-
|
| 113 |
-
xyxy[:, 0] = (boxes_xywh[:, 0] - boxes_xywh[:, 2] / 2) * sx
|
| 114 |
-
xyxy[:, 1] = (boxes_xywh[:, 1] - boxes_xywh[:, 3] / 2) * sy
|
| 115 |
-
xyxy[:, 2] = (boxes_xywh[:, 0] + boxes_xywh[:, 2] / 2) * sx
|
| 116 |
-
xyxy[:, 3] = (boxes_xywh[:, 1] + boxes_xywh[:, 3] / 2) * sy
|
| 117 |
-
|
| 118 |
-
# Apply NMS to deduplicate overlapping detections.
|
| 119 |
-
keep = cv2.dnn.NMSBoxes(
|
| 120 |
-
bboxes=[[float(x1), float(y1), float(x2 - x1), float(y2 - y1)]
|
| 121 |
-
for x1, y1, x2, y2 in xyxy],
|
| 122 |
-
scores=confidences.tolist(),
|
| 123 |
-
score_threshold=CONF_THRESHOLD,
|
| 124 |
-
nms_threshold=IOU_THRESHOLD,
|
| 125 |
-
)
|
| 126 |
-
|
| 127 |
-
crowd_count = len(keep)
|
| 128 |
print(f"Detected persons: {crowd_count}")
|
| 129 |
|
| 130 |
-
for
|
| 131 |
-
x1
|
|
|
|
|
|
|
|
|
|
| 132 |
cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
| 133 |
|
| 134 |
cv2.putText(
|
| 135 |
image, f"Crowd count: {crowd_count}", (10, 30),
|
| 136 |
cv2.FONT_HERSHEY_SIMPLEX, 1.0, (0, 255, 0), 2,
|
| 137 |
)
|
| 138 |
-
cv2.imwrite("
|
| 139 |
```
|
| 140 |
|
| 141 |
### Try It on a Sample Image
|
| 142 |
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
```bash
|
| 146 |
-
wget -O test.jpg https://ultralytics.com/images/bus.jpg
|
| 147 |
-
```
|
| 148 |
-
|
| 149 |
Re-run the OpenVINO sample above.
|
| 150 |
-
The script reads `test.jpg`, prints the crowd count to the console, and writes the annotated frame to `
|
| 151 |
|
| 152 |
-
Expected console output
|
| 153 |
|
| 154 |
```text
|
| 155 |
-
Detected persons:
|
| 156 |
```
|
| 157 |
|
| 158 |
-
`
|
| 159 |
-
|
| 160 |
-
The reference image actually contains four people; the FP16 IR (`yolo11n_openvino_model/yolo11n.xml`) detects all four.
|
| 161 |
-
The INT8 model produced with random calibration data in `export_and_quantize.sh` typically detects three.
|
| 162 |
-
Replace the random calibration tensors with representative frames from your deployment site to recover the missing detection.
|
| 163 |
|
| 164 |
### DLStreamer Sample
|
| 165 |
|
| 166 |
-
The pipeline below runs the FP16
|
| 167 |
`gvadetect`, filters detections to the `person` class in a buffer probe using
|
| 168 |
the DLStreamer Python bindings (`gstgva.VideoFrame`), overlays bounding boxes,
|
| 169 |
-
and prints the
|
| 170 |
|
| 171 |
> **Notes on running this sample:**
|
| 172 |
>
|
| 173 |
-
> - Use the FP16 IR (`
|
| 174 |
> On DLStreamer 2026.0.0, `gvadetect` cannot auto-derive a YOLO post-processor
|
| 175 |
> from the INT8 model produced by the bundled script.
|
| 176 |
> To use the INT8 model, supply a matching `model-proc` JSON.
|
| 177 |
-
> -
|
|
|
|
|
|
|
| 178 |
> - Filtering with `object-class=person` directly on `gvadetect` is rejected
|
| 179 |
> when `inference-region` is `full-frame` (the default), so the sample
|
| 180 |
> filters by `region.label()` in the buffer probe instead.
|
|
@@ -186,9 +175,6 @@ and prints the per-frame crowd count.
|
|
| 186 |
> export PYTHONPATH=/opt/intel/dlstreamer/python:\
|
| 187 |
> /opt/intel/dlstreamer/gstreamer/lib/python3/dist-packages:${PYTHONPATH:-}
|
| 188 |
> ```
|
| 189 |
-
>
|
| 190 |
-
> Create `coco.txt` once with the 80 COCO class names in COCO order, one per
|
| 191 |
-
> line (see the loitering-detection README for a ready-to-paste snippet).
|
| 192 |
|
| 193 |
```python
|
| 194 |
import gi
|
|
@@ -201,14 +187,18 @@ from gstgva import VideoFrame
|
|
| 201 |
Gst.init(None)
|
| 202 |
|
| 203 |
pipeline_str = (
|
| 204 |
-
"filesrc location=
|
| 205 |
"video/x-raw,format=BGR ! "
|
| 206 |
-
"gvadetect model=
|
| 207 |
-
"
|
| 208 |
-
"gvawatermark ! videoconvert !
|
|
|
|
| 209 |
)
|
| 210 |
pipeline = Gst.parse_launch(pipeline_str)
|
| 211 |
|
|
|
|
|
|
|
|
|
|
| 212 |
|
| 213 |
def on_buffer(pad, info):
|
| 214 |
buf = info.get_buffer()
|
|
@@ -216,12 +206,10 @@ def on_buffer(pad, info):
|
|
| 216 |
frame = VideoFrame(buf, caps=caps)
|
| 217 |
crowd_count = sum(1 for r in frame.regions() if r.label() == "person")
|
| 218 |
if crowd_count:
|
| 219 |
-
print(f"Crowd count
|
| 220 |
return Gst.PadProbeReturn.OK
|
| 221 |
|
| 222 |
|
| 223 |
-
sink = pipeline.get_by_name("sink")
|
| 224 |
-
sink_pad = sink.get_static_pad("sink")
|
| 225 |
sink_pad.add_probe(Gst.PadProbeType.BUFFER, on_buffer)
|
| 226 |
|
| 227 |
pipeline.set_state(Gst.State.PLAYING)
|
|
@@ -233,6 +221,10 @@ bus.timed_pop_filtered(
|
|
| 233 |
pipeline.set_state(Gst.State.NULL)
|
| 234 |
```
|
| 235 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
---
|
| 237 |
|
| 238 |
## License
|
|
@@ -242,9 +234,9 @@ Licensed under the MIT License. See [LICENSE](LICENSE) for details.
|
|
| 242 |
|
| 243 |
## References
|
| 244 |
|
| 245 |
-
- [
|
| 246 |
-
- [OpenVINO
|
| 247 |
- [COCO Dataset](https://cocodataset.org/)
|
| 248 |
- [OpenVINO Documentation](https://docs.openvino.ai/)
|
| 249 |
- [NNCF Post-Training Quantization](https://docs.openvino.ai/latest/nncf_ptq_introduction.html)
|
| 250 |
-
- [Intel DLStreamer](https://
|
|
|
|
| 1 |
+
# Crowd Detection
|
| 2 |
|
| 3 |
+
> **Validated with:** OpenVINO 2026.0.0, NNCF 3.0.0, DLStreamer 2026.0, Ultralytics 8.3.0, Python 3.11+
|
|
|
|
|
|
|
| 4 |
|
| 5 |
| Property | Value |
|
| 6 |
|---|---|
|
| 7 |
| **Category** | Object Detection (Crowd / Person Counting) |
|
| 8 |
| **Source Framework** | PyTorch (Ultralytics) |
|
| 9 |
+
| **Supported Precisions** | FP32, FP16, FP16-INT8 |
|
| 10 |
| **Inference Engine** | OpenVINO |
|
| 11 |
| **Hardware** | CPU, GPU, NPU |
|
| 12 |
| **Detected Class** | `person` (COCO class 0) |
|
|
|
|
| 16 |
## Overview
|
| 17 |
|
| 18 |
Crowd Detection is a Metro Analytics use case that detects and counts people in video streams to estimate occupancy and identify crowd build-up.
|
| 19 |
+
It is built on [YOLO26](https://docs.ultralytics.com/models/yolo26/), a real-time object detector trained on the COCO dataset, filtered at runtime to the `person` class.
|
| 20 |
Typical Metro deployments include:
|
| 21 |
|
| 22 |
- **Platform Occupancy** -- count waiting passengers on station platforms.
|
|
|
|
| 24 |
- **Crowd Build-up Alerts** -- trigger notifications when person counts cross a threshold.
|
| 25 |
- **Public Safety Analytics** -- support situational awareness in transit hubs and venues.
|
| 26 |
|
| 27 |
+
Available variants: `yolo26n`, `yolo26s`, `yolo26m`, `yolo26l`, `yolo26x`.
|
| 28 |
+
Smaller variants (`yolo26n`, `yolo26s`) are recommended for high-FPS edge deployment; larger variants improve recall in dense crowds.
|
| 29 |
|
| 30 |
---
|
| 31 |
|
| 32 |
## Prerequisites
|
| 33 |
|
| 34 |
+
- Python 3.11+
|
| 35 |
- [Install OpenVINO 2026.0.0](https://docs.openvino.ai/2026/get-started/install-openvino.html)
|
| 36 |
+
- [Install Intel DLStreamer](https://docs.openedgeplatform.intel.com/2026.0/edge-ai-libraries/dlstreamer/get_started/install/install_guide_ubuntu.html)
|
| 37 |
+
|
| 38 |
+
Create and activate a Python virtual environment before running the scripts:
|
| 39 |
+
|
| 40 |
+
```bash
|
| 41 |
+
python3 -m venv .venv --system-site-packages
|
| 42 |
+
source .venv/bin/activate
|
| 43 |
+
```
|
| 44 |
|
| 45 |
---
|
| 46 |
|
|
|
|
| 48 |
|
| 49 |
### Download and Quantize Model
|
| 50 |
|
| 51 |
+
Run the provided script to download, export to OpenVINO IR, and optionally quantize:
|
| 52 |
|
| 53 |
```bash
|
| 54 |
chmod +x export_and_quantize.sh
|
| 55 |
+
./export_and_quantize.sh yolo26n # default: FP16
|
| 56 |
+
./export_and_quantize.sh yolo26n FP32 # full-precision
|
| 57 |
+
./export_and_quantize.sh yolo26n INT8 # quantized
|
| 58 |
```
|
| 59 |
|
| 60 |
+
Replace `yolo26n` with any variant (`yolo26s`, `yolo26m`, `yolo26l`, `yolo26x`).
|
| 61 |
+
The second argument selects the precision (`FP32`, `FP16`, `INT8`); the default is **FP16**.
|
| 62 |
|
| 63 |
The script performs the following steps:
|
| 64 |
|
| 65 |
+
1. Installs dependencies (`openvino`, `ultralytics`; adds `nncf` for INT8).
|
| 66 |
+
2. Downloads a sample test image (`test.jpg`).
|
| 67 |
+
3. Downloads the PyTorch weights and exports to OpenVINO IR.
|
| 68 |
+
4. *(INT8 only)* Quantizes the model using NNCF post-training quantization.
|
| 69 |
|
| 70 |
Output files:
|
| 71 |
|
| 72 |
+
- `yolo26n_openvino_model/` -- FP32 or FP16 OpenVINO IR model directory.
|
| 73 |
+
- `yolo26n_crowd_int8.xml` / `yolo26n_crowd_int8.bin` -- INT8 quantized model *(only when `INT8` is selected)*.
|
| 74 |
+
|
| 75 |
+
#### Precision / Device Compatibility
|
| 76 |
+
|
| 77 |
+
| Precision | CPU | GPU | NPU |
|
| 78 |
+
|---|---|---|---|
|
| 79 |
+
| FP32 | Yes | Yes | No |
|
| 80 |
+
| FP16 | Yes | Yes | Yes |
|
| 81 |
+
| INT8 | Yes | Yes | Yes |
|
| 82 |
|
| 83 |
> **Note:** For production accuracy, replace the random calibration tensors in
|
| 84 |
> `export_and_quantize.sh` with a representative sample of frames from the
|
|
|
|
| 86 |
|
| 87 |
### OpenVINO Sample
|
| 88 |
|
| 89 |
+
The sample below runs YOLO26 inference, filters to the `person` class, applies
|
| 90 |
non-maximum suppression, and reports the crowd count for a single image.
|
| 91 |
|
| 92 |
```python
|
|
|
|
| 96 |
|
| 97 |
PERSON_CLASS_ID = 0
|
| 98 |
CONF_THRESHOLD = 0.4
|
|
|
|
| 99 |
INPUT_SIZE = 640
|
| 100 |
|
| 101 |
core = ov.Core()
|
| 102 |
+
model = core.read_model("yolo26n_openvino_model/yolo26n.xml")
|
| 103 |
compiled = core.compile_model(model, "CPU") # or "GPU", "NPU"
|
| 104 |
|
| 105 |
image = cv2.imread("test.jpg")
|
|
|
|
| 110 |
blob = cv2.cvtColor(blob, cv2.COLOR_BGR2RGB).astype(np.float32) / 255.0
|
| 111 |
blob = blob.transpose(2, 0, 1)[np.newaxis, ...] # NCHW
|
| 112 |
|
| 113 |
+
# YOLO26 end-to-end output: [1, 300, 6] = [x1, y1, x2, y2, confidence, class_id]
|
| 114 |
+
# No NMS is needed -- YOLO26 is natively end-to-end.
|
| 115 |
+
output = compiled([blob])[compiled.output(0)][0]
|
| 116 |
+
mask = (output[:, 4] >= CONF_THRESHOLD) & (output[:, 5].astype(int) == PERSON_CLASS_ID)
|
| 117 |
+
dets = output[mask]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
|
|
|
| 119 |
sx, sy = w0 / INPUT_SIZE, h0 / INPUT_SIZE
|
| 120 |
+
crowd_count = len(dets)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
print(f"Detected persons: {crowd_count}")
|
| 122 |
|
| 123 |
+
for det in dets:
|
| 124 |
+
x1 = int(det[0] * sx)
|
| 125 |
+
y1 = int(det[1] * sy)
|
| 126 |
+
x2 = int(det[2] * sx)
|
| 127 |
+
y2 = int(det[3] * sy)
|
| 128 |
cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
| 129 |
|
| 130 |
cv2.putText(
|
| 131 |
image, f"Crowd count: {crowd_count}", (10, 30),
|
| 132 |
cv2.FONT_HERSHEY_SIMPLEX, 1.0, (0, 255, 0), 2,
|
| 133 |
)
|
| 134 |
+
cv2.imwrite("output.jpg", image)
|
| 135 |
```
|
| 136 |
|
| 137 |
### Try It on a Sample Image
|
| 138 |
|
| 139 |
+
The `export_and_quantize.sh` script downloads `test.jpg` automatically.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
Re-run the OpenVINO sample above.
|
| 141 |
+
The script reads `test.jpg`, prints the crowd count to the console, and writes the annotated frame to `output.jpg`.
|
| 142 |
|
| 143 |
+
Expected console output:
|
| 144 |
|
| 145 |
```text
|
| 146 |
+
Detected persons: 4
|
| 147 |
```
|
| 148 |
|
| 149 |
+
`output.jpg` is the same image with a green bounding box drawn around each detected person and the text `Crowd count: 4` overlaid in the top-left corner.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
### DLStreamer Sample
|
| 152 |
|
| 153 |
+
The pipeline below runs the FP16 YOLO26 detector on a test image via
|
| 154 |
`gvadetect`, filters detections to the `person` class in a buffer probe using
|
| 155 |
the DLStreamer Python bindings (`gstgva.VideoFrame`), overlays bounding boxes,
|
| 156 |
+
saves the annotated result to `output.jpg`, and prints the crowd count.
|
| 157 |
|
| 158 |
> **Notes on running this sample:**
|
| 159 |
>
|
| 160 |
+
> - Use the FP16 IR (`yolo26n_openvino_model/yolo26n.xml`).
|
| 161 |
> On DLStreamer 2026.0.0, `gvadetect` cannot auto-derive a YOLO post-processor
|
| 162 |
> from the INT8 model produced by the bundled script.
|
| 163 |
> To use the INT8 model, supply a matching `model-proc` JSON.
|
| 164 |
+
> - Class names are read automatically from the model's embedded
|
| 165 |
+
> `metadata.yaml` by DLStreamer 2026.0+ -- no external `labels-file` is
|
| 166 |
+
> required.
|
| 167 |
> - Filtering with `object-class=person` directly on `gvadetect` is rejected
|
| 168 |
> when `inference-region` is `full-frame` (the default), so the sample
|
| 169 |
> filters by `region.label()` in the buffer probe instead.
|
|
|
|
| 175 |
> export PYTHONPATH=/opt/intel/dlstreamer/python:\
|
| 176 |
> /opt/intel/dlstreamer/gstreamer/lib/python3/dist-packages:${PYTHONPATH:-}
|
| 177 |
> ```
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
```python
|
| 180 |
import gi
|
|
|
|
| 187 |
Gst.init(None)
|
| 188 |
|
| 189 |
pipeline_str = (
|
| 190 |
+
"filesrc location=test.jpg ! jpegdec ! videoconvert ! "
|
| 191 |
"video/x-raw,format=BGR ! "
|
| 192 |
+
"gvadetect model=yolo26n_openvino_model/yolo26n.xml "
|
| 193 |
+
"device=CPU threshold=0.4 ! queue ! "
|
| 194 |
+
"gvawatermark ! videoconvert ! jpegenc ! "
|
| 195 |
+
"filesink name=sink location=output.jpg"
|
| 196 |
)
|
| 197 |
pipeline = Gst.parse_launch(pipeline_str)
|
| 198 |
|
| 199 |
+
sink = pipeline.get_by_name("sink")
|
| 200 |
+
sink_pad = sink.get_static_pad("sink")
|
| 201 |
+
|
| 202 |
|
| 203 |
def on_buffer(pad, info):
|
| 204 |
buf = info.get_buffer()
|
|
|
|
| 206 |
frame = VideoFrame(buf, caps=caps)
|
| 207 |
crowd_count = sum(1 for r in frame.regions() if r.label() == "person")
|
| 208 |
if crowd_count:
|
| 209 |
+
print(f"Crowd count: {crowd_count}", flush=True)
|
| 210 |
return Gst.PadProbeReturn.OK
|
| 211 |
|
| 212 |
|
|
|
|
|
|
|
| 213 |
sink_pad.add_probe(Gst.PadProbeType.BUFFER, on_buffer)
|
| 214 |
|
| 215 |
pipeline.set_state(Gst.State.PLAYING)
|
|
|
|
| 221 |
pipeline.set_state(Gst.State.NULL)
|
| 222 |
```
|
| 223 |
|
| 224 |
+
To run on integrated GPU, change `device=CPU` to `device=GPU` and add
|
| 225 |
+
`vapostproc` after `jpegdec` for zero-copy color conversion.
|
| 226 |
+
For NPU, change `device=CPU` to `device=NPU`.
|
| 227 |
+
|
| 228 |
---
|
| 229 |
|
| 230 |
## License
|
|
|
|
| 234 |
|
| 235 |
## References
|
| 236 |
|
| 237 |
+
- [YOLO26 Documentation](https://docs.ultralytics.com/models/yolo26/)
|
| 238 |
+
- [OpenVINO YOLO26 Notebook](https://github.com/openvinotoolkit/openvino_notebooks/blob/latest/notebooks/yolov26-optimization/yolov26-object-detection.ipynb)
|
| 239 |
- [COCO Dataset](https://cocodataset.org/)
|
| 240 |
- [OpenVINO Documentation](https://docs.openvino.ai/)
|
| 241 |
- [NNCF Post-Training Quantization](https://docs.openvino.ai/latest/nncf_ptq_introduction.html)
|
| 242 |
+
- [Intel DLStreamer](https://docs.openedgeplatform.intel.com/2026.0/edge-ai-libraries/dlstreamer/index.html)
|
export_and_quantize.sh
CHANGED
|
@@ -2,28 +2,68 @@
|
|
| 2 |
# SPDX-License-Identifier: MIT
|
| 3 |
# Copyright (C) Intel Corporation
|
| 4 |
#
|
| 5 |
-
# Export a
|
| 6 |
-
# Usage: ./export_and_quantize.sh [MODEL_VARIANT]
|
| 7 |
-
# Example: ./export_and_quantize.sh
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
set -euo pipefail
|
| 10 |
|
| 11 |
-
MODEL_NAME="${1:-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
echo "--- Installing dependencies ---"
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
python3 -c "
|
| 18 |
from ultralytics import YOLO
|
| 19 |
|
| 20 |
model = YOLO('${MODEL_NAME}.pt')
|
| 21 |
-
model.export(format='openvino', half=
|
| 22 |
print('Export complete: ${MODEL_NAME}_openvino_model/')
|
| 23 |
"
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
|
|
|
| 27 |
import nncf
|
| 28 |
import openvino as ov
|
| 29 |
import numpy as np
|
|
@@ -46,8 +86,5 @@ quantized = nncf.quantize(
|
|
| 46 |
ov.save_model(quantized, '${MODEL_NAME}_crowd_int8.xml')
|
| 47 |
print('Quantization complete: ${MODEL_NAME}_crowd_int8.xml')
|
| 48 |
"
|
| 49 |
-
|
| 50 |
-
echo "--- Benchmarking ---"
|
| 51 |
-
benchmark_app -m "${MODEL_NAME}_crowd_int8.xml" -d CPU -niter 50 -api async
|
| 52 |
-
|
| 53 |
echo "--- Done ---"
|
|
|
|
| 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
|
| 11 |
+
# FP16 -- Half-precision floating-point weights (default)
|
| 12 |
+
# INT8 -- Quantized 8-bit integer weights (requires NNCF)
|
| 13 |
+
#
|
| 14 |
+
# Precision / device compatibility:
|
| 15 |
+
# | Precision | CPU | GPU | NPU |
|
| 16 |
+
# |-----------|-----|-----|-----|
|
| 17 |
+
# | FP32 | Yes | Yes | No |
|
| 18 |
+
# | FP16 | Yes | Yes | Yes |
|
| 19 |
+
# | INT8 | Yes | Yes | Yes |
|
| 20 |
|
| 21 |
set -euo pipefail
|
| 22 |
|
| 23 |
+
MODEL_NAME="${1:-yolo26n}"
|
| 24 |
+
PRECISION="${2:-FP16}"
|
| 25 |
+
PRECISION="$(echo "${PRECISION}" | tr '[:lower:]' '[:upper:]')"
|
| 26 |
+
|
| 27 |
+
if [[ "${PRECISION}" != "FP32" && "${PRECISION}" != "FP16" && "${PRECISION}" != "INT8" ]]; then
|
| 28 |
+
echo "ERROR: unsupported precision '${PRECISION}'. Choose FP32, FP16, or INT8." >&2
|
| 29 |
+
exit 1
|
| 30 |
+
fi
|
| 31 |
|
| 32 |
echo "--- Installing dependencies ---"
|
| 33 |
+
if [[ "${PRECISION}" == "INT8" ]]; then
|
| 34 |
+
pip install -qU "openvino>=2026.0.0" "nncf>=3.0.0" ultralytics
|
| 35 |
+
else
|
| 36 |
+
pip install -qU "openvino>=2026.0.0" ultralytics
|
| 37 |
+
fi
|
| 38 |
+
|
| 39 |
+
echo "--- Downloading sample test image ---"
|
| 40 |
+
if [[ ! -f test.jpg ]]; then
|
| 41 |
+
wget -q -O test.jpg https://ultralytics.com/images/bus.jpg
|
| 42 |
+
echo "Downloaded: test.jpg"
|
| 43 |
+
else
|
| 44 |
+
echo "Already present: test.jpg"
|
| 45 |
+
fi
|
| 46 |
|
| 47 |
+
if [[ "${PRECISION}" == "FP32" ]]; then
|
| 48 |
+
HALF_FLAG="False"
|
| 49 |
+
EXPORT_LABEL="FP32"
|
| 50 |
+
else
|
| 51 |
+
HALF_FLAG="True"
|
| 52 |
+
EXPORT_LABEL="FP16"
|
| 53 |
+
fi
|
| 54 |
+
|
| 55 |
+
echo "--- Exporting ${MODEL_NAME} to OpenVINO IR (${EXPORT_LABEL}) ---"
|
| 56 |
python3 -c "
|
| 57 |
from ultralytics import YOLO
|
| 58 |
|
| 59 |
model = YOLO('${MODEL_NAME}.pt')
|
| 60 |
+
model.export(format='openvino', half=${HALF_FLAG}, dynamic=False, imgsz=640)
|
| 61 |
print('Export complete: ${MODEL_NAME}_openvino_model/')
|
| 62 |
"
|
| 63 |
|
| 64 |
+
if [[ "${PRECISION}" == "INT8" ]]; then
|
| 65 |
+
echo "--- Quantizing to INT8 with NNCF ---"
|
| 66 |
+
python3 -c "
|
| 67 |
import nncf
|
| 68 |
import openvino as ov
|
| 69 |
import numpy as np
|
|
|
|
| 86 |
ov.save_model(quantized, '${MODEL_NAME}_crowd_int8.xml')
|
| 87 |
print('Quantization complete: ${MODEL_NAME}_crowd_int8.xml')
|
| 88 |
"
|
| 89 |
+
fi
|
|
|
|
|
|
|
|
|
|
| 90 |
echo "--- Done ---"
|