qaihm-bot commited on
Commit
25d1318
1 Parent(s): a7cbef9

Upload README.md with huggingface_hub

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