Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Rosten__Erik
Beginner
1,148 Views

OpenCV-OpenVINO vs OpenCV

Hi Everyone,

 

I'm using the cv2.dnn module to read in a pytorch model and perform inference, but also am using some pretrained openVINO optimized models as well. I've found that when using the pytorch model and performing inference on the same input, the output differs before and after running the openVINO setupvars.sh. The reason seems to be that after setting up the variables, importing cv2 points to the /opt/intel/openvino/python/python3.5 library instead of the one installed using pip. I'm not sure what the difference is, but is there a way to import the original cv2 and openvino cv2 separately in python code? Furthermore, what is the reason for the differences in the outputs?

 

Thanks,

Erik

0 Kudos
8 Replies
Rosten__Erik
Beginner
1,148 Views

Bump

1,148 Views

Hi Erik,

When you source the setupvars.sh, w.r.t. python it will -

  • check if the python is installed or not by using the python --version command
  • If it is installed, it will check for the python version and captures the major and minor numbers.
  • At last, it will point the "PYTHONPATH" to %INTEL_OPENVINO_DIR%\python\python%Major%.%Minor%;%PYTHONPATH%

In your case, it is pointing to /opt/intel/openvino/python/python3.5 which seems to be correct.

If you have multiple versions of python or want to maintain sanity by having openvino specific python and system python, python virtual environment can be installed. This is provided as an option while installing model optimizer > install_prerequisites >  install_prerequisites*.sh followed by venv. So when you use venv and source the setupvars.sh it will point to openvino version of python and when you deactivate the venv and run your code directly without sourcing the setupvars.sh in a different terminal, it can point to system installed opencv. However carefully observe the setupvars.sh script and can be modified according to your specific requirements if any.

(I'm posting an excerpt for the Windows setupvars.bat but for Linux it should be similar):

:: OpenCV
if exist "%INTEL_OPENVINO_DIR%\opencv\setupvars.bat" (
call "%INTEL_OPENVINO_DIR%\opencv\setupvars.bat"
) else (
set "OpenCV_DIR=%INTEL_OPENVINO_DIR%\opencv\x64\vc14\lib"
set "PATH=%INTEL_OPENVINO_DIR%\opencv\x64\vc14\bin;%PATH%"
)

What you must do is set OpenCV_DIR to point to your OpenCV installation lib directory.

Ref. https://software.intel.com/en-us/forums/computer-vision/topic/802287

Rosten__Erik
Beginner
1,148 Views

Thank you for the feedback! While it's been very helpful, I need to be running both versions of opencv in the same "terminal" so to speak. As a last question, what might be the source of the differences between opencv and opencv-openvino when performing inference with the torch model. Is the source code for the cv2.dnn module inherently different?

 

Edit: Since the entire python version is being overwritten by openvino's setup script, is it possible that the source of the differences are not within opencv-openvino vs opencv, but another library altogether?

 

Best,

Erik

1,148 Views

Hi Erik, 

There is no source difference between stock opencv and openvino's opencv. OpenVINO does some hardware and software optimizations at the library level. 

Maksim_S_Intel
Employee
1,148 Views

Probably OpenCV provided with OpenVINO use InferenceEngine backend by default, you should explicitly set backend to DNN_BACKEND_OPENCV (Net::setPreferableBackend) to get same results as OpenCV from PIP. Also results can differ due to version difference.

 

You can't load two different cv2 modules in single Python process.

fei__wang
Beginner
1,148 Views

Hemanth Kumar G. (Intel) wrote:

Hi Erik, 

opencv版本和opencv-openvino版本之间只是优化了openvino嘛?在编译时cmake参数有什么变化嘛

There is no source difference between stock opencv and openvino's opencv. OpenVINO does some hardware and software optimizations at the library level. 

Hoško__Filip
Beginner
1,148 Views

Hemanth Kumar G. (Intel) wrote:

Hi Erik, 

There is no source difference between stock opencv and openvino's opencv. OpenVINO does some hardware and software optimizations at the library level. 

That's fine but the problem is when we would like to load modules that are listed as "extra" and are part of the opencv-contrib-python. For example, I would like to use the Tracker API but as far as I know, I can't do it without the contrib package. Is there a way I can use the OpenCV Tracker API with OpenVINO?

_Mai_
Novice
812 Views

There is a way to install the contrib modules by giving it to the make function 

git clone https://github.com/opencv/opencv.git
cd opencv && git checkout 4.1.2openvino
cd .. && git clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib && git checkout 4.1.2
 
 
cd ../opencv && mkdir build && cd build
cmake -D CMAKE_INSTALL_PREFIX=/opt/intel/openvino/opencv \
-D OPENCV_PYTHON3_INSTALL_PATH=/opt/intel/openvino/python/python3.6 \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules\
-D PYTHON3_EXECUTABLE=/home/demo/anaconda3/envs/openvino/bin/python ..
make all -j32 && make install -j32 
# 32 represents your number of cpu cores (so for 8 cores you'd use: make all -j8 && make install -j8)

 

Reply