qaihm-bot commited on
Commit
dc1bcb4
1 Parent(s): d577104

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +222 -0
README.md ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ datasets:
3
+ - COCO
4
+ library_name: pytorch
5
+ license: apache-2.0
6
+ pipeline_tag: object-detection
7
+ tags:
8
+ - real_time
9
+ - quantized
10
+ - android
11
+
12
+ ---
13
+
14
+ ![](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/yolonas_quantized/web-assets/model_demo.png)
15
+
16
+ # Yolo-NAS-Quantized: Optimized for Mobile Deployment
17
+ ## Quantized real-time object detection optimized for mobile and edge
18
+
19
+ YoloNAS is a machine learning model that predicts bounding boxes and classes of objects in an image. This model is post-training quantized to int8 using samples from the COCO dataset.
20
+
21
+ This model is an implementation of Yolo-NAS-Quantized found [here](https://github.com/Deci-AI/super-gradients).
22
+ This repository provides scripts to run Yolo-NAS-Quantized on Qualcomm® devices.
23
+ More details on model performance across various devices, can be found
24
+ [here](https://aihub.qualcomm.com/models/yolonas_quantized).
25
+
26
+
27
+ ### Model Details
28
+
29
+ - **Model Type:** Object detection
30
+ - **Model Stats:**
31
+ - Model checkpoint: YoloNAS Small
32
+ - Input resolution: 640x640
33
+ - Number of parameters: 12.2M
34
+ - Model size: 12.1 MB
35
+
36
+
37
+ | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Precision | Primary Compute Unit | Target Model
38
+ | ---|---|---|---|---|---|---|---|
39
+ | Samsung Galaxy S23 Ultra (Android 13) | Snapdragon® 8 Gen 2 | TFLite | 6.961 ms | 9 - 12 MB | INT8 | NPU | [Yolo-NAS-Quantized.tflite](https://huggingface.co/qualcomm/Yolo-NAS-Quantized/blob/main/Yolo-NAS-Quantized.tflite)
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[yolonas_quantized]"
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.yolonas_quantized.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.yolonas_quantized.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.yolonas_quantized.export
95
+ ```
96
+
97
+ ## How does this work?
98
+
99
+ This [export script](https://github.com/quic/ai-hub-models/blob/main/qai_hub_models/models/Yolo-NAS-Quantized/export.py)
100
+ leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
101
+ on-device. Lets go through each step below in detail:
102
+
103
+ Step 1: **Compile model for on-device deployment**
104
+
105
+ To compile a PyTorch model for on-device deployment, we first trace the model
106
+ in memory using the `jit.trace` and then call the `submit_compile_job` API.
107
+
108
+ ```python
109
+ import torch
110
+
111
+ import qai_hub as hub
112
+ from qai_hub_models.models.yolonas_quantized import Model
113
+
114
+ # Load the model
115
+ torch_model = Model.from_pretrained()
116
+ torch_model.eval()
117
+
118
+ # Device
119
+ device = hub.Device("Samsung Galaxy S23")
120
+
121
+ # Trace model
122
+ input_shape = torch_model.get_input_spec()
123
+ sample_inputs = torch_model.sample_inputs()
124
+
125
+ pt_model = torch.jit.trace(torch_model, [torch.tensor(data[0]) for _, data in sample_inputs.items()])
126
+
127
+ # Compile model on a specific device
128
+ compile_job = hub.submit_compile_job(
129
+ model=pt_model,
130
+ device=device,
131
+ input_specs=torch_model.get_input_spec(),
132
+ )
133
+
134
+ # Get target model to run on-device
135
+ target_model = compile_job.get_target_model()
136
+
137
+ ```
138
+
139
+
140
+ Step 2: **Performance profiling on cloud-hosted device**
141
+
142
+ After compiling models from step 1. Models can be profiled model on-device using the
143
+ `target_model`. Note that this scripts runs the model on a device automatically
144
+ provisioned in the cloud. Once the job is submitted, you can navigate to a
145
+ provided job URL to view a variety of on-device performance metrics.
146
+ ```python
147
+ profile_job = hub.submit_profile_job(
148
+ model=target_model,
149
+ device=device,
150
+ )
151
+
152
+ ```
153
+
154
+ Step 3: **Verify on-device accuracy**
155
+
156
+ To verify the accuracy of the model on-device, you can run on-device inference
157
+ on sample input data on the same cloud hosted device.
158
+ ```python
159
+ input_data = torch_model.sample_inputs()
160
+ inference_job = hub.submit_inference_job(
161
+ model=target_model,
162
+ device=device,
163
+ inputs=input_data,
164
+ )
165
+
166
+ on_device_output = inference_job.download_output_data()
167
+
168
+ ```
169
+ With the output of the model, you can compute like PSNR, relative errors or
170
+ spot check the output with expected output.
171
+
172
+ **Note**: This on-device profiling and inference requires access to Qualcomm®
173
+ AI Hub. [Sign up for access](https://myaccount.qualcomm.com/signup).
174
+
175
+
176
+ ## Run demo on a cloud-hosted device
177
+
178
+ You can also run the demo on-device.
179
+
180
+ ```bash
181
+ python -m qai_hub_models.models.yolonas_quantized.demo --on-device
182
+ ```
183
+
184
+ **NOTE**: If you want running in a Jupyter Notebook or Google Colab like
185
+ environment, please add the following to your cell (instead of the above).
186
+ ```
187
+ %run -m qai_hub_models.models.yolonas_quantized.demo -- --on-device
188
+ ```
189
+
190
+
191
+ ## Deploying compiled model to Android
192
+
193
+
194
+ The models can be deployed using multiple runtimes:
195
+ - TensorFlow Lite (`.tflite` export): [This
196
+ tutorial](https://www.tensorflow.org/lite/android/quickstart) provides a
197
+ guide to deploy the .tflite model in an Android application.
198
+
199
+
200
+ - QNN (`.so` export ): This [sample
201
+ app](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/sample_app.html)
202
+ provides instructions on how to use the `.so` shared library in an Android application.
203
+
204
+
205
+ ## View on Qualcomm® AI Hub
206
+ Get more details on Yolo-NAS-Quantized's performance across various devices [here](https://aihub.qualcomm.com/models/yolonas_quantized).
207
+ Explore all available models on [Qualcomm® AI Hub](https://aihub.qualcomm.com/)
208
+
209
+ ## License
210
+ - The license for the original implementation of Yolo-NAS-Quantized can be found
211
+ [here](https://github.com/Deci-AI/super-gradients/blob/master/LICENSE.YOLONAS.md).
212
+ - The license for the compiled assets for on-device deployment can be found [here]({deploy_license_url})
213
+
214
+ ## References
215
+ * [YOLO-NAS by Deci Achieves SOTA Performance on Object Detection Using Neural Architecture Search](https://deci.ai/blog/yolo-nas-object-detection-foundation-model/)
216
+ * [Source Model Implementation](https://github.com/Deci-AI/super-gradients)
217
+
218
+ ## Community
219
+ * Join [our AI Hub Slack community](https://qualcomm-ai-hub.slack.com/join/shared_invite/zt-2d5zsmas3-Sj0Q9TzslueCjS31eXG2UA#/shared-invite/email) to collaborate, post questions and learn more about on-device AI.
220
+ * For questions or feedback please [reach out to us](mailto:ai-hub-support@qti.qualcomm.com).
221
+
222
+