v0.30.5
Browse filesSee https://github.com/quic/ai-hub-models/releases/v0.30.5 for changelog.
- Mobile-VIT.onnx +3 -0
- Mobile-VIT.tflite +3 -0
- Mobile-VIT_w8a16.onnx +3 -0
- README.md +270 -0
Mobile-VIT.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3d6a762787772c01f48b2558df319fd64c19eeb09c1e3f2294b1f874077d698e
|
3 |
+
size 22448772
|
Mobile-VIT.tflite
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:79dfe96dc20eff22356d4622464a78e2f908d38bffe2951369e954d26df2fd33
|
3 |
+
size 22400324
|
Mobile-VIT_w8a16.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6abc280771a0c3dcd6a07f8ebab46b89682df64fd9f9d65092af00bda5f08c0f
|
3 |
+
size 22899050
|
README.md
ADDED
@@ -0,0 +1,270 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
library_name: pytorch
|
3 |
+
license: other
|
4 |
+
tags:
|
5 |
+
- backbone
|
6 |
+
- android
|
7 |
+
pipeline_tag: image-classification
|
8 |
+
|
9 |
+
---
|
10 |
+
|
11 |
+

|
12 |
+
|
13 |
+
# Mobile-VIT: Optimized for Mobile Deployment
|
14 |
+
## Imagenet classifier and general purpose backbone
|
15 |
+
|
16 |
+
|
17 |
+
MobileVit 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 Mobile-VIT found [here](https://github.com/apple/ml-cvnets).
|
20 |
+
|
21 |
+
|
22 |
+
This repository provides scripts to run Mobile-VIT on Qualcomm® devices.
|
23 |
+
More details on model performance across various devices, can be found
|
24 |
+
[here](https://aihub.qualcomm.com/models/mobile_vit).
|
25 |
+
|
26 |
+
|
27 |
+
### Model Details
|
28 |
+
|
29 |
+
- **Model Type:** Model_use_case.image_classification
|
30 |
+
- **Model Stats:**
|
31 |
+
- Model checkpoint: Imagenet
|
32 |
+
- Input resolution: 224x224
|
33 |
+
- Number of parameters: None
|
34 |
+
- Model size (float): None
|
35 |
+
|
36 |
+
| Model | Precision | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Primary Compute Unit | Target Model
|
37 |
+
|---|---|---|---|---|---|---|---|---|
|
38 |
+
| Mobile-VIT | float | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | TFLITE | 42.749 ms | 0 - 43 MB | NPU | [Mobile-VIT.tflite](https://huggingface.co/qualcomm/Mobile-VIT/blob/main/Mobile-VIT.tflite) |
|
39 |
+
| Mobile-VIT | float | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | QNN | 41.881 ms | 1 - 11 MB | NPU | Use Export Script |
|
40 |
+
| Mobile-VIT | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | TFLITE | 6.725 ms | 0 - 52 MB | NPU | [Mobile-VIT.tflite](https://huggingface.co/qualcomm/Mobile-VIT/blob/main/Mobile-VIT.tflite) |
|
41 |
+
| Mobile-VIT | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | QNN | 6.479 ms | 1 - 48 MB | NPU | Use Export Script |
|
42 |
+
| Mobile-VIT | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | TFLITE | 4.795 ms | 0 - 70 MB | NPU | [Mobile-VIT.tflite](https://huggingface.co/qualcomm/Mobile-VIT/blob/main/Mobile-VIT.tflite) |
|
43 |
+
| Mobile-VIT | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | QNN | 4.334 ms | 1 - 4 MB | NPU | Use Export Script |
|
44 |
+
| Mobile-VIT | float | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | TFLITE | 5.624 ms | 0 - 44 MB | NPU | [Mobile-VIT.tflite](https://huggingface.co/qualcomm/Mobile-VIT/blob/main/Mobile-VIT.tflite) |
|
45 |
+
| Mobile-VIT | float | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | QNN | 5.144 ms | 1 - 12 MB | NPU | Use Export Script |
|
46 |
+
| Mobile-VIT | float | SA7255P ADP | Qualcomm® SA7255P | TFLITE | 42.749 ms | 0 - 43 MB | NPU | [Mobile-VIT.tflite](https://huggingface.co/qualcomm/Mobile-VIT/blob/main/Mobile-VIT.tflite) |
|
47 |
+
| Mobile-VIT | float | SA7255P ADP | Qualcomm® SA7255P | QNN | 41.881 ms | 1 - 11 MB | NPU | Use Export Script |
|
48 |
+
| Mobile-VIT | float | SA8255 (Proxy) | Qualcomm® SA8255P (Proxy) | TFLITE | 4.752 ms | 0 - 69 MB | NPU | [Mobile-VIT.tflite](https://huggingface.co/qualcomm/Mobile-VIT/blob/main/Mobile-VIT.tflite) |
|
49 |
+
| Mobile-VIT | float | SA8255 (Proxy) | Qualcomm® SA8255P (Proxy) | QNN | 4.334 ms | 1 - 3 MB | NPU | Use Export Script |
|
50 |
+
| Mobile-VIT | float | SA8295P ADP | Qualcomm® SA8295P | TFLITE | 7.903 ms | 0 - 42 MB | NPU | [Mobile-VIT.tflite](https://huggingface.co/qualcomm/Mobile-VIT/blob/main/Mobile-VIT.tflite) |
|
51 |
+
| Mobile-VIT | float | SA8295P ADP | Qualcomm® SA8295P | QNN | 7.332 ms | 1 - 17 MB | NPU | Use Export Script |
|
52 |
+
| Mobile-VIT | float | SA8650 (Proxy) | Qualcomm® SA8650P (Proxy) | TFLITE | 4.753 ms | 0 - 71 MB | NPU | [Mobile-VIT.tflite](https://huggingface.co/qualcomm/Mobile-VIT/blob/main/Mobile-VIT.tflite) |
|
53 |
+
| Mobile-VIT | float | SA8650 (Proxy) | Qualcomm® SA8650P (Proxy) | QNN | 4.32 ms | 1 - 3 MB | NPU | Use Export Script |
|
54 |
+
| Mobile-VIT | float | SA8775P ADP | Qualcomm® SA8775P | TFLITE | 5.624 ms | 0 - 44 MB | NPU | [Mobile-VIT.tflite](https://huggingface.co/qualcomm/Mobile-VIT/blob/main/Mobile-VIT.tflite) |
|
55 |
+
| Mobile-VIT | float | SA8775P ADP | Qualcomm® SA8775P | QNN | 5.144 ms | 1 - 12 MB | NPU | Use Export Script |
|
56 |
+
| Mobile-VIT | float | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 Mobile | TFLITE | 4.766 ms | 0 - 70 MB | NPU | [Mobile-VIT.tflite](https://huggingface.co/qualcomm/Mobile-VIT/blob/main/Mobile-VIT.tflite) |
|
57 |
+
| Mobile-VIT | float | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 Mobile | QNN | 4.345 ms | 1 - 13 MB | NPU | Use Export Script |
|
58 |
+
| Mobile-VIT | float | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 Mobile | ONNX | 4.682 ms | 0 - 43 MB | NPU | [Mobile-VIT.onnx](https://huggingface.co/qualcomm/Mobile-VIT/blob/main/Mobile-VIT.onnx) |
|
59 |
+
| Mobile-VIT | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | TFLITE | 3.288 ms | 0 - 55 MB | NPU | [Mobile-VIT.tflite](https://huggingface.co/qualcomm/Mobile-VIT/blob/main/Mobile-VIT.tflite) |
|
60 |
+
| Mobile-VIT | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | QNN | 2.918 ms | 0 - 55 MB | NPU | Use Export Script |
|
61 |
+
| Mobile-VIT | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | ONNX | 3.179 ms | 0 - 63 MB | NPU | [Mobile-VIT.onnx](https://huggingface.co/qualcomm/Mobile-VIT/blob/main/Mobile-VIT.onnx) |
|
62 |
+
| Mobile-VIT | float | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite Mobile | TFLITE | 3.199 ms | 0 - 46 MB | NPU | [Mobile-VIT.tflite](https://huggingface.co/qualcomm/Mobile-VIT/blob/main/Mobile-VIT.tflite) |
|
63 |
+
| Mobile-VIT | float | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite Mobile | QNN | 2.804 ms | 1 - 50 MB | NPU | Use Export Script |
|
64 |
+
| Mobile-VIT | float | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite Mobile | ONNX | 2.547 ms | 0 - 51 MB | NPU | [Mobile-VIT.onnx](https://huggingface.co/qualcomm/Mobile-VIT/blob/main/Mobile-VIT.onnx) |
|
65 |
+
| Mobile-VIT | float | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 4.718 ms | 1 - 1 MB | NPU | Use Export Script |
|
66 |
+
| Mobile-VIT | float | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 5.012 ms | 12 - 12 MB | NPU | [Mobile-VIT.onnx](https://huggingface.co/qualcomm/Mobile-VIT/blob/main/Mobile-VIT.onnx) |
|
67 |
+
| Mobile-VIT | w8a16 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 Mobile | ONNX | 13.426 ms | 16 - 65 MB | NPU | [Mobile-VIT.onnx](https://huggingface.co/qualcomm/Mobile-VIT/blob/main/Mobile-VIT_w8a16.onnx) |
|
68 |
+
| Mobile-VIT | w8a16 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | ONNX | 9.98 ms | 17 - 159 MB | NPU | [Mobile-VIT.onnx](https://huggingface.co/qualcomm/Mobile-VIT/blob/main/Mobile-VIT_w8a16.onnx) |
|
69 |
+
| Mobile-VIT | w8a16 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite Mobile | ONNX | 8.743 ms | 16 - 131 MB | NPU | [Mobile-VIT.onnx](https://huggingface.co/qualcomm/Mobile-VIT/blob/main/Mobile-VIT_w8a16.onnx) |
|
70 |
+
| Mobile-VIT | w8a16 | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 13.048 ms | 29 - 29 MB | NPU | [Mobile-VIT.onnx](https://huggingface.co/qualcomm/Mobile-VIT/blob/main/Mobile-VIT_w8a16.onnx) |
|
71 |
+
|
72 |
+
|
73 |
+
|
74 |
+
|
75 |
+
## Installation
|
76 |
+
|
77 |
+
|
78 |
+
Install the package via pip:
|
79 |
+
```bash
|
80 |
+
pip install "qai-hub-models[mobile-vit]"
|
81 |
+
```
|
82 |
+
|
83 |
+
|
84 |
+
## Configure Qualcomm® AI Hub to run this model on a cloud-hosted device
|
85 |
+
|
86 |
+
Sign-in to [Qualcomm® AI Hub](https://app.aihub.qualcomm.com/) with your
|
87 |
+
Qualcomm® ID. Once signed in navigate to `Account -> Settings -> API Token`.
|
88 |
+
|
89 |
+
With this API token, you can configure your client to run models on the cloud
|
90 |
+
hosted devices.
|
91 |
+
```bash
|
92 |
+
qai-hub configure --api_token API_TOKEN
|
93 |
+
```
|
94 |
+
Navigate to [docs](https://app.aihub.qualcomm.com/docs/) for more information.
|
95 |
+
|
96 |
+
|
97 |
+
|
98 |
+
## Demo off target
|
99 |
+
|
100 |
+
The package contains a simple end-to-end demo that downloads pre-trained
|
101 |
+
weights and runs this model on a sample input.
|
102 |
+
|
103 |
+
```bash
|
104 |
+
python -m qai_hub_models.models.mobile_vit.demo
|
105 |
+
```
|
106 |
+
|
107 |
+
The above demo runs a reference implementation of pre-processing, model
|
108 |
+
inference, and post processing.
|
109 |
+
|
110 |
+
**NOTE**: If you want running in a Jupyter Notebook or Google Colab like
|
111 |
+
environment, please add the following to your cell (instead of the above).
|
112 |
+
```
|
113 |
+
%run -m qai_hub_models.models.mobile_vit.demo
|
114 |
+
```
|
115 |
+
|
116 |
+
|
117 |
+
### Run model on a cloud-hosted device
|
118 |
+
|
119 |
+
In addition to the demo, you can also run the model on a cloud-hosted Qualcomm®
|
120 |
+
device. This script does the following:
|
121 |
+
* Performance check on-device on a cloud-hosted device
|
122 |
+
* Downloads compiled assets that can be deployed on-device for Android.
|
123 |
+
* Accuracy check between PyTorch and on-device outputs.
|
124 |
+
|
125 |
+
```bash
|
126 |
+
python -m qai_hub_models.models.mobile_vit.export
|
127 |
+
```
|
128 |
+
```
|
129 |
+
Profiling Results
|
130 |
+
------------------------------------------------------------
|
131 |
+
Mobile-VIT
|
132 |
+
Device : cs_8275 (ANDROID 14)
|
133 |
+
Runtime : TFLITE
|
134 |
+
Estimated inference time (ms) : 42.7
|
135 |
+
Estimated peak memory usage (MB): [0, 43]
|
136 |
+
Total # Ops : 577
|
137 |
+
Compute Unit(s) : npu (577 ops) gpu (0 ops) cpu (0 ops)
|
138 |
+
```
|
139 |
+
|
140 |
+
|
141 |
+
## How does this work?
|
142 |
+
|
143 |
+
This [export script](https://aihub.qualcomm.com/models/mobile_vit/qai_hub_models/models/Mobile-VIT/export.py)
|
144 |
+
leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
|
145 |
+
on-device. Lets go through each step below in detail:
|
146 |
+
|
147 |
+
Step 1: **Compile model for on-device deployment**
|
148 |
+
|
149 |
+
To compile a PyTorch model for on-device deployment, we first trace the model
|
150 |
+
in memory using the `jit.trace` and then call the `submit_compile_job` API.
|
151 |
+
|
152 |
+
```python
|
153 |
+
import torch
|
154 |
+
|
155 |
+
import qai_hub as hub
|
156 |
+
from qai_hub_models.models.mobile_vit import Model
|
157 |
+
|
158 |
+
# Load the model
|
159 |
+
torch_model = Model.from_pretrained()
|
160 |
+
|
161 |
+
# Device
|
162 |
+
device = hub.Device("Samsung Galaxy S24")
|
163 |
+
|
164 |
+
# Trace model
|
165 |
+
input_shape = torch_model.get_input_spec()
|
166 |
+
sample_inputs = torch_model.sample_inputs()
|
167 |
+
|
168 |
+
pt_model = torch.jit.trace(torch_model, [torch.tensor(data[0]) for _, data in sample_inputs.items()])
|
169 |
+
|
170 |
+
# Compile model on a specific device
|
171 |
+
compile_job = hub.submit_compile_job(
|
172 |
+
model=pt_model,
|
173 |
+
device=device,
|
174 |
+
input_specs=torch_model.get_input_spec(),
|
175 |
+
)
|
176 |
+
|
177 |
+
# Get target model to run on-device
|
178 |
+
target_model = compile_job.get_target_model()
|
179 |
+
|
180 |
+
```
|
181 |
+
|
182 |
+
|
183 |
+
Step 2: **Performance profiling on cloud-hosted device**
|
184 |
+
|
185 |
+
After compiling models from step 1. Models can be profiled model on-device using the
|
186 |
+
`target_model`. Note that this scripts runs the model on a device automatically
|
187 |
+
provisioned in the cloud. Once the job is submitted, you can navigate to a
|
188 |
+
provided job URL to view a variety of on-device performance metrics.
|
189 |
+
```python
|
190 |
+
profile_job = hub.submit_profile_job(
|
191 |
+
model=target_model,
|
192 |
+
device=device,
|
193 |
+
)
|
194 |
+
|
195 |
+
```
|
196 |
+
|
197 |
+
Step 3: **Verify on-device accuracy**
|
198 |
+
|
199 |
+
To verify the accuracy of the model on-device, you can run on-device inference
|
200 |
+
on sample input data on the same cloud hosted device.
|
201 |
+
```python
|
202 |
+
input_data = torch_model.sample_inputs()
|
203 |
+
inference_job = hub.submit_inference_job(
|
204 |
+
model=target_model,
|
205 |
+
device=device,
|
206 |
+
inputs=input_data,
|
207 |
+
)
|
208 |
+
on_device_output = inference_job.download_output_data()
|
209 |
+
|
210 |
+
```
|
211 |
+
With the output of the model, you can compute like PSNR, relative errors or
|
212 |
+
spot check the output with expected output.
|
213 |
+
|
214 |
+
**Note**: This on-device profiling and inference requires access to Qualcomm®
|
215 |
+
AI Hub. [Sign up for access](https://myaccount.qualcomm.com/signup).
|
216 |
+
|
217 |
+
|
218 |
+
|
219 |
+
## Run demo on a cloud-hosted device
|
220 |
+
|
221 |
+
You can also run the demo on-device.
|
222 |
+
|
223 |
+
```bash
|
224 |
+
python -m qai_hub_models.models.mobile_vit.demo --eval-mode on-device
|
225 |
+
```
|
226 |
+
|
227 |
+
**NOTE**: If you want running in a Jupyter Notebook or Google Colab like
|
228 |
+
environment, please add the following to your cell (instead of the above).
|
229 |
+
```
|
230 |
+
%run -m qai_hub_models.models.mobile_vit.demo -- --eval-mode on-device
|
231 |
+
```
|
232 |
+
|
233 |
+
|
234 |
+
## Deploying compiled model to Android
|
235 |
+
|
236 |
+
|
237 |
+
The models can be deployed using multiple runtimes:
|
238 |
+
- TensorFlow Lite (`.tflite` export): [This
|
239 |
+
tutorial](https://www.tensorflow.org/lite/android/quickstart) provides a
|
240 |
+
guide to deploy the .tflite model in an Android application.
|
241 |
+
|
242 |
+
|
243 |
+
- QNN (`.so` export ): This [sample
|
244 |
+
app](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/sample_app.html)
|
245 |
+
provides instructions on how to use the `.so` shared library in an Android application.
|
246 |
+
|
247 |
+
|
248 |
+
## View on Qualcomm® AI Hub
|
249 |
+
Get more details on Mobile-VIT's performance across various devices [here](https://aihub.qualcomm.com/models/mobile_vit).
|
250 |
+
Explore all available models on [Qualcomm® AI Hub](https://aihub.qualcomm.com/)
|
251 |
+
|
252 |
+
|
253 |
+
## License
|
254 |
+
* The license for the original implementation of Mobile-VIT can be found
|
255 |
+
[here](https://github.com/pytorch/vision/blob/main/LICENSE).
|
256 |
+
* 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)
|
257 |
+
|
258 |
+
|
259 |
+
|
260 |
+
## References
|
261 |
+
* [MOBILEVIT: LIGHT-WEIGHT, GENERAL-PURPOSE, AND MOBILE-FRIENDLY VISION TRANSFORMER](https://arxiv.org/abs/2110.02178)
|
262 |
+
* [Source Model Implementation](https://github.com/apple/ml-cvnets)
|
263 |
+
|
264 |
+
|
265 |
+
|
266 |
+
## Community
|
267 |
+
* Join [our AI Hub Slack community](https://aihub.qualcomm.com/community/slack) to collaborate, post questions and learn more about on-device AI.
|
268 |
+
* For questions or feedback please [reach out to us](mailto:[email protected]).
|
269 |
+
|
270 |
+
|