qaihm-bot commited on
Commit
be6f185
·
verified ·
1 Parent(s): 109b8c2

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +241 -0
README.md ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: pytorch
3
+ license: bsd-3-clause
4
+ tags:
5
+ - android
6
+ pipeline_tag: unconditional-image-generation
7
+
8
+ ---
9
+
10
+ ![](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/simple_bev_cam/web-assets/model_demo.png)
11
+
12
+ # Simple-Bev: Optimized for Mobile Deployment
13
+ ## Construct a bird’s eye view from sensors mounted on a vehicle
14
+
15
+
16
+ Simple_bev is a machine learning model for generating a birds eye view represenation from the sensors(cameras) mounted on a vehicle. It uses the ResNet-101 as the backbone and segnet as a segmentation model for specific use cases.
17
+
18
+ This model is an implementation of Simple-Bev found [here](https://github.com/aharley/simple_bev/blob/main/nets/segnet.py).
19
+
20
+
21
+ This repository provides scripts to run Simple-Bev on Qualcomm® devices.
22
+ More details on model performance across various devices, can be found
23
+ [here](https://aihub.qualcomm.com/models/simple_bev_cam).
24
+
25
+
26
+ ### Model Details
27
+
28
+ - **Model Type:** Image generation
29
+ - **Model Stats:**
30
+ - Model checkpoint: model-000025000.pth
31
+ - Input resolution: 448 x 800
32
+ - Number of parameters: 42M
33
+ - Model size: 505 MB
34
+
35
+ | Model | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Precision | Primary Compute Unit | Target Model
36
+ |---|---|---|---|---|---|---|---|---|
37
+ | Simple-Bev | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | QNN | 434.009 ms | 25 - 27 MB | FP16 | NPU | [Simple-Bev.so](https://huggingface.co/qualcomm/Simple-Bev/blob/main/Simple-Bev.so) |
38
+ | Simple-Bev | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | ONNX | 360.438 ms | 57 - 272 MB | FP16 | NPU | [Simple-Bev.onnx](https://huggingface.co/qualcomm/Simple-Bev/blob/main/Simple-Bev.onnx) |
39
+ | Simple-Bev | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | QNN | 301.869 ms | 25 - 40 MB | FP16 | NPU | [Simple-Bev.so](https://huggingface.co/qualcomm/Simple-Bev/blob/main/Simple-Bev.so) |
40
+ | Simple-Bev | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | ONNX | 261.626 ms | 142 - 801 MB | FP16 | NPU | [Simple-Bev.onnx](https://huggingface.co/qualcomm/Simple-Bev/blob/main/Simple-Bev.onnx) |
41
+ | Simple-Bev | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | TFLITE | 16130.835 ms | 0 - 1215 MB | FP16 | NPU | [Simple-Bev.tflite](https://huggingface.co/qualcomm/Simple-Bev/blob/main/Simple-Bev.tflite) |
42
+ | Simple-Bev | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 362.952 ms | 25 - 1013 MB | FP16 | NPU | Use Export Script |
43
+ | Simple-Bev | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | ONNX | 223.613 ms | 130 - 837 MB | FP16 | NPU | [Simple-Bev.onnx](https://huggingface.co/qualcomm/Simple-Bev/blob/main/Simple-Bev.onnx) |
44
+ | Simple-Bev | SA7255P ADP | SA7255P | QNN | 10837.745 ms | 23 - 31 MB | FP16 | NPU | Use Export Script |
45
+ | Simple-Bev | SA8255 (Proxy) | SA8255P Proxy | QNN | 433.305 ms | 25 - 27 MB | FP16 | NPU | Use Export Script |
46
+ | Simple-Bev | SA8295P ADP | SA8295P | TFLITE | 1852.028 ms | 1248 - 2589 MB | FP32 | CPU | [Simple-Bev.tflite](https://huggingface.co/qualcomm/Simple-Bev/blob/main/Simple-Bev.tflite) |
47
+ | Simple-Bev | SA8295P ADP | SA8295P | QNN | 607.673 ms | 25 - 35 MB | FP16 | NPU | Use Export Script |
48
+ | Simple-Bev | SA8650 (Proxy) | SA8650P Proxy | QNN | 435.088 ms | 25 - 28 MB | FP16 | NPU | Use Export Script |
49
+ | Simple-Bev | SA8775P ADP | SA8775P | QNN | 701.224 ms | 25 - 31 MB | FP16 | NPU | Use Export Script |
50
+ | Simple-Bev | QCS8275 (Proxy) | QCS8275 Proxy | QNN | 10837.745 ms | 23 - 31 MB | FP16 | NPU | Use Export Script |
51
+ | Simple-Bev | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 431.407 ms | 25 - 28 MB | FP16 | NPU | Use Export Script |
52
+ | Simple-Bev | QCS9075 (Proxy) | QCS9075 Proxy | QNN | 701.224 ms | 25 - 31 MB | FP16 | NPU | Use Export Script |
53
+ | Simple-Bev | QCS8450 (Proxy) | QCS8450 Proxy | QNN | 644.8 ms | 3 - 686 MB | FP16 | NPU | Use Export Script |
54
+ | Simple-Bev | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 425.896 ms | 25 - 25 MB | FP16 | NPU | Use Export Script |
55
+ | Simple-Bev | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 428.555 ms | 265 - 265 MB | FP16 | NPU | [Simple-Bev.onnx](https://huggingface.co/qualcomm/Simple-Bev/blob/main/Simple-Bev.onnx) |
56
+
57
+
58
+
59
+
60
+ ## Installation
61
+
62
+
63
+ Install the package via pip:
64
+ ```bash
65
+ pip install qai-hub-models
66
+ ```
67
+
68
+
69
+ ## Configure Qualcomm® AI Hub to run this model on a cloud-hosted device
70
+
71
+ Sign-in to [Qualcomm® AI Hub](https://app.aihub.qualcomm.com/) with your
72
+ Qualcomm® ID. Once signed in navigate to `Account -> Settings -> API Token`.
73
+
74
+ With this API token, you can configure your client to run models on the cloud
75
+ hosted devices.
76
+ ```bash
77
+ qai-hub configure --api_token API_TOKEN
78
+ ```
79
+ Navigate to [docs](https://app.aihub.qualcomm.com/docs/) for more information.
80
+
81
+
82
+
83
+ ## Demo off target
84
+
85
+ The package contains a simple end-to-end demo that downloads pre-trained
86
+ weights and runs this model on a sample input.
87
+
88
+ ```bash
89
+ python -m qai_hub_models.models.simple_bev_cam.demo
90
+ ```
91
+
92
+ The above demo runs a reference implementation of pre-processing, model
93
+ inference, and post processing.
94
+
95
+ **NOTE**: If you want running in a Jupyter Notebook or Google Colab like
96
+ environment, please add the following to your cell (instead of the above).
97
+ ```
98
+ %run -m qai_hub_models.models.simple_bev_cam.demo
99
+ ```
100
+
101
+
102
+ ### Run model on a cloud-hosted device
103
+
104
+ In addition to the demo, you can also run the model on a cloud-hosted Qualcomm®
105
+ device. This script does the following:
106
+ * Performance check on-device on a cloud-hosted device
107
+ * Downloads compiled assets that can be deployed on-device for Android.
108
+ * Accuracy check between PyTorch and on-device outputs.
109
+
110
+ ```bash
111
+ python -m qai_hub_models.models.simple_bev_cam.export
112
+ ```
113
+ ```
114
+ Profiling Results
115
+ ------------------------------------------------------------
116
+ Simple-Bev
117
+ Device : Samsung Galaxy S23 (13)
118
+ Runtime : QNN
119
+ Estimated inference time (ms) : 434.0
120
+ Estimated peak memory usage (MB): [25, 27]
121
+ Total # Ops : 376
122
+ Compute Unit(s) : NPU (376 ops)
123
+ ```
124
+
125
+
126
+ ## How does this work?
127
+
128
+ This [export script](https://aihub.qualcomm.com/models/simple_bev_cam/qai_hub_models/models/Simple-Bev/export.py)
129
+ leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
130
+ on-device. Lets go through each step below in detail:
131
+
132
+ Step 1: **Compile model for on-device deployment**
133
+
134
+ To compile a PyTorch model for on-device deployment, we first trace the model
135
+ in memory using the `jit.trace` and then call the `submit_compile_job` API.
136
+
137
+ ```python
138
+ import torch
139
+
140
+ import qai_hub as hub
141
+ from qai_hub_models.models.simple_bev_cam import Model
142
+
143
+ # Load the model
144
+ torch_model = Model.from_pretrained()
145
+
146
+ # Device
147
+ device = hub.Device("Samsung Galaxy S24")
148
+
149
+ # Trace model
150
+ input_shape = torch_model.get_input_spec()
151
+ sample_inputs = torch_model.sample_inputs()
152
+
153
+ pt_model = torch.jit.trace(torch_model, [torch.tensor(data[0]) for _, data in sample_inputs.items()])
154
+
155
+ # Compile model on a specific device
156
+ compile_job = hub.submit_compile_job(
157
+ model=pt_model,
158
+ device=device,
159
+ input_specs=torch_model.get_input_spec(),
160
+ )
161
+
162
+ # Get target model to run on-device
163
+ target_model = compile_job.get_target_model()
164
+
165
+ ```
166
+
167
+
168
+ Step 2: **Performance profiling on cloud-hosted device**
169
+
170
+ After compiling models from step 1. Models can be profiled model on-device using the
171
+ `target_model`. Note that this scripts runs the model on a device automatically
172
+ provisioned in the cloud. Once the job is submitted, you can navigate to a
173
+ provided job URL to view a variety of on-device performance metrics.
174
+ ```python
175
+ profile_job = hub.submit_profile_job(
176
+ model=target_model,
177
+ device=device,
178
+ )
179
+
180
+ ```
181
+
182
+ Step 3: **Verify on-device accuracy**
183
+
184
+ To verify the accuracy of the model on-device, you can run on-device inference
185
+ on sample input data on the same cloud hosted device.
186
+ ```python
187
+ input_data = torch_model.sample_inputs()
188
+ inference_job = hub.submit_inference_job(
189
+ model=target_model,
190
+ device=device,
191
+ inputs=input_data,
192
+ )
193
+ on_device_output = inference_job.download_output_data()
194
+
195
+ ```
196
+ With the output of the model, you can compute like PSNR, relative errors or
197
+ spot check the output with expected output.
198
+
199
+ **Note**: This on-device profiling and inference requires access to Qualcomm®
200
+ AI Hub. [Sign up for access](https://myaccount.qualcomm.com/signup).
201
+
202
+
203
+
204
+
205
+ ## Deploying compiled model to Android
206
+
207
+
208
+ The models can be deployed using multiple runtimes:
209
+ - TensorFlow Lite (`.tflite` export): [This
210
+ tutorial](https://www.tensorflow.org/lite/android/quickstart) provides a
211
+ guide to deploy the .tflite model in an Android application.
212
+
213
+
214
+ - QNN (`.so` export ): This [sample
215
+ app](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/sample_app.html)
216
+ provides instructions on how to use the `.so` shared library in an Android application.
217
+
218
+
219
+ ## View on Qualcomm® AI Hub
220
+ Get more details on Simple-Bev's performance across various devices [here](https://aihub.qualcomm.com/models/simple_bev_cam).
221
+ Explore all available models on [Qualcomm® AI Hub](https://aihub.qualcomm.com/)
222
+
223
+
224
+ ## License
225
+ * The license for the original implementation of Simple-Bev can be found
226
+ [here](https://github.com/aharley/simple_bev/blob/main/LICENSE).
227
+ * 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)
228
+
229
+
230
+
231
+ ## References
232
+ * [Simple-BEV: What Really Matters for Multi-Sensor BEV Perception?](https://arxiv.org/abs/2206.07959)
233
+ * [Source Model Implementation](https://github.com/aharley/simple_bev/blob/main/nets/segnet.py)
234
+
235
+
236
+
237
+ ## Community
238
+ * Join [our AI Hub Slack community](https://aihub.qualcomm.com/community/slack) to collaborate, post questions and learn more about on-device AI.
239
+ * For questions or feedback please [reach out to us](mailto:[email protected]).
240
+
241
+