qaihm-bot commited on
Commit
c3ba7a6
·
verified ·
1 Parent(s): 58670f1

Upload README.md with huggingface_hub

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