Upload README.md with huggingface_hub
Browse files
README.md
ADDED
@@ -0,0 +1,321 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
library_name: pytorch
|
3 |
+
license: apache-2.0
|
4 |
+
tags:
|
5 |
+
- real_time
|
6 |
+
- android
|
7 |
+
pipeline_tag: object-detection
|
8 |
+
|
9 |
+
---
|
10 |
+
|
11 |
+

|
12 |
+
|
13 |
+
# 3D-Deep-BOX: Optimized for Mobile Deployment
|
14 |
+
## Real-time 3D object detection
|
15 |
+
|
16 |
+
|
17 |
+
3D Deep Box is a machine learning model that predicts 3D bounding boxes and classes of objects in an image.
|
18 |
+
|
19 |
+
This model is an implementation of 3D-Deep-BOX found [here](https://github.com/skhadem/3D-BoundingBox/).
|
20 |
+
|
21 |
+
|
22 |
+
This repository provides scripts to run 3D-Deep-BOX on Qualcomm® devices.
|
23 |
+
More details on model performance across various devices, can be found
|
24 |
+
[here](https://aihub.qualcomm.com/models/deepbox).
|
25 |
+
|
26 |
+
|
27 |
+
### Model Details
|
28 |
+
|
29 |
+
- **Model Type:** Object detection
|
30 |
+
- **Model Stats:**
|
31 |
+
- Model checkpoint: YOLOv3-tiny
|
32 |
+
- Input resolution(YOLO): 224x640
|
33 |
+
- Number of parameters(YOLO): 8.85M
|
34 |
+
- Model size(YOLO): 37.3 MB
|
35 |
+
- Input resolution(VGG): 224x224
|
36 |
+
- Number of parameters(VGG): 144M
|
37 |
+
- Model size(VGG): 175.9 MB
|
38 |
+
|
39 |
+
| Model | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Precision | Primary Compute Unit | Target Model
|
40 |
+
|---|---|---|---|---|---|---|---|---|
|
41 |
+
| Yolo | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | TFLITE | 22.238 ms | 0 - 59 MB | FP16 | NPU | [3D-Deep-BOX.tflite](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/Yolo.tflite) |
|
42 |
+
| Yolo | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | QNN | 2.992 ms | 2 - 4 MB | FP16 | NPU | [3D-Deep-BOX.so](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/Yolo.so) |
|
43 |
+
| Yolo | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | ONNX | 5.749 ms | 0 - 51 MB | FP16 | NPU | [3D-Deep-BOX.onnx](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/Yolo.onnx) |
|
44 |
+
| Yolo | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | TFLITE | 16.668 ms | 0 - 39 MB | FP16 | NPU | [3D-Deep-BOX.tflite](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/Yolo.tflite) |
|
45 |
+
| Yolo | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | QNN | 2.085 ms | 0 - 15 MB | FP16 | NPU | [3D-Deep-BOX.so](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/Yolo.so) |
|
46 |
+
| Yolo | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | ONNX | 4.781 ms | 0 - 31 MB | FP16 | NPU | [3D-Deep-BOX.onnx](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/Yolo.onnx) |
|
47 |
+
| Yolo | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | TFLITE | 14.794 ms | 0 - 33 MB | FP16 | NPU | [3D-Deep-BOX.tflite](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/Yolo.tflite) |
|
48 |
+
| Yolo | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 2.519 ms | 2 - 20 MB | FP16 | NPU | Use Export Script |
|
49 |
+
| Yolo | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | ONNX | 4.697 ms | 2 - 27 MB | FP16 | NPU | [3D-Deep-BOX.onnx](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/Yolo.onnx) |
|
50 |
+
| Yolo | SA7255P ADP | SA7255P | TFLITE | 67.992 ms | 0 - 26 MB | FP16 | NPU | [3D-Deep-BOX.tflite](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/Yolo.tflite) |
|
51 |
+
| Yolo | SA7255P ADP | SA7255P | QNN | 35.592 ms | 2 - 9 MB | FP16 | NPU | Use Export Script |
|
52 |
+
| Yolo | SA8255 (Proxy) | SA8255P Proxy | TFLITE | 22.79 ms | 0 - 68 MB | FP16 | NPU | [3D-Deep-BOX.tflite](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/Yolo.tflite) |
|
53 |
+
| Yolo | SA8255 (Proxy) | SA8255P Proxy | QNN | 2.993 ms | 2 - 4 MB | FP16 | NPU | Use Export Script |
|
54 |
+
| Yolo | SA8295P ADP | SA8295P | TFLITE | 24.177 ms | 0 - 28 MB | FP16 | NPU | [3D-Deep-BOX.tflite](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/Yolo.tflite) |
|
55 |
+
| Yolo | SA8295P ADP | SA8295P | QNN | 4.686 ms | 2 - 12 MB | FP16 | NPU | Use Export Script |
|
56 |
+
| Yolo | SA8650 (Proxy) | SA8650P Proxy | TFLITE | 22.426 ms | 0 - 68 MB | FP16 | NPU | [3D-Deep-BOX.tflite](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/Yolo.tflite) |
|
57 |
+
| Yolo | SA8650 (Proxy) | SA8650P Proxy | QNN | 3.01 ms | 2 - 4 MB | FP16 | NPU | Use Export Script |
|
58 |
+
| Yolo | SA8775P ADP | SA8775P | TFLITE | 27.588 ms | 0 - 26 MB | FP16 | NPU | [3D-Deep-BOX.tflite](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/Yolo.tflite) |
|
59 |
+
| Yolo | SA8775P ADP | SA8775P | QNN | 4.599 ms | 2 - 9 MB | FP16 | NPU | Use Export Script |
|
60 |
+
| Yolo | QCS8275 (Proxy) | QCS8275 Proxy | TFLITE | 67.992 ms | 0 - 26 MB | FP16 | NPU | [3D-Deep-BOX.tflite](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/Yolo.tflite) |
|
61 |
+
| Yolo | QCS8275 (Proxy) | QCS8275 Proxy | QNN | 35.592 ms | 2 - 9 MB | FP16 | NPU | Use Export Script |
|
62 |
+
| Yolo | QCS8550 (Proxy) | QCS8550 Proxy | TFLITE | 22.471 ms | 0 - 78 MB | FP16 | NPU | [3D-Deep-BOX.tflite](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/Yolo.tflite) |
|
63 |
+
| Yolo | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 2.999 ms | 2 - 5 MB | FP16 | NPU | Use Export Script |
|
64 |
+
| Yolo | QCS9075 (Proxy) | QCS9075 Proxy | TFLITE | 27.588 ms | 0 - 26 MB | FP16 | NPU | [3D-Deep-BOX.tflite](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/Yolo.tflite) |
|
65 |
+
| Yolo | QCS9075 (Proxy) | QCS9075 Proxy | QNN | 4.599 ms | 2 - 9 MB | FP16 | NPU | Use Export Script |
|
66 |
+
| Yolo | QCS8450 (Proxy) | QCS8450 Proxy | TFLITE | 22.488 ms | 0 - 37 MB | FP16 | NPU | [3D-Deep-BOX.tflite](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/Yolo.tflite) |
|
67 |
+
| Yolo | QCS8450 (Proxy) | QCS8450 Proxy | QNN | 4.033 ms | 2 - 21 MB | FP16 | NPU | Use Export Script |
|
68 |
+
| Yolo | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 3.126 ms | 2 - 2 MB | FP16 | NPU | Use Export Script |
|
69 |
+
| Yolo | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 6.548 ms | 10 - 10 MB | FP16 | NPU | [3D-Deep-BOX.onnx](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/Yolo.onnx) |
|
70 |
+
| VGG | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | TFLITE | 4.776 ms | 0 - 616 MB | FP16 | NPU | [3D-Deep-BOX.tflite](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/VGG.tflite) |
|
71 |
+
| VGG | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | QNN | 4.873 ms | 1 - 3 MB | FP16 | NPU | [3D-Deep-BOX.so](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/VGG.so) |
|
72 |
+
| VGG | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | ONNX | 5.567 ms | 0 - 553 MB | FP16 | NPU | [3D-Deep-BOX.onnx](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/VGG.onnx) |
|
73 |
+
| VGG | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | TFLITE | 3.581 ms | 0 - 36 MB | FP16 | NPU | [3D-Deep-BOX.tflite](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/VGG.tflite) |
|
74 |
+
| VGG | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | QNN | 3.842 ms | 0 - 15 MB | FP16 | NPU | [3D-Deep-BOX.so](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/VGG.so) |
|
75 |
+
| VGG | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | ONNX | 4.37 ms | 1 - 39 MB | FP16 | NPU | [3D-Deep-BOX.onnx](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/VGG.onnx) |
|
76 |
+
| VGG | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | TFLITE | 2.982 ms | 0 - 30 MB | FP16 | NPU | [3D-Deep-BOX.tflite](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/VGG.tflite) |
|
77 |
+
| VGG | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 3.561 ms | 1 - 31 MB | FP16 | NPU | Use Export Script |
|
78 |
+
| VGG | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | ONNX | 4.191 ms | 1 - 33 MB | FP16 | NPU | [3D-Deep-BOX.onnx](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/VGG.onnx) |
|
79 |
+
| VGG | SA7255P ADP | SA7255P | TFLITE | 257.893 ms | 0 - 24 MB | FP16 | NPU | [3D-Deep-BOX.tflite](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/VGG.tflite) |
|
80 |
+
| VGG | SA7255P ADP | SA7255P | QNN | 258.233 ms | 1 - 8 MB | FP16 | NPU | Use Export Script |
|
81 |
+
| VGG | SA8255 (Proxy) | SA8255P Proxy | TFLITE | 4.77 ms | 0 - 612 MB | FP16 | NPU | [3D-Deep-BOX.tflite](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/VGG.tflite) |
|
82 |
+
| VGG | SA8255 (Proxy) | SA8255P Proxy | QNN | 4.865 ms | 1 - 3 MB | FP16 | NPU | Use Export Script |
|
83 |
+
| VGG | SA8295P ADP | SA8295P | TFLITE | 9.774 ms | 0 - 26 MB | FP16 | NPU | [3D-Deep-BOX.tflite](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/VGG.tflite) |
|
84 |
+
| VGG | SA8295P ADP | SA8295P | QNN | 9.966 ms | 1 - 11 MB | FP16 | NPU | Use Export Script |
|
85 |
+
| VGG | SA8650 (Proxy) | SA8650P Proxy | TFLITE | 4.778 ms | 0 - 612 MB | FP16 | NPU | [3D-Deep-BOX.tflite](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/VGG.tflite) |
|
86 |
+
| VGG | SA8650 (Proxy) | SA8650P Proxy | QNN | 4.865 ms | 1 - 3 MB | FP16 | NPU | Use Export Script |
|
87 |
+
| VGG | SA8775P ADP | SA8775P | TFLITE | 10.858 ms | 0 - 24 MB | FP16 | NPU | [3D-Deep-BOX.tflite](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/VGG.tflite) |
|
88 |
+
| VGG | SA8775P ADP | SA8775P | QNN | 11.071 ms | 1 - 8 MB | FP16 | NPU | Use Export Script |
|
89 |
+
| VGG | QCS8275 (Proxy) | QCS8275 Proxy | TFLITE | 257.893 ms | 0 - 24 MB | FP16 | NPU | [3D-Deep-BOX.tflite](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/VGG.tflite) |
|
90 |
+
| VGG | QCS8275 (Proxy) | QCS8275 Proxy | QNN | 258.233 ms | 1 - 8 MB | FP16 | NPU | Use Export Script |
|
91 |
+
| VGG | QCS8550 (Proxy) | QCS8550 Proxy | TFLITE | 4.766 ms | 0 - 612 MB | FP16 | NPU | [3D-Deep-BOX.tflite](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/VGG.tflite) |
|
92 |
+
| VGG | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 4.857 ms | 1 - 4 MB | FP16 | NPU | Use Export Script |
|
93 |
+
| VGG | QCS9075 (Proxy) | QCS9075 Proxy | TFLITE | 10.858 ms | 0 - 24 MB | FP16 | NPU | [3D-Deep-BOX.tflite](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/VGG.tflite) |
|
94 |
+
| VGG | QCS9075 (Proxy) | QCS9075 Proxy | QNN | 11.071 ms | 1 - 8 MB | FP16 | NPU | Use Export Script |
|
95 |
+
| VGG | QCS8450 (Proxy) | QCS8450 Proxy | TFLITE | 8.327 ms | 0 - 32 MB | FP16 | NPU | [3D-Deep-BOX.tflite](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/VGG.tflite) |
|
96 |
+
| VGG | QCS8450 (Proxy) | QCS8450 Proxy | QNN | 8.448 ms | 1 - 33 MB | FP16 | NPU | Use Export Script |
|
97 |
+
| VGG | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 5.078 ms | 1 - 1 MB | FP16 | NPU | Use Export Script |
|
98 |
+
| VGG | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 5.547 ms | 90 - 90 MB | FP16 | NPU | [3D-Deep-BOX.onnx](https://huggingface.co/qualcomm/3D-Deep-BOX/blob/main/VGG.onnx) |
|
99 |
+
|
100 |
+
|
101 |
+
|
102 |
+
|
103 |
+
## Installation
|
104 |
+
|
105 |
+
|
106 |
+
Install the package via pip:
|
107 |
+
```bash
|
108 |
+
pip install "qai-hub-models[deepbox]"
|
109 |
+
```
|
110 |
+
|
111 |
+
|
112 |
+
## Configure Qualcomm® AI Hub to run this model on a cloud-hosted device
|
113 |
+
|
114 |
+
Sign-in to [Qualcomm® AI Hub](https://app.aihub.qualcomm.com/) with your
|
115 |
+
Qualcomm® ID. Once signed in navigate to `Account -> Settings -> API Token`.
|
116 |
+
|
117 |
+
With this API token, you can configure your client to run models on the cloud
|
118 |
+
hosted devices.
|
119 |
+
```bash
|
120 |
+
qai-hub configure --api_token API_TOKEN
|
121 |
+
```
|
122 |
+
Navigate to [docs](https://app.aihub.qualcomm.com/docs/) for more information.
|
123 |
+
|
124 |
+
|
125 |
+
|
126 |
+
## Demo off target
|
127 |
+
|
128 |
+
The package contains a simple end-to-end demo that downloads pre-trained
|
129 |
+
weights and runs this model on a sample input.
|
130 |
+
|
131 |
+
```bash
|
132 |
+
python -m qai_hub_models.models.deepbox.demo
|
133 |
+
```
|
134 |
+
|
135 |
+
The above demo runs a reference implementation of pre-processing, model
|
136 |
+
inference, and post processing.
|
137 |
+
|
138 |
+
**NOTE**: If you want running in a Jupyter Notebook or Google Colab like
|
139 |
+
environment, please add the following to your cell (instead of the above).
|
140 |
+
```
|
141 |
+
%run -m qai_hub_models.models.deepbox.demo
|
142 |
+
```
|
143 |
+
|
144 |
+
|
145 |
+
### Run model on a cloud-hosted device
|
146 |
+
|
147 |
+
In addition to the demo, you can also run the model on a cloud-hosted Qualcomm®
|
148 |
+
device. This script does the following:
|
149 |
+
* Performance check on-device on a cloud-hosted device
|
150 |
+
* Downloads compiled assets that can be deployed on-device for Android.
|
151 |
+
* Accuracy check between PyTorch and on-device outputs.
|
152 |
+
|
153 |
+
```bash
|
154 |
+
python -m qai_hub_models.models.deepbox.export
|
155 |
+
```
|
156 |
+
```
|
157 |
+
Profiling Results
|
158 |
+
------------------------------------------------------------
|
159 |
+
Yolo
|
160 |
+
Device : Samsung Galaxy S23 (13)
|
161 |
+
Runtime : TFLITE
|
162 |
+
Estimated inference time (ms) : 22.2
|
163 |
+
Estimated peak memory usage (MB): [0, 59]
|
164 |
+
Total # Ops : 128
|
165 |
+
Compute Unit(s) : NPU (128 ops)
|
166 |
+
|
167 |
+
------------------------------------------------------------
|
168 |
+
VGG
|
169 |
+
Device : Samsung Galaxy S23 (13)
|
170 |
+
Runtime : TFLITE
|
171 |
+
Estimated inference time (ms) : 4.8
|
172 |
+
Estimated peak memory usage (MB): [0, 616]
|
173 |
+
Total # Ops : 40
|
174 |
+
Compute Unit(s) : NPU (40 ops)
|
175 |
+
```
|
176 |
+
|
177 |
+
|
178 |
+
## How does this work?
|
179 |
+
|
180 |
+
This [export script](https://aihub.qualcomm.com/models/deepbox/qai_hub_models/models/3D-Deep-BOX/export.py)
|
181 |
+
leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
|
182 |
+
on-device. Lets go through each step below in detail:
|
183 |
+
|
184 |
+
Step 1: **Compile model for on-device deployment**
|
185 |
+
|
186 |
+
To compile a PyTorch model for on-device deployment, we first trace the model
|
187 |
+
in memory using the `jit.trace` and then call the `submit_compile_job` API.
|
188 |
+
|
189 |
+
```python
|
190 |
+
import torch
|
191 |
+
|
192 |
+
import qai_hub as hub
|
193 |
+
from qai_hub_models.models.deepbox import Model
|
194 |
+
|
195 |
+
# Load the model
|
196 |
+
model = Model.from_pretrained()
|
197 |
+
bbox2D_dectector_model = model.bbox2D_dectector
|
198 |
+
bbox3D_dectector_model = model.bbox3D_dectector
|
199 |
+
|
200 |
+
# Device
|
201 |
+
device = hub.Device("Samsung Galaxy S23")
|
202 |
+
|
203 |
+
# Trace model
|
204 |
+
bbox2D_dectector_input_shape = bbox2D_dectector_model.get_input_spec()
|
205 |
+
bbox2D_dectector_sample_inputs = bbox2D_dectector_model.sample_inputs()
|
206 |
+
|
207 |
+
traced_bbox2D_dectector_model = torch.jit.trace(bbox2D_dectector_model, [torch.tensor(data[0]) for _, data in bbox2D_dectector_sample_inputs.items()])
|
208 |
+
|
209 |
+
# Compile model on a specific device
|
210 |
+
bbox2D_dectector_compile_job = hub.submit_compile_job(
|
211 |
+
model=traced_bbox2D_dectector_model ,
|
212 |
+
device=device,
|
213 |
+
input_specs=bbox2D_dectector_model.get_input_spec(),
|
214 |
+
)
|
215 |
+
|
216 |
+
# Get target model to run on-device
|
217 |
+
bbox2D_dectector_target_model = bbox2D_dectector_compile_job.get_target_model()
|
218 |
+
# Trace model
|
219 |
+
bbox3D_dectector_input_shape = bbox3D_dectector_model.get_input_spec()
|
220 |
+
bbox3D_dectector_sample_inputs = bbox3D_dectector_model.sample_inputs()
|
221 |
+
|
222 |
+
traced_bbox3D_dectector_model = torch.jit.trace(bbox3D_dectector_model, [torch.tensor(data[0]) for _, data in bbox3D_dectector_sample_inputs.items()])
|
223 |
+
|
224 |
+
# Compile model on a specific device
|
225 |
+
bbox3D_dectector_compile_job = hub.submit_compile_job(
|
226 |
+
model=traced_bbox3D_dectector_model ,
|
227 |
+
device=device,
|
228 |
+
input_specs=bbox3D_dectector_model.get_input_spec(),
|
229 |
+
)
|
230 |
+
|
231 |
+
# Get target model to run on-device
|
232 |
+
bbox3D_dectector_target_model = bbox3D_dectector_compile_job.get_target_model()
|
233 |
+
|
234 |
+
```
|
235 |
+
|
236 |
+
|
237 |
+
Step 2: **Performance profiling on cloud-hosted device**
|
238 |
+
|
239 |
+
After compiling models from step 1. Models can be profiled model on-device using the
|
240 |
+
`target_model`. Note that this scripts runs the model on a device automatically
|
241 |
+
provisioned in the cloud. Once the job is submitted, you can navigate to a
|
242 |
+
provided job URL to view a variety of on-device performance metrics.
|
243 |
+
```python
|
244 |
+
bbox2D_dectector_profile_job = hub.submit_profile_job(
|
245 |
+
model=bbox2D_dectector_target_model,
|
246 |
+
device=device,
|
247 |
+
)
|
248 |
+
bbox3D_dectector_profile_job = hub.submit_profile_job(
|
249 |
+
model=bbox3D_dectector_target_model,
|
250 |
+
device=device,
|
251 |
+
)
|
252 |
+
|
253 |
+
```
|
254 |
+
|
255 |
+
Step 3: **Verify on-device accuracy**
|
256 |
+
|
257 |
+
To verify the accuracy of the model on-device, you can run on-device inference
|
258 |
+
on sample input data on the same cloud hosted device.
|
259 |
+
```python
|
260 |
+
bbox2D_dectector_input_data = bbox2D_dectector_model.sample_inputs()
|
261 |
+
bbox2D_dectector_inference_job = hub.submit_inference_job(
|
262 |
+
model=bbox2D_dectector_target_model,
|
263 |
+
device=device,
|
264 |
+
inputs=bbox2D_dectector_input_data,
|
265 |
+
)
|
266 |
+
bbox2D_dectector_inference_job.download_output_data()
|
267 |
+
bbox3D_dectector_input_data = bbox3D_dectector_model.sample_inputs()
|
268 |
+
bbox3D_dectector_inference_job = hub.submit_inference_job(
|
269 |
+
model=bbox3D_dectector_target_model,
|
270 |
+
device=device,
|
271 |
+
inputs=bbox3D_dectector_input_data,
|
272 |
+
)
|
273 |
+
bbox3D_dectector_inference_job.download_output_data()
|
274 |
+
|
275 |
+
```
|
276 |
+
With the output of the model, you can compute like PSNR, relative errors or
|
277 |
+
spot check the output with expected output.
|
278 |
+
|
279 |
+
**Note**: This on-device profiling and inference requires access to Qualcomm®
|
280 |
+
AI Hub. [Sign up for access](https://myaccount.qualcomm.com/signup).
|
281 |
+
|
282 |
+
|
283 |
+
|
284 |
+
|
285 |
+
## Deploying compiled model to Android
|
286 |
+
|
287 |
+
|
288 |
+
The models can be deployed using multiple runtimes:
|
289 |
+
- TensorFlow Lite (`.tflite` export): [This
|
290 |
+
tutorial](https://www.tensorflow.org/lite/android/quickstart) provides a
|
291 |
+
guide to deploy the .tflite model in an Android application.
|
292 |
+
|
293 |
+
|
294 |
+
- QNN (`.so` export ): This [sample
|
295 |
+
app](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/sample_app.html)
|
296 |
+
provides instructions on how to use the `.so` shared library in an Android application.
|
297 |
+
|
298 |
+
|
299 |
+
## View on Qualcomm® AI Hub
|
300 |
+
Get more details on 3D-Deep-BOX's performance across various devices [here](https://aihub.qualcomm.com/models/deepbox).
|
301 |
+
Explore all available models on [Qualcomm® AI Hub](https://aihub.qualcomm.com/)
|
302 |
+
|
303 |
+
|
304 |
+
## License
|
305 |
+
* The license for the original implementation of 3D-Deep-BOX can be found
|
306 |
+
[here](https://github.com/skhadem/3D-BoundingBox/blob/master/LICENSE).
|
307 |
+
* 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)
|
308 |
+
|
309 |
+
|
310 |
+
|
311 |
+
## References
|
312 |
+
* [3D Bounding Box Estimation Using Deep Learning and Geometry](https://arxiv.org/abs/1612.00496)
|
313 |
+
* [Source Model Implementation](https://github.com/skhadem/3D-BoundingBox/)
|
314 |
+
|
315 |
+
|
316 |
+
|
317 |
+
## Community
|
318 |
+
* Join [our AI Hub Slack community](https://aihub.qualcomm.com/community/slack) to collaborate, post questions and learn more about on-device AI.
|
319 |
+
* For questions or feedback please [reach out to us](mailto:[email protected]).
|
320 |
+
|
321 |
+
|