Sync vehicle-detection from metro-analytics-catalog
Browse files- README.md +48 -20
- expected_output_dlstreamer.gif +3 -0
- expected_output_openvino.jpg +3 -0
- export_and_quantize.sh +9 -0
README.md
CHANGED
|
@@ -1,6 +1,25 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |
| Property | Value |
|
| 6 |
|---|---|
|
|
@@ -78,7 +97,7 @@ The second argument selects the precision (`FP32`, `FP16`, `INT8`); the default
|
|
| 78 |
The script performs the following steps:
|
| 79 |
|
| 80 |
1. Installs dependencies (`openvino`, `ultralytics`; adds `nncf` for INT8).
|
| 81 |
-
2. Downloads a sample test image (`test.jpg`).
|
| 82 |
3. Downloads the PyTorch weights and exports to OpenVINO IR.
|
| 83 |
4. *(INT8 only)* Quantizes the model using NNCF post-training quantization.
|
| 84 |
|
|
@@ -154,7 +173,7 @@ for det in dets:
|
|
| 154 |
cv2.FONT_HERSHEY_SIMPLEX, 0.6, color, 2)
|
| 155 |
print(f" {label} at ({x1},{y1})-({x2},{y2})")
|
| 156 |
|
| 157 |
-
cv2.imwrite("
|
| 158 |
```
|
| 159 |
|
| 160 |
**Device targets:**
|
|
@@ -167,7 +186,7 @@ cv2.imwrite("output.jpg", image)
|
|
| 167 |
|
| 168 |
The `export_and_quantize.sh` script downloads `test.jpg` automatically.
|
| 169 |
Re-run the OpenVINO sample above.
|
| 170 |
-
The script reads `test.jpg`, prints each detected vehicle to the console, and writes the annotated frame to `
|
| 171 |
|
| 172 |
Expected console output:
|
| 173 |
|
|
@@ -176,12 +195,17 @@ Detected vehicles: 1
|
|
| 176 |
bus 0.92 at (0,229)-(804,744)
|
| 177 |
```
|
| 178 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
### DLStreamer Sample
|
| 180 |
|
| 181 |
-
The pipeline below runs the FP16 YOLO26 detector on
|
| 182 |
`gvadetect`, filters detections to vehicle classes in a buffer probe using
|
| 183 |
the DLStreamer Python bindings (`gstgva.VideoFrame`), overlays bounding boxes,
|
| 184 |
-
and prints the vehicle count
|
|
|
|
| 185 |
|
| 186 |
> **Notes on running this sample:**
|
| 187 |
>
|
|
@@ -197,8 +221,6 @@ and prints the vehicle count.
|
|
| 197 |
> /opt/intel/dlstreamer/gstreamer/lib/python3/dist-packages:${PYTHONPATH:-}
|
| 198 |
> ```
|
| 199 |
|
| 200 |
-
**Image-based quick test** (uses `filesrc` with a single JPEG):
|
| 201 |
-
|
| 202 |
```python
|
| 203 |
import gi
|
| 204 |
|
|
@@ -209,18 +231,20 @@ from gstgva import VideoFrame
|
|
| 209 |
|
| 210 |
Gst.init(None)
|
| 211 |
|
|
|
|
| 212 |
VEHICLE_LABELS = {"car", "motorcycle", "bus", "truck"}
|
| 213 |
|
| 214 |
-
# For
|
| 215 |
-
#
|
| 216 |
-
# pre-process-backend=vaapi-surface-sharing on gvadetect.
|
| 217 |
-
# For NPU: change device=CPU to device=NPU (batch-size=1 recommended).
|
| 218 |
pipeline_str = (
|
| 219 |
-
"filesrc location=
|
| 220 |
-
"
|
| 221 |
"gvadetect model=yolo26n_openvino_model/yolo26n.xml "
|
| 222 |
-
"device=
|
| 223 |
-
"
|
|
|
|
|
|
|
|
|
|
| 224 |
)
|
| 225 |
pipeline = Gst.parse_launch(pipeline_str)
|
| 226 |
|
|
@@ -250,11 +274,15 @@ bus.timed_pop_filtered(
|
|
| 250 |
pipeline.set_state(Gst.State.NULL)
|
| 251 |
```
|
| 252 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
**Device targets:**
|
| 254 |
|
| 255 |
-
- `device=
|
| 256 |
-
- `device=
|
| 257 |
-
- `device=NPU` -- use `batch-size=1` and `nireq=4` for best NPU utilization.
|
| 258 |
|
| 259 |
---
|
| 260 |
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
license_name: intel-custom
|
| 4 |
+
license_link: LICENSE
|
| 5 |
+
library_name: openvino
|
| 6 |
+
pipeline_tag: object-detection
|
| 7 |
+
tags:
|
| 8 |
+
- openvino
|
| 9 |
+
- intel
|
| 10 |
+
- yolo
|
| 11 |
+
- yolo26
|
| 12 |
+
- vehicle-detection
|
| 13 |
+
- edge-ai
|
| 14 |
+
- metro
|
| 15 |
+
- dlstreamer
|
| 16 |
+
datasets:
|
| 17 |
+
- detection-datasets/coco
|
| 18 |
+
language:
|
| 19 |
+
- en
|
| 20 |
+
---
|
| 21 |
|
| 22 |
+
# Vehicle Detection
|
| 23 |
|
| 24 |
| Property | Value |
|
| 25 |
|---|---|
|
|
|
|
| 97 |
The script performs the following steps:
|
| 98 |
|
| 99 |
1. Installs dependencies (`openvino`, `ultralytics`; adds `nncf` for INT8).
|
| 100 |
+
2. Downloads a sample test image (`test.jpg`) and a sample test video (`test_video.mp4`).
|
| 101 |
3. Downloads the PyTorch weights and exports to OpenVINO IR.
|
| 102 |
4. *(INT8 only)* Quantizes the model using NNCF post-training quantization.
|
| 103 |
|
|
|
|
| 173 |
cv2.FONT_HERSHEY_SIMPLEX, 0.6, color, 2)
|
| 174 |
print(f" {label} at ({x1},{y1})-({x2},{y2})")
|
| 175 |
|
| 176 |
+
cv2.imwrite("output_openvino.jpg", image)
|
| 177 |
```
|
| 178 |
|
| 179 |
**Device targets:**
|
|
|
|
| 186 |
|
| 187 |
The `export_and_quantize.sh` script downloads `test.jpg` automatically.
|
| 188 |
Re-run the OpenVINO sample above.
|
| 189 |
+
The script reads `test.jpg`, prints each detected vehicle to the console, and writes the annotated frame to `output_openvino.jpg`.
|
| 190 |
|
| 191 |
Expected console output:
|
| 192 |
|
|
|
|
| 195 |
bus 0.92 at (0,229)-(804,744)
|
| 196 |
```
|
| 197 |
|
| 198 |
+
#### Expected Output
|
| 199 |
+
|
| 200 |
+

|
| 201 |
+
|
| 202 |
### DLStreamer Sample
|
| 203 |
|
| 204 |
+
The pipeline below runs the FP16 YOLO26 detector on the sample video via
|
| 205 |
`gvadetect`, filters detections to vehicle classes in a buffer probe using
|
| 206 |
the DLStreamer Python bindings (`gstgva.VideoFrame`), overlays bounding boxes,
|
| 207 |
+
saves the annotated result to `output_dlstreamer.mp4`, and prints the vehicle count per
|
| 208 |
+
frame.
|
| 209 |
|
| 210 |
> **Notes on running this sample:**
|
| 211 |
>
|
|
|
|
| 221 |
> /opt/intel/dlstreamer/gstreamer/lib/python3/dist-packages:${PYTHONPATH:-}
|
| 222 |
> ```
|
| 223 |
|
|
|
|
|
|
|
| 224 |
```python
|
| 225 |
import gi
|
| 226 |
|
|
|
|
| 231 |
|
| 232 |
Gst.init(None)
|
| 233 |
|
| 234 |
+
INPUT_VIDEO = "test_video.mp4"
|
| 235 |
VEHICLE_LABELS = {"car", "motorcycle", "bus", "truck"}
|
| 236 |
|
| 237 |
+
# For CPU: change device=GPU to device=CPU.
|
| 238 |
+
# For NPU: change device=GPU to device=NPU (batch-size=1, nireq=4 recommended).
|
|
|
|
|
|
|
| 239 |
pipeline_str = (
|
| 240 |
+
f"filesrc location={INPUT_VIDEO} ! decodebin3 ! "
|
| 241 |
+
"videoconvert ! "
|
| 242 |
"gvadetect model=yolo26n_openvino_model/yolo26n.xml "
|
| 243 |
+
"device=GPU "
|
| 244 |
+
"threshold=0.4 ! queue ! "
|
| 245 |
+
"gvawatermark ! videoconvert ! video/x-raw,format=I420 ! "
|
| 246 |
+
"openh264enc ! h264parse ! "
|
| 247 |
+
"mp4mux ! filesink name=sink location=output_dlstreamer.mp4"
|
| 248 |
)
|
| 249 |
pipeline = Gst.parse_launch(pipeline_str)
|
| 250 |
|
|
|
|
| 274 |
pipeline.set_state(Gst.State.NULL)
|
| 275 |
```
|
| 276 |
|
| 277 |
+
#### Expected Output
|
| 278 |
+
|
| 279 |
+

|
| 280 |
+
|
| 281 |
**Device targets:**
|
| 282 |
|
| 283 |
+
- `device=GPU` -- default in the sample code.
|
| 284 |
+
- `device=CPU` -- change `device=GPU` to `device=CPU`.
|
| 285 |
+
- `device=NPU` -- change `device=GPU` to `device=NPU`; use `batch-size=1` and `nireq=4` for best NPU utilization.
|
| 286 |
|
| 287 |
---
|
| 288 |
|
expected_output_dlstreamer.gif
ADDED
|
Git LFS Details
|
expected_output_openvino.jpg
ADDED
|
Git LFS Details
|
export_and_quantize.sh
CHANGED
|
@@ -44,6 +44,15 @@ else
|
|
| 44 |
echo "Already present: test.jpg"
|
| 45 |
fi
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
if [[ "${PRECISION}" == "FP32" ]]; then
|
| 48 |
HALF_FLAG="False"
|
| 49 |
EXPORT_LABEL="FP32"
|
|
|
|
| 44 |
echo "Already present: test.jpg"
|
| 45 |
fi
|
| 46 |
|
| 47 |
+
echo "--- Downloading sample test video ---"
|
| 48 |
+
if [[ ! -f test_video.mp4 ]]; then
|
| 49 |
+
wget -q -O test_video.mp4 \
|
| 50 |
+
https://github.com/intel-iot-devkit/sample-videos/raw/master/car-detection.mp4
|
| 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"
|