qaihm-bot commited on
Commit
f8f180d
1 Parent(s): 186c6ad

Upload README.md with huggingface_hub

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