qaihm-bot commited on
Commit
d154217
1 Parent(s): 9c2646a

Upload README.md with huggingface_hub

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