Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

How to build a Python wheel package from the main branch of OpenVINO™?

0.00/5 (No votes)
27 Sep 2022 2  
A step-by-step walkthrough on OpenVINO compilation from source

What is a wheel package?

The wheel is a Python ecosystem component that simplifies package installation. It provides quicker installation times and more reliability in the package distribution process. The format contains files and metadata that only need to be moved to the correct location on the target system to be installed. If you used pip to install a Python package, it was most likely a wheel package. And we want to make a .whl file for ease of installation.

Why would I need to build the main branch if there are stable releases?

Sometimes, it’s desirable to use the bleeding-edge build for the following reasons:

  1. There are bugs even in stable releases. If you need those fixes and cannot wait until the next release — the only solution is to build the main branch.
  2. You need a new feature that has already been implemented but is pending for the official releases — once again, build the main branch.
  3. Your resources are limited. Therefore, you need a custom package with only the required modules — customize the compilation and build the main branch.
  4. Because it’s open source, and you can DYI.

How to compile OpenVINO™ and build the Python package? A step-by-step walkthrough

To build the OpenVINO™ Toolkit, you can use a clean Ubuntu 20.04. To avoid dependency issues, we recommend using Docker with your existing OS environment.

Let’s get started.

1. Set up Docker

The very first step is to install Docker. Follow the instructions in the official Docker documentation and post-installation for Linux to address permission issues. We also recommend that you allocate at least 8GB of RAM for an 8-core machine. Please increase the RAM size and rerun the scripts if you ever run a compilation error. Once the installation and configuration process are completed, let’s check that Docker is working.

docker run hello-world

You’re ready to download and run the Ubuntu container. You can use either 18.04 or 20.04. However, please be aware that in the near future support for Ubuntu 18.04 will be dropped.

docker pull ubuntu:20.04
docker run -it ubuntu:20.04

You’re in the new Ubuntu 20.04 container now! The last step at this stage is to install git and sudo inside the Docker and change the directory to /opt.

apt update
apt install git sudo
cd /opt

All the following steps should be run in the container you are in.

2. Clone the repositories

The next step is to clone the repository and the sub-repositories. OpenVINO™ uses packages such as oneDNN and OpenCV, and during the checkout, you will retrieve the latest source from them. There are many submodules, so be sure you run with the --recurse-submodules flag. This may take a while, depending on your internet connection.

git clone --recurse-submodules --single-branch --branch=master https://github.com/openvinotoolkit/openvino.git

3. Install Build Dependencies

There is a helpful script, but it does not install dependencies for Python, so additional steps are required.

cd openvino
./install_build_dependencies.sh
apt install cython3
pip3 install --upgrade pip
pip3 install -r src/bindings/python/wheel/requirements-dev.txt

You must install compute runtime for OpenCL if you want to build a GPU plugin (support for integrated GPUs). If you see any errors, see the instructions here.

apt install intel-opencl-icd

4. Compile the source

Your environment is now ready, and you can configure and run cmake with Python and wheel options enabled. This will create the wheel and all other C++ binaries you can use for releases.

mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_PYTHON=ON -DENABLE_SYSTEM_PUGIXML=OFF -DENABLE_WHEEL=ON ..

Ensure the following options are shown, indicating that plug-ins for CPU, GPU, and VPU will be built, as well as Python support (Python 3.8.10 in this case). To compile against other versions of Python, use the additional options -DPYTHON_EXECUTABLE, -DPYTHON_LIBRARY, and -DPYTHON_INCLUDE_DIR options. For more, see this.

Run make with as many threads as you have and wait 15 to 30 minutes (depending on your machine).

make --jobs=$(nproc --all)

Very rarely, there may be a situation where the OS kills your compilation. If you encounter such a situation (like below), please increase your RAM or make again with fewer jobs concurrently.

When everything is ready, you can find the wheel packages in the wheels directory under the build folder. There are runtime and development packages that look like the following.

The packages are in the container. The last thing you need to do is copy them to your machine. Press Ctrl+P, then Ctrl+Q to exit the container without stopping it. Then run docker ps to get the id of your container and copy the files to your host.

docker ps -a
docker cp <container_id>:/opt/openvino/build/wheels/openvino_dev-2022.3.0–000-py3-none-any.whl .
docker cp <container_id>:/opt/openvino/build/wheels/openvino-2022.3.0–000-cp38-cp38-manylinux_2_31_x86_64.whl .

Finally, you’re ready to use OpenVINO™ bleeding-edge!

Use your new package on your target machine

Create a new virtual environment and install openvino-dev in it. You should use the same version of Python and Ubuntu OS that you compiled OpenVINO™ against.

python3.8 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install openvino-2022.3.0–000-cp38-cp38-manylinux_2_31_x86_64.whl 
pip install openvino_dev-2022.3.0–000-py3-none-any.whl

Let’s run a benchmark to see if everything works. Let it be a person detection model from Open Model Zoo running on the CPU. You may also need to install libgl-dev with apt.

omz_downloader --name person-detection-0200
benchmark_app -m intel/person-detection-0200/FP16-INT8/person-detection-0200.xml -d CPU -t 10

It works! So, now you are ready to import OpenVINO™ and run your code in Python (Python 3.8.10 in this case).

Python 3.8.10 (default, Jun 22 2022, 20:18:18) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import openvino
>>>

Disclaimer: Although you were able to build and run a bleeding edge of OpenVINO™, please note that the main branch is unstable and may have unidentified bugs. This compilation was done on the top of 000f5d8049fd45ddb8b070b0d7a892b2a14ebe11 commit.

References

Solomon Brad, What Are Python Wheels and Why Should You Care? Available at: https://realpython.com/python-wheels/ (accessed: 23rd Aug 2022)

Docker Team, Install Docker Engine on Ubuntu. Available at: https://docs.docker.com/engine/install/ubuntu/ (accessed: 23rd Aug 2022)

Docker Team, Post-installation steps for Linux. Available at: https://docs.docker.com/engine/install/linux-postinstall/ (accessed: 23rd Aug 2022)

Docker Team, Runtime options with Memory, CPUs, and GPUs. Available at: https://docs.docker.com/config/containers/resource_constraints/ (accessed: 23rd Aug 2022)

Intel, GPGPU Installation guide Ubuntu 20.04. Available at: https://dgpu-docs.intel.com/installation-guides/ubuntu/ubuntu-focal.html (accessed: 23rd Aug 2022)

OpenVINO Team, Building for Linux. Available at: https://github.com/openvinotoolkit/openvino/wiki/BuildingForLinux (accessed: 23rd Aug 2022)

OpenVINO Team, Open Model Zoo. Available at: https://github.com/openvinotoolkit/open_model_zoo (accessed: 23rd Aug 2022)

Resources

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here