raymondlo84 / openvino-paddlepaddle-demo

This repository provides examples of PaddlePaddle and OpenVINO integration.
Apache License 2.0
22 stars 11 forks source link

OpenVINO PaddlePaddle Integration Demo Preview

[English] | [简体中文]

Note: The work presented in this repository is for demo and preview purposes only.

This repository provides a set of sample code that demostrate how to run PaddlePaddle models in OpenVINO.

scrnli_8_12_2021_7-58-54 PM

How to Setup

Step 0 - Clone the repository

Download this OpenVINO PaddlePaddle sample repository! Please note that we will install materials inside the openvino-paddlepaddle-demo folder as the default working directory.

git clone https://github.com/raymondlo84/openvino-paddlepaddle-demo.git
cd openvino-paddlepaddle-demo

Step 1 - Install OpenVINO from source

Upcoming release openvino 2022.1 will officially support PaddlePaddle. But users can experience this feature from OpenVINO github master branch in advance.

We install the OpenVINO source library to the openvino/openvino_dist directory by default. Users can change it by modifying the cmake option "CMAKE_INSTALL_PREFIX".

For users who may have connection problem to github, may add this configuration to ~/.gitconfig :

    [url "git://github.com"]
          insteadOf="https://github.com"

Clone the OpenVINO source code from GitHub.

git clone https://github.com/openvinotoolkit/openvino.git
cd openvino
git submodule update --init --recursive

Install the dependencies for OpenVINO source and Python.

Compile the source code with the Python option enabled. It may take a few minute depending on your pc.

export OPENVINO_BASEDIR=`pwd`
mkdir build
cd build
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="${OPENVINO_BASEDIR}/openvino_dist" \
-DPYTHON_EXECUTABLE=$(which python3) \
-DENABLE_MYRIAD=OFF \
-DENABLE_VPU=OFF \
-DENABLE_PYTHON=ON \
-DNGRAPH_PYTHON_BUILD_ENABLE=ON \
..

make -j$(nproc); make install

Step 2 - Setup the OpenVINO PaddlePaddle Sample from GitHub

Create the virtual environment and install dependencies. Now let's start from the working directory openvino-paddlepaddle-demo.

cd openvino-paddlepaddle-demo
python3 -m venv openvino_env
source openvino_env/bin/activate

#install the dependencies
python -m pip install --upgrade pip
pip install -r requirements.txt -i https://mirror.baidu.com/pypi/simple

#install the kernel to Jupyter
python -m ipykernel install --user --name openvino_env

Step 3 - Setup PaddleDetection and Dependencies

This step is required as we are going to export the static paddlepaddle model from PaddlePaddle Open Model Zoo PaddleDetection, and may also do inference with PaddlePaddle as well.

# Note: please make sure you are in the openvino-paddlepaddle-demo directory.
git clone https://github.com/PaddlePaddle/PaddleDetection.git
cd PaddleDetection && git checkout release/2.1 && cd - 
pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
pip install --upgrade -r PaddleDetection/requirements.txt -i https://mirror.baidu.com/pypi/simple
#Optional
#python PaddeDetection/setup.py install

Step 4 - Execute the Jupyter Notebooks

Enable the virtual environment, and also the OpenVINO environment. Then, execute the jupyter lab. These steps are required if a new session is used (i.e., the terminal was closed or restarted).

#For Linux and Mac
source openvino_env/bin/activate
source openvino/openvino_dist/setupvars.sh
jupyter lab notebooks

Sample Output

PPYolo - notebooks/101-object-detection-yolo. yolo-output MobilenetV3 Large - notebooks/100-mobilenetv3. scrnli_8_22_2021_7-13-22 PM

Note: Please make sure you select the openvino_env as the Kernel in the Notebooks.

References:

Notes and Disclaimers