[PYTHON] Run OpenVino on macOS Catalina

What is this

After a long time, I wanted to run the OpenVino demo on osx, but it didn't work. I was thinking of using it in a lecture, but I was in trouble, so I managed to make a memorandum of the matter.

environment

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

Installation

From here, get dmg and install it. The installation directory is / opt / intel. Then run Tutorial to check operation. Anyone else who has had problems so far.

Run python demo

A complete copy of the python demo.

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

Let's start the face_recoginition demo.

$ cd python_demos/face_recognition_demo/
$ python3 ./face_recognition_demo.py -h
Traceback (most recent call last):
  File "./face_recognition_demo.py", line 24, in <module>
    import cv2
ImportError: dlopen(/opt/intel/openvino_2020.2.117/python/python3/cv2.so, 2): Library not loaded: @rpath/libopencv_ml.4.3.dylib
  Referenced from: /opt/intel/openvino_2020.2.117/python/python3/cv2.so
  Reason: image not found

Atmosphere that another library linked can not be read from opencv made by intel. Let's see what's going on.

$ otool -L /opt/intel/openvino_2020.2.117/python/python3/cv2.so
/opt/intel/openvino_2020.2.117/python/python3/cv2.so:
	@rpath/libopencv_ml.4.3.dylib (compatibility version 4.3.0, current version 4.3.0)
	@rpath/libopencv_photo.4.3.dylib (compatibility version 4.3.0, current version 4.3.0)
	@rpath/libopencv_dnn.4.3.dylib (compatibility version 4.3.0, current version 4.3.0)
	@rpath/libopencv_highgui.4.3.dylib (compatibility version 4.3.0, current version 4.3.0)
	@rpath/libopencv_objdetect.4.3.dylib (compatibility version 4.3.0, current version 4.3.0)
	@rpath/libopencv_stitching.4.3.dylib (compatibility version 4.3.0, current version 4.3.0)
	@rpath/libopencv_video.4.3.dylib (compatibility version 4.3.0, current version 4.3.0)
	@rpath/libopencv_videoio.4.3.dylib (compatibility version 4.3.0, current version 4.3.0)
	@rpath/libopencv_imgcodecs.4.3.dylib (compatibility version 4.3.0, current version 4.3.0)
	@rpath/libopencv_calib3d.4.3.dylib (compatibility version 4.3.0, current version 4.3.0)
	@rpath/libopencv_features2d.4.3.dylib (compatibility version 4.3.0, current version 4.3.0)
	@rpath/libopencv_flann.4.3.dylib (compatibility version 4.3.0, current version 4.3.0)
	@rpath/libopencv_imgproc.4.3.dylib (compatibility version 4.3.0, current version 4.3.0)
	@rpath/libopencv_core.4.3.dylib (compatibility version 4.3.0, current version 4.3.0)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.4)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.250.1)

Hey, I have a lot of links, but the problem seems to be that I haven't been told what the rpath is. Let's check the environment variable settings.

/opt/intel/openvino/opencv/setupvars.sh


export OpenCV_DIR=$INSTALLDIR/opencv/cmake
export LD_LIBRARY_PATH=$INSTALLDIR/opencv/lib:$LD_LIBRARY_PATH

Hmmm, what does it mean that you can't use it even though it seems to be set? As a result of investigation, it seems that LD_LIBRARY_PATH cannot be used unless the system is messed up after El Capitan to enhance security. The easiest thing to do is to put everything that seems to be relevant in / usr / local / lib, but I don't want to do it because Uninstalling is a hassle. You can compile from source, but I don't want to compile the opencv class program because it will take a long time. I can't think of a good way, so let's set the rpath directly in the binary as a first aid.

$ sudo install_name_tool -add_rpath '/opt/intel/openvino/opencv/lib' /opt/intel/openvino_2020.2.117/python/python3/cv2.so
Password:
$ sudo install_name_tool -add_rpath '/opt/intel/openvino/inference_engine/lib/intel64' /opt/intel/openvino_2020.2.117/python/python3/cv2.so
$ sudo install_name_tool -add_rpath '/opt/intel/openvino/deployment_tools/ngraph/lib' /opt/intel/openvino_2020.2.117/python/python3/cv2.so
$ sudo 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 
$ sudo install_name_tool -add_rpath '/opt/intel/openvino/inference_engine/lib/intel64' /opt/intel/openvino/deployment_tools/inference_engine/lib/intel64/libMKLDNNPlugin.dylib
$ sudo install_name_tool -add_rpath '/opt/intel/openvino/inference_engine/lib/intel64' /opt/intel/openvino/python/python3.7/openvino/inference_engine/ie_api.so
$ sudo 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
$ sudo install_name_tool -add_rpath '/opt/intel/openvino/deployment_tools/ngraph/lib' /opt/intel/openvino/deployment_tools/inference_engine/lib/intel64/libinference_engine.dylib
$ sudo 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

There are others, but for now I'll leave it at this level. If something happens again, it should be solved in the same way. Now download the model and run it again.

$ /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
$ python3 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 -fg ./test

It is said to be messy, but it works for the time being. And some demos don't work (but I think it's another problem).

Compile a C ++ demo

If you have run the rite of passage security_barrier demo during installation, you should have an inference_engine_demos_build directory in your home directory. This is equivalent to / opt / intel / openvino / deployment_tools / open_model_zoo / demos /.

When I read the README, some Python demos say that native Python extension modules are needed, so I enable Python modules and cmake them.

$ cd ~/inference_engine_demos_build
$ rm CMakeCache.txt
$ cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_PYTHON=ON /opt/intel/openvino/deployment_tools/inference_engine/demos
...... Omitted ...
$ make -j2
...... Omitted ...
/opt/intel/openvino/deployment_tools/open_model_zoo/demos/multi_channel/common/input.cpp:292:11: error: 
      'getAvgReadTime' overrides a member function but is not marked 'override'
      [-Werror,-Winconsistent-missing-override]
    float getAvgReadTime() const {
          ^
/opt/intel/openvino/deployment_tools/open_model_zoo/demos/multi_channel/common/input.cpp:43:19: note: overridden
      virtual function is here
    virtual float getAvgReadTime() const = 0;
                  ^
3 errors generated.
make[2]: *** [multi_channel/common/CMakeFiles/common.dir/input.cpp.o] Error 1
make[1]: *** [multi_channel/common/CMakeFiles/common.dir/all] Error 2
make: *** [all] Error 2
...... Omitted ...

Oh? !! Jesus, I got some small words. In such a case, the through power is important. If it doesn't work, think about it again. Let's flag the horse's ear as a Nembutsu in CMakeCache.txt.

CMakeCache.txt


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

Now run make again. O.K.Done. I don't care about the details. Binaries are built under intel64 / Release. The C ++ version of the demo is now working, so you can play as it is.

Afterword

I used to move smoothly, but I had a lot of trouble. OpenVino is a PC that doesn't have nvidia GPU, and I want to implement something like a demo using DNN quickly! I think it's quite convenient when you want to let students who mainly use macbooks experience the place where they are moving quickly, but there is not much information about macOS ... ・. I wonder if there aren't many people using it. I noticed when I was writing the sentence, but mac does not support built-in HD Graphics! The special merit is ... I hope you will respond as soon as possible.

Also, since the rpath of all libraries does not pass, you may encounter the same problem in the future, but you can break through by the above method. I'd really like to be able to use environment variables, but I'm not sure about macOS these days. A great person to teach.

update

2020.5.19 Confirmed with macOS 10.15.4. C ++ programs will not work unless rpath is set, so change the execution and order of python. Added missing rpath settings.

Recommended Posts

Run OpenVino on macOS Catalina
Run OpenVino on macOS and pyenv and pipenv environment
Install Python less than 3.5.3 on macOS Catalina
If Fabric becomes unavailable on macOS Catalina
Run pip install on MacOS Python 3.7 or later
Install Python 3 on MacOS Catalina (with Homebrew only)
Install Python and libraries for Python on MacOS Catalina
Run Django on PythonAnywhere
Run mysqlclient on Lambda
Run OpenMVG on Mac
Notes on creating a python development environment on macOS Catalina
Run Jupyter on Ubuntu on Windows
Run Openpose on Python (Windows)
Use Python 3 introduced with command line tools on macOS Catalina
Install OpenPose on mac (Catalina)
Run Python CGI on CORESERVER
Run unix command on python
Run IPython Notebook on Docker
Catalina on Mac and pyenv
Run YOLO v3 on AWS v2
Run Jupyter Notebook on windows
Run FreeBSD on Linux + qemu
Run YOLO v3 on AWS
Run MuJoCo on WSL (2) (also GUI)
Install and run dropbox on Ubuntu 20.04
Preparing to run Flask on EC2
Get started with MicroPython (on macOS)
Run Tensorflow natively supported on windows
How to install graph-tool on macOS
Run a Linux server on GCP
Run Python on Schedule on AWS Lambda
How to run matplotlib on heroku
Run SwitchBot on Windows 10 with Bleak
Run Matplotlib on a Docker container
Python development environment construction on macOS
Run azure ML on jupyter notebook
Run headless-chrome on a Debian-based image
Run XGBoost on Bash on Ubuntu on Windows
Run TensorFlow2 on a VPS server
Run vmware horizon client on Debian
[Note] Run Django on Amazon Linux 2
Run PartiQL on Dynamodb via boto3
Run Keras on Google Colaboratory TPU
Run docker-compose on Amazon Linux2 on ARM64
Run Yocto on Ubuntu using QEMU.
[Python] Make pip available on macOS
Install Java2Python on macOS High Sierra (10.13)
Run Sesame on Sony's PaSoRi (RCS370)
Periodically run Python on Heroku Scheduler
Run cron on Amazon Linux (set on Linux)