Run OpenVino on macOS and pyenv and pipenv environment

What is this?

A memorandum on how to get openvino to work well on macOS Catalina when pyenv is also using pipenv. This is a sequel to "Running OpenVino on macOS Catalina". If you are not using a virtual environment or are good at building an environment, please refer to that. This is a brush-up of the content for beginners who are using the above environment.

environment

macOS Catalina(10.15.4) OpenVino(2020.2.117) Python 3.7.5 cmake 3.17.1

Precautions in general

If you install OpenVino and run it according to the tutorial, you will pass the path to opencv made by the user or use pip without permission, so it makes no sense to use pyenv or pipenv accidentally. Look at the sauce first, not as it was said. It's a little annoying, but if you don't write the $ source /opt/intel/openvino/bin/setupvars.sh mystery in .bash_profile etc. and execute it every time you start the terminal, it may conflict with other development environments. It will be lower.

Download and install OpenVino

Download and unzip the dmg for macOS from here Run. It is usually installed as the root user. When you're done, you'll be taken to a web page, but don't run the tutorial demo yet here!

Building a project environment

Create a project directory and set pyenv and pipenv. The recommended version of python for OpenVino is 3.7.5, so install 3.7.5 for pyenv.

$ pyenv install 3.7.5
$ mkdir ~/Documents/openvino-projects
$ cd ~/Documents/openvino-projects
$ source /opt/intel/openvino/bin/setupvars.sh
[setupvars.sh] OpenVINO environment initialized

We've put together a tutorial demo and some libraries used in other demos. Place the following content in the project directory (here ~ / Documents / openvino-projects) with the name Pipfile.

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
tensorflow = "<2.0.0,>=1.2.0"
mxnet = ">=1.0.0,<=1.5.1"
networkx = ">=1.11"
numpy = ">=1.12.0"
protobuf = "==3.6.1"
onnx = ">=1.1.2"
defusedxml = ">=0.5.0"
pyyaml = "*"
requests = "*"
scipy = "*"

[requires]
python_version = "3.7"

Build a virtual environment and enter the shell.

$ cd ~/Documents/openvino-projects
$ pyenv local 3.7.5
$ pipenv --python 3.7.5
........Abbreviation
$ pipenv install
#Locking here..If it doesn't end forever, it's unavoidable (although I can't recommend it very much), so after forcibly terminating,
pipenv install --skip-Let's lock.
........Abbreviation
$ pipenv shell

Run the tutorial

The tutorial demo on the web page that appears after installation just runs a script that downloads, transforms, and even runs the model, but that does some extra work, so I'll fix it a bit.

$ cd /opt/intel/openvino/deployment_tools/demo/
$ sudo cp ./demo_squeezenet_download_convert_run.sh ./demo_squeezenet_download_convert_run2.sh

Comment out lines 146-150 of demo_squeezenet_download_convert_run2.sh and save (requires root privileges).

demo_squeezenet_download_convert_run2.sh


#if [[ "$OSTYPE" == "darwin"* ]]; then
#    $pip_binary install -r $ROOT_DIR/../open_model_zoo/tools/downloader/requirements.in
#else
#    sudo -E $pip_binary install -r $ROOT_DIR/../open_model_zoo/tools/downloader/requirements.in
#fi

Run.

$ ./demo_squeezenet_download_convert_run2.sh
........Abbreviation
$ ./demo_security_barrier_camera.sh
........Abbreviation

If there is no error and the result is something like WEB page

Run a C ++ demo

Save the following content in your project directory as update_rpath.sh.

update_rpath.sh


install_name_tool -add_rpath '/opt/intel/openvino/opencv/lib' /opt/intel/openvino_2020.2.117/python/python3/cv2.so
install_name_tool -add_rpath '/opt/intel/openvino/inference_engine/lib/intel64' /opt/intel/openvino_2020.2.117/python/python3/cv2.so
install_name_tool -add_rpath '/opt/intel/openvino/deployment_tools/ngraph/lib' /opt/intel/openvino_2020.2.117/python/python3/cv2.so
install_name_tool -add_rpath '/opt/intel/openvino/inference_engine/external/tbb/lib' /opt/intel/openvino/deployment_tools/inference_engine/lib/intel64/libinference_engine_legacy.dylib
install_name_tool -add_rpath '/opt/intel/openvino/inference_engine/lib/intel64' /opt/intel/openvino/deployment_tools/inference_engine/lib/intel64/libMKLDNNPlugin.dylib
install_name_tool -add_rpath '/opt/intel/openvino/inference_engine/lib/intel64' /opt/intel/openvino/python/python3.7/openvino/inference_engine/ie_api.so
install_name_tool -add_rpath '/opt/intel/openvino/inference_engine/external/tbb/lib' /opt/intel/openvino/python/python3.7/openvino/inference_engine/ie_api.so
install_name_tool -add_rpath '/opt/intel/openvino/deployment_tools/ngraph/lib' /opt/intel/openvino/deployment_tools/inference_engine/lib/intel64/libinference_engine.dylib
install_name_tool -add_rpath '/opt/intel/openvino/deployment_tools/ngraph/lib' /opt/intel/openvino/deployment_tools/inference_engine/lib/intel64/libinference_engine_legacy.dylib

Run the above file (see previous post (https://qiita.com/y-fuku/items/ed70fac7f65ef73f80f6) for more information on why this is done).

$ cd ~/Documents/openvino-projects
$ chmod 755 ./update_rpath.sh
$ sudo ./update_rpath.sh

Copy the directory containing the demo files to your project directory.

$ cp -r /opt/intel/openvino/deployment_tools/open_model_zoo/demos .

cmake with the python module option.

$ cd demos
$ cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_PYTHON=ON .
......Abbreviation

However, it will not compile as it is, so edit CmakeCache.txt (line 34).

CMakeCache.txt


...... Omitted ...
//Flags used by the CXX compiler during all build types.
CMAKE_CXX_FLAGS:STRING=-Wno-inconsistent-missing-override
...... Omitted ...

make

$ make -j2
...... Omitted ...

The executable file is built under intel64 / Release. Let's run crossroad_camera_demo. First, take a look at the Explanation page for each sample.

crossroad_camera_demo is the page here. Let's read it carefully for the time being. First of all, you need to download the necessary model files. Download the required model as follows.

$ cd ~/Documents/openvino-projects
$ /opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/downloader.py --name person-vehicle-bike-detection-crossroad-0078
...... Omitted ...
$ /opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/downloader.py --name person-attributes-recognition-crossroad-0230
...... Omitted ...
$ /opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/downloader.py --name person-reidentification-retail-0031
...... Omitted ...

The model will be downloaded under openvino-projects / intel /. crossroad_camera_demo can use a video file or camera as input, but a PC camera is not suitable for taking pictures of passersby, so use a suitable video file. Useful resources for the demo are here.

Let's use people-detection.mp4 here.

$ mkdir sample-videos
# people-detection.Download mp4 and sample-Put it in the videos folder.

$ ./demos/intel64/Release/crossroad_camera_demo \
-i ./sample-videos/people-detection.mp4 \
-m ./intel/person-vehicle-bike-detection-crossroad-0078/FP16/person-vehicle-bike-detection-crossroad-0078.xml \
-m_pa ./intel/person-attributes-recognition-crossroad-0230/FP16/person-attributes-recognition-crossroad-0230.xml \
-m_reid ./intel/person-reidentification-retail-0031/FP16/person-reidentification-retail-0031.xml \
-d CPU -d_pa CPU -d_reid CPU

In this demo, we will use separate models to detect people, estimate attribute information, and perform tracking.

Run a python demo

A demo for python can be found under demos / python_demos /. Let's run a demo of Face Recognition. Click here for the Face Recognition explanation page. Similarly, download and run the required model file. This time I will use a PC camera. In this demo, you can use the simple face recognition function with the --run_detector option. Take a photo of the target face.

$ cd ~/Documents/openvino-projects
$ mkdir face-data
#Take a picture of yourself, myname.jpg, etc., face-Put it in data.

#Download model (execute directly under the project directory)
$ /opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/downloader.py --name face-detection-retail-0004 
$ /opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/downloader.py --name landmarks-regression-retail-0009
$ /opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/downloader.py --name face-reidentification-retail-0095

#Run demo
$ python3 demos/python_demos/face_recognition_demo/face_recognition_demo.py \
-m_fd ./intel/face-detection-retail-0004/FP16/face-detection-retail-0004.xml \
-m_lm ./intel/landmarks-regression-retail-0009/FP16/landmarks-regression-retail-0009.xml \
-m_reid ./intel/face-reidentification-retail-0095/FP16/face-reidentification-retail-0095.xml \
--verbose --run_detector -fg ./face-data

When you start it, you will be asked to enter your name in the face photo taken on another screen. Enter a name of your choice. Next, another image (what was originally included?) Will be displayed, so answer this as appropriate.

The camera will start and recognize your image.

Recommended Posts

Run OpenVino on macOS and pyenv and pipenv environment
Run OpenVino on macOS Catalina
Remove old pyenv environment on Mac and update
Build a Python development environment using pyenv on MacOS
Notes on pyenv and Atom
Catalina on Mac and pyenv
Install and run dropbox on Ubuntu 20.04
Python development environment construction on macOS
Build Python 3.8 + Pipenv environment on Ubuntu 18.04
Environment construction with pyenv and pyenv-virtualenv
Addition of local development environment on MacOS
Build Python3 and OpenCV environment on Ubuntu 18.04
Build a python environment on MacOS (Catallina)
Python virtual environment and packages on Ubuntu
Notes on building Python and pyenv on Mac
Python and machine learning environment construction (macOS)
Run flake8 and pytest on GitLab CI
Run py.test on Windows Anaconda and MinGW
Notes on setting pyenv and python environment using Homebrew on Mac OS Marvericks
Install pyenv and Python 3.6.8 on Ubuntu 18.04 LTS
Create a Python3 environment with pyenv on Mac and display a NetworkX graph
Install pyenv and rbenv on CentOS system-wide
I want to use Python in the environment of pyenv + pipenv on Windows 10
How to run a Django application on a Docker container (development and production environment)
Python3 TensorFlow environment construction (Mac and pyenv virtualenv)
Install and run Python3.5 + NumPy + SciPy on Windows 10
MacOS 10.11 environment construction: Powerline with Anaconda and Dein.vim
Build python environment with pyenv on EC2 (ubuntu)
Run pip install on MacOS Python 3.7 or later
I want to do pyenv + pipenv on Windows
Prepare VSCode's pyhton environment (pyenv) (MacOS, flake8 + autopep8)
Install Python and libraries for Python on MacOS Catalina
How to create a Python 3.6.0 environment by putting pyenv on Amazon Linux and Ubuntu
Until you create a machine learning environment with Python on Windows 7 and run it
Pipenv and Pipfile.lock
Clean install and work environment update for macOS Catalina
Install Python3 on Mac and build environment [Definitive Edition]
Create and run Discord Bot on one Android device
Install Apache 2.4 on Ubuntu 19.10 Eoan Ermine and run CGI
Notes on creating a python development environment on macOS Catalina
Build a Python environment on your Mac using pyenv
[Python] Django environment construction (pyenv + pyenv-virtualenv + Anaconda) for macOS
Install Docker on Arch Linux and run it remotely
Install pyenv on Raspberry Pi and version control Python
Create a decent shell and python environment on Windows
Install Python environment on local PC (pyenv, venv on Mac)
Build a numerical calculation environment with pyenv and miniconda3