qaihm-bot commited on
Commit
101f643
·
verified ·
1 Parent(s): ba44c6e

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +252 -0
README.md ADDED
@@ -0,0 +1,252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: pytorch
3
+ license: cc-by-4.0
4
+ tags:
5
+ - backbone
6
+ - android
7
+ pipeline_tag: video-classification
8
+
9
+ ---
10
+
11
+ ![](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/video_mae/web-assets/model_demo.png)
12
+
13
+ # Video-MAE: Optimized for Mobile Deployment
14
+ ## Sports and human action recognition in videos
15
+
16
+
17
+ Video MAE (Masked Auto Encoder) is a network for doing video classification that uses the ViT (Vision Transformer) backbone.
18
+
19
+ This model is an implementation of Video-MAE found [here](https://github.com/MCG-NJU/VideoMAE).
20
+
21
+
22
+ This repository provides scripts to run Video-MAE on Qualcomm® devices.
23
+ More details on model performance across various devices, can be found
24
+ [here](https://aihub.qualcomm.com/models/video_mae).
25
+
26
+
27
+ ### Model Details
28
+
29
+ - **Model Type:** Video classification
30
+ - **Model Stats:**
31
+ - Model checkpoint: Kinectics-400
32
+ - Input resolution: 224x224
33
+ - Number of parameters: 87.7M
34
+ - Model size: 335 MB
35
+
36
+ | Model | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Precision | Primary Compute Unit | Target Model
37
+ |---|---|---|---|---|---|---|---|---|
38
+ | Video-MAE | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | TFLITE | 208.803 ms | 0 - 40 MB | FP16 | NPU | [Video-MAE.tflite](https://huggingface.co/qualcomm/Video-MAE/blob/main/Video-MAE.tflite) |
39
+ | Video-MAE | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | QNN | 449.531 ms | 9 - 12 MB | FP16 | NPU | [Video-MAE.so](https://huggingface.co/qualcomm/Video-MAE/blob/main/Video-MAE.so) |
40
+ | Video-MAE | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | ONNX | 688.074 ms | 0 - 374 MB | FP16 | NPU | [Video-MAE.onnx](https://huggingface.co/qualcomm/Video-MAE/blob/main/Video-MAE.onnx) |
41
+ | Video-MAE | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | TFLITE | 152.411 ms | 0 - 484 MB | FP16 | NPU | [Video-MAE.tflite](https://huggingface.co/qualcomm/Video-MAE/blob/main/Video-MAE.tflite) |
42
+ | Video-MAE | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | QNN | 370.594 ms | 9 - 29 MB | FP16 | NPU | [Video-MAE.so](https://huggingface.co/qualcomm/Video-MAE/blob/main/Video-MAE.so) |
43
+ | Video-MAE | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | ONNX | 520.976 ms | 9 - 294 MB | FP16 | NPU | [Video-MAE.onnx](https://huggingface.co/qualcomm/Video-MAE/blob/main/Video-MAE.onnx) |
44
+ | Video-MAE | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | TFLITE | 140.087 ms | 0 - 486 MB | FP16 | NPU | [Video-MAE.tflite](https://huggingface.co/qualcomm/Video-MAE/blob/main/Video-MAE.tflite) |
45
+ | Video-MAE | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 363.831 ms | 9 - 424 MB | FP16 | NPU | Use Export Script |
46
+ | Video-MAE | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | ONNX | 625.199 ms | 9 - 300 MB | FP16 | NPU | [Video-MAE.onnx](https://huggingface.co/qualcomm/Video-MAE/blob/main/Video-MAE.onnx) |
47
+ | Video-MAE | SA7255P ADP | SA7255P | TFLITE | 2612.002 ms | 0 - 486 MB | FP16 | NPU | [Video-MAE.tflite](https://huggingface.co/qualcomm/Video-MAE/blob/main/Video-MAE.tflite) |
48
+ | Video-MAE | SA7255P ADP | SA7255P | QNN | 3186.456 ms | 3 - 13 MB | FP16 | NPU | Use Export Script |
49
+ | Video-MAE | SA8255 (Proxy) | SA8255P Proxy | TFLITE | 206.797 ms | 0 - 39 MB | FP16 | NPU | [Video-MAE.tflite](https://huggingface.co/qualcomm/Video-MAE/blob/main/Video-MAE.tflite) |
50
+ | Video-MAE | SA8255 (Proxy) | SA8255P Proxy | QNN | 450.019 ms | 9 - 12 MB | FP16 | NPU | Use Export Script |
51
+ | Video-MAE | SA8295P ADP | SA8295P | TFLITE | 351.185 ms | 0 - 495 MB | FP16 | NPU | [Video-MAE.tflite](https://huggingface.co/qualcomm/Video-MAE/blob/main/Video-MAE.tflite) |
52
+ | Video-MAE | SA8295P ADP | SA8295P | QNN | 668.586 ms | 0 - 17 MB | FP16 | NPU | Use Export Script |
53
+ | Video-MAE | SA8650 (Proxy) | SA8650P Proxy | TFLITE | 208.932 ms | 0 - 38 MB | FP16 | NPU | [Video-MAE.tflite](https://huggingface.co/qualcomm/Video-MAE/blob/main/Video-MAE.tflite) |
54
+ | Video-MAE | SA8650 (Proxy) | SA8650P Proxy | QNN | 449.795 ms | 9 - 12 MB | FP16 | NPU | Use Export Script |
55
+ | Video-MAE | SA8775P ADP | SA8775P | TFLITE | 282.557 ms | 0 - 486 MB | FP16 | NPU | [Video-MAE.tflite](https://huggingface.co/qualcomm/Video-MAE/blob/main/Video-MAE.tflite) |
56
+ | Video-MAE | SA8775P ADP | SA8775P | QNN | 605.641 ms | 9 - 19 MB | FP16 | NPU | Use Export Script |
57
+ | Video-MAE | QCS8275 (Proxy) | QCS8275 Proxy | TFLITE | 2612.002 ms | 0 - 486 MB | FP16 | NPU | [Video-MAE.tflite](https://huggingface.co/qualcomm/Video-MAE/blob/main/Video-MAE.tflite) |
58
+ | Video-MAE | QCS8275 (Proxy) | QCS8275 Proxy | QNN | 3186.456 ms | 3 - 13 MB | FP16 | NPU | Use Export Script |
59
+ | Video-MAE | QCS8550 (Proxy) | QCS8550 Proxy | TFLITE | 208.693 ms | 0 - 42 MB | FP16 | NPU | [Video-MAE.tflite](https://huggingface.co/qualcomm/Video-MAE/blob/main/Video-MAE.tflite) |
60
+ | Video-MAE | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 449.8 ms | 9 - 12 MB | FP16 | NPU | Use Export Script |
61
+ | Video-MAE | QCS9075 (Proxy) | QCS9075 Proxy | TFLITE | 282.557 ms | 0 - 486 MB | FP16 | NPU | [Video-MAE.tflite](https://huggingface.co/qualcomm/Video-MAE/blob/main/Video-MAE.tflite) |
62
+ | Video-MAE | QCS9075 (Proxy) | QCS9075 Proxy | QNN | 605.641 ms | 9 - 19 MB | FP16 | NPU | Use Export Script |
63
+ | Video-MAE | QCS8450 (Proxy) | QCS8450 Proxy | TFLITE | 315.69 ms | 0 - 494 MB | FP16 | NPU | [Video-MAE.tflite](https://huggingface.co/qualcomm/Video-MAE/blob/main/Video-MAE.tflite) |
64
+ | Video-MAE | QCS8450 (Proxy) | QCS8450 Proxy | QNN | 630.074 ms | 9 - 434 MB | FP16 | NPU | Use Export Script |
65
+ | Video-MAE | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 472.11 ms | 9 - 9 MB | FP16 | NPU | Use Export Script |
66
+ | Video-MAE | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 720.056 ms | 187 - 187 MB | FP16 | NPU | [Video-MAE.onnx](https://huggingface.co/qualcomm/Video-MAE/blob/main/Video-MAE.onnx) |
67
+
68
+
69
+
70
+
71
+ ## Installation
72
+
73
+
74
+ Install the package via pip:
75
+ ```bash
76
+ pip install "qai-hub-models[video-mae]"
77
+ ```
78
+
79
+
80
+ ## Configure Qualcomm® AI Hub to run this model on a cloud-hosted device
81
+
82
+ Sign-in to [Qualcomm® AI Hub](https://app.aihub.qualcomm.com/) with your
83
+ Qualcomm® ID. Once signed in navigate to `Account -> Settings -> API Token`.
84
+
85
+ With this API token, you can configure your client to run models on the cloud
86
+ hosted devices.
87
+ ```bash
88
+ qai-hub configure --api_token API_TOKEN
89
+ ```
90
+ Navigate to [docs](https://app.aihub.qualcomm.com/docs/) for more information.
91
+
92
+
93
+
94
+ ## Demo off target
95
+
96
+ The package contains a simple end-to-end demo that downloads pre-trained
97
+ weights and runs this model on a sample input.
98
+
99
+ ```bash
100
+ python -m qai_hub_models.models.video_mae.demo
101
+ ```
102
+
103
+ The above demo runs a reference implementation of pre-processing, model
104
+ inference, and post processing.
105
+
106
+ **NOTE**: If you want running in a Jupyter Notebook or Google Colab like
107
+ environment, please add the following to your cell (instead of the above).
108
+ ```
109
+ %run -m qai_hub_models.models.video_mae.demo
110
+ ```
111
+
112
+
113
+ ### Run model on a cloud-hosted device
114
+
115
+ In addition to the demo, you can also run the model on a cloud-hosted Qualcomm®
116
+ device. This script does the following:
117
+ * Performance check on-device on a cloud-hosted device
118
+ * Downloads compiled assets that can be deployed on-device for Android.
119
+ * Accuracy check between PyTorch and on-device outputs.
120
+
121
+ ```bash
122
+ python -m qai_hub_models.models.video_mae.export
123
+ ```
124
+ ```
125
+ Profiling Results
126
+ ------------------------------------------------------------
127
+ Video-MAE
128
+ Device : Samsung Galaxy S23 (13)
129
+ Runtime : TFLITE
130
+ Estimated inference time (ms) : 208.8
131
+ Estimated peak memory usage (MB): [0, 40]
132
+ Total # Ops : 558
133
+ Compute Unit(s) : NPU (558 ops)
134
+ ```
135
+
136
+
137
+ ## How does this work?
138
+
139
+ This [export script](https://aihub.qualcomm.com/models/video_mae/qai_hub_models/models/Video-MAE/export.py)
140
+ leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
141
+ on-device. Lets go through each step below in detail:
142
+
143
+ Step 1: **Compile model for on-device deployment**
144
+
145
+ To compile a PyTorch model for on-device deployment, we first trace the model
146
+ in memory using the `jit.trace` and then call the `submit_compile_job` API.
147
+
148
+ ```python
149
+ import torch
150
+
151
+ import qai_hub as hub
152
+ from qai_hub_models.models.video_mae import Model
153
+
154
+ # Load the model
155
+ torch_model = Model.from_pretrained()
156
+
157
+ # Device
158
+ device = hub.Device("Samsung Galaxy S24")
159
+
160
+ # Trace model
161
+ input_shape = torch_model.get_input_spec()
162
+ sample_inputs = torch_model.sample_inputs()
163
+
164
+ pt_model = torch.jit.trace(torch_model, [torch.tensor(data[0]) for _, data in sample_inputs.items()])
165
+
166
+ # Compile model on a specific device
167
+ compile_job = hub.submit_compile_job(
168
+ model=pt_model,
169
+ device=device,
170
+ input_specs=torch_model.get_input_spec(),
171
+ )
172
+
173
+ # Get target model to run on-device
174
+ target_model = compile_job.get_target_model()
175
+
176
+ ```
177
+
178
+
179
+ Step 2: **Performance profiling on cloud-hosted device**
180
+
181
+ After compiling models from step 1. Models can be profiled model on-device using the
182
+ `target_model`. Note that this scripts runs the model on a device automatically
183
+ provisioned in the cloud. Once the job is submitted, you can navigate to a
184
+ provided job URL to view a variety of on-device performance metrics.
185
+ ```python
186
+ profile_job = hub.submit_profile_job(
187
+ model=target_model,
188
+ device=device,
189
+ )
190
+
191
+ ```
192
+
193
+ Step 3: **Verify on-device accuracy**
194
+
195
+ To verify the accuracy of the model on-device, you can run on-device inference
196
+ on sample input data on the same cloud hosted device.
197
+ ```python
198
+ input_data = torch_model.sample_inputs()
199
+ inference_job = hub.submit_inference_job(
200
+ model=target_model,
201
+ device=device,
202
+ inputs=input_data,
203
+ )
204
+ on_device_output = inference_job.download_output_data()
205
+
206
+ ```
207
+ With the output of the model, you can compute like PSNR, relative errors or
208
+ spot check the output with expected output.
209
+
210
+ **Note**: This on-device profiling and inference requires access to Qualcomm®
211
+ AI Hub. [Sign up for access](https://myaccount.qualcomm.com/signup).
212
+
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 Video-MAE's performance across various devices [here](https://aihub.qualcomm.com/models/video_mae).
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 Video-MAE can be found
237
+ [here](https://github.com/MCG-NJU/VideoMAE/blob/main/LICENSE).
238
+ * 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)
239
+
240
+
241
+
242
+ ## References
243
+ * [Masked Autoencoders are Data-Efficient Learners for Self-Supervised Video Pre-Training](https://arxiv.org/abs/2203.12602)
244
+ * [Source Model Implementation](https://github.com/MCG-NJU/VideoMAE)
245
+
246
+
247
+
248
+ ## Community
249
+ * Join [our AI Hub Slack community](https://aihub.qualcomm.com/community/slack) to collaborate, post questions and learn more about on-device AI.
250
+ * For questions or feedback please [reach out to us](mailto:[email protected]).
251
+
252
+