qaihm-bot commited on
Commit
13d3888
·
verified ·
1 Parent(s): efc5715

See https://github.com/quic/ai-hub-models/releases/v0.43.0 for changelog.

.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ DEPLOYMENT_MODEL_LICENSE.pdf filter=lfs diff=lfs merge=lfs -text
37
+ PSPNet_float.dlc filter=lfs diff=lfs merge=lfs -text
DEPLOYMENT_MODEL_LICENSE.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4409f93b0e82531303b3e10f52f1fdfb56467a25f05b7441c6bbd8bb8a64b42c
3
+ size 109629
LICENSE ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ The license of the original trained model can be found at https://github.com/hszhao/semseg/blob/master/LICENSE.
2
+ The license for the deployable model files (.tflite, .onnx, .dlc, .bin, etc.) can be found in DEPLOYMENT_MODEL_LICENSE.pdf.
PSPNet_float.dlc ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4db192da35b8d0a56efe1d09773d8473100811bb7f2a05a29f855900e02117f4
3
+ size 263161228
PSPNet_float.onnx.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7ba7e8599b00f1a87d7c80e727bbeeb73be9f5b3352cfdba93a803541ee55c88
3
+ size 245551257
PSPNet_float.tflite ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a4ddb059e3fa5c0e1c1f05404a1c6fe80148dda67d7d2caa56bbaf5a46d11878
3
+ size 262937828
README.md ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: pytorch
3
+ license: other
4
+ tags:
5
+ - android
6
+ pipeline_tag: image-segmentation
7
+
8
+ ---
9
+
10
+ ![](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/pspnet/web-assets/model_demo.png)
11
+
12
+ # PSPNet: Optimized for Mobile Deployment
13
+ ## Deep learning model for pixel-level semantic segmentation using pyramid pooling
14
+
15
+ PSPNet (Pyramid Scene Parsing Network) is a semantic segmentation model that captures global context information by applying pyramid pooling modules. It is designed to improve scene understanding by aggregating contextual features at multiple scales.
16
+
17
+ This repository provides scripts to run PSPNet on Qualcomm® devices.
18
+ More details on model performance across various devices, can be found
19
+ [here](https://aihub.qualcomm.com/models/pspnet).
20
+
21
+
22
+
23
+ ### Model Details
24
+
25
+ - **Model Type:** Model_use_case.semantic_segmentation
26
+ - **Model Stats:**
27
+ - Model checkpoint: pspnet101_ade20k.pth
28
+ - Input resolution: 1x3x473x473
29
+ - Number of parameters: 65.7M
30
+ - Model size (float): 251 MB
31
+
32
+ | Model | Precision | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Primary Compute Unit | Target Model
33
+ |---|---|---|---|---|---|---|---|---|
34
+ | PSPNet | float | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | TFLITE | 3725.883 ms | 114 - 621 MB | NPU | [PSPNet.tflite](https://huggingface.co/qualcomm/PSPNet/blob/main/PSPNet.tflite) |
35
+ | PSPNet | float | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | QNN_DLC | 1502.055 ms | 0 - 465 MB | NPU | [PSPNet.dlc](https://huggingface.co/qualcomm/PSPNet/blob/main/PSPNet.dlc) |
36
+ | PSPNet | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | TFLITE | 2139.674 ms | 10 - 273 MB | NPU | [PSPNet.tflite](https://huggingface.co/qualcomm/PSPNet/blob/main/PSPNet.tflite) |
37
+ | PSPNet | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | QNN_DLC | 1124.616 ms | 0 - 152 MB | NPU | [PSPNet.dlc](https://huggingface.co/qualcomm/PSPNet/blob/main/PSPNet.dlc) |
38
+ | PSPNet | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | TFLITE | 1724.95 ms | 0 - 48 MB | NPU | [PSPNet.tflite](https://huggingface.co/qualcomm/PSPNet/blob/main/PSPNet.tflite) |
39
+ | PSPNet | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | QNN_DLC | 599.215 ms | 3 - 38 MB | NPU | [PSPNet.dlc](https://huggingface.co/qualcomm/PSPNet/blob/main/PSPNet.dlc) |
40
+ | PSPNet | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | ONNX | 1308.365 ms | 0 - 345 MB | NPU | [PSPNet.onnx.zip](https://huggingface.co/qualcomm/PSPNet/blob/main/PSPNet.onnx.zip) |
41
+ | PSPNet | float | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | TFLITE | 1814.63 ms | 127 - 636 MB | NPU | [PSPNet.tflite](https://huggingface.co/qualcomm/PSPNet/blob/main/PSPNet.tflite) |
42
+ | PSPNet | float | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | QNN_DLC | 647.279 ms | 0 - 463 MB | NPU | [PSPNet.dlc](https://huggingface.co/qualcomm/PSPNet/blob/main/PSPNet.dlc) |
43
+ | PSPNet | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | TFLITE | 1277.954 ms | 0 - 689 MB | NPU | [PSPNet.tflite](https://huggingface.co/qualcomm/PSPNet/blob/main/PSPNet.tflite) |
44
+ | PSPNet | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | QNN_DLC | 476.866 ms | 3 - 528 MB | NPU | [PSPNet.dlc](https://huggingface.co/qualcomm/PSPNet/blob/main/PSPNet.dlc) |
45
+ | PSPNet | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | ONNX | 1003.333 ms | 32 - 418 MB | NPU | [PSPNet.onnx.zip](https://huggingface.co/qualcomm/PSPNet/blob/main/PSPNet.onnx.zip) |
46
+ | PSPNet | float | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | TFLITE | 1251.199 ms | 0 - 507 MB | NPU | [PSPNet.tflite](https://huggingface.co/qualcomm/PSPNet/blob/main/PSPNet.tflite) |
47
+ | PSPNet | float | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | QNN_DLC | 376.561 ms | 0 - 456 MB | NPU | [PSPNet.dlc](https://huggingface.co/qualcomm/PSPNet/blob/main/PSPNet.dlc) |
48
+ | PSPNet | float | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | ONNX | 974.643 ms | 8 - 391 MB | NPU | [PSPNet.onnx.zip](https://huggingface.co/qualcomm/PSPNet/blob/main/PSPNet.onnx.zip) |
49
+ | PSPNet | float | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen5 Mobile | TFLITE | 1311.447 ms | 0 - 520 MB | NPU | [PSPNet.tflite](https://huggingface.co/qualcomm/PSPNet/blob/main/PSPNet.tflite) |
50
+ | PSPNet | float | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen5 Mobile | QNN_DLC | 380.886 ms | 3 - 471 MB | NPU | [PSPNet.dlc](https://huggingface.co/qualcomm/PSPNet/blob/main/PSPNet.dlc) |
51
+ | PSPNet | float | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen5 Mobile | ONNX | 1045.72 ms | 10 - 404 MB | NPU | [PSPNet.onnx.zip](https://huggingface.co/qualcomm/PSPNet/blob/main/PSPNet.onnx.zip) |
52
+ | PSPNet | float | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN_DLC | 600.96 ms | 85 - 85 MB | NPU | [PSPNet.dlc](https://huggingface.co/qualcomm/PSPNet/blob/main/PSPNet.dlc) |
53
+ | PSPNet | float | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 1032.499 ms | 265 - 265 MB | NPU | [PSPNet.onnx.zip](https://huggingface.co/qualcomm/PSPNet/blob/main/PSPNet.onnx.zip) |
54
+
55
+
56
+
57
+
58
+ ## Installation
59
+
60
+
61
+ Install the package via pip:
62
+ ```bash
63
+ pip install qai-hub-models
64
+ ```
65
+
66
+
67
+ ## Configure Qualcomm® AI Hub Workbench to run this model on a cloud-hosted device
68
+
69
+ Sign-in to [Qualcomm® AI Hub Workbench](https://workbench.aihub.qualcomm.com/) with your
70
+ Qualcomm® ID. Once signed in navigate to `Account -> Settings -> API Token`.
71
+
72
+ With this API token, you can configure your client to run models on the cloud
73
+ hosted devices.
74
+ ```bash
75
+ qai-hub configure --api_token API_TOKEN
76
+ ```
77
+ Navigate to [docs](https://workbench.aihub.qualcomm.com/docs/) for more information.
78
+
79
+
80
+
81
+ ## Demo off target
82
+
83
+ The package contains a simple end-to-end demo that downloads pre-trained
84
+ weights and runs this model on a sample input.
85
+
86
+ ```bash
87
+ python -m qai_hub_models.models.pspnet.demo
88
+ ```
89
+
90
+ The above demo runs a reference implementation of pre-processing, model
91
+ inference, and post processing.
92
+
93
+ **NOTE**: If you want running in a Jupyter Notebook or Google Colab like
94
+ environment, please add the following to your cell (instead of the above).
95
+ ```
96
+ %run -m qai_hub_models.models.pspnet.demo
97
+ ```
98
+
99
+
100
+ ### Run model on a cloud-hosted device
101
+
102
+ In addition to the demo, you can also run the model on a cloud-hosted Qualcomm®
103
+ device. This script does the following:
104
+ * Performance check on-device on a cloud-hosted device
105
+ * Downloads compiled assets that can be deployed on-device for Android.
106
+ * Accuracy check between PyTorch and on-device outputs.
107
+
108
+ ```bash
109
+ python -m qai_hub_models.models.pspnet.export
110
+ ```
111
+
112
+
113
+
114
+ ## How does this work?
115
+
116
+ This [export script](https://aihub.qualcomm.com/models/pspnet/qai_hub_models/models/PSPNet/export.py)
117
+ leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
118
+ on-device. Lets go through each step below in detail:
119
+
120
+ Step 1: **Compile model for on-device deployment**
121
+
122
+ To compile a PyTorch model for on-device deployment, we first trace the model
123
+ in memory using the `jit.trace` and then call the `submit_compile_job` API.
124
+
125
+ ```python
126
+ import torch
127
+
128
+ import qai_hub as hub
129
+ from qai_hub_models.models.pspnet import Model
130
+
131
+ # Load the model
132
+ torch_model = Model.from_pretrained()
133
+
134
+ # Device
135
+ device = hub.Device("Samsung Galaxy S25")
136
+
137
+ # Trace model
138
+ input_shape = torch_model.get_input_spec()
139
+ sample_inputs = torch_model.sample_inputs()
140
+
141
+ pt_model = torch.jit.trace(torch_model, [torch.tensor(data[0]) for _, data in sample_inputs.items()])
142
+
143
+ # Compile model on a specific device
144
+ compile_job = hub.submit_compile_job(
145
+ model=pt_model,
146
+ device=device,
147
+ input_specs=torch_model.get_input_spec(),
148
+ )
149
+
150
+ # Get target model to run on-device
151
+ target_model = compile_job.get_target_model()
152
+
153
+ ```
154
+
155
+
156
+ Step 2: **Performance profiling on cloud-hosted device**
157
+
158
+ After compiling models from step 1. Models can be profiled model on-device using the
159
+ `target_model`. Note that this scripts runs the model on a device automatically
160
+ provisioned in the cloud. Once the job is submitted, you can navigate to a
161
+ provided job URL to view a variety of on-device performance metrics.
162
+ ```python
163
+ profile_job = hub.submit_profile_job(
164
+ model=target_model,
165
+ device=device,
166
+ )
167
+
168
+ ```
169
+
170
+ Step 3: **Verify on-device accuracy**
171
+
172
+ To verify the accuracy of the model on-device, you can run on-device inference
173
+ on sample input data on the same cloud hosted device.
174
+ ```python
175
+ input_data = torch_model.sample_inputs()
176
+ inference_job = hub.submit_inference_job(
177
+ model=target_model,
178
+ device=device,
179
+ inputs=input_data,
180
+ )
181
+ on_device_output = inference_job.download_output_data()
182
+
183
+ ```
184
+ With the output of the model, you can compute like PSNR, relative errors or
185
+ spot check the output with expected output.
186
+
187
+ **Note**: This on-device profiling and inference requires access to Qualcomm®
188
+ AI Hub Workbench. [Sign up for access](https://myaccount.qualcomm.com/signup).
189
+
190
+
191
+
192
+ ## Run demo on a cloud-hosted device
193
+
194
+ You can also run the demo on-device.
195
+
196
+ ```bash
197
+ python -m qai_hub_models.models.pspnet.demo --eval-mode on-device
198
+ ```
199
+
200
+ **NOTE**: If you want running in a Jupyter Notebook or Google Colab like
201
+ environment, please add the following to your cell (instead of the above).
202
+ ```
203
+ %run -m qai_hub_models.models.pspnet.demo -- --eval-mode on-device
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 PSPNet's performance across various devices [here](https://aihub.qualcomm.com/models/pspnet).
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 PSPNet can be found
228
+ [here](https://github.com/hszhao/semseg/blob/master/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
+
234
+ ## Community
235
+ * Join [our AI Hub Slack community](https://aihub.qualcomm.com/community/slack) to collaborate, post questions and learn more about on-device AI.
236
+ * For questions or feedback please [reach out to us](mailto:ai-hub-support@qti.qualcomm.com).
237
+
238
+
tool-versions.yaml ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ tool_versions:
2
+ onnx:
3
+ qairt: 2.37.1.250807093845_124904
4
+ onnx_runtime: 1.23.0