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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
library_name: pytorch
|
3 |
+
license: other
|
4 |
+
tags:
|
5 |
+
- real_time
|
6 |
+
- android
|
7 |
+
pipeline_tag: image-segmentation
|
8 |
+
|
9 |
+
---
|
10 |
+
|
11 |
+

|
12 |
+
|
13 |
+
# BiseNet: Optimized for Mobile Deployment
|
14 |
+
## Segment images or video by class in real-time on device
|
15 |
+
|
16 |
+
|
17 |
+
BiSeNet (Bilateral Segmentation Network) is a novel architecture designed for real-time semantic segmentation. It addresses the challenge of balancing spatial resolution and receptive field by employing a Spatial Path to preserve high-resolution features and a context path to capture sufficient receptive field.
|
18 |
+
|
19 |
+
This model is an implementation of BiseNet found [here](https://github.com/ooooverflow/BiSeNet).
|
20 |
+
|
21 |
+
|
22 |
+
This repository provides scripts to run BiseNet on Qualcomm® devices.
|
23 |
+
More details on model performance across various devices, can be found
|
24 |
+
[here](https://aihub.qualcomm.com/models/bisenet).
|
25 |
+
|
26 |
+
|
27 |
+
### Model Details
|
28 |
+
|
29 |
+
- **Model Type:** Semantic segmentation
|
30 |
+
- **Model Stats:**
|
31 |
+
- Model checkpoint: best_dice_loss_miou_0.655.pth
|
32 |
+
- Inference latency: RealTime
|
33 |
+
- Input resolution: 720x960
|
34 |
+
- Number of parameters: 12.0M
|
35 |
+
- Model size: 45.7 MB
|
36 |
+
|
37 |
+
| Model | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Precision | Primary Compute Unit | Target Model
|
38 |
+
|---|---|---|---|---|---|---|---|---|
|
39 |
+
| BiseNet | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | TFLITE | 28.162 ms | 12 - 46 MB | FP16 | NPU | [BiseNet.tflite](https://huggingface.co/qualcomm/BiseNet/blob/main/BiseNet.tflite) |
|
40 |
+
| BiseNet | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | QNN | 26.93 ms | 8 - 11 MB | FP16 | NPU | [BiseNet.so](https://huggingface.co/qualcomm/BiseNet/blob/main/BiseNet.so) |
|
41 |
+
| BiseNet | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 | ONNX | 37.632 ms | 63 - 124 MB | FP16 | NPU | [BiseNet.onnx](https://huggingface.co/qualcomm/BiseNet/blob/main/BiseNet.onnx) |
|
42 |
+
| BiseNet | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | TFLITE | 21.228 ms | 31 - 78 MB | FP16 | NPU | [BiseNet.tflite](https://huggingface.co/qualcomm/BiseNet/blob/main/BiseNet.tflite) |
|
43 |
+
| BiseNet | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | QNN | 20.423 ms | 8 - 26 MB | FP16 | NPU | [BiseNet.so](https://huggingface.co/qualcomm/BiseNet/blob/main/BiseNet.so) |
|
44 |
+
| BiseNet | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 | ONNX | 27.205 ms | 65 - 98 MB | FP16 | NPU | [BiseNet.onnx](https://huggingface.co/qualcomm/BiseNet/blob/main/BiseNet.onnx) |
|
45 |
+
| BiseNet | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | TFLITE | 19.018 ms | 30 - 58 MB | FP16 | NPU | [BiseNet.tflite](https://huggingface.co/qualcomm/BiseNet/blob/main/BiseNet.tflite) |
|
46 |
+
| BiseNet | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | QNN | 19.088 ms | 8 - 34 MB | FP16 | NPU | Use Export Script |
|
47 |
+
| BiseNet | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite | ONNX | 25.844 ms | 73 - 103 MB | FP16 | NPU | [BiseNet.onnx](https://huggingface.co/qualcomm/BiseNet/blob/main/BiseNet.onnx) |
|
48 |
+
| BiseNet | SA7255P ADP | SA7255P | TFLITE | 485.254 ms | 30 - 56 MB | FP16 | NPU | [BiseNet.tflite](https://huggingface.co/qualcomm/BiseNet/blob/main/BiseNet.tflite) |
|
49 |
+
| BiseNet | SA7255P ADP | SA7255P | QNN | 484.503 ms | 1 - 11 MB | FP16 | NPU | Use Export Script |
|
50 |
+
| BiseNet | SA8255 (Proxy) | SA8255P Proxy | TFLITE | 28.306 ms | 32 - 109 MB | FP16 | NPU | [BiseNet.tflite](https://huggingface.co/qualcomm/BiseNet/blob/main/BiseNet.tflite) |
|
51 |
+
| BiseNet | SA8255 (Proxy) | SA8255P Proxy | QNN | 26.505 ms | 8 - 10 MB | FP16 | NPU | Use Export Script |
|
52 |
+
| BiseNet | SA8295P ADP | SA8295P | TFLITE | 37.834 ms | 32 - 58 MB | FP16 | NPU | [BiseNet.tflite](https://huggingface.co/qualcomm/BiseNet/blob/main/BiseNet.tflite) |
|
53 |
+
| BiseNet | SA8295P ADP | SA8295P | QNN | 35.674 ms | 3 - 20 MB | FP16 | NPU | Use Export Script |
|
54 |
+
| BiseNet | SA8650 (Proxy) | SA8650P Proxy | TFLITE | 28.145 ms | 7 - 27 MB | FP16 | NPU | [BiseNet.tflite](https://huggingface.co/qualcomm/BiseNet/blob/main/BiseNet.tflite) |
|
55 |
+
| BiseNet | SA8650 (Proxy) | SA8650P Proxy | QNN | 27.056 ms | 8 - 10 MB | FP16 | NPU | Use Export Script |
|
56 |
+
| BiseNet | SA8775P ADP | SA8775P | TFLITE | 41.242 ms | 32 - 58 MB | FP16 | NPU | [BiseNet.tflite](https://huggingface.co/qualcomm/BiseNet/blob/main/BiseNet.tflite) |
|
57 |
+
| BiseNet | SA8775P ADP | SA8775P | QNN | 39.463 ms | 2 - 12 MB | FP16 | NPU | Use Export Script |
|
58 |
+
| BiseNet | QCS8275 (Proxy) | QCS8275 Proxy | TFLITE | 485.254 ms | 30 - 56 MB | FP16 | NPU | [BiseNet.tflite](https://huggingface.co/qualcomm/BiseNet/blob/main/BiseNet.tflite) |
|
59 |
+
| BiseNet | QCS8275 (Proxy) | QCS8275 Proxy | QNN | 484.503 ms | 1 - 11 MB | FP16 | NPU | Use Export Script |
|
60 |
+
| BiseNet | QCS8550 (Proxy) | QCS8550 Proxy | TFLITE | 27.951 ms | 13 - 72 MB | FP16 | NPU | [BiseNet.tflite](https://huggingface.co/qualcomm/BiseNet/blob/main/BiseNet.tflite) |
|
61 |
+
| BiseNet | QCS8550 (Proxy) | QCS8550 Proxy | QNN | 26.856 ms | 8 - 10 MB | FP16 | NPU | Use Export Script |
|
62 |
+
| BiseNet | QCS9075 (Proxy) | QCS9075 Proxy | TFLITE | 41.242 ms | 32 - 58 MB | FP16 | NPU | [BiseNet.tflite](https://huggingface.co/qualcomm/BiseNet/blob/main/BiseNet.tflite) |
|
63 |
+
| BiseNet | QCS9075 (Proxy) | QCS9075 Proxy | QNN | 39.463 ms | 2 - 12 MB | FP16 | NPU | Use Export Script |
|
64 |
+
| BiseNet | QCS8450 (Proxy) | QCS8450 Proxy | TFLITE | 35.572 ms | 32 - 80 MB | FP16 | NPU | [BiseNet.tflite](https://huggingface.co/qualcomm/BiseNet/blob/main/BiseNet.tflite) |
|
65 |
+
| BiseNet | QCS8450 (Proxy) | QCS8450 Proxy | QNN | 35.517 ms | 8 - 40 MB | FP16 | NPU | Use Export Script |
|
66 |
+
| BiseNet | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 25.281 ms | 8 - 8 MB | FP16 | NPU | Use Export Script |
|
67 |
+
| BiseNet | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 36.024 ms | 66 - 66 MB | FP16 | NPU | [BiseNet.onnx](https://huggingface.co/qualcomm/BiseNet/blob/main/BiseNet.onnx) |
|
68 |
+
|
69 |
+
|
70 |
+
|
71 |
+
|
72 |
+
## Installation
|
73 |
+
|
74 |
+
|
75 |
+
Install the package via pip:
|
76 |
+
```bash
|
77 |
+
pip install qai-hub-models
|
78 |
+
```
|
79 |
+
|
80 |
+
|
81 |
+
## Configure Qualcomm® AI Hub to run this model on a cloud-hosted device
|
82 |
+
|
83 |
+
Sign-in to [Qualcomm® AI Hub](https://app.aihub.qualcomm.com/) with your
|
84 |
+
Qualcomm® ID. Once signed in navigate to `Account -> Settings -> API Token`.
|
85 |
+
|
86 |
+
With this API token, you can configure your client to run models on the cloud
|
87 |
+
hosted devices.
|
88 |
+
```bash
|
89 |
+
qai-hub configure --api_token API_TOKEN
|
90 |
+
```
|
91 |
+
Navigate to [docs](https://app.aihub.qualcomm.com/docs/) for more information.
|
92 |
+
|
93 |
+
|
94 |
+
|
95 |
+
## Demo off target
|
96 |
+
|
97 |
+
The package contains a simple end-to-end demo that downloads pre-trained
|
98 |
+
weights and runs this model on a sample input.
|
99 |
+
|
100 |
+
```bash
|
101 |
+
python -m qai_hub_models.models.bisenet.demo
|
102 |
+
```
|
103 |
+
|
104 |
+
The above demo runs a reference implementation of pre-processing, model
|
105 |
+
inference, and post processing.
|
106 |
+
|
107 |
+
**NOTE**: If you want running in a Jupyter Notebook or Google Colab like
|
108 |
+
environment, please add the following to your cell (instead of the above).
|
109 |
+
```
|
110 |
+
%run -m qai_hub_models.models.bisenet.demo
|
111 |
+
```
|
112 |
+
|
113 |
+
|
114 |
+
### Run model on a cloud-hosted device
|
115 |
+
|
116 |
+
In addition to the demo, you can also run the model on a cloud-hosted Qualcomm®
|
117 |
+
device. This script does the following:
|
118 |
+
* Performance check on-device on a cloud-hosted device
|
119 |
+
* Downloads compiled assets that can be deployed on-device for Android.
|
120 |
+
* Accuracy check between PyTorch and on-device outputs.
|
121 |
+
|
122 |
+
```bash
|
123 |
+
python -m qai_hub_models.models.bisenet.export
|
124 |
+
```
|
125 |
+
```
|
126 |
+
Profiling Results
|
127 |
+
------------------------------------------------------------
|
128 |
+
BiseNet
|
129 |
+
Device : Samsung Galaxy S23 (13)
|
130 |
+
Runtime : TFLITE
|
131 |
+
Estimated inference time (ms) : 28.2
|
132 |
+
Estimated peak memory usage (MB): [12, 46]
|
133 |
+
Total # Ops : 63
|
134 |
+
Compute Unit(s) : NPU (63 ops)
|
135 |
+
```
|
136 |
+
|
137 |
+
|
138 |
+
## How does this work?
|
139 |
+
|
140 |
+
This [export script](https://aihub.qualcomm.com/models/bisenet/qai_hub_models/models/BiseNet/export.py)
|
141 |
+
leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
|
142 |
+
on-device. Lets go through each step below in detail:
|
143 |
+
|
144 |
+
Step 1: **Compile model for on-device deployment**
|
145 |
+
|
146 |
+
To compile a PyTorch model for on-device deployment, we first trace the model
|
147 |
+
in memory using the `jit.trace` and then call the `submit_compile_job` API.
|
148 |
+
|
149 |
+
```python
|
150 |
+
import torch
|
151 |
+
|
152 |
+
import qai_hub as hub
|
153 |
+
from qai_hub_models.models.bisenet import Model
|
154 |
+
|
155 |
+
# Load the model
|
156 |
+
torch_model = Model.from_pretrained()
|
157 |
+
|
158 |
+
# Device
|
159 |
+
device = hub.Device("Samsung Galaxy S24")
|
160 |
+
|
161 |
+
# Trace model
|
162 |
+
input_shape = torch_model.get_input_spec()
|
163 |
+
sample_inputs = torch_model.sample_inputs()
|
164 |
+
|
165 |
+
pt_model = torch.jit.trace(torch_model, [torch.tensor(data[0]) for _, data in sample_inputs.items()])
|
166 |
+
|
167 |
+
# Compile model on a specific device
|
168 |
+
compile_job = hub.submit_compile_job(
|
169 |
+
model=pt_model,
|
170 |
+
device=device,
|
171 |
+
input_specs=torch_model.get_input_spec(),
|
172 |
+
)
|
173 |
+
|
174 |
+
# Get target model to run on-device
|
175 |
+
target_model = compile_job.get_target_model()
|
176 |
+
|
177 |
+
```
|
178 |
+
|
179 |
+
|
180 |
+
Step 2: **Performance profiling on cloud-hosted device**
|
181 |
+
|
182 |
+
After compiling models from step 1. Models can be profiled model on-device using the
|
183 |
+
`target_model`. Note that this scripts runs the model on a device automatically
|
184 |
+
provisioned in the cloud. Once the job is submitted, you can navigate to a
|
185 |
+
provided job URL to view a variety of on-device performance metrics.
|
186 |
+
```python
|
187 |
+
profile_job = hub.submit_profile_job(
|
188 |
+
model=target_model,
|
189 |
+
device=device,
|
190 |
+
)
|
191 |
+
|
192 |
+
```
|
193 |
+
|
194 |
+
Step 3: **Verify on-device accuracy**
|
195 |
+
|
196 |
+
To verify the accuracy of the model on-device, you can run on-device inference
|
197 |
+
on sample input data on the same cloud hosted device.
|
198 |
+
```python
|
199 |
+
input_data = torch_model.sample_inputs()
|
200 |
+
inference_job = hub.submit_inference_job(
|
201 |
+
model=target_model,
|
202 |
+
device=device,
|
203 |
+
inputs=input_data,
|
204 |
+
)
|
205 |
+
on_device_output = inference_job.download_output_data()
|
206 |
+
|
207 |
+
```
|
208 |
+
With the output of the model, you can compute like PSNR, relative errors or
|
209 |
+
spot check the output with expected output.
|
210 |
+
|
211 |
+
**Note**: This on-device profiling and inference requires access to Qualcomm®
|
212 |
+
AI Hub. [Sign up for access](https://myaccount.qualcomm.com/signup).
|
213 |
+
|
214 |
+
|
215 |
+
|
216 |
+
## Run demo on a cloud-hosted device
|
217 |
+
|
218 |
+
You can also run the demo on-device.
|
219 |
+
|
220 |
+
```bash
|
221 |
+
python -m qai_hub_models.models.bisenet.demo --on-device
|
222 |
+
```
|
223 |
+
|
224 |
+
**NOTE**: If you want running in a Jupyter Notebook or Google Colab like
|
225 |
+
environment, please add the following to your cell (instead of the above).
|
226 |
+
```
|
227 |
+
%run -m qai_hub_models.models.bisenet.demo -- --on-device
|
228 |
+
```
|
229 |
+
|
230 |
+
|
231 |
+
## Deploying compiled model to Android
|
232 |
+
|
233 |
+
|
234 |
+
The models can be deployed using multiple runtimes:
|
235 |
+
- TensorFlow Lite (`.tflite` export): [This
|
236 |
+
tutorial](https://www.tensorflow.org/lite/android/quickstart) provides a
|
237 |
+
guide to deploy the .tflite model in an Android application.
|
238 |
+
|
239 |
+
|
240 |
+
- QNN (`.so` export ): This [sample
|
241 |
+
app](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/sample_app.html)
|
242 |
+
provides instructions on how to use the `.so` shared library in an Android application.
|
243 |
+
|
244 |
+
|
245 |
+
## View on Qualcomm® AI Hub
|
246 |
+
Get more details on BiseNet's performance across various devices [here](https://aihub.qualcomm.com/models/bisenet).
|
247 |
+
Explore all available models on [Qualcomm® AI Hub](https://aihub.qualcomm.com/)
|
248 |
+
|
249 |
+
|
250 |
+
## License
|
251 |
+
* The license for the original implementation of BiseNet can be found
|
252 |
+
[here](This model's original implementation does not provide a LICENSE.).
|
253 |
+
* 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)
|
254 |
+
|
255 |
+
|
256 |
+
|
257 |
+
## References
|
258 |
+
* [BiSeNet Bilateral Segmentation Network for Real-time Semantic Segmentation](https://arxiv.org/abs/1808.00897)
|
259 |
+
* [Source Model Implementation](https://github.com/ooooverflow/BiSeNet)
|
260 |
+
|
261 |
+
|
262 |
+
|
263 |
+
## Community
|
264 |
+
* Join [our AI Hub Slack community](https://aihub.qualcomm.com/community/slack) to collaborate, post questions and learn more about on-device AI.
|
265 |
+
* For questions or feedback please [reach out to us](mailto:[email protected]).
|
266 |
+
|
267 |
+
|