qaihm-bot commited on
Commit
45f5a12
·
verified ·
1 Parent(s): 0f5475e

Upload README.md with huggingface_hub

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