qaihm-bot commited on
Commit
576684b
·
verified ·
1 Parent(s): dc7e17a

See https://github.com/quic/ai-hub-models/releases/v0.42.0 for changelog.

.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ DEPLOYMENT_MODEL_LICENSE.pdf filter=lfs diff=lfs merge=lfs -text
37
+ SwinV2-Base_float.dlc filter=lfs diff=lfs merge=lfs -text
DEPLOYMENT_MODEL_LICENSE.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4409f93b0e82531303b3e10f52f1fdfb56467a25f05b7441c6bbd8bb8a64b42c
3
+ size 109629
LICENSE ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ The license of the original trained model can be found at https://github.com/pytorch/vision/blob/main/LICENSE.
2
+ The license for the deployable model files (.tflite, .onnx, .dlc, .bin, etc.) can be found in DEPLOYMENT_MODEL_LICENSE.pdf.
README.md ADDED
@@ -0,0 +1,254 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: pytorch
3
+ license: other
4
+ tags:
5
+ - backbone
6
+ - android
7
+ pipeline_tag: image-classification
8
+
9
+ ---
10
+
11
+ ![](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/swinv2_base/web-assets/model_demo.png)
12
+
13
+ # SwinV2-Base: Optimized for Mobile Deployment
14
+ ## Imagenet classifier and general purpose backbone
15
+
16
+
17
+ SwinV2Base 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 SwinV2-Base found [here](https://github.com/pytorch/vision/blob/main/torchvision/models/swin_transformer.py).
20
+
21
+
22
+ This repository provides scripts to run SwinV2-Base on Qualcomm® devices.
23
+ More details on model performance across various devices, can be found
24
+ [here](https://aihub.qualcomm.com/models/swinv2_base).
25
+
26
+
27
+
28
+ ### Model Details
29
+
30
+ - **Model Type:** Model_use_case.image_classification
31
+ - **Model Stats:**
32
+ - Model checkpoint: Imagenet
33
+ - Input resolution: 256x256
34
+ - Number of parameters: 88.8M
35
+ - Model size (float): 339 MB
36
+ - Model size (w8a16): 90.2 MB
37
+
38
+ | Model | Precision | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Primary Compute Unit | Target Model
39
+ |---|---|---|---|---|---|---|---|---|
40
+ | SwinV2-Base | float | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | TFLITE | 85.729 ms | 0 - 399 MB | NPU | [SwinV2-Base.tflite](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.tflite) |
41
+ | SwinV2-Base | float | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | QNN_DLC | 69.336 ms | 1 - 378 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) |
42
+ | SwinV2-Base | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | TFLITE | 43.52 ms | 0 - 503 MB | NPU | [SwinV2-Base.tflite](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.tflite) |
43
+ | SwinV2-Base | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | QNN_DLC | 39.262 ms | 1 - 368 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) |
44
+ | SwinV2-Base | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | TFLITE | 37.263 ms | 0 - 36 MB | NPU | [SwinV2-Base.tflite](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.tflite) |
45
+ | SwinV2-Base | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | QNN_DLC | 28.244 ms | 0 - 53 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) |
46
+ | SwinV2-Base | float | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | TFLITE | 41.214 ms | 0 - 399 MB | NPU | [SwinV2-Base.tflite](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.tflite) |
47
+ | SwinV2-Base | float | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | QNN_DLC | 144.249 ms | 1 - 407 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) |
48
+ | SwinV2-Base | float | SA7255P ADP | Qualcomm® SA7255P | TFLITE | 85.729 ms | 0 - 399 MB | NPU | [SwinV2-Base.tflite](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.tflite) |
49
+ | SwinV2-Base | float | SA7255P ADP | Qualcomm® SA7255P | QNN_DLC | 69.336 ms | 1 - 378 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) |
50
+ | SwinV2-Base | float | SA8255 (Proxy) | Qualcomm® SA8255P (Proxy) | TFLITE | 37.27 ms | 0 - 31 MB | NPU | [SwinV2-Base.tflite](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.tflite) |
51
+ | SwinV2-Base | float | SA8255 (Proxy) | Qualcomm® SA8255P (Proxy) | QNN_DLC | 28.125 ms | 0 - 37 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) |
52
+ | SwinV2-Base | float | SA8295P ADP | Qualcomm® SA8295P | TFLITE | 49.6 ms | 0 - 376 MB | NPU | [SwinV2-Base.tflite](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.tflite) |
53
+ | SwinV2-Base | float | SA8295P ADP | Qualcomm® SA8295P | QNN_DLC | 38.959 ms | 1 - 368 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) |
54
+ | SwinV2-Base | float | SA8650 (Proxy) | Qualcomm® SA8650P (Proxy) | TFLITE | 37.581 ms | 0 - 34 MB | NPU | [SwinV2-Base.tflite](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.tflite) |
55
+ | SwinV2-Base | float | SA8650 (Proxy) | Qualcomm® SA8650P (Proxy) | QNN_DLC | 28.012 ms | 0 - 58 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) |
56
+ | SwinV2-Base | float | SA8775P ADP | Qualcomm® SA8775P | TFLITE | 41.214 ms | 0 - 399 MB | NPU | [SwinV2-Base.tflite](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.tflite) |
57
+ | SwinV2-Base | float | SA8775P ADP | Qualcomm® SA8775P | QNN_DLC | 144.249 ms | 1 - 407 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) |
58
+ | SwinV2-Base | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | TFLITE | 25.758 ms | 0 - 396 MB | NPU | [SwinV2-Base.tflite](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.tflite) |
59
+ | SwinV2-Base | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | QNN_DLC | 19.517 ms | 0 - 380 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) |
60
+ | SwinV2-Base | float | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | TFLITE | 21.025 ms | 0 - 391 MB | NPU | [SwinV2-Base.tflite](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.tflite) |
61
+ | SwinV2-Base | float | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | QNN_DLC | 15.165 ms | 0 - 378 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) |
62
+ | SwinV2-Base | float | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen5 Mobile | TFLITE | 18.056 ms | 0 - 390 MB | NPU | [SwinV2-Base.tflite](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.tflite) |
63
+ | SwinV2-Base | float | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen5 Mobile | QNN_DLC | 11.895 ms | 1 - 389 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) |
64
+ | SwinV2-Base | float | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN_DLC | 29.222 ms | 1033 - 1033 MB | NPU | [SwinV2-Base.dlc](https://huggingface.co/qualcomm/SwinV2-Base/blob/main/SwinV2-Base.dlc) |
65
+
66
+
67
+
68
+
69
+ ## Installation
70
+
71
+
72
+ Install the package via pip:
73
+ ```bash
74
+ pip install qai-hub-models
75
+ ```
76
+
77
+
78
+ ## Configure Qualcomm® AI Hub Workbench to run this model on a cloud-hosted device
79
+
80
+ Sign-in to [Qualcomm® AI Hub Workbench](https://workbench.aihub.qualcomm.com/) with your
81
+ Qualcomm® ID. Once signed in navigate to `Account -> Settings -> API Token`.
82
+
83
+ With this API token, you can configure your client to run models on the cloud
84
+ hosted devices.
85
+ ```bash
86
+ qai-hub configure --api_token API_TOKEN
87
+ ```
88
+ Navigate to [docs](https://workbench.aihub.qualcomm.com/docs/) for more information.
89
+
90
+
91
+
92
+ ## Demo off target
93
+
94
+ The package contains a simple end-to-end demo that downloads pre-trained
95
+ weights and runs this model on a sample input.
96
+
97
+ ```bash
98
+ python -m qai_hub_models.models.swinv2_base.demo
99
+ ```
100
+
101
+ The above demo runs a reference implementation of pre-processing, model
102
+ inference, and post processing.
103
+
104
+ **NOTE**: If you want running in a Jupyter Notebook or Google Colab like
105
+ environment, please add the following to your cell (instead of the above).
106
+ ```
107
+ %run -m qai_hub_models.models.swinv2_base.demo
108
+ ```
109
+
110
+
111
+ ### Run model on a cloud-hosted device
112
+
113
+ In addition to the demo, you can also run the model on a cloud-hosted Qualcomm®
114
+ device. This script does the following:
115
+ * Performance check on-device on a cloud-hosted device
116
+ * Downloads compiled assets that can be deployed on-device for Android.
117
+ * Accuracy check between PyTorch and on-device outputs.
118
+
119
+ ```bash
120
+ python -m qai_hub_models.models.swinv2_base.export
121
+ ```
122
+
123
+
124
+
125
+ ## How does this work?
126
+
127
+ This [export script](https://aihub.qualcomm.com/models/swinv2_base/qai_hub_models/models/SwinV2-Base/export.py)
128
+ leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
129
+ on-device. Lets go through each step below in detail:
130
+
131
+ Step 1: **Compile model for on-device deployment**
132
+
133
+ To compile a PyTorch model for on-device deployment, we first trace the model
134
+ in memory using the `jit.trace` and then call the `submit_compile_job` API.
135
+
136
+ ```python
137
+ import torch
138
+
139
+ import qai_hub as hub
140
+ from qai_hub_models.models.swinv2_base import Model
141
+
142
+ # Load the model
143
+ torch_model = Model.from_pretrained()
144
+
145
+ # Device
146
+ device = hub.Device("Samsung Galaxy S25")
147
+
148
+ # Trace model
149
+ input_shape = torch_model.get_input_spec()
150
+ sample_inputs = torch_model.sample_inputs()
151
+
152
+ pt_model = torch.jit.trace(torch_model, [torch.tensor(data[0]) for _, data in sample_inputs.items()])
153
+
154
+ # Compile model on a specific device
155
+ compile_job = hub.submit_compile_job(
156
+ model=pt_model,
157
+ device=device,
158
+ input_specs=torch_model.get_input_spec(),
159
+ )
160
+
161
+ # Get target model to run on-device
162
+ target_model = compile_job.get_target_model()
163
+
164
+ ```
165
+
166
+
167
+ Step 2: **Performance profiling on cloud-hosted device**
168
+
169
+ After compiling models from step 1. Models can be profiled model on-device using the
170
+ `target_model`. Note that this scripts runs the model on a device automatically
171
+ provisioned in the cloud. Once the job is submitted, you can navigate to a
172
+ provided job URL to view a variety of on-device performance metrics.
173
+ ```python
174
+ profile_job = hub.submit_profile_job(
175
+ model=target_model,
176
+ device=device,
177
+ )
178
+
179
+ ```
180
+
181
+ Step 3: **Verify on-device accuracy**
182
+
183
+ To verify the accuracy of the model on-device, you can run on-device inference
184
+ on sample input data on the same cloud hosted device.
185
+ ```python
186
+ input_data = torch_model.sample_inputs()
187
+ inference_job = hub.submit_inference_job(
188
+ model=target_model,
189
+ device=device,
190
+ inputs=input_data,
191
+ )
192
+ on_device_output = inference_job.download_output_data()
193
+
194
+ ```
195
+ With the output of the model, you can compute like PSNR, relative errors or
196
+ spot check the output with expected output.
197
+
198
+ **Note**: This on-device profiling and inference requires access to Qualcomm®
199
+ AI Hub Workbench. [Sign up for access](https://myaccount.qualcomm.com/signup).
200
+
201
+
202
+
203
+ ## Run demo on a cloud-hosted device
204
+
205
+ You can also run the demo on-device.
206
+
207
+ ```bash
208
+ python -m qai_hub_models.models.swinv2_base.demo --eval-mode on-device
209
+ ```
210
+
211
+ **NOTE**: If you want running in a Jupyter Notebook or Google Colab like
212
+ environment, please add the following to your cell (instead of the above).
213
+ ```
214
+ %run -m qai_hub_models.models.swinv2_base.demo -- --eval-mode on-device
215
+ ```
216
+
217
+
218
+ ## Deploying compiled model to Android
219
+
220
+
221
+ The models can be deployed using multiple runtimes:
222
+ - TensorFlow Lite (`.tflite` export): [This
223
+ tutorial](https://www.tensorflow.org/lite/android/quickstart) provides a
224
+ guide to deploy the .tflite model in an Android application.
225
+
226
+
227
+ - QNN (`.so` export ): This [sample
228
+ app](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/sample_app.html)
229
+ provides instructions on how to use the `.so` shared library in an Android application.
230
+
231
+
232
+ ## View on Qualcomm® AI Hub
233
+ Get more details on SwinV2-Base's performance across various devices [here](https://aihub.qualcomm.com/models/swinv2_base).
234
+ Explore all available models on [Qualcomm® AI Hub](https://aihub.qualcomm.com/)
235
+
236
+
237
+ ## License
238
+ * The license for the original implementation of SwinV2-Base can be found
239
+ [here](https://github.com/pytorch/vision/blob/main/LICENSE).
240
+ * 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)
241
+
242
+
243
+
244
+ ## References
245
+ * [Swin Transformer V2: Scaling Up Capacity and Resolution](https://arxiv.org/abs/2111.09883)
246
+ * [Source Model Implementation](https://github.com/pytorch/vision/blob/main/torchvision/models/swin_transformer.py)
247
+
248
+
249
+
250
+ ## Community
251
+ * Join [our AI Hub Slack community](https://aihub.qualcomm.com/community/slack) to collaborate, post questions and learn more about on-device AI.
252
+ * For questions or feedback please [reach out to us](mailto:ai-hub-support@qti.qualcomm.com).
253
+
254
+
SwinV2-Base_float.dlc ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:91a3c1908cfd7bd91e6fb2e1be6d327fc755045f7fddf5560a7e09889dd3b582
3
+ size 359463044
SwinV2-Base_float.tflite ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:413a52eff1da1c1a7b2815310ea8439c77154c4b754c2b31f953f635382dee70
3
+ size 361828916
tool-versions.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ tool_versions:
2
+ qnn_dlc:
3
+ qairt: 2.40.0.251030114326_189385