vagheshpatel commited on
Commit
a8485ae
·
verified ·
1 Parent(s): de0acd1

Sync delivery-package-verification from metro-analytics-catalog

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ expected_output_dlstreamer.gif filter=lfs diff=lfs merge=lfs -text
37
+ expected_output_openvino.gif filter=lfs diff=lfs merge=lfs -text
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) Intel Corporation.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
README.md ADDED
@@ -0,0 +1,325 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ license_link: LICENSE
4
+ library_name: openvino
5
+ pipeline_tag: object-detection
6
+ tags:
7
+ - openvino
8
+ - intel
9
+ - yolo
10
+ - yolo26
11
+ - delivery
12
+ - package-verification
13
+ - edge-ai
14
+ - metro
15
+ - dlstreamer
16
+ language:
17
+ - en
18
+ ---
19
+
20
+ # Delivery/Package Verification
21
+
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 |
30
+ | **Detected Class(es)** | `package` (COCO `backpack`/`handbag`/`suitcase`, relabeled) |
31
+
32
+ ---
33
+
34
+ ## Overview
35
+
36
+ Delivery/Package Verification is a Metro Analytics use case that detects and
37
+ counts delivery parcels, bags, and luggage items in camera feeds.
38
+ It is built on [YOLO26](https://docs.ultralytics.com/models/yolo26/), a
39
+ state-of-the-art real-time object detector trained on the COCO dataset,
40
+ quantized to INT8 and filtered at runtime to the COCO classes that best match
41
+ delivery parcels -- `backpack`, `handbag`, and `suitcase` -- which are all
42
+ relabeled to a single `package` class in the output.
43
+
44
+ These COCO classes provide reliable coverage for typical delivery and package
45
+ verification scenarios (for example a courier carrying a cardboard box) without
46
+ requiring a custom-trained model.
47
+ For label or text reading on packages, pair this with the
48
+ [ocr-text-recognition](../ocr-text-recognition/) use case.
49
+
50
+ Typical Metro deployments include:
51
+
52
+ - **Delivery Dock Monitoring** -- verify parcels placed or removed at a loading area.
53
+ - **Abandoned Luggage Detection** -- flag unattended bags on platforms.
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
+
72
+ ```bash
73
+ python3 -m venv .venv --system-site-packages
74
+ source .venv/bin/activate
75
+ ```
76
+
77
+ > **Note:** The `--system-site-packages` flag is required so the virtual
78
+ > environment can access the system-installed OpenVINO and DLStreamer Python
79
+ > packages.
80
+
81
+ ---
82
+
83
+ ## Getting Started
84
+
85
+ ### Download and Quantize Model
86
+
87
+ Run the provided script to download, export to OpenVINO IR, and optionally quantize:
88
+
89
+ ```bash
90
+ chmod +x export_and_quantize.sh
91
+ ./export_and_quantize.sh
92
+ ```
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)*.
115
+
116
+ #### Precision / Device Compatibility
117
+
118
+ | Precision | CPU | GPU | NPU |
119
+ |---|---|---|---|
120
+ | FP32 | Yes | Yes | No |
121
+ | FP16 | Yes | Yes | Yes |
122
+ | INT8 | Yes | Yes | Yes |
123
+
124
+ ### OpenVINO Sample
125
+
126
+ The sample below runs YOLO26 inference on the sample video, filters detections
127
+ to the delivery-package classes (COCO `backpack`, `handbag`, `suitcase`, all
128
+ shown as `package`), annotates each frame, and writes the result to
129
+ `output_openvino.mp4` while printing the package count per frame.
130
+ Frames are letterboxed (aspect-ratio-preserving resize with padding) before
131
+ 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
139
+
140
+ # COCO classes used as delivery-package proxies; all shown as "package".
141
+ 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")
153
+
154
+
155
+ def letterbox(image, size=INPUT_SIZE):
156
+ """Resize keeping aspect ratio and pad to a square (matches gvadetect)."""
157
+ h, w = image.shape[:2]
158
+ ratio = min(size / h, size / w)
159
+ nw, nh = int(round(w * ratio)), int(round(h * ratio))
160
+ resized = cv2.resize(image, (nw, nh))
161
+ canvas = np.full((size, size, 3), 114, dtype=np.uint8)
162
+ pad_x, pad_y = (size - nw) // 2, (size - nh) // 2
163
+ canvas[pad_y:pad_y + nh, pad_x:pad_x + nw] = resized
164
+ return canvas, ratio, pad_x, pad_y
165
+
166
+
167
+ cap = cv2.VideoCapture(INPUT_VIDEO)
168
+ fps = cap.get(cv2.CAP_PROP_FPS) or 30.0
169
+ width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
170
+ height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
171
+ writer = cv2.VideoWriter(
172
+ "output_openvino.mp4", cv2.VideoWriter_fourcc(*"mp4v"), fps, (width, height))
173
+
174
+ frame_idx = 0
175
+ while True:
176
+ ok, frame = cap.read()
177
+ if not ok:
178
+ break
179
+ frame_idx += 1
180
+
181
+ padded, ratio, pad_x, pad_y = letterbox(frame, INPUT_SIZE)
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))
189
+ dets = output[mask]
190
+
191
+ for det in dets:
192
+ # Undo the letterbox padding and scaling to map boxes back to the frame.
193
+ x1 = int((det[0] - pad_x) / ratio)
194
+ y1 = int((det[1] - pad_y) / ratio)
195
+ x2 = int((det[2] - pad_x) / ratio)
196
+ y2 = int((det[3] - pad_y) / ratio)
197
+ conf = float(det[4])
198
+ label = f"{PACKAGE_LABEL} {conf:.2f}"
199
+ cv2.rectangle(frame, (x1, y1), (x2, y2), BOX_COLOR, 2)
200
+ cv2.putText(frame, label, (x1, y1 - 5),
201
+ cv2.FONT_HERSHEY_SIMPLEX, 0.6, BOX_COLOR, 2)
202
+
203
+ writer.write(frame)
204
+ print(f"Frame {frame_idx}: Packages detected: {len(dets)}", flush=True)
205
+
206
+ cap.release()
207
+ writer.release()
208
+ ```
209
+
210
+ **Device targets:**
211
+
212
+ - `"CPU"` -- default, works on all Intel platforms.
213
+ - `"GPU"` -- Intel integrated or discrete GPU.
214
+ - `"NPU"` -- Intel NPU (validate with `benchmark_app -d NPU`).
215
+
216
+ #### Expected Output
217
+
218
+ ![OpenVINO expected output](expected_output_openvino.gif)
219
+
220
+ ### DLStreamer Sample
221
+
222
+ The pipeline below runs the FP16 YOLO26 detector on the sample video via
223
+ `gvadetect`, renders only package bounding boxes using `gvawatermark` with
224
+ `displ-cfg=show-roi=package`, saves the annotated result to
225
+ `output_dlstreamer.mp4`, and prints the package count per frame.
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
233
+ > `package` label.
234
+ > - Export `PYTHONPATH` so the DLStreamer Python module is importable:
235
+ >
236
+ > ```bash
237
+ > source /opt/intel/openvino_2026/setupvars.sh
238
+ > source /opt/intel/dlstreamer/scripts/setup_dls_env.sh
239
+ > export PYTHONPATH=/opt/intel/dlstreamer/python:\
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")
247
+ gi.require_version("GstAnalytics", "1.0")
248
+ from gi.repository import Gst, GLib, GstAnalytics
249
+
250
+ Gst.init([])
251
+
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 ! "
264
+ "gvawatermark displ-cfg=show-roi=package ! "
265
+ "videoconvert ! video/x-raw,format=I420 ! "
266
+ "openh264enc bitrate=4000000 ! h264parse ! "
267
+ "mp4mux ! filesink name=sink location=output_dlstreamer.mp4"
268
+ )
269
+ pipeline = Gst.parse_launch(pipeline_str)
270
+
271
+
272
+ def on_buffer(pad, info):
273
+ buf = info.get_buffer()
274
+ rmeta = GstAnalytics.buffer_get_analytics_relation_meta(buf)
275
+ if rmeta is None:
276
+ return Gst.PadProbeReturn.OK
277
+ packages = []
278
+ idx = 1
279
+ while True:
280
+ ok, od = rmeta.get_od_mtd(idx)
281
+ if not ok:
282
+ break
283
+ label = GLib.quark_to_string(od.get_obj_type())
284
+ if label in PACKAGE_LABELS:
285
+ packages.append(label)
286
+ idx += 1
287
+ if packages:
288
+ print(f"Packages detected: {len(packages)} ({', '.join(packages)})",
289
+ flush=True)
290
+ return Gst.PadProbeReturn.OK
291
+
292
+
293
+ sink = pipeline.get_by_name("sink")
294
+ sink.get_static_pad("sink").add_probe(Gst.PadProbeType.BUFFER, on_buffer)
295
+
296
+ pipeline.set_state(Gst.State.PLAYING)
297
+ bus = pipeline.get_bus()
298
+ bus.timed_pop_filtered(
299
+ Gst.CLOCK_TIME_NONE,
300
+ Gst.MessageType.EOS | Gst.MessageType.ERROR,
301
+ )
302
+ pipeline.set_state(Gst.State.NULL)
303
+ ```
304
+
305
+ **Device targets:**
306
+
307
+ - `device=GPU` -- default in the sample code.
308
+ - `device=CPU` -- change `device=GPU` to `device=CPU`.
309
+ - `device=NPU` -- change `device=GPU` to `device=NPU`; use `batch-size=1` and `nireq=4` for best NPU utilization.
310
+
311
+ #### Expected Output
312
+
313
+ ![DLStreamer expected output](expected_output_dlstreamer.gif)
314
+
315
+ ---
316
+
317
+ ## License
318
+
319
+ Licensed under the MIT License. See [LICENSE](LICENSE) for details.
320
+
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)
expected_output_dlstreamer.gif ADDED

Git LFS Details

  • SHA256: 94070d26dee6a42e4fead1d99021a074df492fbe2bb0246f16c31f7c5f9aad42
  • Pointer size: 133 Bytes
  • Size of remote file: 10.6 MB
expected_output_openvino.gif ADDED

Git LFS Details

  • SHA256: 9ac3da48fefe3b09cddba53ea51843689dac1a99ae0d97ba8e6352fd39ab0e57
  • Pointer size: 133 Bytes
  • Size of remote file: 15.4 MB
export_and_quantize.sh ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
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
+
12
+ MODEL_NAME="${1:-yolo26n}"
13
+ PRECISION="${2:-FP16}"
14
+ PRECISION="$(echo "${PRECISION}" | tr '[:lower:]' '[:upper:]')"
15
+
16
+ if [[ "${PRECISION}" != "FP32" && "${PRECISION}" != "FP16" && "${PRECISION}" != "INT8" ]]; then
17
+ echo "ERROR: unsupported precision '${PRECISION}'. Choose FP32, FP16, or INT8." >&2
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 ""
30
+ echo "This script will download:"
31
+ echo " - Model weights and/or sample files"
32
+ echo ""
33
+ read -p "Continue with downloads? (yes/no): " APPROVAL
34
+ if [[ "${APPROVAL}" != "yes" ]]; then
35
+ echo "Download cancelled by user."
36
+ exit 0
37
+ fi
38
+ echo ""
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
+ echo ""
47
+ echo "--- Downloading sample test video ---"
48
+ if [[ ! -f test_video.mp4 ]]; then
49
+ wget -q -O test_video.mp4 \
50
+ "https://www.pexels.com/download/video/6170052/?fps=25&w=540&h=960"
51
+ echo "Downloaded: test_video.mp4"
52
+ else
53
+ echo "Already present: test_video.mp4"
54
+ fi
55
+
56
+ if [[ "${PRECISION}" == "FP32" ]]; then
57
+ HALF_FLAG="False"
58
+ EXPORT_LABEL="FP32"
59
+ else
60
+ HALF_FLAG="True"
61
+ EXPORT_LABEL="FP16"
62
+ fi
63
+
64
+ echo "--- Exporting ${MODEL_NAME} to OpenVINO IR (${EXPORT_LABEL}) ---"
65
+ python3 -c "
66
+ from ultralytics import YOLO
67
+
68
+ model = YOLO('${MODEL_NAME}.pt')
69
+ model.export(format='openvino', half=${HALF_FLAG}, dynamic=False, imgsz=640)
70
+ print('Export complete: ${MODEL_NAME}_openvino_model/')
71
+ "
72
+
73
+ echo "--- Writing package label map (relabels backpack/handbag/suitcase -> package) ---"
74
+ python3 - "${MODEL_NAME}" <<'PY'
75
+ import sys
76
+ import yaml
77
+
78
+ name = sys.argv[1]
79
+ with open(f"{name}_openvino_model/metadata.yaml") as f:
80
+ meta = yaml.safe_load(f)
81
+ names = meta["names"]
82
+ labels = [names[i] for i in range(len(names))]
83
+ for i in (24, 26, 28): # backpack, handbag, suitcase -> package
84
+ labels[i] = "package"
85
+ with open("coco_package_labels.txt", "w") as f:
86
+ f.write("\n".join(labels) + "\n")
87
+ print(f"Wrote coco_package_labels.txt ({len(labels)} labels)")
88
+ PY
89
+
90
+ if [[ "${PRECISION}" == "INT8" ]]; then
91
+ echo "--- Quantizing to INT8 with NNCF ---"
92
+ python3 -c "
93
+ import nncf
94
+ import openvino as ov
95
+ import numpy as np
96
+ import cv2
97
+
98
+ core = ov.Core()
99
+ model = core.read_model('${MODEL_NAME}_openvino_model/${MODEL_NAME}.xml')
100
+
101
+ img = cv2.imread('test.jpg')
102
+ img = cv2.resize(img, (640, 640))
103
+ img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB).astype(np.float32) / 255.0
104
+ img = img.transpose(2, 0, 1)[np.newaxis, ...]
105
+
106
+ def transform_fn(data_item):
107
+ return img
108
+
109
+ calibration_dataset = nncf.Dataset(list(range(300)), transform_fn)
110
+
111
+ quantized = nncf.quantize(
112
+ model,
113
+ calibration_dataset,
114
+ preset=nncf.QuantizationPreset.MIXED,
115
+ subset_size=300,
116
+ )
117
+
118
+ ov.save_model(quantized, '${MODEL_NAME}_package_int8.xml')
119
+ print('Quantization complete: ${MODEL_NAME}_package_int8.xml')
120
+ "
121
+ fi
122
+ echo "--- Done ---"