File size: 4,424 Bytes
f3689ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8091a0d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
---
license: apache-2.0
language:
- en
base_model:
- briaai/RMBG-1.4
pipeline_tag: image-segmentation
---
# RMBG-1.4 

This version of RMBG-1.4 has been converted to run on the Axera NPU using **w8a8** quantization.

Compatible with Pulsar2 version: 5.1

## Convert tools links:

For those who are interested in model conversion, you can try to export axmodel through

- [The repo of AXera Platform](https://github.com/AXERA-TECH/ax-samples), which you can get the detial of guide
- [Pulsar2 Link, How to Convert ONNX to axmodel](https://pulsar2-docs.readthedocs.io/en/latest/pulsar2/introduction.html)


## Support Platform

- AX650

  - [M4N-Dock(爱芯派Pro)](https://wiki.sipeed.com/hardware/zh/maixIV/m4ndock/m4ndock.html)

  - [M.2 Accelerator card](https://axcl-docs.readthedocs.io/zh-cn/latest/doc_introduction.html)

| Chips | cost   |
| ----- | ------ |
| AX650 | 128 ms |

## How to use

Download all files from this repository to the device

```bash
(base) root@ax650:/home/ax650/RMBG-1.4# tree
.
├── ax_inference.py
├── axmodel
│   ├── build_config.json
│   └── rmbg1_4_ax650.axmodel
├── ax_rmbg
├── img
│   ├── 3_1920x1080.jpg
│   └── example_input.jpg
├── mask.png
├── README.md
├── result.png
└── rmbg_1_4_sim.onnx
```

### Inference

If you Inference with python,pyaxengine is need,you can install by:

```python
wget https://github.com/AXERA-TECH/pyaxengine/releases/download/0.1.3.rc1/axengine-0.1.3-py3-none-any.whl
pip install axengine-0.1.3-py3-none-any.whl
```

Inference with AX650 Host, such as M4N-Dock(爱芯派Pro)

```python
(base) root@ax650:/home/ax650/RMBG-1.4# python3 ax_inference.py -m ./axmodel/rmbg1_4_ax650.axmodel -i ./img/example_input.jpg
Command: ax_inference.py -m ./axmodel/rmbg1_4_ax650.axmodel -i ./img/example_input.jpg
Parameters:
  --model: ./axmodel/rmbg1_4_ax650.axmodel
  --img_path: ./img/example_input.jpg
  --save_path: ./result.png
[INFO] Available providers:  ['AxEngineExecutionProvider']
[INFO] Using provider: AxEngineExecutionProvider
[INFO] Chip type: ChipType.MC50
[INFO] VNPU type: VNPUType.DISABLED
[INFO] Engine version: 2.12.0s
[INFO] Model type: 0 (single core)
[INFO] Compiler version: 5.1 59c683ff
输入名称:input,输入尺寸:[1024, 1024]
推理时间:121.97 ms
推理完成,带透明通道的结果已保存至:./result.png
```

|                            Input                             |                            Output                            |
| :----------------------------------------------------------: | :----------------------------------------------------------: |
| <img src="./img/example_input.jpg" alt="example_input" style="zoom: 33%;" /> | <img src="./img/example_input_result.png" alt="example_input_result" style="zoom:33%;" /> |

Inference with C++ version :

```
(base) root@ax650:/home/ax650/RMBG-1.4# ./ax_rmbg -m ./axmodel/rmbg1_4_ax650.axmodel -i ./img/3_1920x1080.jpg
--------------------------------------
Model file: ./axmodel/rmbg1_4_ax650.axmodel
Input image: ./img/3_1920x1080.jpg
Output image: result.png
Model input size: 1024 x 1024
Repeat count: 1
--------------------------------------
Original image size: 1920 x 1080, channels: 3
Engine creating handle is done.
Engine creating context is done.
Engine get io info is done. 
Inputs:
  [0] name: input, shape: [1, 3, 1024, 1024]
Outputs:
  [0] name: output, shape: [1, 1, 1024, 1024]
Engine alloc io is done. 
Engine push input is done. 
--------------------------------------
post process cost time:23.89 ms 
--------------------------------------
Repeat 1 times, avg time 106.16 ms, max_time 106.16 ms, min_time 106.16 ms
--------------------------------------
Saved result image: result.png
Saved mask: mask.png
```

| Input                                                        | Output                                                       | Mask                                                         |
| ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
| <img src="./img/3_1920x1080.jpg" alt="3_1920x1080" style="zoom:20%;" /> | <img src="./img/3_1920x1080_result.png" alt="3_1920x1080_result" style="zoom:20%;" /> | <img src="./img/3_1920x1080_mask.png" alt="3_1920x1080_mask" style="zoom:20%;" /> |