Skip to content

Commit

Permalink
New version: 4.5.0 + 2021.1
Browse files Browse the repository at this point in the history
* upd new version

* OpenBLAS faster than JIT

* wheel already manylinux and should not be used for win

* upd

* upd

* 4.4.0 ready

* submodules test (#11)

* Update TODO.md

* tensorflow-cpu==2.2.0 -> tensorflow-cpu==2.2.1

* preparations for new version

* all set. waiting for opencv-4.5.0

* upd README.md

* opencv 4.5.0 is here
  • Loading branch information
banderlog authored Oct 12, 2020
1 parent 5f0a808 commit ce216ee
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 55 deletions.
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[submodule "dldt"]
path = dldt
url = https://github.com/openvinotoolkit/openvino
[submodule "opencv"]
path = opencv
url = https://github.com/opencv/opencv
[submodule "openblas"]
path = openblas
url = https://github.com/xianyi/OpenBLAS
[submodule "ffmpeg"]
path = ffmpeg
url = https://github.com/FFmpeg/FFmpeg
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pip3 install opencv-python-inference-engine
## Why

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).
Wellr-known [opencv-python](https://github.com/skvark/opencv-python) can't do this.
Well-known [opencv-python](https://github.com/skvark/opencv-python) can't do this.
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).


Expand Down Expand Up @@ -68,7 +68,7 @@ Better to find a model description [here](https://github.com/opencv/open_model_z

## Compiling from source

You will need ~6GB RAM and ~10GB disk space
You will need ~7GB RAM and ~10GB disk space

I am using Ubuntu 18.04 [multipass](https://multipass.run/) instance: `multipass launch -c 6 -d 10G -m 7G`.

Expand All @@ -91,11 +91,12 @@ From [opencv](https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html)

```bash
# We need newer `cmake` for dldt (commands from <https://apt.kitware.com/>)
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | sudo apt-key add -
sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main'
sudo apt remove --purge cmake
hash -r
sudo snap install cmake --classic

sudo apt-get update
sudo apt install build-essential cmake git pkg-config python3-dev nasm python3 virtualenv libusb-1.0-0-dev chrpath autoconf libtool-bin
sudo apt install build-essential git pkg-config python3-dev nasm python3 virtualenv libusb-1.0-0-dev chrpath autoconf libtool-bin

# for ngraph
# the `dldt/_deps/ext_onnx-src/onnx/gen_proto.py` has `#!/usr/bin/env python` string and will throw an error otherwise
Expand All @@ -104,9 +105,11 @@ sudo ln -s /usr/bin/python3 /usr/bin/python

### Preparing

1. `git clone https://github.com/banderlog/opencv-python-inference-engine`
2. `cd opencv-python-inference-engine`
3. run `download_all_stuff.sh` (refer for script code for details)
```bash
git clone https://github.com/banderlog/opencv-python-inference-engine
cd opencv-python-inference-engine
./download_all_stuff.sh
```

### Compilation

Expand All @@ -126,6 +129,8 @@ cd ../dldt
./dldt_setup.sh &&
make -j6

# NB: check `-D INF_ENGINE_RELEASE` value
# should be in form YYYYAABBCC (e.g. 2020.1.0.2 -> 2020010002)")
cd ../opencv
./opencv_setup.sh &&
make -j6
Expand All @@ -152,6 +157,7 @@ cd create_wheel
for i in cv2/*.so; do chrpath -r '$ORIGIN' $i; done

# final .whl will be in /create_wheel/dist/
# NB: check versions in the `setup.py`
../venv/bin/python3 setup.py bdist_wheel
```

Expand Down
5 changes: 2 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# TODO list

+ Auto value for `-D INF_ENGINE_RELEASE`
+ Try to submodule things instead of downloading archives of them
+ check tar.gz integrity otherwise
+ Auto value for `-D INF_ENGINE_RELEASE`: https://github.com/openvinotoolkit/openvino/issues/1435

1 change: 0 additions & 1 deletion build/dldt/dldt_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ cmake -D CMAKE_BUILD_TYPE=Release \
-D NGRAPH_UNIT_TEST_ENABLE=OFF \
-D NGRAPH_TEST_UTIL_ENABLE=OFF \
-D NGRAPH_ONNX_IMPORT_ENABLE=ON \
-D NGRAPH_JSON_ENABLE=ON \
-D BLAS_LIBRARIES="$BLAS_LIB" \
-D BLAS_INCLUDE_DIRS="$BLAS_INC" \
-D ENABLE_CLDNN=OFF \
Expand Down
6 changes: 4 additions & 2 deletions build/opencv/opencv_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#
# -DINF_ENGINE_RELEASE= should match dldt version
# See <https://github.com/opencv/dldt/issues/248#issuecomment-590102331>
# From <https://github.com/opencv/opencv/blob/c8ebe0eb86fca1c2de9de516e27be685eaba3e69/cmake/OpenCVDetectInferenceEngine.cmake#L134>
# "Force IE version, should be in form YYYYAABBCC (e.g. 2020.1.0.2 -> 2020010002)")

tmp=$(pwd)
ABS_PORTION=${tmp%%"/build/opencv"}
Expand Down Expand Up @@ -73,8 +75,8 @@ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D WITH_NGRAPH=ON \
-D ngraph_DIR=$ABS_PORTION/build/dldt/ngraph \
-D WITH_INF_ENGINE=ON \
-D INF_ENGINE_RELEASE=2020040000 \
-D INF_ENGINE_RELEASE=2021010000 \
-D INF_ENGINE_INCLUDE_DIRS=$ABS_PORTION/dldt/inference-engine/include \
-D INF_ENGINE_LIB_DIRS=$ABS_PORTION/dldt/bin/intel64/Release/lib \
-D CPU_BASELINE=SSE4_2 \
-D CPU_DISPATCH=AVX,AVX2,FP16,AVX512 ../../opencv
-D CPU_DISPATCH=AVX,AVX2,FP16,AVX512 ../../opencv
4 changes: 2 additions & 2 deletions create_wheel/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ def __len__(self):

setuptools.setup(
name="opencv-python-inference-engine",
version="4.4.0.0",
version="4.5.0.0",
url="https://github.com/banderlog/opencv-python-inference-engine",
maintainer="Kabakov Borys",
license='MIT, BSD, Intel Simplified Software License',
description="Wrapper package for OpenCV 4.4.0 with Inference Engine 2020.4 python bindings",
description="Wrapper package for OpenCV 4.5.0 with Inference Engine 2021.1 python bindings",
long_description=long_description,
long_description_content_type="text/markdown",
ext_modules=EmptyListWithLength(),
Expand Down
1 change: 1 addition & 0 deletions dldt
Submodule dldt added at f557dc
Empty file removed dldt/.gitkeep
Empty file.
39 changes: 4 additions & 35 deletions download_all_stuff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,9 @@ red () {

ROOT_DIR=$(pwd)

green "DOWNLOAD ALL ARCHIVES"
wget -c https://github.com/opencv/opencv/archive/4.4.0.tar.gz -O opencv.tar.gz
wget -c https://github.com/openvinotoolkit/openvino/archive/2020.4.tar.gz -O dldt.tar.gz
wget -c https://github.com/FFmpeg/FFmpeg/archive/n4.3.1.tar.gz -O ffmpeg.tar.gz
wget -c https://github.com/xianyi/OpenBLAS/archive/v0.3.10.tar.gz -O openblas.tar.gz


green "CLEAN LIB DIRS"
rm -drf ./dldt/*
rm -drf ./ffmpeg/*
rm -drf ./opencv/*
rm -drf ./openblas/*
green "RESET GIT SUBMODULES"
# use `git pull && git checkout tags/<tag>` for update
git submodule update --init --recursive

green "CLEAN BUILD DIRS"
find build/dldt/ -mindepth 1 -not -name 'dldt_setup.sh' -delete
Expand All @@ -42,32 +33,10 @@ rm -drf create_wheel/build
rm -drf create_wheel/dist
rm -drf create_wheel/*egg-info

green "UNZIP ALL STUFF"
tar -xf opencv.tar.gz --strip-components=1 -C ./opencv/
tar -xf dldt.tar.gz --strip-components=1 -C ./dldt/
tar -xf ffmpeg.tar.gz --strip-components=1 -C ./ffmpeg/
tar -xf openblas.tar.gz --strip-components=1 -C ./openblas/

green "GIT RESET FOR ade"
cd ./dldt/inference-engine/thirdparty/ade
git clone https://github.com/opencv/ade/ ./
git reset --hard cbe2db6

green "GIT RESET FOR mkl-dnn"
cd ../mkl-dnn
git clone https://github.com/openvinotoolkit/oneDNN/ ./
git reset --hard 2706f56

green "GIT RESET FOR IE samples gflags"
cd ../../samples/thirdparty/gflags/
git clone https://github.com/gflags/gflags ./
git reset --hard 46f73f8


green "CREATE VENV"
cd $ROOT_DIR

if [[ ! -d ./venv ]]; then
virtualenv --clear --always-copy -p /usr/bin/python3 ./venv
./venv/bin/pip3 install numpy
fi
fi
1 change: 1 addition & 0 deletions ffmpeg
Submodule ffmpeg added at 6b6b9e
Empty file removed ffmpeg/.gitkeep
Empty file.
1 change: 1 addition & 0 deletions openblas
Submodule openblas added at 63b03e
Empty file removed openblas/.gitkeep
Empty file.
1 change: 1 addition & 0 deletions opencv
Submodule opencv added at d5fd2f
Empty file removed opencv/.gitkeep
Empty file.
8 changes: 5 additions & 3 deletions tests/prepare_and_run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ red () {
echo -e "${red}${1}${end}"
}


# check if (no ARG and no some appropriate files are compiled) or
# (some args provided but arg1 is not existing file)
# of course, you could shoot your leg here in different ways
Expand All @@ -33,13 +34,14 @@ green "INSTALLING DEPENDENCIES"
if [ $1 ]; then
# install ARGV1
green "Installing from provided path"
./venv_t/bin/pip3 install --force-reinstall "$1"
WHEEL="$1"
else
# install compiled wheel
green "Installing from default path"
./venv_t/bin/pip3 install --force-reinstall ../create_wheel/dist/opencv_python_inference_engine*.whl
WHEEL=$(realpath ../create_wheel/dist/opencv_python_inference_engine*.whl)
fi

./venv_t/bin/pip3 install --force-reinstall "$WHEEL"
./venv_t/bin/pip3 install -r requirements.txt


Expand Down Expand Up @@ -88,7 +90,7 @@ for i in "${!se_net[@]}"; do
fi
done

green "For \"$1\""
green "For \"$WHEEL\""
green "RUN TESTS with ./venv_t/bin/python ./tests.py"
./venv_t/bin/python ./tests.py
green "RUN TESTS with ./venv_t/bin/python ./speed_test.py"
Expand Down
3 changes: 2 additions & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
numpy>=1.16.0,<1.19.0
tensorflow-cpu==2.2.1
scipy==1.4.1
scikit-image
ipython
ipython

0 comments on commit ce216ee

Please sign in to comment.