qaihm-bot commited on
Commit
9b2cc22
·
verified ·
1 Parent(s): 7fae861

Upload README.md with huggingface_hub

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