shreyajn commited on
Commit
2ddd4c2
1 Parent(s): 618d7b5

Upload README.md with huggingface_hub

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