qaihm-bot commited on
Commit
4322088
·
verified ·
1 Parent(s): 0e53c9d

Upload README.md with huggingface_hub

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