qaihm-bot commited on
Commit
395e7b3
1 Parent(s): 31ae33b

Upload README.md with huggingface_hub

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