vagheshpatel commited on
Commit
ca15802
·
verified ·
1 Parent(s): 6e10d27

Sync worker-safety-detection from metro-analytics-catalog

Browse files
Files changed (3) hide show
  1. LICENSE +42 -0
  2. README.md +161 -5
  3. export_and_quantize.sh +49 -0
LICENSE CHANGED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ Worker Safety Gear Detection Model
33
+ -----------------------------------
34
+
35
+ The Worker Safety Gear Detection model is developed by Intel and distributed
36
+ via the Intel Edge AI Resources repository under the Apache License 2.0.
37
+
38
+ Source: https://github.com/open-edge-platform/edge-ai-resources
39
+ Model: https://github.com/open-edge-platform/edge-ai-resources/blob/main/models/INT8/worker-safety-gear-detection.zip
40
+
41
+ Users must comply with the applicable license terms when using or distributing
42
+ the model weights.
README.md CHANGED
@@ -1,5 +1,161 @@
1
- ---
2
- license: other
3
- license_name: other
4
- license_link: LICENSE
5
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Worker Safety Detection
2
+
3
+ > **Validated with:** OpenVINO 2026.1.0, DLStreamer 2026.0, Python 3.11+
4
+
5
+ | Property | Value |
6
+ |---|---|
7
+ | **Category** | Object Detection (PPE / Safety Compliance) |
8
+ | **Base Model** | [Worker Safety Gear Detection](https://github.com/open-edge-platform/edge-ai-resources/blob/main/models/FP32/worker-safety-gear-detection.zip) (Intel Edge AI Resources, Geti-trained) |
9
+ | **Source Framework** | Intel Geti (OpenVINO IR) |
10
+ | **Supported Precisions** | FP32 |
11
+ | **Inference Engine** | OpenVINO |
12
+ | **Hardware** | CPU, GPU, NPU |
13
+ | **Detected Class(es)** | `safety_jacket` (class 0), `safety_helmet` (class 1) |
14
+
15
+ ---
16
+
17
+ ## Overview
18
+
19
+ Worker Safety Compliance Detection is a Metro Analytics use case that detects safety gear on workers to verify compliance with personal protective equipment (PPE) requirements.
20
+ It uses a pre-trained FP32 detection model from [Intel Edge AI Resources](https://github.com/open-edge-platform/edge-ai-resources), trained with [Intel Geti](https://geti.intel.com/) on worker safety imagery.
21
+ The model detects two classes: `safety_jacket` (high-visibility vest) and `safety_helmet` (hard hat).
22
+ Frames where expected PPE is not detected indicate non-compliance.
23
+
24
+ The FP32 model ships as an OpenVINO IR, ready for deployment on Intel CPUs and GPUs without additional conversion steps.
25
+
26
+ Typical deployments include:
27
+
28
+ - **Construction Site Safety** -- verify that all workers wear hard hats and high-visibility vests before entering active zones.
29
+ - **Warehouse Compliance** -- enforce PPE policies at loading docks and forklift areas.
30
+ - **Industrial Zone Monitoring** -- continuous compliance scanning at facility entry points.
31
+ - **Automated Incident Reporting** -- generate alerts when expected `safety_helmet` or `safety_jacket` detections are absent for detected persons.
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 Model
53
+
54
+ Run the provided script to download and extract the pre-trained FP32 model from Intel Edge AI Resources:
55
+
56
+ ```bash
57
+ chmod +x export_and_quantize.sh
58
+ ./export_and_quantize.sh
59
+ ```
60
+
61
+ The script performs the following steps:
62
+
63
+ 1. Installs dependencies (`openvino`).
64
+ 2. Downloads a sample test video (`test_video.avi`) from Intel Edge AI Resources.
65
+ 3. Downloads `worker-safety-gear-detection.zip` from the Intel Edge AI Resources repository.
66
+ 4. Extracts the FP32 OpenVINO IR model.
67
+
68
+ Output files:
69
+
70
+ - `./models/worker-safety-gear-detection/` -- extracted model directory containing the FP32 OpenVINO IR (`model.xml`, `model.bin`).
71
+
72
+ > **Note:** The FP32 model is ready for production use on CPU and GPU.
73
+ > An INT8 variant is also available from the [INT8 models directory](https://github.com/open-edge-platform/edge-ai-resources/tree/main/models/INT8) for higher throughput.
74
+
75
+ ### DLStreamer Sample
76
+
77
+ The pipeline below runs the worker safety FP32 detector on the sample video via
78
+ `gvadetect`, overlays bounding boxes with `gvawatermark`, and saves the
79
+ annotated result to `output.mp4`.
80
+
81
+ > **Notes on running this sample:**
82
+ >
83
+ > - The Geti-exported model embeds post-processing and labels internally.
84
+ > `gvadetect` auto-discovers the model type for Geti-exported IRs.
85
+ > - Export `PYTHONPATH` so the DLStreamer Python module is importable:
86
+ >
87
+ > ```bash
88
+ > source /opt/intel/openvino_2026/setupvars.sh
89
+ > source /opt/intel/dlstreamer/scripts/setup_dls_env.sh
90
+ > export PYTHONPATH=/opt/intel/dlstreamer/python:\
91
+ > /opt/intel/dlstreamer/gstreamer/lib/python3/dist-packages:${PYTHONPATH:-}
92
+ > ```
93
+
94
+ ```python
95
+ import gi
96
+
97
+ gi.require_version("Gst", "1.0")
98
+ gi.require_version("GstVideo", "1.0")
99
+ from gi.repository import Gst
100
+ from gstgva import VideoFrame
101
+
102
+ Gst.init(None)
103
+
104
+ MODEL_XML = "models/worker-safety-gear-detection/deployment/Detection/model/model.xml"
105
+ INPUT_VIDEO = "test_video.avi"
106
+
107
+ # For GPU: change device=CPU to device=GPU and add vapostproc after decodebin.
108
+ # For NPU: change device=CPU to device=NPU (batch-size=1, nireq=4 recommended).
109
+ pipeline_str = (
110
+ f"filesrc location={INPUT_VIDEO} ! decodebin3 ! "
111
+ f"gvadetect model={MODEL_XML} device=CPU threshold=0.4 ! queue ! "
112
+ f"gvawatermark ! videoconvert ! video/x-raw,format=I420 ! "
113
+ f"openh264enc ! h264parse ! "
114
+ f"mp4mux ! filesink name=sink location=output.mp4"
115
+ )
116
+ pipeline = Gst.parse_launch(pipeline_str)
117
+
118
+
119
+ def on_buffer(pad, info):
120
+ buf = info.get_buffer()
121
+ caps = pad.get_current_caps()
122
+ frame = VideoFrame(buf, caps=caps)
123
+ for region in frame.regions():
124
+ label = region.label()
125
+ print(f" [PPE] {label} conf={region.confidence():.2f}", flush=True)
126
+ return Gst.PadProbeReturn.OK
127
+
128
+
129
+ sink = pipeline.get_by_name("sink")
130
+ sink_pad = sink.get_static_pad("sink")
131
+ sink_pad.add_probe(Gst.PadProbeType.BUFFER, on_buffer)
132
+
133
+ pipeline.set_state(Gst.State.PLAYING)
134
+ bus = pipeline.get_bus()
135
+ bus.timed_pop_filtered(
136
+ Gst.CLOCK_TIME_NONE,
137
+ Gst.MessageType.EOS | Gst.MessageType.ERROR,
138
+ )
139
+ pipeline.set_state(Gst.State.NULL)
140
+ ```
141
+
142
+ **Device targets:**
143
+
144
+ - `device=CPU` -- default in the sample code.
145
+ - `device=GPU` -- add `vapostproc` after `decodebin` for zero-copy color conversion.
146
+ - `device=NPU` -- use `batch-size=1` and `nireq=4` for best NPU utilization.
147
+
148
+ ---
149
+
150
+ ## License
151
+
152
+ Copyright (C) Intel Corporation. All rights reserved.
153
+ Licensed under the MIT License. See [LICENSE](LICENSE) for details.
154
+
155
+ ## References
156
+
157
+ - [Intel Edge AI Resources -- Worker Safety Gear Detection Model](https://github.com/open-edge-platform/edge-ai-resources/blob/main/models/FP32/worker-safety-gear-detection.zip)
158
+ - [Worker Safety Gear Detection Application (Edge AI Suites)](https://github.com/open-edge-platform/edge-ai-suites/tree/main/manufacturing-ai-suite/industrial-edge-insights-vision)
159
+ - [Intel Geti Platform](https://geti.intel.com/)
160
+ - [OpenVINO Documentation](https://docs.openvino.ai/)
161
+ - [Intel DLStreamer](https://docs.openedgeplatform.intel.com/2026.0/edge-ai-libraries/dlstreamer/index.html)
export_and_quantize.sh ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # SPDX-License-Identifier: MIT
3
+ # Copyright (C) Intel Corporation
4
+ #
5
+ # Download the pre-trained FP32 Worker Safety Gear Detection model
6
+ # from Intel Edge AI Resources.
7
+ # Usage: ./export_and_quantize.sh [OUTPUT_DIR]
8
+ # Example: ./export_and_quantize.sh ./models
9
+
10
+ set -euo pipefail
11
+
12
+ OUTPUT_DIR="${1:-./models}"
13
+ MODEL_DIR="${OUTPUT_DIR}/worker-safety-gear-detection"
14
+ ZIP_URL="https://github.com/open-edge-platform/edge-ai-resources/raw/main/models/FP32/worker-safety-gear-detection.zip"
15
+ ZIP_FILE="${OUTPUT_DIR}/worker-safety-gear-detection.zip"
16
+
17
+ echo "--- Installing dependencies ---"
18
+ pip install -qU "openvino>=2026.0.0"
19
+
20
+ echo "--- Downloading sample test video ---"
21
+ if [[ ! -f test_video.avi ]]; then
22
+ wget -q -O test_video.avi \
23
+ https://github.com/open-edge-platform/edge-ai-resources/raw/refs/heads/main/videos/Safety_Full_Hat_and_Vest.avi
24
+ echo "Downloaded: test_video.avi"
25
+ else
26
+ echo "Already present: test_video.avi"
27
+ fi
28
+
29
+ echo "--- Downloading worker-safety-gear-detection FP32 model ---"
30
+ mkdir -p "${OUTPUT_DIR}"
31
+ if [[ ! -f "${ZIP_FILE}" ]]; then
32
+ wget -q -O "${ZIP_FILE}" "${ZIP_URL}"
33
+ echo "Downloaded: ${ZIP_FILE}"
34
+ else
35
+ echo "Already downloaded: ${ZIP_FILE}"
36
+ fi
37
+
38
+ echo "--- Extracting model ---"
39
+ unzip -qo "${ZIP_FILE}" -d "${MODEL_DIR}"
40
+ echo "Extracted to: ${MODEL_DIR}"
41
+
42
+ # Locate the model XML.
43
+ MODEL_XML=$(find "${MODEL_DIR}" -name "model.xml" -type f | head -1)
44
+ if [[ -z "${MODEL_XML}" ]]; then
45
+ echo "ERROR: model.xml not found in extracted archive." >&2
46
+ exit 1
47
+ fi
48
+ echo "Model IR found: ${MODEL_XML}"
49
+ echo "--- Done ---"