qaihm-bot commited on
Commit
fc1f451
·
verified ·
1 Parent(s): 7e7fe27

Upload README.md with huggingface_hub

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