qaihm-bot commited on
Commit
034a359
·
verified ·
1 Parent(s): ceb7823

Upload README.md with huggingface_hub

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