qaihm-bot commited on
Commit
280fa15
·
verified ·
1 Parent(s): 395714d

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +239 -0
README.md ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: pytorch
3
+ license: bsd-3-clause
4
+ pipeline_tag: object-detection
5
+ tags:
6
+ - real_time
7
+ - android
8
+
9
+ ---
10
+
11
+ ![](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/gear_guard_net/web-assets/model_demo.png)
12
+
13
+ # PPE-Detection: Optimized for Mobile Deployment
14
+ ## Object detection for personal protective equipments (PPE)
15
+
16
+ Detect if a person is wearing personal protective equipments (PPE) in real-time.
17
+
18
+ This model is an implementation of PPE-Detection found [here]({source_repo}).
19
+ This repository provides scripts to run PPE-Detection on Qualcomm® devices.
20
+ More details on model performance across various devices, can be found
21
+ [here](https://aihub.qualcomm.com/models/gear_guard_net).
22
+
23
+
24
+ ### Model Details
25
+
26
+ - **Model Type:** Object detection
27
+ - **Model Stats:**
28
+ - Inference latency: RealTime
29
+ - Input resolution: 320x192
30
+ - Number of parameters: 7.02M
31
+ - Model size: 13.5 MB
32
+ - Number of output classes: 2
33
+
34
+ | Model | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Precision | Primary Compute Unit | Target Model
35
+ |---|---|---|---|---|---|---|---|---|
36
+ | PPE-Detection | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | TFLITE | 0.67 ms | 0 - 232 MB | FP16 | NPU | [PPE-Detection.tflite](https://huggingface.co/qualcomm/PPE-Detection/blob/main/PPE-Detection.tflite) |
37
+ | PPE-Detection | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | QNN | 0.725 ms | 0 - 49 MB | FP16 | NPU | [PPE-Detection.so](https://huggingface.co/qualcomm/PPE-Detection/blob/main/PPE-Detection.so) |
38
+ | PPE-Detection | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | ONNX | 1.105 ms | 0 - 15 MB | FP16 | NPU | [PPE-Detection.onnx](https://huggingface.co/qualcomm/PPE-Detection/blob/main/PPE-Detection.onnx) |
39
+ | PPE-Detection | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | TFLITE | 0.561 ms | 0 - 42 MB | FP16 | NPU | [PPE-Detection.tflite](https://huggingface.co/qualcomm/PPE-Detection/blob/main/PPE-Detection.tflite) |
40
+ | PPE-Detection | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | QNN | 0.613 ms | 1 - 16 MB | FP16 | NPU | [PPE-Detection.so](https://huggingface.co/qualcomm/PPE-Detection/blob/main/PPE-Detection.so) |
41
+ | PPE-Detection | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | ONNX | 0.943 ms | 0 - 46 MB | FP16 | NPU | [PPE-Detection.onnx](https://huggingface.co/qualcomm/PPE-Detection/blob/main/PPE-Detection.onnx) |
42
+ | PPE-Detection | QCS8550 (Proxy) | QCS8550 Proxy | TFLITE | 0.666 ms | 0 - 4 MB | FP16 | NPU | [PPE-Detection.tflite](https://huggingface.co/qualcomm/PPE-Detection/blob/main/PPE-Detection.tflite) |
43
+ | PPE-Detection | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 0.722 ms | 1 - 2 MB | FP16 | NPU | Use Export Script |
44
+ | PPE-Detection | SA8255 (Proxy) | SA8255P Proxy | TFLITE | 0.671 ms | 0 - 242 MB | FP16 | NPU | [PPE-Detection.tflite](https://huggingface.co/qualcomm/PPE-Detection/blob/main/PPE-Detection.tflite) |
45
+ | PPE-Detection | SA8255 (Proxy) | SA8255P Proxy | QNN | 0.728 ms | 1 - 2 MB | FP16 | NPU | Use Export Script |
46
+ | PPE-Detection | SA8775 (Proxy) | SA8775P Proxy | TFLITE | 0.669 ms | 0 - 174 MB | FP16 | NPU | [PPE-Detection.tflite](https://huggingface.co/qualcomm/PPE-Detection/blob/main/PPE-Detection.tflite) |
47
+ | PPE-Detection | SA8775 (Proxy) | SA8775P Proxy | QNN | 0.731 ms | 1 - 2 MB | FP16 | NPU | Use Export Script |
48
+ | PPE-Detection | SA8650 (Proxy) | SA8650P Proxy | TFLITE | 0.666 ms | 0 - 7 MB | FP16 | NPU | [PPE-Detection.tflite](https://huggingface.co/qualcomm/PPE-Detection/blob/main/PPE-Detection.tflite) |
49
+ | PPE-Detection | SA8650 (Proxy) | SA8650P Proxy | QNN | 0.73 ms | 1 - 2 MB | FP16 | NPU | Use Export Script |
50
+ | PPE-Detection | QCS8450 (Proxy) | QCS8450 Proxy | TFLITE | 1.428 ms | 0 - 39 MB | FP16 | NPU | [PPE-Detection.tflite](https://huggingface.co/qualcomm/PPE-Detection/blob/main/PPE-Detection.tflite) |
51
+ | PPE-Detection | QCS8450 (Proxy) | QCS8450 Proxy | QNN | 1.492 ms | 1 - 16 MB | FP16 | NPU | Use Export Script |
52
+ | PPE-Detection | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | TFLITE | 0.48 ms | 0 - 22 MB | FP16 | NPU | [PPE-Detection.tflite](https://huggingface.co/qualcomm/PPE-Detection/blob/main/PPE-Detection.tflite) |
53
+ | PPE-Detection | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 0.44 ms | 0 - 14 MB | FP16 | NPU | Use Export Script |
54
+ | PPE-Detection | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | ONNX | 0.713 ms | 0 - 24 MB | FP16 | NPU | [PPE-Detection.onnx](https://huggingface.co/qualcomm/PPE-Detection/blob/main/PPE-Detection.onnx) |
55
+ | PPE-Detection | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 0.853 ms | 1 - 1 MB | FP16 | NPU | Use Export Script |
56
+ | PPE-Detection | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 1.173 ms | 13 - 13 MB | FP16 | NPU | [PPE-Detection.onnx](https://huggingface.co/qualcomm/PPE-Detection/blob/main/PPE-Detection.onnx) |
57
+
58
+
59
+
60
+
61
+ ## Installation
62
+
63
+ This model can be installed as a Python package via pip.
64
+
65
+ ```bash
66
+ pip install qai-hub-models
67
+ ```
68
+
69
+
70
+ ## Configure Qualcomm® AI Hub to run this model on a cloud-hosted device
71
+
72
+ Sign-in to [Qualcomm® AI Hub](https://app.aihub.qualcomm.com/) with your
73
+ Qualcomm® ID. Once signed in navigate to `Account -> Settings -> API Token`.
74
+
75
+ With this API token, you can configure your client to run models on the cloud
76
+ hosted devices.
77
+ ```bash
78
+ qai-hub configure --api_token API_TOKEN
79
+ ```
80
+ Navigate to [docs](https://app.aihub.qualcomm.com/docs/) for more information.
81
+
82
+
83
+
84
+ ## Demo off target
85
+
86
+ The package contains a simple end-to-end demo that downloads pre-trained
87
+ weights and runs this model on a sample input.
88
+
89
+ ```bash
90
+ python -m qai_hub_models.models.gear_guard_net.demo
91
+ ```
92
+
93
+ The above demo runs a reference implementation of pre-processing, model
94
+ inference, and post processing.
95
+
96
+ **NOTE**: If you want running in a Jupyter Notebook or Google Colab like
97
+ environment, please add the following to your cell (instead of the above).
98
+ ```
99
+ %run -m qai_hub_models.models.gear_guard_net.demo
100
+ ```
101
+
102
+
103
+ ### Run model on a cloud-hosted device
104
+
105
+ In addition to the demo, you can also run the model on a cloud-hosted Qualcomm®
106
+ device. This script does the following:
107
+ * Performance check on-device on a cloud-hosted device
108
+ * Downloads compiled assets that can be deployed on-device for Android.
109
+ * Accuracy check between PyTorch and on-device outputs.
110
+
111
+ ```bash
112
+ python -m qai_hub_models.models.gear_guard_net.export
113
+ ```
114
+ ```
115
+ Profiling Results
116
+ ------------------------------------------------------------
117
+ PPE-Detection
118
+ Device : Samsung Galaxy S23 (13)
119
+ Runtime : TFLITE
120
+ Estimated inference time (ms) : 0.7
121
+ Estimated peak memory usage (MB): [0, 232]
122
+ Total # Ops : 80
123
+ Compute Unit(s) : NPU (80 ops)
124
+ ```
125
+
126
+
127
+ ## How does this work?
128
+
129
+ This [export script](https://aihub.qualcomm.com/models/gear_guard_net/qai_hub_models/models/PPE-Detection/export.py)
130
+ leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
131
+ on-device. Lets go through each step below in detail:
132
+
133
+ Step 1: **Compile model for on-device deployment**
134
+
135
+ To compile a PyTorch model for on-device deployment, we first trace the model
136
+ in memory using the `jit.trace` and then call the `submit_compile_job` API.
137
+
138
+ ```python
139
+ import torch
140
+
141
+ import qai_hub as hub
142
+ from qai_hub_models.models.gear_guard_net import
143
+
144
+ # Load the model
145
+
146
+ # Device
147
+ device = hub.Device("Samsung Galaxy S23")
148
+
149
+
150
+ ```
151
+
152
+
153
+ Step 2: **Performance profiling on cloud-hosted device**
154
+
155
+ After compiling models from step 1. Models can be profiled model on-device using the
156
+ `target_model`. Note that this scripts runs the model on a device automatically
157
+ provisioned in the cloud. Once the job is submitted, you can navigate to a
158
+ provided job URL to view a variety of on-device performance metrics.
159
+ ```python
160
+ profile_job = hub.submit_profile_job(
161
+ model=target_model,
162
+ device=device,
163
+ )
164
+
165
+ ```
166
+
167
+ Step 3: **Verify on-device accuracy**
168
+
169
+ To verify the accuracy of the model on-device, you can run on-device inference
170
+ on sample input data on the same cloud hosted device.
171
+ ```python
172
+ input_data = torch_model.sample_inputs()
173
+ inference_job = hub.submit_inference_job(
174
+ model=target_model,
175
+ device=device,
176
+ inputs=input_data,
177
+ )
178
+ on_device_output = inference_job.download_output_data()
179
+
180
+ ```
181
+ With the output of the model, you can compute like PSNR, relative errors or
182
+ spot check the output with expected output.
183
+
184
+ **Note**: This on-device profiling and inference requires access to Qualcomm®
185
+ AI Hub. [Sign up for access](https://myaccount.qualcomm.com/signup).
186
+
187
+
188
+
189
+ ## Run demo on a cloud-hosted device
190
+
191
+ You can also run the demo on-device.
192
+
193
+ ```bash
194
+ python -m qai_hub_models.models.gear_guard_net.demo --on-device
195
+ ```
196
+
197
+ **NOTE**: If you want running in a Jupyter Notebook or Google Colab like
198
+ environment, please add the following to your cell (instead of the above).
199
+ ```
200
+ %run -m qai_hub_models.models.gear_guard_net.demo -- --on-device
201
+ ```
202
+
203
+
204
+ ## Deploying compiled model to Android
205
+
206
+
207
+ The models can be deployed using multiple runtimes:
208
+ - TensorFlow Lite (`.tflite` export): [This
209
+ tutorial](https://www.tensorflow.org/lite/android/quickstart) provides a
210
+ guide to deploy the .tflite model in an Android application.
211
+
212
+
213
+ - QNN (`.so` export ): This [sample
214
+ app](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/sample_app.html)
215
+ provides instructions on how to use the `.so` shared library in an Android application.
216
+
217
+
218
+ ## View on Qualcomm® AI Hub
219
+ Get more details on PPE-Detection's performance across various devices [here](https://aihub.qualcomm.com/models/gear_guard_net).
220
+ Explore all available models on [Qualcomm® AI Hub](https://aihub.qualcomm.com/)
221
+
222
+
223
+ ## License
224
+ * The license for the original implementation of PPE-Detection can be found [here](https://github.com/qcom-ai-hub/ai-hub-models-internal/blob/main/LICENSE).
225
+ * The license for the compiled assets for on-device deployment can be found [here](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/Qualcomm+AI+Hub+Proprietary+License.pdf)
226
+
227
+
228
+
229
+ ## References
230
+ * [None](None)
231
+ * [Source Model Implementation](https://github.com/quic/ai-hub-models/blob/main/qai_hub_models/models/gear_guard_net/model.py)
232
+
233
+
234
+
235
+ ## Community
236
+ * Join [our AI Hub Slack community](https://aihub.qualcomm.com/community/slack) to collaborate, post questions and learn more about on-device AI.
237
+ * For questions or feedback please [reach out to us](mailto:[email protected]).
238
+
239
+