bhushans commited on
Commit
24b307a
·
verified ·
1 Parent(s): 9a3d68c

Upload README.md with huggingface_hub

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