Sync person-detection from metro-analytics-catalog
Browse files- .gitattributes +2 -0
- README.md +31 -22
- expected_output_dlstreamer.gif +3 -0
- expected_output_openvino.jpg +3 -0
- export_and_quantize.sh +9 -0
.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.jpg filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,7 +1,5 @@
|
|
| 1 |
# Person Detection
|
| 2 |
|
| 3 |
-
> **Validated with:** OpenVINO 2026.1.0, NNCF 3.0.0, DLStreamer 2026.0, Ultralytics 8.4.46, Python 3.11+
|
| 4 |
-
|
| 5 |
| Property | Value |
|
| 6 |
|---|---|
|
| 7 |
| **Category** | Object Detection (Person Detection) |
|
|
@@ -78,7 +76,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 |
|
|
@@ -147,7 +145,7 @@ cv2.putText(
|
|
| 147 |
image, f"Persons: {person_count}", (10, 30),
|
| 148 |
cv2.FONT_HERSHEY_SIMPLEX, 1.0, (0, 255, 0), 2,
|
| 149 |
)
|
| 150 |
-
cv2.imwrite("
|
| 151 |
```
|
| 152 |
|
| 153 |
**Device targets:**
|
|
@@ -160,7 +158,7 @@ cv2.imwrite("output.jpg", image)
|
|
| 160 |
|
| 161 |
The `export_and_quantize.sh` script downloads `test.jpg` automatically.
|
| 162 |
Re-run the OpenVINO sample above.
|
| 163 |
-
The script reads `test.jpg`, prints the person count to the console, and writes the annotated frame to `
|
| 164 |
|
| 165 |
Expected console output:
|
| 166 |
|
|
@@ -168,14 +166,19 @@ Expected console output:
|
|
| 168 |
Detected persons: 2
|
| 169 |
```
|
| 170 |
|
| 171 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
### DLStreamer Sample
|
| 174 |
|
| 175 |
-
The pipeline below runs the FP16 YOLO26 detector on
|
| 176 |
`gvadetect`, filters detections to the `person` class in a buffer probe using
|
| 177 |
the DLStreamer Python bindings (`gstgva.VideoFrame`), overlays bounding boxes,
|
| 178 |
-
and prints the person count
|
|
|
|
| 179 |
|
| 180 |
> **Notes on running this sample:**
|
| 181 |
>
|
|
@@ -195,8 +198,6 @@ and prints the person count.
|
|
| 195 |
> /opt/intel/dlstreamer/gstreamer/lib/python3/dist-packages:${PYTHONPATH:-}
|
| 196 |
> ```
|
| 197 |
|
| 198 |
-
**Image-based quick test** (uses `filesrc` with a single JPEG):
|
| 199 |
-
|
| 200 |
```python
|
| 201 |
import gi
|
| 202 |
|
|
@@ -207,16 +208,19 @@ from gstgva import VideoFrame
|
|
| 207 |
|
| 208 |
Gst.init(None)
|
| 209 |
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
#
|
| 213 |
-
# For NPU: change device=
|
| 214 |
pipeline_str = (
|
| 215 |
-
"filesrc location=
|
| 216 |
-
"
|
| 217 |
"gvadetect model=yolo26n_openvino_model/yolo26n.xml "
|
| 218 |
-
"device=
|
| 219 |
-
"
|
|
|
|
|
|
|
|
|
|
| 220 |
)
|
| 221 |
pipeline = Gst.parse_launch(pipeline_str)
|
| 222 |
|
|
@@ -226,7 +230,8 @@ def on_buffer(pad, info):
|
|
| 226 |
caps = pad.get_current_caps()
|
| 227 |
frame = VideoFrame(buf, caps=caps)
|
| 228 |
person_count = sum(1 for r in frame.regions() if r.label() == "person")
|
| 229 |
-
|
|
|
|
| 230 |
return Gst.PadProbeReturn.OK
|
| 231 |
|
| 232 |
|
|
@@ -243,11 +248,15 @@ bus.timed_pop_filtered(
|
|
| 243 |
pipeline.set_state(Gst.State.NULL)
|
| 244 |
```
|
| 245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
**Device targets:**
|
| 247 |
|
| 248 |
-
- `device=
|
| 249 |
-
- `device=
|
| 250 |
-
- `device=NPU` -- use `batch-size=1` and `nireq=4` for best NPU utilization.
|
| 251 |
|
| 252 |
---
|
| 253 |
|
|
|
|
| 1 |
# Person Detection
|
| 2 |
|
|
|
|
|
|
|
| 3 |
| Property | Value |
|
| 4 |
|---|---|
|
| 5 |
| **Category** | Object Detection (Person Detection) |
|
|
|
|
| 76 |
The script performs the following steps:
|
| 77 |
|
| 78 |
1. Installs dependencies (`openvino`, `ultralytics`; adds `nncf` for INT8).
|
| 79 |
+
2. Downloads a sample test image (`test.jpg`) and a sample test video (`test_video.mp4`).
|
| 80 |
3. Downloads the PyTorch weights and exports to OpenVINO IR.
|
| 81 |
4. *(INT8 only)* Quantizes the model using NNCF post-training quantization.
|
| 82 |
|
|
|
|
| 145 |
image, f"Persons: {person_count}", (10, 30),
|
| 146 |
cv2.FONT_HERSHEY_SIMPLEX, 1.0, (0, 255, 0), 2,
|
| 147 |
)
|
| 148 |
+
cv2.imwrite("output_openvino.jpg", image)
|
| 149 |
```
|
| 150 |
|
| 151 |
**Device targets:**
|
|
|
|
| 158 |
|
| 159 |
The `export_and_quantize.sh` script downloads `test.jpg` automatically.
|
| 160 |
Re-run the OpenVINO sample above.
|
| 161 |
+
The script reads `test.jpg`, prints the person count to the console, and writes the annotated frame to `output_openvino.jpg`.
|
| 162 |
|
| 163 |
Expected console output:
|
| 164 |
|
|
|
|
| 166 |
Detected persons: 2
|
| 167 |
```
|
| 168 |
|
| 169 |
+
`output_openvino.jpg` shows a green bounding box around each detected person and the text `Persons: 2` in the top-left corner.
|
| 170 |
+
|
| 171 |
+
#### Expected Output
|
| 172 |
+
|
| 173 |
+

|
| 174 |
|
| 175 |
### DLStreamer Sample
|
| 176 |
|
| 177 |
+
The pipeline below runs the FP16 YOLO26 detector on the sample video via
|
| 178 |
`gvadetect`, filters detections to the `person` class in a buffer probe using
|
| 179 |
the DLStreamer Python bindings (`gstgva.VideoFrame`), overlays bounding boxes,
|
| 180 |
+
saves the annotated result to `output_dlstreamer.mp4`, and prints the person count per
|
| 181 |
+
frame.
|
| 182 |
|
| 183 |
> **Notes on running this sample:**
|
| 184 |
>
|
|
|
|
| 198 |
> /opt/intel/dlstreamer/gstreamer/lib/python3/dist-packages:${PYTHONPATH:-}
|
| 199 |
> ```
|
| 200 |
|
|
|
|
|
|
|
| 201 |
```python
|
| 202 |
import gi
|
| 203 |
|
|
|
|
| 208 |
|
| 209 |
Gst.init(None)
|
| 210 |
|
| 211 |
+
INPUT_VIDEO = "test_video.mp4"
|
| 212 |
+
|
| 213 |
+
# For CPU: change device=GPU to device=CPU.
|
| 214 |
+
# For NPU: change device=GPU to device=NPU (batch-size=1, nireq=4 recommended).
|
| 215 |
pipeline_str = (
|
| 216 |
+
f"filesrc location={INPUT_VIDEO} ! decodebin3 ! "
|
| 217 |
+
"videoconvert ! "
|
| 218 |
"gvadetect model=yolo26n_openvino_model/yolo26n.xml "
|
| 219 |
+
"device=GPU "
|
| 220 |
+
"threshold=0.4 ! queue ! "
|
| 221 |
+
"gvawatermark ! videoconvert ! video/x-raw,format=I420 ! "
|
| 222 |
+
"openh264enc ! h264parse ! "
|
| 223 |
+
"mp4mux ! filesink name=sink location=output_dlstreamer.mp4"
|
| 224 |
)
|
| 225 |
pipeline = Gst.parse_launch(pipeline_str)
|
| 226 |
|
|
|
|
| 230 |
caps = pad.get_current_caps()
|
| 231 |
frame = VideoFrame(buf, caps=caps)
|
| 232 |
person_count = sum(1 for r in frame.regions() if r.label() == "person")
|
| 233 |
+
if person_count:
|
| 234 |
+
print(f"Person count: {person_count}", flush=True)
|
| 235 |
return Gst.PadProbeReturn.OK
|
| 236 |
|
| 237 |
|
|
|
|
| 248 |
pipeline.set_state(Gst.State.NULL)
|
| 249 |
```
|
| 250 |
|
| 251 |
+
#### Expected Output
|
| 252 |
+
|
| 253 |
+

|
| 254 |
+
|
| 255 |
**Device targets:**
|
| 256 |
|
| 257 |
+
- `device=GPU` -- default in the sample code.
|
| 258 |
+
- `device=CPU` -- change `device=GPU` to `device=CPU`.
|
| 259 |
+
- `device=NPU` -- change `device=GPU` to `device=NPU`; use `batch-size=1` and `nireq=4` for best NPU utilization.
|
| 260 |
|
| 261 |
---
|
| 262 |
|
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/people-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"
|