|
| 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