shreyajn commited on
Commit
d26d07f
1 Parent(s): 1659c6f

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +240 -0
README.md ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: pytorch
3
+ license: apache-2.0
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/mediapipe_face/web-assets/banner.png)
12
+
13
+ # MediaPipe-Face-Detection: Optimized for Mobile Deployment
14
+ ## Detect faces and locate facial features in real-time video and image streams
15
+
16
+ Designed for sub-millisecond processing, this model predicts bounding boxes and pose skeletons (left eye, right eye, nose tip, mouth, left eye tragion, and right eye tragion) of faces in an image.
17
+
18
+ This model is an implementation of MediaPipe-Face-Detection found [here](https://github.com/zmurez/MediaPipePyTorch/).
19
+ This repository provides scripts to run MediaPipe-Face-Detection on Qualcomm® devices.
20
+ More details on model performance across various devices, can be found
21
+ [here](https://aihub.qualcomm.com/models/mediapipe_face).
22
+
23
+
24
+ ### Model Details
25
+
26
+ - **Model Type:** Object detection
27
+ - **Model Stats:**
28
+ - Input resolution: 256x256
29
+ - Number of parameters (MediaPipeFaceDetector): 135K
30
+ - Model size (MediaPipeFaceDetector): 565 KB
31
+ - Number of parameters (MediaPipeFaceLandmarkDetector): 603K
32
+ - Model size (MediaPipeFaceLandmarkDetector): 2.34 MB
33
+
34
+
35
+ | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Precision | Primary Compute Unit | Target Model
36
+ | ---|---|---|---|---|---|---|---|
37
+ | Samsung Galaxy S23 Ultra (Android 13) | Snapdragon® 8 Gen 2 | TFLite | 0.536 ms | 0 - 1 MB | FP16 | NPU | [MediaPipeFaceDetector.tflite](https://huggingface.co/qualcomm/MediaPipe-Face-Detection/blob/main/MediaPipeFaceDetector.tflite)
38
+ | Samsung Galaxy S23 Ultra (Android 13) | Snapdragon® 8 Gen 2 | TFLite | 0.209 ms | 0 - 2 MB | FP16 | NPU | [MediaPipeFaceLandmarkDetector.tflite](https://huggingface.co/qualcomm/MediaPipe-Face-Detection/blob/main/MediaPipeFaceLandmarkDetector.tflite)
39
+ | Samsung Galaxy S23 Ultra (Android 13) | Snapdragon® 8 Gen 2 | QNN Model Library | 0.592 ms | 1 - 55 MB | FP16 | NPU | [MediaPipeFaceDetector.so](https://huggingface.co/qualcomm/MediaPipe-Face-Detection/blob/main/MediaPipeFaceDetector.so)
40
+ | Samsung Galaxy S23 Ultra (Android 13) | Snapdragon® 8 Gen 2 | QNN Model Library | 0.286 ms | 0 - 8 MB | FP16 | NPU | [MediaPipeFaceLandmarkDetector.so](https://huggingface.co/qualcomm/MediaPipe-Face-Detection/blob/main/MediaPipeFaceLandmarkDetector.so)
41
+
42
+
43
+ ## Installation
44
+
45
+ This model can be installed as a Python package via pip.
46
+
47
+ ```bash
48
+ pip install "qai-hub-models[mediapipe_face]"
49
+ ```
50
+
51
+
52
+
53
+ ## Configure Qualcomm® AI Hub to run this model on a cloud-hosted device
54
+
55
+ Sign-in to [Qualcomm® AI Hub](https://app.aihub.qualcomm.com/) with your
56
+ Qualcomm® ID. Once signed in navigate to `Account -> Settings -> API Token`.
57
+
58
+ With this API token, you can configure your client to run models on the cloud
59
+ hosted devices.
60
+ ```bash
61
+ qai-hub configure --api_token API_TOKEN
62
+ ```
63
+ Navigate to [docs](https://app.aihub.qualcomm.com/docs/) for more information.
64
+
65
+
66
+
67
+ ## Demo off target
68
+
69
+ The package contains a simple end-to-end demo that downloads pre-trained
70
+ weights and runs this model on a sample input.
71
+
72
+ ```bash
73
+ python -m qai_hub_models.models.mediapipe_face.demo
74
+ ```
75
+
76
+ The above demo runs a reference implementation of pre-processing, model
77
+ inference, and post processing.
78
+
79
+ **NOTE**: If you want running in a Jupyter Notebook or Google Colab like
80
+ environment, please add the following to your cell (instead of the above).
81
+ ```
82
+ %run -m qai_hub_models.models.mediapipe_face.demo
83
+ ```
84
+
85
+
86
+ ### Run model on a cloud-hosted device
87
+
88
+ In addition to the demo, you can also run the model on a cloud-hosted Qualcomm®
89
+ device. This script does the following:
90
+ * Performance check on-device on a cloud-hosted device
91
+ * Downloads compiled assets that can be deployed on-device for Android.
92
+ * Accuracy check between PyTorch and on-device outputs.
93
+
94
+ ```bash
95
+ python -m qai_hub_models.models.mediapipe_face.export
96
+ ```
97
+
98
+ ```
99
+ Profile Job summary of MediaPipeFaceDetector
100
+ --------------------------------------------------
101
+ Device: Samsung Galaxy S23 Ultra (13)
102
+ Estimated Inference Time: 0.54 ms
103
+ Estimated Peak Memory Range: 0.01-1.47 MB
104
+ Compute Units: NPU (111) | Total (111)
105
+
106
+ Profile Job summary of MediaPipeFaceLandmarkDetector
107
+ --------------------------------------------------
108
+ Device: Samsung Galaxy S23 Ultra (13)
109
+ Estimated Inference Time: 0.21 ms
110
+ Estimated Peak Memory Range: 0.02-1.72 MB
111
+ Compute Units: NPU (100) | Total (100)
112
+
113
+ Profile Job summary of MediaPipeFaceDetector
114
+ --------------------------------------------------
115
+ Device: Samsung Galaxy S23 Ultra (13)
116
+ Estimated Inference Time: 0.59 ms
117
+ Estimated Peak Memory Range: 0.77-54.90 MB
118
+ Compute Units: NPU (147) | Total (147)
119
+
120
+ Profile Job summary of MediaPipeFaceLandmarkDetector
121
+ --------------------------------------------------
122
+ Device: Samsung Galaxy S23 Ultra (13)
123
+ Estimated Inference Time: 0.29 ms
124
+ Estimated Peak Memory Range: 0.44-8.36 MB
125
+ Compute Units: NPU (106) | Total (106)
126
+
127
+
128
+ ```
129
+ ## How does this work?
130
+
131
+ This [export script](https://github.com/quic/ai-hub-models/blob/main/qai_hub_models/models/MediaPipe-Face-Detection/export.py)
132
+ leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
133
+ on-device. Lets go through each step below in detail:
134
+
135
+ Step 1: **Compile model for on-device deployment**
136
+
137
+ To compile a PyTorch model for on-device deployment, we first trace the model
138
+ in memory using the `jit.trace` and then call the `submit_compile_job` API.
139
+
140
+ ```python
141
+ import torch
142
+
143
+ import qai_hub as hub
144
+ from qai_hub_models.models.mediapipe_face import Model
145
+
146
+ # Load the model
147
+ torch_model = Model.from_pretrained()
148
+ torch_model.eval()
149
+
150
+ # Device
151
+ device = hub.Device("Samsung Galaxy S23")
152
+
153
+ # Trace model
154
+ input_shape = torch_model.get_input_spec()
155
+ sample_inputs = torch_model.sample_inputs()
156
+
157
+ pt_model = torch.jit.trace(torch_model, [torch.tensor(data[0]) for _, data in sample_inputs.items()])
158
+
159
+ # Compile model on a specific device
160
+ compile_job = hub.submit_compile_job(
161
+ model=pt_model,
162
+ device=device,
163
+ input_specs=torch_model.get_input_spec(),
164
+ )
165
+
166
+ # Get target model to run on-device
167
+ target_model = compile_job.get_target_model()
168
+
169
+ ```
170
+
171
+
172
+ Step 2: **Performance profiling on cloud-hosted device**
173
+
174
+ After compiling models from step 1. Models can be profiled model on-device using the
175
+ `target_model`. Note that this scripts runs the model on a device automatically
176
+ provisioned in the cloud. Once the job is submitted, you can navigate to a
177
+ provided job URL to view a variety of on-device performance metrics.
178
+ ```python
179
+ profile_job = hub.submit_profile_job(
180
+ model=target_model,
181
+ device=device,
182
+ )
183
+
184
+ ```
185
+
186
+ Step 3: **Verify on-device accuracy**
187
+
188
+ To verify the accuracy of the model on-device, you can run on-device inference
189
+ on sample input data on the same cloud hosted device.
190
+ ```python
191
+ input_data = torch_model.sample_inputs()
192
+ inference_job = hub.submit_inference_job(
193
+ model=target_model,
194
+ device=device,
195
+ inputs=input_data,
196
+ )
197
+
198
+ on_device_output = inference_job.download_output_data()
199
+
200
+ ```
201
+ With the output of the model, you can compute like PSNR, relative errors or
202
+ spot check the output with expected output.
203
+
204
+ **Note**: This on-device profiling and inference requires access to Qualcomm®
205
+ AI Hub. [Sign up for early access](https://aihub.qualcomm.com/sign-up).
206
+
207
+
208
+
209
+ ## Deploying compiled model to Android
210
+
211
+
212
+ The models can be deployed using multiple runtimes:
213
+ - TensorFlow Lite (`.tflite` export): [This
214
+ tutorial](https://www.tensorflow.org/lite/android/quickstart) provides a
215
+ guide to deploy the .tflite model in an Android application.
216
+
217
+
218
+ - QNN (`.so` export ): This [sample
219
+ app](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/sample_app.html)
220
+ provides instructions on how to use the `.so` shared library in an Android application.
221
+
222
+
223
+ ## View on Qualcomm® AI Hub
224
+ Get more details on MediaPipe-Face-Detection's performance across various devices [here](https://aihub.qualcomm.com/models/mediapipe_face).
225
+ Explore all available models on [Qualcomm® AI Hub](https://aihub.qualcomm.com/)
226
+
227
+ ## License
228
+ - The license for the original implementation of MediaPipe-Face-Detection can be found
229
+ [here](https://github.com/zmurez/MediaPipePyTorch/blob/master/LICENSE).
230
+ - 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).
231
+
232
+ ## References
233
+ * [BlazeFace: Sub-millisecond Neural Face Detection on Mobile GPUs](https://arxiv.org/abs/1907.05047)
234
+ * [Source Model Implementation](https://github.com/zmurez/MediaPipePyTorch/)
235
+
236
+ ## Community
237
+ * Join [our AI Hub Slack community](https://join.slack.com/t/qualcomm-ai-hub/shared_invite/zt-2dgf95loi-CXHTDRR1rvPgQWPO~ZZZJg) to collaborate, post questions and learn more about on-device AI.
238
+ * For questions or feedback please [reach out to us](mailto:ai-hub-support@qti.qualcomm.com).
239
+
240
+