qaihm-bot commited on
Commit
764a74f
·
verified ·
1 Parent(s): 7d642a6

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +235 -0
README.md ADDED
@@ -0,0 +1,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_b4/web-assets/model_demo.png)
12
+
13
+ # EfficientNet-B4: Optimized for Mobile Deployment
14
+ ## Imagenet classifier and general purpose backbone
15
+
16
+
17
+ EfficientNetB4 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-B4 found [here](https://github.com/pytorch/vision/blob/main/torchvision/models/efficientnet.py).
20
+
21
+
22
+ This repository provides scripts to run EfficientNet-B4 on Qualcomm® devices.
23
+ More details on model performance across various devices, can be found
24
+ [here](https://aihub.qualcomm.com/models/efficientnet_b4).
25
+
26
+
27
+ ### Model Details
28
+
29
+ - **Model Type:** Image classification
30
+ - **Model Stats:**
31
+ - Model checkpoint: Imagenet
32
+ - Input resolution: 380x380
33
+ - Number of parameters: 19.34M
34
+ - Model size: 74.5 MB
35
+
36
+ | Model | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Precision | Primary Compute Unit | Target Model
37
+ |---|---|---|---|---|---|---|---|---|
38
+ | EfficientNet-B4 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | TFLITE | 3.624 ms | 0 - 3 MB | FP16 | NPU | [EfficientNet-B4.tflite](https://huggingface.co/qualcomm/EfficientNet-B4/blob/main/EfficientNet-B4.tflite) |
39
+ | EfficientNet-B4 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | QNN | 3.726 ms | 0 - 230 MB | FP16 | NPU | [EfficientNet-B4.so](https://huggingface.co/qualcomm/EfficientNet-B4/blob/main/EfficientNet-B4.so) |
40
+ | EfficientNet-B4 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | ONNX | 3.571 ms | 0 - 50 MB | FP16 | NPU | [EfficientNet-B4.onnx](https://huggingface.co/qualcomm/EfficientNet-B4/blob/main/EfficientNet-B4.onnx) |
41
+ | EfficientNet-B4 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | TFLITE | 2.629 ms | 0 - 159 MB | FP16 | NPU | [EfficientNet-B4.tflite](https://huggingface.co/qualcomm/EfficientNet-B4/blob/main/EfficientNet-B4.tflite) |
42
+ | EfficientNet-B4 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | QNN | 2.694 ms | 0 - 27 MB | FP16 | NPU | [EfficientNet-B4.so](https://huggingface.co/qualcomm/EfficientNet-B4/blob/main/EfficientNet-B4.so) |
43
+ | EfficientNet-B4 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | ONNX | 2.589 ms | 0 - 164 MB | FP16 | NPU | [EfficientNet-B4.onnx](https://huggingface.co/qualcomm/EfficientNet-B4/blob/main/EfficientNet-B4.onnx) |
44
+ | EfficientNet-B4 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | TFLITE | 2.106 ms | 0 - 63 MB | FP16 | NPU | [EfficientNet-B4.tflite](https://huggingface.co/qualcomm/EfficientNet-B4/blob/main/EfficientNet-B4.tflite) |
45
+ | EfficientNet-B4 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 2.548 ms | 0 - 25 MB | FP16 | NPU | Use Export Script |
46
+ | EfficientNet-B4 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | ONNX | 2.505 ms | 0 - 68 MB | FP16 | NPU | [EfficientNet-B4.onnx](https://huggingface.co/qualcomm/EfficientNet-B4/blob/main/EfficientNet-B4.onnx) |
47
+ | EfficientNet-B4 | QCS8550 (Proxy) | QCS8550 Proxy | TFLITE | 3.61 ms | 0 - 2 MB | FP16 | NPU | [EfficientNet-B4.tflite](https://huggingface.co/qualcomm/EfficientNet-B4/blob/main/EfficientNet-B4.tflite) |
48
+ | EfficientNet-B4 | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 3.321 ms | 1 - 2 MB | FP16 | NPU | Use Export Script |
49
+ | EfficientNet-B4 | QCS8450 (Proxy) | QCS8450 Proxy | TFLITE | 7.289 ms | 0 - 174 MB | FP16 | NPU | [EfficientNet-B4.tflite](https://huggingface.co/qualcomm/EfficientNet-B4/blob/main/EfficientNet-B4.tflite) |
50
+ | EfficientNet-B4 | QCS8450 (Proxy) | QCS8450 Proxy | QNN | 7.403 ms | 0 - 34 MB | FP16 | NPU | Use Export Script |
51
+ | EfficientNet-B4 | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 3.659 ms | 1 - 1 MB | FP16 | NPU | Use Export Script |
52
+ | EfficientNet-B4 | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 3.728 ms | 47 - 47 MB | FP16 | NPU | [EfficientNet-B4.onnx](https://huggingface.co/qualcomm/EfficientNet-B4/blob/main/EfficientNet-B4.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_b4.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_b4.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_b4.export
109
+ ```
110
+ ```
111
+ Profiling Results
112
+ ------------------------------------------------------------
113
+ EfficientNet-B4
114
+ Device : Samsung Galaxy S23 (13)
115
+ Runtime : TFLITE
116
+ Estimated inference time (ms) : 3.6
117
+ Estimated peak memory usage (MB): [0, 3]
118
+ Total # Ops : 482
119
+ Compute Unit(s) : NPU (482 ops)
120
+ ```
121
+
122
+
123
+ ## How does this work?
124
+
125
+ This [export script](https://aihub.qualcomm.com/models/efficientnet_b4/qai_hub_models/models/EfficientNet-B4/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_b4 import
139
+
140
+ # Load the model
141
+
142
+ # Device
143
+ device = hub.Device("Samsung Galaxy S23")
144
+
145
+
146
+ ```
147
+
148
+
149
+ Step 2: **Performance profiling on cloud-hosted device**
150
+
151
+ After compiling models from step 1. Models can be profiled model on-device using the
152
+ `target_model`. Note that this scripts runs the model on a device automatically
153
+ provisioned in the cloud. Once the job is submitted, you can navigate to a
154
+ provided job URL to view a variety of on-device performance metrics.
155
+ ```python
156
+ profile_job = hub.submit_profile_job(
157
+ model=target_model,
158
+ device=device,
159
+ )
160
+
161
+ ```
162
+
163
+ Step 3: **Verify on-device accuracy**
164
+
165
+ To verify the accuracy of the model on-device, you can run on-device inference
166
+ on sample input data on the same cloud hosted device.
167
+ ```python
168
+ input_data = torch_model.sample_inputs()
169
+ inference_job = hub.submit_inference_job(
170
+ model=target_model,
171
+ device=device,
172
+ inputs=input_data,
173
+ )
174
+ on_device_output = inference_job.download_output_data()
175
+
176
+ ```
177
+ With the output of the model, you can compute like PSNR, relative errors or
178
+ spot check the output with expected output.
179
+
180
+ **Note**: This on-device profiling and inference requires access to Qualcomm®
181
+ AI Hub. [Sign up for access](https://myaccount.qualcomm.com/signup).
182
+
183
+
184
+
185
+ ## Run demo on a cloud-hosted device
186
+
187
+ You can also run the demo on-device.
188
+
189
+ ```bash
190
+ python -m qai_hub_models.models.efficientnet_b4.demo --on-device
191
+ ```
192
+
193
+ **NOTE**: If you want running in a Jupyter Notebook or Google Colab like
194
+ environment, please add the following to your cell (instead of the above).
195
+ ```
196
+ %run -m qai_hub_models.models.efficientnet_b4.demo -- --on-device
197
+ ```
198
+
199
+
200
+ ## Deploying compiled model to Android
201
+
202
+
203
+ The models can be deployed using multiple runtimes:
204
+ - TensorFlow Lite (`.tflite` export): [This
205
+ tutorial](https://www.tensorflow.org/lite/android/quickstart) provides a
206
+ guide to deploy the .tflite model in an Android application.
207
+
208
+
209
+ - QNN (`.so` export ): This [sample
210
+ app](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/sample_app.html)
211
+ provides instructions on how to use the `.so` shared library in an Android application.
212
+
213
+
214
+ ## View on Qualcomm® AI Hub
215
+ Get more details on EfficientNet-B4's performance across various devices [here](https://aihub.qualcomm.com/models/efficientnet_b4).
216
+ Explore all available models on [Qualcomm® AI Hub](https://aihub.qualcomm.com/)
217
+
218
+
219
+ ## License
220
+ * The license for the original implementation of EfficientNet-B4 can be found [here](https://github.com/pytorch/vision/blob/main/LICENSE).
221
+ * 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)
222
+
223
+
224
+
225
+ ## References
226
+ * [EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks](https://arxiv.org/abs/1905.11946)
227
+ * [Source Model Implementation](https://github.com/pytorch/vision/blob/main/torchvision/models/efficientnet.py)
228
+
229
+
230
+
231
+ ## Community
232
+ * Join [our AI Hub Slack community](https://aihub.qualcomm.com/community/slack) to collaborate, post questions and learn more about on-device AI.
233
+ * For questions or feedback please [reach out to us](mailto:[email protected]).
234
+
235
+