bhushans commited on
Commit
983311f
·
verified ·
1 Parent(s): ff40a7c

Upload README.md with huggingface_hub

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