shreyajn commited on
Commit
1cbfac7
·
verified ·
1 Parent(s): 959d6c1

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +214 -0
README.md ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: pytorch
3
+ license: bsd-3-clause
4
+ pipeline_tag: video-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/resnet_mixed/web-assets/model_demo.png)
12
+
13
+ # ResNet-Mixed-Convolution: Optimized for Mobile Deployment
14
+ ## Sports and human action recognition in videos
15
+
16
+
17
+ ResNet Mixed Convolutions is a network with a mixture of 2D and 3D convolutions used for video understanding.
18
+
19
+ This model is an implementation of ResNet-Mixed-Convolution found [here](https://github.com/pytorch/vision/blob/main/torchvision/models/video/resnet.py).
20
+
21
+
22
+ This repository provides scripts to run ResNet-Mixed-Convolution on Qualcomm® devices.
23
+ More details on model performance across various devices, can be found
24
+ [here](https://aihub.qualcomm.com/models/resnet_mixed).
25
+
26
+
27
+ ### Model Details
28
+
29
+ - **Model Type:** Video classification
30
+ - **Model Stats:**
31
+ - Model checkpoint: Kinectics-400
32
+ - Input resolution: 112x112
33
+ - Number of parameters: 11.7M
34
+ - Model size: 44.7 MB
35
+
36
+ | Model | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Precision | Primary Compute Unit | Target Model
37
+ |---|---|---|---|---|---|---|---|---|
38
+
39
+
40
+
41
+
42
+ ## Installation
43
+
44
+ This model can be installed as a Python package via pip.
45
+
46
+ ```bash
47
+ pip install "qai-hub-models[resnet_mixed]"
48
+ ```
49
+
50
+
51
+
52
+ ## Configure Qualcomm® AI Hub to run this model on a cloud-hosted device
53
+
54
+ Sign-in to [Qualcomm® AI Hub](https://app.aihub.qualcomm.com/) with your
55
+ Qualcomm® ID. Once signed in navigate to `Account -> Settings -> API Token`.
56
+
57
+ With this API token, you can configure your client to run models on the cloud
58
+ hosted devices.
59
+ ```bash
60
+ qai-hub configure --api_token API_TOKEN
61
+ ```
62
+ Navigate to [docs](https://app.aihub.qualcomm.com/docs/) for more information.
63
+
64
+
65
+
66
+ ## Demo off target
67
+
68
+ The package contains a simple end-to-end demo that downloads pre-trained
69
+ weights and runs this model on a sample input.
70
+
71
+ ```bash
72
+ python -m qai_hub_models.models.resnet_mixed.demo
73
+ ```
74
+
75
+ The above demo runs a reference implementation of pre-processing, model
76
+ inference, and post processing.
77
+
78
+ **NOTE**: If you want running in a Jupyter Notebook or Google Colab like
79
+ environment, please add the following to your cell (instead of the above).
80
+ ```
81
+ %run -m qai_hub_models.models.resnet_mixed.demo
82
+ ```
83
+
84
+
85
+ ### Run model on a cloud-hosted device
86
+
87
+ In addition to the demo, you can also run the model on a cloud-hosted Qualcomm®
88
+ device. This script does the following:
89
+ * Performance check on-device on a cloud-hosted device
90
+ * Downloads compiled assets that can be deployed on-device for Android.
91
+ * Accuracy check between PyTorch and on-device outputs.
92
+
93
+ ```bash
94
+ python -m qai_hub_models.models.resnet_mixed.export
95
+ ```
96
+ ```
97
+ Profiling Results```
98
+
99
+
100
+ ## How does this work?
101
+
102
+ This [export script](https://aihub.qualcomm.com/models/resnet_mixed/qai_hub_models/models/ResNet-Mixed-Convolution/export.py)
103
+ leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
104
+ on-device. Lets go through each step below in detail:
105
+
106
+ Step 1: **Compile model for on-device deployment**
107
+
108
+ To compile a PyTorch model for on-device deployment, we first trace the model
109
+ in memory using the `jit.trace` and then call the `submit_compile_job` API.
110
+
111
+ ```python
112
+ import torch
113
+
114
+ import qai_hub as hub
115
+ from qai_hub_models.models.resnet_mixed import Model
116
+
117
+ # Load the model
118
+ torch_model = Model.from_pretrained()
119
+
120
+ # Device
121
+ device = hub.Device("Samsung Galaxy S23")
122
+
123
+ # Trace model
124
+ input_shape = torch_model.get_input_spec()
125
+ sample_inputs = torch_model.sample_inputs()
126
+
127
+ pt_model = torch.jit.trace(torch_model, [torch.tensor(data[0]) for _, data in sample_inputs.items()])
128
+
129
+ # Compile model on a specific device
130
+ compile_job = hub.submit_compile_job(
131
+ model=pt_model,
132
+ device=device,
133
+ input_specs=torch_model.get_input_spec(),
134
+ )
135
+
136
+ # Get target model to run on-device
137
+ target_model = compile_job.get_target_model()
138
+
139
+ ```
140
+
141
+
142
+ Step 2: **Performance profiling on cloud-hosted device**
143
+
144
+ After compiling models from step 1. Models can be profiled model on-device using the
145
+ `target_model`. Note that this scripts runs the model on a device automatically
146
+ provisioned in the cloud. Once the job is submitted, you can navigate to a
147
+ provided job URL to view a variety of on-device performance metrics.
148
+ ```python
149
+ profile_job = hub.submit_profile_job(
150
+ model=target_model,
151
+ device=device,
152
+ )
153
+
154
+ ```
155
+
156
+ Step 3: **Verify on-device accuracy**
157
+
158
+ To verify the accuracy of the model on-device, you can run on-device inference
159
+ on sample input data on the same cloud hosted device.
160
+ ```python
161
+ input_data = torch_model.sample_inputs()
162
+ inference_job = hub.submit_inference_job(
163
+ model=target_model,
164
+ device=device,
165
+ inputs=input_data,
166
+ )
167
+ on_device_output = inference_job.download_output_data()
168
+
169
+ ```
170
+ With the output of the model, you can compute like PSNR, relative errors or
171
+ spot check the output with expected output.
172
+
173
+ **Note**: This on-device profiling and inference requires access to Qualcomm®
174
+ AI Hub. [Sign up for access](https://myaccount.qualcomm.com/signup).
175
+
176
+
177
+
178
+
179
+ ## Deploying compiled model to Android
180
+
181
+
182
+ The models can be deployed using multiple runtimes:
183
+ - TensorFlow Lite (`.tflite` export): [This
184
+ tutorial](https://www.tensorflow.org/lite/android/quickstart) provides a
185
+ guide to deploy the .tflite model in an Android application.
186
+
187
+
188
+ - QNN (`.so` export ): This [sample
189
+ app](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/sample_app.html)
190
+ provides instructions on how to use the `.so` shared library in an Android application.
191
+
192
+
193
+ ## View on Qualcomm® AI Hub
194
+ Get more details on ResNet-Mixed-Convolution's performance across various devices [here](https://aihub.qualcomm.com/models/resnet_mixed).
195
+ Explore all available models on [Qualcomm® AI Hub](https://aihub.qualcomm.com/)
196
+
197
+
198
+ ## License
199
+ * The license for the original implementation of ResNet-Mixed-Convolution can be found [here](https://github.com/pytorch/vision/blob/main/LICENSE).
200
+ * 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)
201
+
202
+
203
+
204
+ ## References
205
+ * [A Closer Look at Spatiotemporal Convolutions for Action Recognition](https://arxiv.org/abs/1711.11248)
206
+ * [Source Model Implementation](https://github.com/pytorch/vision/blob/main/torchvision/models/video/resnet.py)
207
+
208
+
209
+
210
+ ## Community
211
+ * Join [our AI Hub Slack community](https://aihub.qualcomm.com/community/slack) to collaborate, post questions and learn more about on-device AI.
212
+ * For questions or feedback please [reach out to us](mailto:[email protected]).
213
+
214
+