shreyajn commited on
Commit
dd2bca6
·
verified ·
1 Parent(s): 46ffaf4

Upload README.md with huggingface_hub

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