qaihm-bot commited on
Commit
2fd35c5
·
verified ·
1 Parent(s): d768541

See https://github.com/quic/ai-hub-models/releases/v0.32.0 for changelog.

Files changed (6) hide show
  1. .gitattributes +1 -0
  2. DEPLOYMENT_MODEL_LICENSE.pdf +3 -0
  3. LICENSE +2 -0
  4. README.md +252 -0
  5. RF-DETR.onnx.zip +3 -0
  6. RF-DETR.tflite +3 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ DEPLOYMENT_MODEL_LICENSE.pdf filter=lfs diff=lfs merge=lfs -text
DEPLOYMENT_MODEL_LICENSE.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4409f93b0e82531303b3e10f52f1fdfb56467a25f05b7441c6bbd8bb8a64b42c
3
+ size 109629
LICENSE ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ The license of the original trained model can be found at https://github.com/roboflow/rf-detr/blob/develop/LICENSE.
2
+ The license for the deployable model files (.tflite, .onnx, .dlc, .bin, etc.) can be found in DEPLOYMENT_MODEL_LICENSE.pdf.
README.md ADDED
@@ -0,0 +1,252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: pytorch
3
+ license: other
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/rf_detr/web-assets/model_demo.png)
11
+
12
+ # RF-DETR: Optimized for Mobile Deployment
13
+ ## Transformer based object detection model architecture developed by Roboflow
14
+
15
+
16
+ DETR is a machine learning model that can detect objects (trained on COCO dataset).
17
+
18
+ This model is an implementation of RF-DETR found [here](https://github.com/roboflow/rf-detr).
19
+
20
+
21
+ This repository provides scripts to run RF-DETR on Qualcomm® devices.
22
+ More details on model performance across various devices, can be found
23
+ [here](https://aihub.qualcomm.com/models/rf_detr).
24
+
25
+
26
+ ### Model Details
27
+
28
+ - **Model Type:** Model_use_case.object_detection
29
+ - **Model Stats:**
30
+ - Model checkpoint: RF-DETR-base
31
+ - Input resolution: 560x560
32
+ - Number of parameters: 29.0M
33
+ - Model size: 116MB
34
+
35
+ | Model | Precision | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Primary Compute Unit | Target Model
36
+ |---|---|---|---|---|---|---|---|---|
37
+ | RF-DETR | float | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | TFLITE | 342.041 ms | 0 - 447 MB | NPU | [RF-DETR.tflite](https://huggingface.co/qualcomm/RF-DETR/blob/main/RF-DETR.tflite) |
38
+ | RF-DETR | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | TFLITE | 210.543 ms | 4 - 427 MB | NPU | [RF-DETR.tflite](https://huggingface.co/qualcomm/RF-DETR/blob/main/RF-DETR.tflite) |
39
+ | RF-DETR | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | TFLITE | 177.646 ms | 7 - 51 MB | NPU | [RF-DETR.tflite](https://huggingface.co/qualcomm/RF-DETR/blob/main/RF-DETR.tflite) |
40
+ | RF-DETR | float | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | TFLITE | 178.364 ms | 3 - 450 MB | NPU | [RF-DETR.tflite](https://huggingface.co/qualcomm/RF-DETR/blob/main/RF-DETR.tflite) |
41
+ | RF-DETR | float | SA7255P ADP | Qualcomm® SA7255P | TFLITE | 342.041 ms | 0 - 447 MB | NPU | [RF-DETR.tflite](https://huggingface.co/qualcomm/RF-DETR/blob/main/RF-DETR.tflite) |
42
+ | RF-DETR | float | SA8255 (Proxy) | Qualcomm® SA8255P (Proxy) | TFLITE | 187.996 ms | 2 - 48 MB | NPU | [RF-DETR.tflite](https://huggingface.co/qualcomm/RF-DETR/blob/main/RF-DETR.tflite) |
43
+ | RF-DETR | float | SA8295P ADP | Qualcomm® SA8295P | TFLITE | 237.79 ms | 4 - 423 MB | NPU | [RF-DETR.tflite](https://huggingface.co/qualcomm/RF-DETR/blob/main/RF-DETR.tflite) |
44
+ | RF-DETR | float | SA8650 (Proxy) | Qualcomm® SA8650P (Proxy) | TFLITE | 186.385 ms | 4 - 51 MB | NPU | [RF-DETR.tflite](https://huggingface.co/qualcomm/RF-DETR/blob/main/RF-DETR.tflite) |
45
+ | RF-DETR | float | SA8775P ADP | Qualcomm® SA8775P | TFLITE | 178.364 ms | 3 - 450 MB | NPU | [RF-DETR.tflite](https://huggingface.co/qualcomm/RF-DETR/blob/main/RF-DETR.tflite) |
46
+ | RF-DETR | float | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 Mobile | TFLITE | 189.682 ms | 4 - 52 MB | NPU | [RF-DETR.tflite](https://huggingface.co/qualcomm/RF-DETR/blob/main/RF-DETR.tflite) |
47
+ | RF-DETR | float | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 Mobile | ONNX | 85.877 ms | 32 - 63 MB | NPU | [RF-DETR.onnx](https://huggingface.co/qualcomm/RF-DETR/blob/main/RF-DETR.onnx) |
48
+ | RF-DETR | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | TFLITE | 132.582 ms | 2 - 454 MB | NPU | [RF-DETR.tflite](https://huggingface.co/qualcomm/RF-DETR/blob/main/RF-DETR.tflite) |
49
+ | RF-DETR | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | ONNX | 66.076 ms | 27 - 405 MB | NPU | [RF-DETR.onnx](https://huggingface.co/qualcomm/RF-DETR/blob/main/RF-DETR.onnx) |
50
+ | RF-DETR | float | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite Mobile | TFLITE | 115.078 ms | 2 - 381 MB | NPU | [RF-DETR.tflite](https://huggingface.co/qualcomm/RF-DETR/blob/main/RF-DETR.tflite) |
51
+ | RF-DETR | float | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite Mobile | ONNX | 53.889 ms | 27 - 341 MB | NPU | [RF-DETR.onnx](https://huggingface.co/qualcomm/RF-DETR/blob/main/RF-DETR.onnx) |
52
+ | RF-DETR | float | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 176.705 ms | 71 - 71 MB | NPU | [RF-DETR.onnx](https://huggingface.co/qualcomm/RF-DETR/blob/main/RF-DETR.onnx) |
53
+
54
+
55
+
56
+
57
+ ## Installation
58
+
59
+
60
+ Install the package via pip:
61
+ ```bash
62
+ pip install "qai-hub-models[rf-detr]"
63
+ ```
64
+
65
+
66
+ ## Configure Qualcomm® AI Hub to run this model on a cloud-hosted device
67
+
68
+ Sign-in to [Qualcomm® AI Hub](https://app.aihub.qualcomm.com/) with your
69
+ Qualcomm® ID. Once signed in navigate to `Account -> Settings -> API Token`.
70
+
71
+ With this API token, you can configure your client to run models on the cloud
72
+ hosted devices.
73
+ ```bash
74
+ qai-hub configure --api_token API_TOKEN
75
+ ```
76
+ Navigate to [docs](https://app.aihub.qualcomm.com/docs/) for more information.
77
+
78
+
79
+
80
+ ## Demo off target
81
+
82
+ The package contains a simple end-to-end demo that downloads pre-trained
83
+ weights and runs this model on a sample input.
84
+
85
+ ```bash
86
+ python -m qai_hub_models.models.rf_detr.demo
87
+ ```
88
+
89
+ The above demo runs a reference implementation of pre-processing, model
90
+ inference, and post processing.
91
+
92
+ **NOTE**: If you want running in a Jupyter Notebook or Google Colab like
93
+ environment, please add the following to your cell (instead of the above).
94
+ ```
95
+ %run -m qai_hub_models.models.rf_detr.demo
96
+ ```
97
+
98
+
99
+ ### Run model on a cloud-hosted device
100
+
101
+ In addition to the demo, you can also run the model on a cloud-hosted Qualcomm®
102
+ device. This script does the following:
103
+ * Performance check on-device on a cloud-hosted device
104
+ * Downloads compiled assets that can be deployed on-device for Android.
105
+ * Accuracy check between PyTorch and on-device outputs.
106
+
107
+ ```bash
108
+ python -m qai_hub_models.models.rf_detr.export
109
+ ```
110
+ ```
111
+ Profiling Results
112
+ ------------------------------------------------------------
113
+ RF-DETR
114
+ Device : cs_8275 (ANDROID 14)
115
+ Runtime : TFLITE
116
+ Estimated inference time (ms) : 342.0
117
+ Estimated peak memory usage (MB): [0, 447]
118
+ Total # Ops : 1230
119
+ Compute Unit(s) : npu (1189 ops) gpu (0 ops) cpu (41 ops)
120
+ ```
121
+
122
+
123
+ ## How does this work?
124
+
125
+ This [export script](https://aihub.qualcomm.com/models/rf_detr/qai_hub_models/models/RF-DETR/export.py)
126
+ leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
127
+ on-device. Lets go through each step below in detail:
128
+
129
+ Step 1: **Compile model for on-device deployment**
130
+
131
+ To compile a PyTorch model for on-device deployment, we first trace the model
132
+ in memory using the `jit.trace` and then call the `submit_compile_job` API.
133
+
134
+ ```python
135
+ import torch
136
+
137
+ import qai_hub as hub
138
+ from qai_hub_models.models.rf_detr import Model
139
+
140
+ # Load the model
141
+ torch_model = Model.from_pretrained()
142
+
143
+ # Device
144
+ device = hub.Device("Samsung Galaxy S24")
145
+
146
+ # Trace model
147
+ input_shape = torch_model.get_input_spec()
148
+ sample_inputs = torch_model.sample_inputs()
149
+
150
+ pt_model = torch.jit.trace(torch_model, [torch.tensor(data[0]) for _, data in sample_inputs.items()])
151
+
152
+ # Compile model on a specific device
153
+ compile_job = hub.submit_compile_job(
154
+ model=pt_model,
155
+ device=device,
156
+ input_specs=torch_model.get_input_spec(),
157
+ )
158
+
159
+ # Get target model to run on-device
160
+ target_model = compile_job.get_target_model()
161
+
162
+ ```
163
+
164
+
165
+ Step 2: **Performance profiling on cloud-hosted device**
166
+
167
+ After compiling models from step 1. Models can be profiled model on-device using the
168
+ `target_model`. Note that this scripts runs the model on a device automatically
169
+ provisioned in the cloud. Once the job is submitted, you can navigate to a
170
+ provided job URL to view a variety of on-device performance metrics.
171
+ ```python
172
+ profile_job = hub.submit_profile_job(
173
+ model=target_model,
174
+ device=device,
175
+ )
176
+
177
+ ```
178
+
179
+ Step 3: **Verify on-device accuracy**
180
+
181
+ To verify the accuracy of the model on-device, you can run on-device inference
182
+ on sample input data on the same cloud hosted device.
183
+ ```python
184
+ input_data = torch_model.sample_inputs()
185
+ inference_job = hub.submit_inference_job(
186
+ model=target_model,
187
+ device=device,
188
+ inputs=input_data,
189
+ )
190
+ on_device_output = inference_job.download_output_data()
191
+
192
+ ```
193
+ With the output of the model, you can compute like PSNR, relative errors or
194
+ spot check the output with expected output.
195
+
196
+ **Note**: This on-device profiling and inference requires access to Qualcomm®
197
+ AI Hub. [Sign up for access](https://myaccount.qualcomm.com/signup).
198
+
199
+
200
+
201
+ ## Run demo on a cloud-hosted device
202
+
203
+ You can also run the demo on-device.
204
+
205
+ ```bash
206
+ python -m qai_hub_models.models.rf_detr.demo --eval-mode on-device
207
+ ```
208
+
209
+ **NOTE**: If you want running in a Jupyter Notebook or Google Colab like
210
+ environment, please add the following to your cell (instead of the above).
211
+ ```
212
+ %run -m qai_hub_models.models.rf_detr.demo -- --eval-mode on-device
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 RF-DETR's performance across various devices [here](https://aihub.qualcomm.com/models/rf_detr).
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 RF-DETR can be found
237
+ [here](https://github.com/roboflow/rf-detr/blob/develop/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
+ * [RF-DETR A SOTA Real-Time Object Detection Model](https://blog.roboflow.com/rf-detr/)
244
+ * [Source Model Implementation](https://github.com/roboflow/rf-detr)
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
+
RF-DETR.onnx.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:be54ea6b1a164a9a070442a3abff4596d3b8aa24149b4e8680fa5393d42e3e81
3
+ size 100208769
RF-DETR.tflite ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:589c4d4dc8c4b37098bdbdd9fbb301a3a5fe974fd737444368c4b8de5268e188
3
+ size 107840916