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|
3 |
+
- VOC2012
|
4 |
+
library_name: pytorch
|
5 |
+
license: mit
|
6 |
+
pipeline_tag: image-segmentation
|
7 |
+
tags:
|
8 |
+
- quantized
|
9 |
+
- android
|
10 |
+
|
11 |
+
---
|
12 |
+
|
13 |
+
![](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/deeplabv3_plus_mobilenet_quantized/web-assets/model_demo.png)
|
14 |
+
|
15 |
+
# DeepLabV3-Plus-MobileNet-Quantized: Optimized for Mobile Deployment
|
16 |
+
## Quantized Deep Convolutional Neural Network model for semantic segmentation
|
17 |
+
|
18 |
+
DeepLabV3 Quantized is designed for semantic segmentation at multiple scales, trained on various datasets. It uses MobileNet as a backbone.
|
19 |
+
|
20 |
+
This model is an implementation of DeepLabV3-Plus-MobileNet-Quantized found [here](https://github.com/jfzhang95/pytorch-deeplab-xception).
|
21 |
+
This repository provides scripts to run DeepLabV3-Plus-MobileNet-Quantized on Qualcomm® devices.
|
22 |
+
More details on model performance across various devices, can be found
|
23 |
+
[here](https://aihub.qualcomm.com/models/deeplabv3_plus_mobilenet_quantized).
|
24 |
+
|
25 |
+
|
26 |
+
### Model Details
|
27 |
+
|
28 |
+
- **Model Type:** Semantic segmentation
|
29 |
+
- **Model Stats:**
|
30 |
+
- Model checkpoint: VOC2012
|
31 |
+
- Input resolution: 513x513
|
32 |
+
- Number of parameters: 5.80M
|
33 |
+
- Model size: 6.04 MB
|
34 |
+
|
35 |
+
|
36 |
+
| Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Precision | Primary Compute Unit | Target Model
|
37 |
+
| ---|---|---|---|---|---|---|---|
|
38 |
+
| Samsung Galaxy S23 Ultra (Android 13) | Snapdragon® 8 Gen 2 | TFLite | 3.523 ms | 0 - 2 MB | INT8 | NPU | [DeepLabV3-Plus-MobileNet-Quantized.tflite](https://huggingface.co/qualcomm/DeepLabV3-Plus-MobileNet-Quantized/blob/main/DeepLabV3-Plus-MobileNet-Quantized.tflite)
|
39 |
+
| Samsung Galaxy S23 Ultra (Android 13) | Snapdragon® 8 Gen 2 | QNN Model Library | 5.308 ms | 1 - 9 MB | INT8 | NPU | [DeepLabV3-Plus-MobileNet-Quantized.so](https://huggingface.co/qualcomm/DeepLabV3-Plus-MobileNet-Quantized/blob/main/DeepLabV3-Plus-MobileNet-Quantized.so)
|
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
|
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.deeplabv3_plus_mobilenet_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.deeplabv3_plus_mobilenet_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.deeplabv3_plus_mobilenet_quantized.export
|
94 |
+
```
|
95 |
+
|
96 |
+
```
|
97 |
+
Profile Job summary of DeepLabV3-Plus-MobileNet-Quantized
|
98 |
+
--------------------------------------------------
|
99 |
+
Device: QCS8550 (Proxy) (12)
|
100 |
+
Estimated Inference Time: 3.53 ms
|
101 |
+
Estimated Peak Memory Range: 0.01-16.76 MB
|
102 |
+
Compute Units: NPU (99) | Total (99)
|
103 |
+
|
104 |
+
Profile Job summary of DeepLabV3-Plus-MobileNet-Quantized
|
105 |
+
--------------------------------------------------
|
106 |
+
Device: QCS8550 (Proxy) (12)
|
107 |
+
Estimated Inference Time: 5.30 ms
|
108 |
+
Estimated Peak Memory Range: 0.79-13.51 MB
|
109 |
+
Compute Units: NPU (100) | Total (100)
|
110 |
+
|
111 |
+
|
112 |
+
```
|
113 |
+
## How does this work?
|
114 |
+
|
115 |
+
This [export script](https://github.com/quic/ai-hub-models/blob/main/qai_hub_models/models/DeepLabV3-Plus-MobileNet-Quantized/export.py)
|
116 |
+
leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
|
117 |
+
on-device. Lets go through each step below in detail:
|
118 |
+
|
119 |
+
Step 1: **Compile model for on-device deployment**
|
120 |
+
|
121 |
+
To compile a PyTorch model for on-device deployment, we first trace the model
|
122 |
+
in memory using the `jit.trace` and then call the `submit_compile_job` API.
|
123 |
+
|
124 |
+
```python
|
125 |
+
import torch
|
126 |
+
|
127 |
+
import qai_hub as hub
|
128 |
+
from qai_hub_models.models.deeplabv3_plus_mobilenet_quantized import Model
|
129 |
+
|
130 |
+
# Load the model
|
131 |
+
torch_model = Model.from_pretrained()
|
132 |
+
torch_model.eval()
|
133 |
+
|
134 |
+
# Device
|
135 |
+
device = hub.Device("Samsung Galaxy S23")
|
136 |
+
|
137 |
+
# Trace model
|
138 |
+
input_shape = torch_model.get_input_spec()
|
139 |
+
sample_inputs = torch_model.sample_inputs()
|
140 |
+
|
141 |
+
pt_model = torch.jit.trace(torch_model, [torch.tensor(data[0]) for _, data in sample_inputs.items()])
|
142 |
+
|
143 |
+
# Compile model on a specific device
|
144 |
+
compile_job = hub.submit_compile_job(
|
145 |
+
model=pt_model,
|
146 |
+
device=device,
|
147 |
+
input_specs=torch_model.get_input_spec(),
|
148 |
+
)
|
149 |
+
|
150 |
+
# Get target model to run on-device
|
151 |
+
target_model = compile_job.get_target_model()
|
152 |
+
|
153 |
+
```
|
154 |
+
|
155 |
+
|
156 |
+
Step 2: **Performance profiling on cloud-hosted device**
|
157 |
+
|
158 |
+
After compiling models from step 1. Models can be profiled model on-device using the
|
159 |
+
`target_model`. Note that this scripts runs the model on a device automatically
|
160 |
+
provisioned in the cloud. Once the job is submitted, you can navigate to a
|
161 |
+
provided job URL to view a variety of on-device performance metrics.
|
162 |
+
```python
|
163 |
+
profile_job = hub.submit_profile_job(
|
164 |
+
model=target_model,
|
165 |
+
device=device,
|
166 |
+
)
|
167 |
+
|
168 |
+
```
|
169 |
+
|
170 |
+
Step 3: **Verify on-device accuracy**
|
171 |
+
|
172 |
+
To verify the accuracy of the model on-device, you can run on-device inference
|
173 |
+
on sample input data on the same cloud hosted device.
|
174 |
+
```python
|
175 |
+
input_data = torch_model.sample_inputs()
|
176 |
+
inference_job = hub.submit_inference_job(
|
177 |
+
model=target_model,
|
178 |
+
device=device,
|
179 |
+
inputs=input_data,
|
180 |
+
)
|
181 |
+
|
182 |
+
on_device_output = inference_job.download_output_data()
|
183 |
+
|
184 |
+
```
|
185 |
+
With the output of the model, you can compute like PSNR, relative errors or
|
186 |
+
spot check the output with expected output.
|
187 |
+
|
188 |
+
**Note**: This on-device profiling and inference requires access to Qualcomm®
|
189 |
+
AI Hub. [Sign up for access](https://myaccount.qualcomm.com/signup).
|
190 |
+
|
191 |
+
|
192 |
+
## Run demo on a cloud-hosted device
|
193 |
+
|
194 |
+
You can also run the demo on-device.
|
195 |
+
|
196 |
+
```bash
|
197 |
+
python -m qai_hub_models.models.deeplabv3_plus_mobilenet_quantized.demo --on-device
|
198 |
+
```
|
199 |
+
|
200 |
+
**NOTE**: If you want running in a Jupyter Notebook or Google Colab like
|
201 |
+
environment, please add the following to your cell (instead of the above).
|
202 |
+
```
|
203 |
+
%run -m qai_hub_models.models.deeplabv3_plus_mobilenet_quantized.demo -- --on-device
|
204 |
+
```
|
205 |
+
|
206 |
+
|
207 |
+
## Deploying compiled model to Android
|
208 |
+
|
209 |
+
|
210 |
+
The models can be deployed using multiple runtimes:
|
211 |
+
- TensorFlow Lite (`.tflite` export): [This
|
212 |
+
tutorial](https://www.tensorflow.org/lite/android/quickstart) provides a
|
213 |
+
guide to deploy the .tflite model in an Android application.
|
214 |
+
|
215 |
+
|
216 |
+
- QNN (`.so` export ): This [sample
|
217 |
+
app](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/sample_app.html)
|
218 |
+
provides instructions on how to use the `.so` shared library in an Android application.
|
219 |
+
|
220 |
+
|
221 |
+
## View on Qualcomm® AI Hub
|
222 |
+
Get more details on DeepLabV3-Plus-MobileNet-Quantized's performance across various devices [here](https://aihub.qualcomm.com/models/deeplabv3_plus_mobilenet_quantized).
|
223 |
+
Explore all available models on [Qualcomm® AI Hub](https://aihub.qualcomm.com/)
|
224 |
+
|
225 |
+
## License
|
226 |
+
- The license for the original implementation of DeepLabV3-Plus-MobileNet-Quantized can be found
|
227 |
+
[here](https://github.com/quic/aimet-model-zoo/blob/develop/LICENSE.pdf).
|
228 |
+
- The license for the compiled assets for on-device deployment can be found [here]({deploy_license_url})
|
229 |
+
|
230 |
+
## References
|
231 |
+
* [Rethinking Atrous Convolution for Semantic Image Segmentation](https://arxiv.org/abs/1706.05587)
|
232 |
+
* [Source Model Implementation](https://github.com/jfzhang95/pytorch-deeplab-xception)
|
233 |
+
|
234 |
+
## Community
|
235 |
+
* 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.
|
236 |
+
* For questions or feedback please [reach out to us](mailto:[email protected]).
|
237 |
+
|
238 |
+
|