Skip to content

Commit 4720be1

Browse files
authored
Dev (#197)
* readme * add openvino * refactor format
1 parent 44b2307 commit 4720be1

File tree

6 files changed

+375
-8
lines changed

6 files changed

+375
-8
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,7 @@ datasets/coco/train.txt
115115
datasets/coco/val.txt
116116
pretrained/*
117117
dist_train.sh
118+
openvino/build/*
119+
openvino/output*
118120

119121
tvm/

README.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# BiSeNetV1 & BiSeNetV2
22

3-
My implementation of [BiSeNetV1](https://arxiv.org/abs/1808.00897) and [BiSeNetV2](https://arxiv.org/abs/1808.00897).
3+
My implementation of [BiSeNetV1](https://arxiv.org/abs/1808.00897) and [BiSeNetV2](https://arxiv.org/abs/2004.02147).
44

55

66
mIOUs and fps on cityscapes val set:
@@ -9,33 +9,39 @@ mIOUs and fps on cityscapes val set:
99
| bisenetv1 | 75.44 | 76.94 | 77.45 | 78.86 | 68/23 | [download](https://github.com/CoinCheung/BiSeNet/releases/download/0.0.0/model_final_v1_city_new.pth) |
1010
| bisenetv2 | 74.95 | 75.58 | 76.53 | 77.08 | 59/21 | [download](https://github.com/CoinCheung/BiSeNet/releases/download/0.0.0/model_final_v2_city.pth) |
1111

12-
1312
mIOUs on cocostuff val2017 set:
1413
| none | ss | ssc | msf | mscf | link |
1514
|------|:--:|:---:|:---:|:----:|:----:|
1615
| bisenetv1 | 31.49 | 31.42 | 32.46 | 32.55 | [download](https://github.com/CoinCheung/BiSeNet/releases/download/0.0.0/model_final_v1_coco_new.pth) |
1716
| bisenetv2 | 30.49 | 30.55 | 31.81 | 31.73 | [download](https://github.com/CoinCheung/BiSeNet/releases/download/0.0.0/model_final_v2_coco.pth) |
1817

1918
Tips:
19+
2020
1. **ss** means single scale evaluation, **ssc** means single scale crop evaluation, **msf** means multi-scale evaluation with flip augment, and **mscf** means multi-scale crop evaluation with flip evaluation. The eval scales and crop size of multi-scales evaluation can be found in [configs](./configs/).
2121

2222
2. The fps is tested in different way from the paper. For more information, please see [here](./tensorrt).
2323

24-
3. For cocostuff dataset: The authors of the paper `bisenetv2` used the "old split" of 9k train set and 1k val set, while I used the "new split" of 118k train set and 5k val set. Thus the above results on cocostuff does not match the paper. The authors of bisenetv1 did not report their results on cocostuff, so here I simply provide a "make it work" result. Following the tradition of object detection, I used "1x"(90k) and "2x"(180k) schedule to train bisenetv1(1x) and bisenetv2(2x) respectively. Maybe you can have a better result by picking up hyper-parameters more carefully.
24+
3. The authors of bisenetv2 used cocostuff-10k, while I used cocostuff-123k(do not know how to say, just same 118k train and 5k val images as object detection). Thus the results maybe different from paper.
2525

2626
4. The model has a big variance, which means that the results of training for many times would vary within a relatively big margin. For example, if you train bisenetv2 for many times, you will observe that the result of **ss** evaluation of bisenetv2 varies between 73.1-75.1.
2727

2828

2929
## deploy trained models
30+
3031
1. tensorrt
31-
You can go to [tensorrt](./tensorrt) for details.
32+
You can go to [tensorrt](./tensorrt) for details.
3233

3334
2. ncnn
34-
You can go to [ncnn](./ncnn) for details.
35+
You can go to [ncnn](./ncnn) for details.
36+
37+
3. openvino
38+
You can go to [openvino](./openvino) for details.
3539

3640

3741
## platform
42+
3843
My platform is like this:
44+
3945
* ubuntu 18.04
4046
* nvidia Tesla T4 gpu, driver 450.51.05
4147
* cuda 10.2
@@ -45,10 +51,13 @@ My platform is like this:
4551

4652

4753
## get start
54+
4855
With a pretrained weight, you can run inference on an single image like this:
56+
4957
```
5058
$ python tools/demo.py --config configs/bisenetv2_city.py --weight-path /path/to/your/weights.pth --img-path ./example.png
5159
```
60+
5261
This would run inference on the image and save the result image to `./res.jpg`.
5362

5463

@@ -95,7 +104,9 @@ Then you need to change the field of `im_root` and `train/val_im_anns` in the co
95104

96105

97106
## train
107+
98108
I used the following command to train the models:
109+
99110
```bash
100111
# bisenetv1 cityscapes
101112
export CUDA_VISIBLE_DEVICES=0,1
@@ -128,6 +139,7 @@ Note:
128139

129140

130141
## finetune from trained model
142+
131143
You can also load the trained model weights and finetune from it, like this:
132144
```
133145
$ export CUDA_VISIBLE_DEVICES=0,1

ncnn/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ Though this demo runs on x86 platform, you can also use it on mobile platforms.
1414
### Install ncnn
1515

1616
#### 1. dependencies
17-
```
18-
$ python -m pip install onnx-simplifier
19-
```
17+
```
18+
$ python -m pip install onnx-simplifier
19+
```
2020

2121
#### 2. build ncnn
2222
Just follow the ncnn official tutoral of [build-for-linux](https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-linux) to install ncnn:

openvino/CMakeLists.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
cmake_minimum_required (VERSION 3.10)
3+
4+
cmake_policy(SET CMP0025 NEW)
5+
6+
project(Samples)
7+
8+
9+
set (CMAKE_CXX_STANDARD 14)
10+
set(CMAKE_BUILD_TYPE "Release")
11+
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wuninitialized -Winit-self")
12+
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
13+
14+
15+
find_package(OpenCV REQUIRED)
16+
find_package(InferenceEngine REQUIRED)
17+
find_package(ngraph REQUIRED)
18+
19+
20+
include_directories(
21+
${CMAKE_CURRENT_SOURCE_DIR}
22+
${CMAKE_CURRENT_BINARY_DIR}
23+
${OpenCV_INCLUDE_DIRS}
24+
)
25+
26+
add_executable(segment main.cpp)
27+
target_link_libraries(
28+
segment
29+
${InferenceEngine_LIBRARIES}
30+
${NGRAPH_LIBRARIES}
31+
${OpenCV_LIBS}
32+
)
33+
34+
35+

openvino/README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
2+
3+
## A demo of using openvino to deploy
4+
5+
Openvino is used to deploy model on intel cpus or "gpu inside cpu".
6+
7+
My cpu is Intel(R) Xeon(R) Gold 6240 CPU @ 2.60GHz.
8+
9+
10+
### preparation
11+
12+
1.Train the model and export it to onnx
13+
```
14+
$ cd BiSeNet/
15+
$ python tools/export_onnx.py --aux-mode eval --config configs/bisenetv2_city.py --weight-path /path/to/your/model.pth --outpath ./model_v2.onnx
16+
```
17+
(Optional) 2.Install 'onnx-simplifier' to simplify the generated onnx model:
18+
```
19+
$ python -m pip install onnx-simplifier
20+
$ python -m onnxsim model_v2.onnx model_v2_sim.onnx
21+
```
22+
23+
24+
### Install and configure openvino
25+
26+
1.pull docker image
27+
```
28+
$ docker pull openvino/ubuntu18_dev
29+
```
30+
31+
2.start a docker container and mount code into it
32+
```
33+
$ docker run -itu root -v /path/to/BiSeNet:/BiSeNet openvino/ubuntu18_dev --device /dev/dri:/dev/dri bash
34+
35+
```
36+
If your cpu does not have intel "gpu inside of cpu" or you do not want to use it, you can remove the option of `--device /dev/dri:/dev/dri`.
37+
38+
After running the above command, you will be in the container.
39+
40+
(optional) 3.install gpu dependencies
41+
If you want to use gpu, you also need to install some dependencies inside the container:
42+
```
43+
# mkdir -p /tmp/opencl && cd /tmp/opencl
44+
# useradd -ms /bin/bash -G video,users openvino
45+
# chown openvino -R /home/openvino
46+
# apt update
47+
# apt install -y --no-install-recommends ocl-icd-libopencl1
48+
# curl -L "https://github.com/intel/compute-runtime/releases/download/19.41.14441/intel-gmmlib_19.3.2_amd64.deb" --output "intel-gmmlib_19.3.2_amd64.deb"
49+
# curl -L "https://github.com/intel/compute-runtime/releases/download/19.41.14441/intel-igc-core_1.0.2597_amd64.deb" --output "intel-igc-core_1.0.2597_amd64.deb"
50+
# curl -L "https://github.com/intel/compute-runtime/releases/download/19.41.14441/intel-igc-opencl_1.0.2597_amd64.deb" --output "intel-igc-opencl_1.0.2597_amd64.deb"
51+
# curl -L "https://github.com/intel/compute-runtime/releases/download/19.41.14441/intel-opencl_19.41.14441_amd64.deb" --output "intel-opencl_19.41.14441_amd64.deb"
52+
# curl -L "https://github.com/intel/compute-runtime/releases/download/19.41.14441/intel-ocloc_19.41.14441_amd64.deb" --output "intel-ocloc_19.04.12237_amd64.deb"
53+
# dpkg -i /tmp/opencl/*.deb
54+
# apt --fix-broken install
55+
# ldconfig
56+
```
57+
58+
I got the above commands from the official docs but I did not test it since my cpu does not have integrated gpu.
59+
60+
61+
4.configure environment
62+
just run this script, and the environment would be ready:
63+
```
64+
# source /opt/intel/openvino_2021.4.689/bin/setupvars.sh
65+
```
66+
67+
68+
### convert model and run demo
69+
70+
1.convert onnx to openvino IR
71+
In the docker container:
72+
```
73+
# cd /opt/intel/openvino_2021.4.689/deployment_tools/model_optimizer
74+
# python3 mo.py --input_model /BiSeNet/model_v2.onnx --output_dir /BiSeNet/openvino/output_v2
75+
```
76+
77+
2.compile and run the demo
78+
```
79+
# cd /BiSeNet/openvino
80+
# mkdir -p build && cd build
81+
# cmake .. && make
82+
# ./segment
83+
```
84+
After this, you will see a segmentation result image named `res.jpg` generated.
85+
86+
87+
88+
### Tipes
89+
90+
1.GPU support: openvino supports intel cpu and intel "gpu inside cpu". Until now(2021.11), other popular isolated gpus are not supported, such as nvidia/amd gpus. Also, other integrated gpus are not supported, such as aspeed graphics family.
91+
92+
2.About low-precision: precision is optimized automatically, and the model will be run in one or several precision mode. We can also manually enforce to use bf16, as long as our cpu have `avx512_bf16` supports. If cpu does not support bf16, it will use simulation which would slow down the inference. If neither native bf16 nor simulation is supported, an error would occur.

0 commit comments

Comments
 (0)