Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit c39d8de

Browse files
authored
Ready for v4.2.0.4 (#6)
* experiments with mkml * Update README.md * Update README.md * openblas experiments * Update README.md * Update README.md * Update README.md * Update README.md * intel license * no IPP * Update README.md * openblas right way * openblas no gfortran * openblas win * rm submodules * dnld fix * minor fixes * :# This is a combination of 4 commits. README upd Update README.md Update README.md Update README.md
1 parent 3c362bb commit c39d8de

File tree

14 files changed

+322
-226
lines changed

14 files changed

+322
-226
lines changed

.gitignore

+25-8
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,47 @@
1-
*cache*
2-
.ipynb_checkpoints
1+
openblas/*
2+
!openblas/.gitkeep
3+
4+
dldt/*
5+
!dldt/.gitkeep
6+
7+
opencv/*
8+
!opencv/.gitkeep
9+
10+
ffmpeg/*
11+
!ffmpeg/.gitkeep
12+
313
build/*
414
!build/opencv
515
build/opencv/*
616
!build/opencv/opencv_setup.sh
17+
718
!build/dldt
819
build/dldt/*
920
!build/dldt/dldt_setup.sh
21+
1022
!build/ffmpeg
1123
build/ffmpeg/*
1224
!build/ffmpeg/ffmpeg_setup.sh
1325
!build/ffmpeg/ffmpeg_premake.sh
26+
27+
!build/openblas
28+
build/openblas/*
29+
!build/openblas/openblas_setup.sh
30+
1431
create_wheel/*
1532
!create_wheel/LICENSE*
1633
!create_wheel/README.md
1734
!create_wheel/setup.py
18-
create_wheel/cv2/*
1935
!create_wheel/cv2
36+
create_wheel/cv2/*
2037
!create_wheel/cv2/__init__.py
21-
dldt/*
22-
opencv/*
23-
ffmpeg/*
24-
!ffmpeg/.gitkeep
25-
venv
38+
2639
tests/venv_t
2740
tests/rateme*
41+
venv
42+
43+
*cache*
44+
.ipynb_checkpoints
2845
*tar.gz
2946
*tar.bz2
3047
*.zip

README.md

+132-84
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,7 @@
22

33
# opencv-python-inference-engine
44

5-
It is *Unofficial* pre-built OpenCV+dldt_module package for Python.
6-
7-
**Why:**
8-
There is a [guy with an exellent pre-built set of OpenCV packages](https://github.com/skvark/opencv-python), but they are all came without [dldt module](https://github.com/opencv/dldt). And you need that module if you want to run models from [Intel's model zoo](https://github.com/opencv/open_model_zoo/).
9-
10-
**UPD:** Presumably, you could also use speech2text model now -- [source](https://docs.openvinotoolkit.org/latest/_inference_engine_samples_speech_libs_and_demos_Speech_libs_and_demos.html)
11-
12-
**Limitations**:
13-
+ Package comes without contrib modules.
14-
+ You need to [add udev rules](https://github.com/opencv/dldt/blob/2019/inference-engine/README.md#for-linux-raspbian-stretch-os) if you want working MYRIAD plugin.
15-
+ It was tested on Ubuntu 18.04, Ubuntu 18.10 as Windows 10 Subsystem and Gentoo.
16-
+ It will not work for Ubuntu 16.04 and below (except v4.1.0.4).
17-
+ I had not made builds for Windows or MacOS.
18-
+ It is 64 bit.
19-
+ It built with `ffmpeg` and `v4l` support (`ffmpeg` libs included).
20-
+ No GTK/QT support -- use `matplotlib` for plotting your results.
21-
22-
This package is most similar to `opencv-python-headless`, main differences are:
23-
+ Usage of `AVX2` instructions
24-
+ No `JPEG 2000`, `WEBP`, `OpenEXR` support
25-
+ `TBB` used as a parallel framework
26-
+ Inference Engine with `MYRIAD` plugin
27-
28-
For additional info read `cv2.getBuildInformation()` output.
5+
This is *Unofficial* pre-built OpenCV with the inference engine part of [dldt module](https://github.com/opencv/dldt/) package for Python.
296

307
## Installing from `pip3`
318

@@ -35,109 +12,109 @@ Remove previously installed versions of `cv2`
3512
pip3 install opencv-python-inference-engine
3613
```
3714

38-
## Downloading intel models
39-
40-
As it appeared it is not an obvious task :)
4115

42-
Please refer to: https://github.com/opencv/open_model_zoo/issues/522
16+
## Why
4317

44-
## Known problems and TODOs
18+
I needed an ability to fast deploy a small package that able to run models from [Intel's model zoo](https://github.com/opencv/open_model_zoo/) and use [Movidius NCS](https://software.intel.com/en-us/neural-compute-stick).
19+
Wellr-known [opencv-python](https://github.com/skvark/opencv-python) can't do this.
20+
The official way is to use OpenVINO, but it is big and clumsy (just try to use it with python venv or fast download it on cloud instance).
4521

46-
### No Ubuntu 16.04 support
4722

48-
Release [v4.1.0.4](https://github.com/banderlog/opencv-python-inference-engine/releases/tag/v4.1.0.4) is working with Ubuntu 16.04 ([#3](https://github.com/banderlog/opencv-python-inference-engine/issues/3)).
23+
## Description
4924

50-
All releases before it were compiled on Ubuntu 18.04 and it has different versions of `glibc`, `cmake`, etc.
51-
So make it Ubuntu 16.04 compatible was pretty easy -- just change one standard build environment to another.
25+
### Limitations
5226

53-
But `dldt-2019R2` requires `cmake-3.7.2`, which is absent in Ubuntu 16.04. And, of course, it can be installed, but works-from-the-box behavior is loosed
54-
from now on.
55-
56-
### No GTK/QT support
27+
+ Package comes without contrib modules.
28+
+ You need to [add udev rules](https://github.com/opencv/dldt/blob/2019/inference-engine/README.md#for-linux-raspbian-stretch-os) if you want working MYRIAD plugin.
29+
+ It was tested on Ubuntu 18.04, Ubuntu 18.10 as Windows 10 Subsystem and Gentoo.
30+
+ It will not work for Ubuntu 16.04 and below (except v4.1.0.4).
31+
+ I had not made builds for Windows or MacOS.
32+
+ It built with `ffmpeg` and `v4l` support (`ffmpeg` libs included).
33+
+ No GTK/QT support -- use `matplotlib` for plotting your results.
34+
+ It is 64 bit.
5735

58-
[skvarks's package](https://github.com/skvark/opencv-python) has `Qt4` GUI for `opencv` and it is +16 MB to file size.
59-
Also it is a lot of problems and extra work to compile Qt\GTK libs from sources.
60-
In 95% of cases `matplotlib.imshow()` will be sufficient, in other 5% use another package for now or compile it with GUI
61-
support by yourself.
36+
### Main differences from `opencv-python-headless`
6237

63-
#### Steps to compile it with `GTK-2` support (checked)
38+
+ Usage of `AVX2` instructions
39+
+ No `JPEG 2000`, `WEBP`, `OpenEXR` support
40+
+ `TBB` used as a parallel framework
41+
+ Inference Engine with `MYRIAD` plugin
6442

65-
Make next changes in `opencv-python-inference-engine/build/opencv/opencv_setup.sh`:
66-
1. change string `-D WITH_GTK=OFF \` to `-D WITH_GTK=ON \`
67-
2. change `export PKG_CONFIG_PATH=$ABS_PORTION/build/ffmpeg/binaries/lib/pkgconfig:$PKG_CONFIG_PATH` -- you will need to
68-
add absolute paths to `.pc` files. On Ubuntu 18.04 it were
69-
`/usr/lib/x86_64-linux-gnu/pkgconfig/:/usr/share/pkgconfig/:/usr/local/lib/pkgconfig/:/usr/lib/pkgconfig/`
43+
### Main differences from OpenVINO
7044

71-
Exporting `PKG_CONFIG_PATH` for `ffmpeg` somehow messes with default values.
45+
+ No model-optimizer
46+
+ OpenBLAS instead of MKL ([details](https://github.com/banderlog/opencv-python-inference-engine/issues))
47+
+ No [ITT](https://software.intel.com/en-us/articles/intel-itt-api-open-source)
48+
+ No [IPP](https://software.intel.com/en-us/ipp)
49+
+ No [Intel Media SDK](https://software.intel.com/en-us/media-sdk)
50+
+ No [OpenVINO IE API](https://github.com/opencv/dldt/tree/2020/inference-engine/ie_bridges/python/src/openvino/inference_engine)
51+
+ No python2 support (it is dead)
52+
+ No Gstreamer (use ffmpeg)
53+
+ No GTK (+16 MB and a lot of problems and extra work to compile Qt\GTK libs from sources.)
7254

73-
### Not really `manylinux1`
55+
For additional info read `cv2.getBuildInformation()` output.
7456

75-
The package is renamed to `manylinux1` from `linux`, because, according to [PEP 513](https://www.python.org/dev/peps/pep-0513/), PyPi repo does not want to apply other architectures.
76-
And compiling it for CentOS 5.11 is pretty challenging (there is no such lxd container plus I do not want to mess with docker) and denies from using some of the necessary libs (like tbb).
77-
Also, I suspect that it will be poorly optimized.
57+
### Versioning
7858

79-
### Build `ffmpeg` with `tbb`
59+
The first 3 letters are the version of OpenCV, the last one -- package version. E.g, `4.1.0.2` -- 2nd version of based on 4.1.0 OpenCV package. Package versions are not continuously numbered -- each new OpenCV version starts its own numbering.
8060

81-
Both `dldt` and `opencv` are compiled with `tbb` support, and `ffmpeg` compiled without it -- this does not feels right.
82-
There is some unproved solution for how to compile `ffmpeg` with `tbb` support:
83-
+ <https://stackoverflow.com/questions/6049798/ffmpeg-mt-and-tbb>
84-
+ <https://stackoverflow.com/questions/14082360/pthread-vs-intel-tbb-and-their-relation-to-openmp>
8561

86-
Maybe someday I will try it.
62+
## Downloading intel models
8763

88-
### Versioning
64+
The official way is clumsy because you need to git clone the whole [model_zoo](https://github.com/opencv/open_model_zoo) ([details](https://github.com/opencv/open_model_zoo/issues/522))
8965

90-
First 3 letters are the version of OpenCV, the last one -- package version. E.g, `4.1.0.2` -- 2nd version of based on 4.1.0 OpenCV package. Package versions are not continuously numbered -- each new OpenCV version starts its own numbering.
66+
Better to find a model description [here](https://github.com/opencv/open_model_zoo/blob/master/models/intel/index.md) and download manually from [here](https://download.01.org/opencv/2020/openvinotoolkit/2020.1/open_model_zoo/models_bin/1/)
9167

9268

9369
## Compiling from source
9470

95-
I compiled it on Ubuntu 18.04 Linux Container.
71+
You will need ~6GB RAM and ~10GB disk space
72+
73+
I am using Ubuntu 18.04 [multipass](https://multipass.run/) instance: `multipass launch -c 6 -d 10G -m 7G`.
9674

9775
### Requirements
9876

99-
+ <https://github.com/opencv/dldt/blob/2018/inference-engine/README.md>
100-
+ <https://docs.opencv.org/4.0.0/d7/d9f/tutorial_linux_install.html> (`build-essential`, `cmake`, `git`, `pkg-config`, `python3-dev`)
101-
+ `nasm` (for ffmpeg)
102-
+ `python3`
77+
+ `build-essential`
78+
+ `cmake`
79+
+ `git`
80+
+ `pkg-config`
81+
+ `python3-dev`
10382
+ `virtualenv`
104-
+ `libusb-1.0-0-dev` (for dldt >= 2019_R1.0.1)
10583
+ `chrpath`
106-
+ `patchelf`
84+
+ `libusb-1.0-0-dev` (for MYRIAD plugin)
85+
+ `nasm` (for ffmpeg)
10786

10887
```
10988
sudo apt-get update
110-
sudo apt install build-essential cmake git pkg-config python3-dev nasm python3 virtualenv libusb-1.0-0-dev chrpath patchelf
89+
sudo apt install build-essential cmake git pkg-config python3-dev nasm python3 virtualenv libusb-1.0-0-dev chrpath
11190
```
11291

113-
**NB:** you will need ~6GB RAM and ~7GB disk space
114-
11592
### Preparing
11693

117-
0. `git clone https://github.com/banderlog/opencv-python-inference-engine`
118-
1. `cd opencv-python-inference-engine`
119-
2. run `download_all_stuff.sh` (refer for script code for details)
94+
1. `git clone https://github.com/banderlog/opencv-python-inference-engine`
95+
2. `cd opencv-python-inference-engine`
96+
3. run `download_all_stuff.sh` (refer for script code for details)
12097

12198
### Compilation
12299

123-
`$ABS_PORTION` is a absolute path to `opencv-python-inference-engine` dir.
124-
125100
```bash
126-
127-
cd build/ffmpeg
128-
./ffmpeg_setup.sh
129-
./ffmpeg_premake.sh
130-
make -j8
101+
cd build/openblas
102+
./openblas_setup.sh &&
103+
make -j8 &&
131104
make install
132105

106+
cd ../ffmpeg
107+
./ffmpeg_setup.sh &&
108+
./ffmpeg_premake.sh &&
109+
make -j8 &&
110+
make install
133111

134112
cd ../dldt
135-
./dldt_setup.sh
113+
./dldt_setup.sh &&
136114
make -j8
137115

138-
139116
cd ../opencv
140-
ABS_PORTION=YOUR_ABSOLUTE_PATH_TO_opencv-python-inference-engine_dir ./opencv_setup.sh
117+
./opencv_setup.sh &&
141118
make -j8
142119
```
143120

@@ -155,11 +132,82 @@ cp dldt/inference-engine/temp/tbb/lib/libtbb.so.2 create_wheel/cv2/
155132

156133
cp build/ffmpeg/binaries/lib/*.so create_wheel/cv2/
157134

135+
cp build/openblas/lib/libopenblas.so.0 create_wheel/cv2/
158136

159-
cd create_wheel
160137
# change RPATH
138+
cd create_wheel
161139
for i in cv2/*.so; do chrpath -r '$ORIGIN' $i; done
162140

163141
# final .whl will be in /create_wheel/dist/
164142
../venv/bin/python3 setup.py bdist_wheel
165143
```
144+
145+
### Optional things to play with
146+
147+
+ [dldt build instruction](https://github.com/opencv/dldt/blob/2020/build-instruction.md)
148+
+ [dldt cmake flags](https://github.com/opencv/dldt/blob/b2140c083a068a63591e8c2e9b5f6b240790519d/inference-engine/cmake/features_ie.cmake)
149+
+ [opencv cmake flags](https://github.com/opencv/opencv/blob/master/CMakeLists.txt)
150+
151+
**NB:** removing `QUIET` from `find_package()` in project Cmake files, could help to solve some problems -- сmake will start to log them.
152+
153+
154+
#### GTK2
155+
156+
Make next changes in `opencv-python-inference-engine/build/opencv/opencv_setup.sh`:
157+
1. change string `-D WITH_GTK=OFF \` to `-D WITH_GTK=ON \`
158+
2. `export PKG_CONFIG_PATH=$ABS_PORTION/build/ffmpeg/binaries/lib/pkgconfig:$PKG_CONFIG_PATH` -- you will need to
159+
add absolute paths to `.pc` files. On Ubuntu 18.04 they here:
160+
`/usr/lib/x86_64-linux-gnu/pkgconfig/:/usr/share/pkgconfig/:/usr/local/lib/pkgconfig/:/usr/lib/pkgconfig/`
161+
162+
Exporting `PKG_CONFIG_PATH` for `ffmpeg` somehow messes with default values.
163+
164+
#### IPP
165+
166+
Just set `-D WITH_IPP=ON` in `opencv_setup.sh`.
167+
168+
It will give +30MB to the final `cv2.so` size. And it will boost _some_ opencv functions.
169+
170+
![](https://www.oreilly.com/library/view/learning-opencv-3/9781491937983/assets/lcv3_0105.png)
171+
(Image from [Learning OpenCV 3 by Gary Bradski, Adrian Kaehler](https://www.oreilly.com/library/view/learning-opencv-3/9781491937983/ch01.html))
172+
173+
[Official Intel's IPP benchmarks](https://software.intel.com/en-us/ipp/benchmarks) (may ask for registration)
174+
175+
#### MKL
176+
177+
You need to download MKL-DNN release and set two flags:`-D GEMM=MKL` , `-D MKLROOT` ([details](https://github.com/opencv/dldt/issues/327))
178+
179+
OpenVino comes with 30MB `libmkl_tiny_tbb.so`, but [you will not be able to compile it](https://github.com/intel/mkl-dnn/issues/674), because it made from proprietary MKL.
180+
181+
Our opensource MKL-DNN experiment will end with 125MB `libmklml_gnu.so` and inference speed compatible with 35MB openblas ([details](https://github.com/banderlog/opencv-python-inference-engine/issues/5)).
182+
183+
#### OpenBLAS
184+
185+
Please refer here for details: https://github.com/xianyi/OpenBLAS/issues/2528
186+
187+
+ [OpenBLAS Installation guide](https://github.com/xianyi/OpenBLAS/wiki/Installation-Guide)
188+
+ [OpenBLAS User Manual](https://github.com/xianyi/OpenBLAS/wiki/User-Manual)
189+
190+
If you compile it with `make FC=gfortran`, you'll need to put `libgfortran.so.4` and `libquadmath.so.0` to wheel and set them rpath via `patchelf --set-rpath \$ORIGIN *.so`
191+
192+
193+
#### CUDA
194+
195+
I did not try it.
196+
197+
+ [Compile OpenCV’s ‘dnn’ module with NVIDIA GPU support](https://www.pyimagesearch.com/2020/02/10/opencv-dnn-with-nvidia-gpus-1549-faster-yolo-ssd-and-mask-r-cnn/)
198+
+ [Use OpenCV’s ‘dnn’ module with NVIDIA GPUs, CUDA, and cuDNN](https://www.pyimagesearch.com/2020/02/03/how-to-use-opencvs-dnn-module-with-nvidia-gpus-cuda-and-cudnn/)
199+
200+
201+
#### Build `ffmpeg` with `tbb`
202+
203+
Both `dldt` and `opencv` are compiled with `tbb` support, and `ffmpeg` compiled without it -- this does not feel right.
204+
There is some unproved solution for how to compile `ffmpeg` with `tbb` support: <https://stackoverflow.com/questions/6049798/ffmpeg-mt-and-tbb>
205+
206+
207+
#### OpenMP
208+
209+
It is possible to compile OpenBLAS, dldt and OpenCV with OpenMP. I am not sure that the result would be better than now, but who knows.
210+
211+
#### Use opencv for NLP
212+
213+
Presumably, you could also use speech2text model now -- [source](https://docs.openvinotoolkit.org/latest/_inference_engine_samples_speech_libs_and_demos_Speech_libs_and_demos.html)

0 commit comments

Comments
 (0)