v0.30.5
Browse filesSee https://github.com/quic/ai-hub-models/releases/v0.30.5 for changelog.
- README.md +303 -0
- Segformer-Base.onnx +3 -0
- Segformer-Base.tflite +3 -0
- Segformer-Base_w8a16.onnx +3 -0
- Segformer-Base_w8a8.onnx +3 -0
- Segformer-Base_w8a8.tflite +3 -0
README.md
ADDED
@@ -0,0 +1,303 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
# Segformer-Base: Optimized for Mobile Deployment
|
14 |
+
## Real-time object segmentation
|
15 |
+
|
16 |
+
|
17 |
+
Segformer Base is a machine learning model that predicts masks and classes of objects in an image.
|
18 |
+
|
19 |
+
This model is an implementation of Segformer-Base found [here](https://github.com/huggingface/transformers/tree/main/src/transformers/models/segformer).
|
20 |
+
|
21 |
+
|
22 |
+
This repository provides scripts to run Segformer-Base on Qualcomm® devices.
|
23 |
+
More details on model performance across various devices, can be found
|
24 |
+
[here](https://aihub.qualcomm.com/models/segformer_base).
|
25 |
+
|
26 |
+
|
27 |
+
### Model Details
|
28 |
+
|
29 |
+
- **Model Type:** Model_use_case.semantic_segmentation
|
30 |
+
- **Model Stats:**
|
31 |
+
- Model checkpoint: nvidia/segformer-b0-finetuned-ade-512-512
|
32 |
+
- Input resolution: 512x512
|
33 |
+
- Number of parameters: 3.7M
|
34 |
+
- Model size: 14.4 MB
|
35 |
+
- Number of output classes: 150
|
36 |
+
|
37 |
+
| Model | Precision | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Primary Compute Unit | Target Model
|
38 |
+
|---|---|---|---|---|---|---|---|---|
|
39 |
+
| Segformer-Base | float | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | TFLITE | 315.099 ms | 9 - 65 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base.tflite) |
|
40 |
+
| Segformer-Base | float | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | QNN | 321.201 ms | 2 - 11 MB | NPU | Use Export Script |
|
41 |
+
| Segformer-Base | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | TFLITE | 114.238 ms | 9 - 66 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base.tflite) |
|
42 |
+
| Segformer-Base | float | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | QNN | 121.029 ms | 3 - 55 MB | NPU | Use Export Script |
|
43 |
+
| Segformer-Base | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | TFLITE | 115.018 ms | 0 - 36 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base.tflite) |
|
44 |
+
| Segformer-Base | float | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | QNN | 116.65 ms | 3 - 6 MB | NPU | Use Export Script |
|
45 |
+
| Segformer-Base | float | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | TFLITE | 117.193 ms | 9 - 66 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base.tflite) |
|
46 |
+
| Segformer-Base | float | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | QNN | 119.038 ms | 1 - 10 MB | NPU | Use Export Script |
|
47 |
+
| Segformer-Base | float | SA7255P ADP | Qualcomm® SA7255P | TFLITE | 315.099 ms | 9 - 65 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base.tflite) |
|
48 |
+
| Segformer-Base | float | SA7255P ADP | Qualcomm® SA7255P | QNN | 321.201 ms | 2 - 11 MB | NPU | Use Export Script |
|
49 |
+
| Segformer-Base | float | SA8255 (Proxy) | Qualcomm® SA8255P (Proxy) | TFLITE | 114.665 ms | 0 - 38 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base.tflite) |
|
50 |
+
| Segformer-Base | float | SA8255 (Proxy) | Qualcomm® SA8255P (Proxy) | QNN | 116.561 ms | 3 - 6 MB | NPU | Use Export Script |
|
51 |
+
| Segformer-Base | float | SA8295P ADP | Qualcomm® SA8295P | TFLITE | 125.933 ms | 9 - 61 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base.tflite) |
|
52 |
+
| Segformer-Base | float | SA8295P ADP | Qualcomm® SA8295P | QNN | 130.6 ms | 0 - 17 MB | NPU | Use Export Script |
|
53 |
+
| Segformer-Base | float | SA8650 (Proxy) | Qualcomm® SA8650P (Proxy) | TFLITE | 114.784 ms | 0 - 33 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base.tflite) |
|
54 |
+
| Segformer-Base | float | SA8650 (Proxy) | Qualcomm® SA8650P (Proxy) | QNN | 116.849 ms | 3 - 5 MB | NPU | Use Export Script |
|
55 |
+
| Segformer-Base | float | SA8775P ADP | Qualcomm® SA8775P | TFLITE | 117.193 ms | 9 - 66 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base.tflite) |
|
56 |
+
| Segformer-Base | float | SA8775P ADP | Qualcomm® SA8775P | QNN | 119.038 ms | 1 - 10 MB | NPU | Use Export Script |
|
57 |
+
| Segformer-Base | float | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 Mobile | TFLITE | 114.86 ms | 0 - 36 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base.tflite) |
|
58 |
+
| Segformer-Base | float | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 Mobile | QNN | 116.832 ms | 3 - 18 MB | NPU | Use Export Script |
|
59 |
+
| Segformer-Base | float | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 Mobile | ONNX | 111.55 ms | 19 - 52 MB | NPU | [Segformer-Base.onnx](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base.onnx) |
|
60 |
+
| Segformer-Base | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | TFLITE | 86.521 ms | 9 - 75 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base.tflite) |
|
61 |
+
| Segformer-Base | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | QNN | 87.898 ms | 3 - 62 MB | NPU | Use Export Script |
|
62 |
+
| Segformer-Base | float | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | ONNX | 83.731 ms | 23 - 81 MB | NPU | [Segformer-Base.onnx](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base.onnx) |
|
63 |
+
| Segformer-Base | float | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite Mobile | TFLITE | 93.336 ms | 8 - 59 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base.tflite) |
|
64 |
+
| Segformer-Base | float | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite Mobile | QNN | 97.56 ms | 3 - 53 MB | NPU | Use Export Script |
|
65 |
+
| Segformer-Base | float | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite Mobile | ONNX | 94.304 ms | 23 - 70 MB | NPU | [Segformer-Base.onnx](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base.onnx) |
|
66 |
+
| Segformer-Base | float | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 121.73 ms | 3 - 3 MB | NPU | Use Export Script |
|
67 |
+
| Segformer-Base | float | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 118.315 ms | 35 - 35 MB | NPU | [Segformer-Base.onnx](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base.onnx) |
|
68 |
+
| Segformer-Base | w8a16 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 Mobile | ONNX | 40.96 ms | 31 - 99 MB | NPU | [Segformer-Base.onnx](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base_w8a16.onnx) |
|
69 |
+
| Segformer-Base | w8a16 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | ONNX | 28.528 ms | 28 - 288 MB | NPU | [Segformer-Base.onnx](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base_w8a16.onnx) |
|
70 |
+
| Segformer-Base | w8a16 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite Mobile | ONNX | 31.159 ms | 27 - 239 MB | NPU | [Segformer-Base.onnx](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base_w8a16.onnx) |
|
71 |
+
| Segformer-Base | w8a16 | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 44.24 ms | 58 - 58 MB | NPU | [Segformer-Base.onnx](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base_w8a16.onnx) |
|
72 |
+
| Segformer-Base | w8a8 | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | TFLITE | 35.944 ms | 2 - 41 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base_w8a8.tflite) |
|
73 |
+
| Segformer-Base | w8a8 | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | QNN | 25.442 ms | 1 - 10 MB | NPU | Use Export Script |
|
74 |
+
| Segformer-Base | w8a8 | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | TFLITE | 13.76 ms | 2 - 49 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base_w8a8.tflite) |
|
75 |
+
| Segformer-Base | w8a8 | QCS8450 (Proxy) | Qualcomm® QCS8450 (Proxy) | QNN | 9.382 ms | 1 - 44 MB | NPU | Use Export Script |
|
76 |
+
| Segformer-Base | w8a8 | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | TFLITE | 13.209 ms | 2 - 14 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base_w8a8.tflite) |
|
77 |
+
| Segformer-Base | w8a8 | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | QNN | 7.852 ms | 1 - 4 MB | NPU | Use Export Script |
|
78 |
+
| Segformer-Base | w8a8 | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | TFLITE | 13.755 ms | 2 - 40 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base_w8a8.tflite) |
|
79 |
+
| Segformer-Base | w8a8 | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | QNN | 8.462 ms | 1 - 13 MB | NPU | Use Export Script |
|
80 |
+
| Segformer-Base | w8a8 | RB3 Gen 2 (Proxy) | Qualcomm® QCS6490 (Proxy) | TFLITE | 122.719 ms | 14 - 55 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base_w8a8.tflite) |
|
81 |
+
| Segformer-Base | w8a8 | RB3 Gen 2 (Proxy) | Qualcomm® QCS6490 (Proxy) | QNN | 33.447 ms | 1 - 13 MB | NPU | Use Export Script |
|
82 |
+
| Segformer-Base | w8a8 | RB5 (Proxy) | Qualcomm® QCS8250 (Proxy) | TFLITE | 415.858 ms | 50 - 68 MB | GPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base_w8a8.tflite) |
|
83 |
+
| Segformer-Base | w8a8 | SA7255P ADP | Qualcomm® SA7255P | TFLITE | 35.944 ms | 2 - 41 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base_w8a8.tflite) |
|
84 |
+
| Segformer-Base | w8a8 | SA7255P ADP | Qualcomm® SA7255P | QNN | 25.442 ms | 1 - 10 MB | NPU | Use Export Script |
|
85 |
+
| Segformer-Base | w8a8 | SA8255 (Proxy) | Qualcomm® SA8255P (Proxy) | TFLITE | 13.24 ms | 2 - 15 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base_w8a8.tflite) |
|
86 |
+
| Segformer-Base | w8a8 | SA8255 (Proxy) | Qualcomm® SA8255P (Proxy) | QNN | 7.806 ms | 1 - 4 MB | NPU | Use Export Script |
|
87 |
+
| Segformer-Base | w8a8 | SA8295P ADP | Qualcomm® SA8295P | TFLITE | 15.501 ms | 2 - 42 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base_w8a8.tflite) |
|
88 |
+
| Segformer-Base | w8a8 | SA8295P ADP | Qualcomm® SA8295P | QNN | 9.948 ms | 1 - 18 MB | NPU | Use Export Script |
|
89 |
+
| Segformer-Base | w8a8 | SA8650 (Proxy) | Qualcomm® SA8650P (Proxy) | TFLITE | 13.25 ms | 2 - 15 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base_w8a8.tflite) |
|
90 |
+
| Segformer-Base | w8a8 | SA8650 (Proxy) | Qualcomm® SA8650P (Proxy) | QNN | 7.81 ms | 1 - 3 MB | NPU | Use Export Script |
|
91 |
+
| Segformer-Base | w8a8 | SA8775P ADP | Qualcomm® SA8775P | TFLITE | 13.755 ms | 2 - 40 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base_w8a8.tflite) |
|
92 |
+
| Segformer-Base | w8a8 | SA8775P ADP | Qualcomm® SA8775P | QNN | 8.462 ms | 1 - 13 MB | NPU | Use Export Script |
|
93 |
+
| Segformer-Base | w8a8 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 Mobile | TFLITE | 13.244 ms | 2 - 15 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base_w8a8.tflite) |
|
94 |
+
| Segformer-Base | w8a8 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 Mobile | QNN | 7.828 ms | 1 - 12 MB | NPU | Use Export Script |
|
95 |
+
| Segformer-Base | w8a8 | Samsung Galaxy S23 | Snapdragon® 8 Gen 2 Mobile | ONNX | 17.979 ms | 3 - 25 MB | NPU | [Segformer-Base.onnx](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base_w8a8.onnx) |
|
96 |
+
| Segformer-Base | w8a8 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | TFLITE | 9.065 ms | 2 - 52 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base_w8a8.tflite) |
|
97 |
+
| Segformer-Base | w8a8 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | QNN | 5.255 ms | 1 - 61 MB | NPU | Use Export Script |
|
98 |
+
| Segformer-Base | w8a8 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | ONNX | 12.47 ms | 5 - 66 MB | NPU | [Segformer-Base.onnx](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base_w8a8.onnx) |
|
99 |
+
| Segformer-Base | w8a8 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite Mobile | TFLITE | 9.279 ms | 2 - 43 MB | NPU | [Segformer-Base.tflite](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base_w8a8.tflite) |
|
100 |
+
| Segformer-Base | w8a8 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite Mobile | QNN | 4.788 ms | 1 - 53 MB | NPU | Use Export Script |
|
101 |
+
| Segformer-Base | w8a8 | Snapdragon 8 Elite QRD | Snapdragon® 8 Elite Mobile | ONNX | 11.956 ms | 5 - 56 MB | NPU | [Segformer-Base.onnx](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base_w8a8.onnx) |
|
102 |
+
| Segformer-Base | w8a8 | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN | 8.692 ms | 1 - 1 MB | NPU | Use Export Script |
|
103 |
+
| Segformer-Base | w8a8 | Snapdragon X Elite CRD | Snapdragon® X Elite | ONNX | 19.372 ms | 9 - 9 MB | NPU | [Segformer-Base.onnx](https://huggingface.co/qualcomm/Segformer-Base/blob/main/Segformer-Base_w8a8.onnx) |
|
104 |
+
|
105 |
+
|
106 |
+
|
107 |
+
|
108 |
+
## Installation
|
109 |
+
|
110 |
+
|
111 |
+
Install the package via pip:
|
112 |
+
```bash
|
113 |
+
pip install qai-hub-models
|
114 |
+
```
|
115 |
+
|
116 |
+
|
117 |
+
## Configure Qualcomm® AI Hub to run this model on a cloud-hosted device
|
118 |
+
|
119 |
+
Sign-in to [Qualcomm® AI Hub](https://app.aihub.qualcomm.com/) with your
|
120 |
+
Qualcomm® ID. Once signed in navigate to `Account -> Settings -> API Token`.
|
121 |
+
|
122 |
+
With this API token, you can configure your client to run models on the cloud
|
123 |
+
hosted devices.
|
124 |
+
```bash
|
125 |
+
qai-hub configure --api_token API_TOKEN
|
126 |
+
```
|
127 |
+
Navigate to [docs](https://app.aihub.qualcomm.com/docs/) for more information.
|
128 |
+
|
129 |
+
|
130 |
+
|
131 |
+
## Demo off target
|
132 |
+
|
133 |
+
The package contains a simple end-to-end demo that downloads pre-trained
|
134 |
+
weights and runs this model on a sample input.
|
135 |
+
|
136 |
+
```bash
|
137 |
+
python -m qai_hub_models.models.segformer_base.demo
|
138 |
+
```
|
139 |
+
|
140 |
+
The above demo runs a reference implementation of pre-processing, model
|
141 |
+
inference, and post processing.
|
142 |
+
|
143 |
+
**NOTE**: If you want running in a Jupyter Notebook or Google Colab like
|
144 |
+
environment, please add the following to your cell (instead of the above).
|
145 |
+
```
|
146 |
+
%run -m qai_hub_models.models.segformer_base.demo
|
147 |
+
```
|
148 |
+
|
149 |
+
|
150 |
+
### Run model on a cloud-hosted device
|
151 |
+
|
152 |
+
In addition to the demo, you can also run the model on a cloud-hosted Qualcomm®
|
153 |
+
device. This script does the following:
|
154 |
+
* Performance check on-device on a cloud-hosted device
|
155 |
+
* Downloads compiled assets that can be deployed on-device for Android.
|
156 |
+
* Accuracy check between PyTorch and on-device outputs.
|
157 |
+
|
158 |
+
```bash
|
159 |
+
python -m qai_hub_models.models.segformer_base.export
|
160 |
+
```
|
161 |
+
```
|
162 |
+
Profiling Results
|
163 |
+
------------------------------------------------------------
|
164 |
+
Segformer-Base
|
165 |
+
Device : cs_8275 (ANDROID 14)
|
166 |
+
Runtime : TFLITE
|
167 |
+
Estimated inference time (ms) : 315.1
|
168 |
+
Estimated peak memory usage (MB): [9, 65]
|
169 |
+
Total # Ops : 545
|
170 |
+
Compute Unit(s) : npu (545 ops) gpu (0 ops) cpu (0 ops)
|
171 |
+
```
|
172 |
+
|
173 |
+
|
174 |
+
## How does this work?
|
175 |
+
|
176 |
+
This [export script](https://aihub.qualcomm.com/models/segformer_base/qai_hub_models/models/Segformer-Base/export.py)
|
177 |
+
leverages [Qualcomm® AI Hub](https://aihub.qualcomm.com/) to optimize, validate, and deploy this model
|
178 |
+
on-device. Lets go through each step below in detail:
|
179 |
+
|
180 |
+
Step 1: **Compile model for on-device deployment**
|
181 |
+
|
182 |
+
To compile a PyTorch model for on-device deployment, we first trace the model
|
183 |
+
in memory using the `jit.trace` and then call the `submit_compile_job` API.
|
184 |
+
|
185 |
+
```python
|
186 |
+
import torch
|
187 |
+
|
188 |
+
import qai_hub as hub
|
189 |
+
from qai_hub_models.models.segformer_base import Model
|
190 |
+
|
191 |
+
# Load the model
|
192 |
+
torch_model = Model.from_pretrained()
|
193 |
+
|
194 |
+
# Device
|
195 |
+
device = hub.Device("Samsung Galaxy S24")
|
196 |
+
|
197 |
+
# Trace model
|
198 |
+
input_shape = torch_model.get_input_spec()
|
199 |
+
sample_inputs = torch_model.sample_inputs()
|
200 |
+
|
201 |
+
pt_model = torch.jit.trace(torch_model, [torch.tensor(data[0]) for _, data in sample_inputs.items()])
|
202 |
+
|
203 |
+
# Compile model on a specific device
|
204 |
+
compile_job = hub.submit_compile_job(
|
205 |
+
model=pt_model,
|
206 |
+
device=device,
|
207 |
+
input_specs=torch_model.get_input_spec(),
|
208 |
+
)
|
209 |
+
|
210 |
+
# Get target model to run on-device
|
211 |
+
target_model = compile_job.get_target_model()
|
212 |
+
|
213 |
+
```
|
214 |
+
|
215 |
+
|
216 |
+
Step 2: **Performance profiling on cloud-hosted device**
|
217 |
+
|
218 |
+
After compiling models from step 1. Models can be profiled model on-device using the
|
219 |
+
`target_model`. Note that this scripts runs the model on a device automatically
|
220 |
+
provisioned in the cloud. Once the job is submitted, you can navigate to a
|
221 |
+
provided job URL to view a variety of on-device performance metrics.
|
222 |
+
```python
|
223 |
+
profile_job = hub.submit_profile_job(
|
224 |
+
model=target_model,
|
225 |
+
device=device,
|
226 |
+
)
|
227 |
+
|
228 |
+
```
|
229 |
+
|
230 |
+
Step 3: **Verify on-device accuracy**
|
231 |
+
|
232 |
+
To verify the accuracy of the model on-device, you can run on-device inference
|
233 |
+
on sample input data on the same cloud hosted device.
|
234 |
+
```python
|
235 |
+
input_data = torch_model.sample_inputs()
|
236 |
+
inference_job = hub.submit_inference_job(
|
237 |
+
model=target_model,
|
238 |
+
device=device,
|
239 |
+
inputs=input_data,
|
240 |
+
)
|
241 |
+
on_device_output = inference_job.download_output_data()
|
242 |
+
|
243 |
+
```
|
244 |
+
With the output of the model, you can compute like PSNR, relative errors or
|
245 |
+
spot check the output with expected output.
|
246 |
+
|
247 |
+
**Note**: This on-device profiling and inference requires access to Qualcomm®
|
248 |
+
AI Hub. [Sign up for access](https://myaccount.qualcomm.com/signup).
|
249 |
+
|
250 |
+
|
251 |
+
|
252 |
+
## Run demo on a cloud-hosted device
|
253 |
+
|
254 |
+
You can also run the demo on-device.
|
255 |
+
|
256 |
+
```bash
|
257 |
+
python -m qai_hub_models.models.segformer_base.demo --eval-mode on-device
|
258 |
+
```
|
259 |
+
|
260 |
+
**NOTE**: If you want running in a Jupyter Notebook or Google Colab like
|
261 |
+
environment, please add the following to your cell (instead of the above).
|
262 |
+
```
|
263 |
+
%run -m qai_hub_models.models.segformer_base.demo -- --eval-mode on-device
|
264 |
+
```
|
265 |
+
|
266 |
+
|
267 |
+
## Deploying compiled model to Android
|
268 |
+
|
269 |
+
|
270 |
+
The models can be deployed using multiple runtimes:
|
271 |
+
- TensorFlow Lite (`.tflite` export): [This
|
272 |
+
tutorial](https://www.tensorflow.org/lite/android/quickstart) provides a
|
273 |
+
guide to deploy the .tflite model in an Android application.
|
274 |
+
|
275 |
+
|
276 |
+
- QNN (`.so` export ): This [sample
|
277 |
+
app](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/sample_app.html)
|
278 |
+
provides instructions on how to use the `.so` shared library in an Android application.
|
279 |
+
|
280 |
+
|
281 |
+
## View on Qualcomm® AI Hub
|
282 |
+
Get more details on Segformer-Base's performance across various devices [here](https://aihub.qualcomm.com/models/segformer_base).
|
283 |
+
Explore all available models on [Qualcomm® AI Hub](https://aihub.qualcomm.com/)
|
284 |
+
|
285 |
+
|
286 |
+
## License
|
287 |
+
* The license for the original implementation of Segformer-Base can be found
|
288 |
+
[here](https://github.com/huggingface/transformers/blob/main/LICENSE).
|
289 |
+
* 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)
|
290 |
+
|
291 |
+
|
292 |
+
|
293 |
+
## References
|
294 |
+
* [SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers](https://arxiv.org/abs/2105.15203)
|
295 |
+
* [Source Model Implementation](https://github.com/huggingface/transformers/tree/main/src/transformers/models/segformer)
|
296 |
+
|
297 |
+
|
298 |
+
|
299 |
+
## Community
|
300 |
+
* Join [our AI Hub Slack community](https://aihub.qualcomm.com/community/slack) to collaborate, post questions and learn more about on-device AI.
|
301 |
+
* For questions or feedback please [reach out to us](mailto:[email protected]).
|
302 |
+
|
303 |
+
|
Segformer-Base.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e7a91ccebd74cb978a659e02b127bb5ae4d1bf9970be76f9688f974721337336
|
3 |
+
size 15145277
|
Segformer-Base.tflite
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:add87dabfd682f27acc59d810a5e6055e09491a4769c8b96190dd77726a30ef4
|
3 |
+
size 15113856
|
Segformer-Base_w8a16.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:825a6b5fc08372f08925e151ec7dc9a87df66ab42277ec0e7b51056f026b87c7
|
3 |
+
size 15454331
|
Segformer-Base_w8a8.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7d98860398daeea7f59e1b0b518a17bbbdefb1cf227c989ac9871e0178f75bcf
|
3 |
+
size 15445355
|
Segformer-Base_w8a8.tflite
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ef433cde49eb9aeb6007d0826a4330b74109ea1acb0566e41480a9dc668c510c
|
3 |
+
size 4087088
|