qaihm-bot commited on
Commit
2a7fd96
·
verified ·
1 Parent(s): 6c94400

Upload README.md with huggingface_hub

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