Sync object-detection from metro-analytics-catalog
Browse files- LICENSE +45 -0
- README.md +272 -5
- export_and_quantize.sh +90 -0
LICENSE
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
This directory contains two categories of content under different licenses.
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
Scripts and Documentation
|
| 5 |
+
-------------------------
|
| 6 |
+
|
| 7 |
+
The scripts (export_and_quantize.sh) and documentation (README.md) in this
|
| 8 |
+
directory are original works by Intel Corporation, licensed under the
|
| 9 |
+
MIT License.
|
| 10 |
+
|
| 11 |
+
Copyright (C) Intel Corporation
|
| 12 |
+
|
| 13 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 14 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 15 |
+
in the Software without restriction, including without limitation the rights
|
| 16 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 17 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 18 |
+
furnished to do so, subject to the following conditions:
|
| 19 |
+
|
| 20 |
+
The above copyright notice and this permission notice shall be included in
|
| 21 |
+
all copies or substantial portions of the Software.
|
| 22 |
+
|
| 23 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 24 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 25 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 26 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 27 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 28 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 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,5 +1,272 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Object Detection
|
| 2 |
+
|
| 3 |
+
> **Validated with:** OpenVINO 2026.1.0, NNCF 3.0.0, DLStreamer 2026.0, Ultralytics 8.3.0, Python 3.11+
|
| 4 |
+
|
| 5 |
+
| Property | Value |
|
| 6 |
+
|---|---|
|
| 7 |
+
| **Category** | General Object Detection (80-class COCO) |
|
| 8 |
+
| **Base Model** | [YOLO26](https://docs.ultralytics.com/models/yolo26/) (Ultralytics) |
|
| 9 |
+
| **Source Framework** | PyTorch (Ultralytics) |
|
| 10 |
+
| **Supported Precisions** | FP32, FP16, FP16-INT8 |
|
| 11 |
+
| **Inference Engine** | OpenVINO |
|
| 12 |
+
| **Hardware** | CPU, GPU, NPU |
|
| 13 |
+
| **Detected Class(es)** | All 80 COCO classes |
|
| 14 |
+
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
## Overview
|
| 18 |
+
|
| 19 |
+
Object Detection is a Metro Analytics use case that detects and classifies objects across the full 80-class COCO taxonomy (person, vehicle, animal, everyday objects, etc.).
|
| 20 |
+
It is built on [YOLO26](https://docs.ultralytics.com/models/yolo26/), a state-of-the-art real-time object detector, quantized to INT8 for efficient inference on Intel hardware.
|
| 21 |
+
Unlike the specialized person or vehicle detectors, this model keeps all 80 classes active, making it suitable for general-purpose scene understanding.
|
| 22 |
+
|
| 23 |
+
Typical Metro deployments include:
|
| 24 |
+
|
| 25 |
+
- **Scene Understanding** -- identify and classify all objects visible in a camera feed.
|
| 26 |
+
- **Inventory Monitoring** -- detect specific items (bags, suitcases, bottles) on platforms.
|
| 27 |
+
- **Anomaly Detection** -- flag unexpected objects in restricted areas.
|
| 28 |
+
- **Multi-Class Analytics** -- gather statistics across people, vehicles, and other categories.
|
| 29 |
+
|
| 30 |
+
Available variants: `yolo26n`, `yolo26s`, `yolo26m`, `yolo26l`, `yolo26x`.
|
| 31 |
+
Smaller variants (`yolo26n`, `yolo26s`) are recommended for high-FPS edge deployment; larger variants improve recall for small objects.
|
| 32 |
+
|
| 33 |
+
---
|
| 34 |
+
|
| 35 |
+
## Prerequisites
|
| 36 |
+
|
| 37 |
+
- Python 3.11+
|
| 38 |
+
- [Install OpenVINO](https://docs.openvino.ai/2026/get-started/install-openvino.html) (latest version)
|
| 39 |
+
- [Install Intel DLStreamer](https://docs.openedgeplatform.intel.com/2026.0/edge-ai-libraries/dlstreamer/get_started/install/install_guide_ubuntu.html) (latest version)
|
| 40 |
+
|
| 41 |
+
Create and activate a Python virtual environment before running the scripts:
|
| 42 |
+
|
| 43 |
+
```bash
|
| 44 |
+
python3 -m venv .venv --system-site-packages
|
| 45 |
+
source .venv/bin/activate
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
---
|
| 49 |
+
|
| 50 |
+
## Getting Started
|
| 51 |
+
|
| 52 |
+
### Download and Quantize Model
|
| 53 |
+
|
| 54 |
+
Run the provided script to download, export to OpenVINO IR, and optionally quantize:
|
| 55 |
+
|
| 56 |
+
```bash
|
| 57 |
+
chmod +x export_and_quantize.sh
|
| 58 |
+
./export_and_quantize.sh yolo26n # default: FP16
|
| 59 |
+
./export_and_quantize.sh yolo26n FP32 # full-precision
|
| 60 |
+
./export_and_quantize.sh yolo26n INT8 # quantized
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
Replace `yolo26n` with any variant (`yolo26s`, `yolo26m`, `yolo26l`, `yolo26x`).
|
| 64 |
+
The second argument selects the precision (`FP32`, `FP16`, `INT8`); the default is **FP16**.
|
| 65 |
+
|
| 66 |
+
The script performs the following steps:
|
| 67 |
+
|
| 68 |
+
1. Installs dependencies (`openvino`, `ultralytics`; adds `nncf` for INT8).
|
| 69 |
+
2. Downloads a sample test image (`test.jpg`).
|
| 70 |
+
3. Downloads the PyTorch weights and exports to OpenVINO IR.
|
| 71 |
+
4. *(INT8 only)* Quantizes the model using NNCF post-training quantization.
|
| 72 |
+
|
| 73 |
+
Output files:
|
| 74 |
+
|
| 75 |
+
- `yolo26n_openvino_model/` -- FP32 or FP16 OpenVINO IR model directory.
|
| 76 |
+
- `yolo26n_objdet_int8.xml` / `yolo26n_objdet_int8.bin` -- INT8 quantized model *(only when `INT8` is selected)*.
|
| 77 |
+
|
| 78 |
+
#### Precision / Device Compatibility
|
| 79 |
+
|
| 80 |
+
| Precision | CPU | GPU | NPU |
|
| 81 |
+
|---|---|---|---|
|
| 82 |
+
| FP32 | Yes | Yes | No |
|
| 83 |
+
| FP16 | Yes | Yes | Yes |
|
| 84 |
+
| INT8 | Yes | Yes | Yes |
|
| 85 |
+
|
| 86 |
+
> **Note:** For production accuracy, replace the random calibration tensors in
|
| 87 |
+
> `export_and_quantize.sh` with a representative sample of frames from the
|
| 88 |
+
> target deployment site.
|
| 89 |
+
|
| 90 |
+
### OpenVINO Sample
|
| 91 |
+
|
| 92 |
+
The sample below runs YOLO26 inference on all 80 COCO classes and prints every detected object with its class name and confidence.
|
| 93 |
+
YOLO26 is end-to-end (NMS-free), so no manual non-maximum suppression is needed.
|
| 94 |
+
Change the `device` string to run on CPU, GPU, or NPU.
|
| 95 |
+
|
| 96 |
+
```python
|
| 97 |
+
import cv2
|
| 98 |
+
import numpy as np
|
| 99 |
+
import openvino as ov
|
| 100 |
+
|
| 101 |
+
COCO_NAMES = [
|
| 102 |
+
"person","bicycle","car","motorcycle","airplane","bus","train","truck",
|
| 103 |
+
"boat","traffic light","fire hydrant","stop sign","parking meter","bench",
|
| 104 |
+
"bird","cat","dog","horse","sheep","cow","elephant","bear","zebra",
|
| 105 |
+
"giraffe","backpack","umbrella","handbag","tie","suitcase","frisbee",
|
| 106 |
+
"skis","snowboard","sports ball","kite","baseball bat","baseball glove",
|
| 107 |
+
"skateboard","surfboard","tennis racket","bottle","wine glass","cup",
|
| 108 |
+
"fork","knife","spoon","bowl","banana","apple","sandwich","orange",
|
| 109 |
+
"broccoli","carrot","hot dog","pizza","donut","cake","chair","couch",
|
| 110 |
+
"potted plant","bed","dining table","toilet","tv","laptop","mouse",
|
| 111 |
+
"remote","keyboard","cell phone","microwave","oven","toaster","sink",
|
| 112 |
+
"refrigerator","book","clock","vase","scissors","teddy bear","hair drier",
|
| 113 |
+
"toothbrush",
|
| 114 |
+
]
|
| 115 |
+
CONF_THRESHOLD = 0.4
|
| 116 |
+
INPUT_SIZE = 640
|
| 117 |
+
|
| 118 |
+
core = ov.Core()
|
| 119 |
+
model = core.read_model("yolo26n_openvino_model/yolo26n.xml")
|
| 120 |
+
|
| 121 |
+
# Change device to "GPU" or "NPU" to run on integrated GPU or NPU.
|
| 122 |
+
compiled = core.compile_model(model, "CPU")
|
| 123 |
+
|
| 124 |
+
image = cv2.imread("test.jpg")
|
| 125 |
+
h0, w0 = image.shape[:2]
|
| 126 |
+
|
| 127 |
+
blob = cv2.resize(image, (INPUT_SIZE, INPUT_SIZE))
|
| 128 |
+
blob = cv2.cvtColor(blob, cv2.COLOR_BGR2RGB).astype(np.float32) / 255.0
|
| 129 |
+
blob = blob.transpose(2, 0, 1)[np.newaxis, ...] # NCHW
|
| 130 |
+
|
| 131 |
+
# YOLO26 end-to-end output: [1, 300, 6] = [x1, y1, x2, y2, confidence, class_id]
|
| 132 |
+
output = compiled([blob])[compiled.output(0)][0]
|
| 133 |
+
mask = output[:, 4] >= CONF_THRESHOLD
|
| 134 |
+
dets = output[mask]
|
| 135 |
+
|
| 136 |
+
sx, sy = w0 / INPUT_SIZE, h0 / INPUT_SIZE
|
| 137 |
+
print(f"Total detections: {len(dets)}")
|
| 138 |
+
|
| 139 |
+
colors = np.random.RandomState(42).randint(0, 255, (80, 3)).tolist()
|
| 140 |
+
for det in dets:
|
| 141 |
+
x1 = int(det[0] * sx)
|
| 142 |
+
y1 = int(det[1] * sy)
|
| 143 |
+
x2 = int(det[2] * sx)
|
| 144 |
+
y2 = int(det[3] * sy)
|
| 145 |
+
cid = int(det[5])
|
| 146 |
+
conf = float(det[4])
|
| 147 |
+
label = f"{COCO_NAMES[cid]} {conf:.2f}"
|
| 148 |
+
color = colors[cid]
|
| 149 |
+
cv2.rectangle(image, (x1, y1), (x2, y2), color, 2)
|
| 150 |
+
cv2.putText(image, label, (x1, y1 - 5),
|
| 151 |
+
cv2.FONT_HERSHEY_SIMPLEX, 0.6, color, 2)
|
| 152 |
+
print(f" {label} at ({x1},{y1})-({x2},{y2})")
|
| 153 |
+
|
| 154 |
+
cv2.imwrite("output.jpg", image)
|
| 155 |
+
```
|
| 156 |
+
|
| 157 |
+
**Device targets:**
|
| 158 |
+
|
| 159 |
+
- `"CPU"` -- default, works on all Intel platforms.
|
| 160 |
+
- `"GPU"` -- Intel integrated or discrete GPU.
|
| 161 |
+
- `"NPU"` -- Intel NPU (validate with `benchmark_app -d NPU`).
|
| 162 |
+
|
| 163 |
+
### Try It on a Sample Image
|
| 164 |
+
|
| 165 |
+
The `export_and_quantize.sh` script downloads `test.jpg` automatically.
|
| 166 |
+
Re-run the OpenVINO sample above.
|
| 167 |
+
The script reads `test.jpg`, prints each detected object to the console, and writes the annotated frame to `output.jpg`.
|
| 168 |
+
|
| 169 |
+
Expected console output (representative):
|
| 170 |
+
|
| 171 |
+
```text
|
| 172 |
+
Total detections: 5
|
| 173 |
+
person 0.92 at (49,396)-(236,904)
|
| 174 |
+
bus 0.92 at (0,229)-(804,744)
|
| 175 |
+
person 0.91 at (670,393)-(809,880)
|
| 176 |
+
person 0.90 at (223,403)-(345,862)
|
| 177 |
+
person 0.50 at (0,553)-(68,869)
|
| 178 |
+
```
|
| 179 |
+
|
| 180 |
+
### DLStreamer Sample
|
| 181 |
+
|
| 182 |
+
The pipeline below runs the FP16 YOLO26 detector on a single image via
|
| 183 |
+
`gvadetect`, overlays bounding boxes, and prints all detections.
|
| 184 |
+
|
| 185 |
+
> **Notes on running this sample:**
|
| 186 |
+
>
|
| 187 |
+
> - Use the FP16 IR (`yolo26n_openvino_model/yolo26n.xml`). Class names are
|
| 188 |
+
> read automatically from the model's embedded `metadata.yaml` by
|
| 189 |
+
> DLStreamer 2026.0+ -- no external `labels-file` is required.
|
| 190 |
+
> - Export `PYTHONPATH` so the DLStreamer Python module is importable:
|
| 191 |
+
>
|
| 192 |
+
> ```bash
|
| 193 |
+
> source /opt/intel/openvino_2026/setupvars.sh
|
| 194 |
+
> source /opt/intel/dlstreamer/scripts/setup_dls_env.sh
|
| 195 |
+
> export PYTHONPATH=/opt/intel/dlstreamer/python:\
|
| 196 |
+
> /opt/intel/dlstreamer/gstreamer/lib/python3/dist-packages:${PYTHONPATH:-}
|
| 197 |
+
> ```
|
| 198 |
+
|
| 199 |
+
**Image-based quick test** (uses `filesrc` with a single JPEG):
|
| 200 |
+
|
| 201 |
+
```python
|
| 202 |
+
import gi
|
| 203 |
+
|
| 204 |
+
gi.require_version("Gst", "1.0")
|
| 205 |
+
gi.require_version("GstVideo", "1.0")
|
| 206 |
+
from gi.repository import Gst
|
| 207 |
+
from gstgva import VideoFrame
|
| 208 |
+
|
| 209 |
+
Gst.init(None)
|
| 210 |
+
|
| 211 |
+
# For GPU: change device=CPU to device=GPU and add vapostproc after decodebin.
|
| 212 |
+
# For NPU: change device=CPU to device=NPU (batch-size=1 recommended).
|
| 213 |
+
pipeline_str = (
|
| 214 |
+
"filesrc location=test.jpg ! jpegdec ! videoconvert ! "
|
| 215 |
+
"video/x-raw,format=BGR ! "
|
| 216 |
+
"gvadetect model=yolo26n_openvino_model/yolo26n.xml "
|
| 217 |
+
"device=CPU threshold=0.4 ! queue ! "
|
| 218 |
+
"gvawatermark ! videoconvert ! jpegenc ! filesink name=sink location=output.jpg"
|
| 219 |
+
)
|
| 220 |
+
pipeline = Gst.parse_launch(pipeline_str)
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
def on_buffer(pad, info):
|
| 224 |
+
buf = info.get_buffer()
|
| 225 |
+
caps = pad.get_current_caps()
|
| 226 |
+
frame = VideoFrame(buf, caps=caps)
|
| 227 |
+
for region in frame.regions():
|
| 228 |
+
print(f" {region.label()} at ({region.rect().x},{region.rect().y})",
|
| 229 |
+
flush=True)
|
| 230 |
+
return Gst.PadProbeReturn.OK
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
it = pipeline.iterate_elements()
|
| 234 |
+
while True:
|
| 235 |
+
ok, elem = it.next()
|
| 236 |
+
if not ok:
|
| 237 |
+
break
|
| 238 |
+
if elem.get_factory() and elem.get_factory().get_name() == "gvawatermark":
|
| 239 |
+
pad = elem.get_static_pad("src")
|
| 240 |
+
pad.add_probe(Gst.PadProbeType.BUFFER, on_buffer)
|
| 241 |
+
break
|
| 242 |
+
|
| 243 |
+
pipeline.set_state(Gst.State.PLAYING)
|
| 244 |
+
bus = pipeline.get_bus()
|
| 245 |
+
bus.timed_pop_filtered(
|
| 246 |
+
Gst.CLOCK_TIME_NONE,
|
| 247 |
+
Gst.MessageType.EOS | Gst.MessageType.ERROR,
|
| 248 |
+
)
|
| 249 |
+
pipeline.set_state(Gst.State.NULL)
|
| 250 |
+
```
|
| 251 |
+
|
| 252 |
+
**Device targets:**
|
| 253 |
+
|
| 254 |
+
- `device=CPU` -- default in the sample code.
|
| 255 |
+
- `device=GPU` -- add `vapostproc` after `decodebin` for zero-copy color conversion.
|
| 256 |
+
- `device=NPU` -- use `batch-size=1` and `nireq=4` for best NPU utilization.
|
| 257 |
+
|
| 258 |
+
---
|
| 259 |
+
|
| 260 |
+
## License
|
| 261 |
+
|
| 262 |
+
Copyright (C) Intel Corporation. All rights reserved.
|
| 263 |
+
Licensed under the MIT License. See [LICENSE](LICENSE) for details.
|
| 264 |
+
|
| 265 |
+
## References
|
| 266 |
+
|
| 267 |
+
- [YOLO26 Documentation](https://docs.ultralytics.com/models/yolo26/)
|
| 268 |
+
- [OpenVINO YOLO26 Notebook](https://github.com/openvinotoolkit/openvino_notebooks/blob/latest/notebooks/yolov26-optimization/yolov26-object-detection.ipynb)
|
| 269 |
+
- [COCO Dataset](https://cocodataset.org/)
|
| 270 |
+
- [OpenVINO Documentation](https://docs.openvino.ai/)
|
| 271 |
+
- [NNCF Post-Training Quantization](https://docs.openvino.ai/latest/nncf_ptq_introduction.html)
|
| 272 |
+
- [Intel DLStreamer](https://docs.openedgeplatform.intel.com/2026.0/edge-ai-libraries/dlstreamer/index.html)
|
export_and_quantize.sh
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 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
|
| 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
|
| 70 |
+
|
| 71 |
+
core = ov.Core()
|
| 72 |
+
model = core.read_model('${MODEL_NAME}_openvino_model/${MODEL_NAME}.xml')
|
| 73 |
+
|
| 74 |
+
def transform_fn(data_item):
|
| 75 |
+
return np.random.rand(1, 3, 640, 640).astype(np.float32)
|
| 76 |
+
|
| 77 |
+
calibration_dataset = nncf.Dataset(list(range(300)), transform_fn)
|
| 78 |
+
|
| 79 |
+
quantized = nncf.quantize(
|
| 80 |
+
model,
|
| 81 |
+
calibration_dataset,
|
| 82 |
+
preset=nncf.QuantizationPreset.MIXED,
|
| 83 |
+
subset_size=300,
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
ov.save_model(quantized, '${MODEL_NAME}_objdet_int8.xml')
|
| 87 |
+
print('Quantization complete: ${MODEL_NAME}_objdet_int8.xml')
|
| 88 |
+
"
|
| 89 |
+
fi
|
| 90 |
+
echo "--- Done ---"
|