Ask Your Question
1

Using the opencv_contrib dnn module (too slow)

asked 2016-11-17 09:49:47 -0600

Kingboom4 gravatar image

I am using a caffemodel (trained for gender classification) with the dnn module of the opencv_contrib library. The issue I am having is that it is running pretty well but it is extremly slow, it takes up to 10 seconds (sometimes) for a face to be processed. I believe the issue is that there is a bottleneck present in the cv::gemm()function - highlighted in this issue https://github.com/opencv/opencv_cont.... According to the issue all you need to do is install OpenBLAS or MKL and the performance will increase, I have never used any of those libraries before, hence I am quite unsure how to approach this. Any guidance in regards to increasing the performance or how to setup a solution with OpenBLAS + opencv_contrib will be greatly appreciated.

This is my setup:

  • C++ VS 2015
  • OpenCV 3.1.0
  • Windows 10
edit retag flag offensive close merge delete

Comments

just curious: "I am using a caffemodel (trained for gender classification)" -- is that gil levy's ? (it did not work with previous dnn versions)

berak gravatar imageberak ( 2016-11-17 10:04:54 -0600 )edit
1

Nope it's from this paper https://data.vision.ee.ethz.ch/cvl/rr... it works flawlessly but the implementation is just too slow.

Kingboom4 gravatar imageKingboom4 ( 2016-11-17 10:11:04 -0600 )edit

What have you try? How can I know that's an answer ?

LBerger gravatar imageLBerger ( 2016-11-17 11:46:44 -0600 )edit

I have tried implementing OpenBLAS using the binary packages provided on the OpenBLAS site, I have included .lib and the include directory into my project. However, I am not sure whether that is the correct way of making opencv_contrib believe that I have OpenBLAS installed, the reason I say that is because inside the source code of the dnn module you have op_blas.cpp which is supposed to check for OpenBLAS but I have no clue how it would do that. I am just unsure as to how I am supposed to use OpenBLAS in this case.

In regards to how I know this is the answer, well I don't know but two separate people on the issue thread have said that they have used BLAS to get better performance.

Kingboom4 gravatar imageKingboom4 ( 2016-11-17 12:14:15 -0600 )edit

Don't you use cmake ? here you can find results with opencv_perf_dnn.exe

LBerger gravatar imageLBerger ( 2016-11-17 12:32:35 -0600 )edit

command line for link using VS2015 /OUT:"F:\lib\opencv\testceres\bin\Debug\opencv_dnn310d.dll" /MANIFEST /NXCOMPAT /PDB:"F:/lib/opencv/testceres/bin/Debug/opencv_dnn310d.pdb" /DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "comdlg32.lib" "advapi32.lib" "....\lib\Debug\opencv_imgproc310d.lib" "F:\lib\opencv\3rdparty\ippicv\unpack\ippicv_win\lib\intel64\ippicvmt.lib" "C:\Program Files\protobuf\lib\libprotobuf.dlib" "F:\lib\OpenBLAS\build\lib\libopenblas.lib" "....\lib\Debug\opencv_core310d.lib" /IMPLIB:"F:/lib/opencv/testceres/lib/Debug/opencv_dnn310d.lib" /DLL /MACHINE:X64 /NODEFAULTLIB:"libc" /INCREMENTAL /PGD:"F:\lib\opencv\testceres\bin\Debug\opencv_dnn310d.pgd"

LBerger gravatar imageLBerger ( 2016-11-17 12:53:36 -0600 )edit

/SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"opencv_dnn.dir\Debug\opencv_dnn310d.dll.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /TLBID:1

LBerger gravatar imageLBerger ( 2016-11-17 12:54:27 -0600 )edit

command line for compiler

/MP /GS /TP /W4 /wd"4251" /wd"4324" /wd"4275" /wd"4589" /wd"4701" /Gy /Zc:wchar_t /I"F:\lib\opencv\3rdparty\ippicv\unpack\ippicv_win\include" /I"F:\lib\opencv\testceres" /I"F:\lib\eigen-eigen" /I"F:\lib\opencv_contrib\modules\dnn\include" /I"F:\lib\opencv_contrib\modules\dnn\src" /I"F:\lib\opencv\testceres\modules\dnn" /I"F:\lib\opencv\modules\core\include" /I"F:\lib\opencv\modules\imgproc\include" /I"C:\Program Files\protobuf\include" /I"f:\lib\openblas" /Zi /Gm- /Od /Ob0 /Fd"F:\lib\opencv\testceres\lib\Debug\opencv_dnn310d.pdb" /Zc:inline /fp:precise /D "WIN32" /D "_WINDOWS" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_SCL_SECURE_NO_WARNINGS" /D "_DEBUG" /D "CVAPI_EXPORTS" /D "_VARIADIC_MAX=10" /D "__OPENCV_BUILD=1" /D "HAVE_PROTOBUF=1"

LBerger gravatar imageLBerger ( 2016-11-17 12:55:22 -0600 )edit

/D "HAVE_CBLAS=1" /D "ENABLE_CAFFE_MODEL_TESTS=1" /D "CMAKE_INTDIR=\"Debug\"" /D "_WINDLL" /D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /RTC1 /GR /Gd /Oi /MDd /Fa"Debug/" /EHa /nologo /Fo"opencv_dnn.dir\Debug\" /Fp"opencv_dnn.dir\Debug\opencv_dnn310d.pch"

LBerger gravatar imageLBerger ( 2016-11-17 12:55:44 -0600 )edit

I didn't use cmake to build OpenBLAS, I just used the binary package they provide for Windows on their site - is this not a good idea? I'm a little confused in regards to what you're referring to, do you mean use cmake to build OpenCV with the opencv_contrib modules (if so, the answer is yes) or do you mean OpenBLAS being built with cmake?

Kingboom4 gravatar imageKingboom4 ( 2016-11-18 04:54:32 -0600 )edit

CMake is used to build opencv.sln not Opencv. (or a makefiles for mingw64). If you want to use opencv_contrib you have to download opencv_contrib and opencv fro github repo (sources files are synchronised) Then you have to use cmake to build both. Then cmake will scan your PC looking for OpenBLAS, eigen .... If CMake don't find some libs you can try to give a good path to include an libs using GUI CMake. Try to use CMake to build both it would be easier to help you

LBerger gravatar imageLBerger ( 2016-11-18 07:40:33 -0600 )edit

Thanks for your reply LeBerger, OpenCV and opencv_contrib are compiled from source using CMake, I do apologise I didn't realise you were referring to OpenCV being compiled from source. Just one question how do I install OpenBLAS for windows? Or how do I ensure OpenBLAS is found by CMake? Do I just point to one of the folders inside the OpenBLAS binary package (bin, include or lib)? If so, which one? I do apologise in advance for asking this many questions but I am slightly lost at the moment.

Kingboom4 gravatar imageKingboom4 ( 2016-11-21 09:41:26 -0600 )edit

Never mind, I think I figured it out, if I still run into problems I'll give you a shout, thanks a lot for helping me out.

Kingboom4 gravatar imageKingboom4 ( 2016-11-21 10:21:23 -0600 )edit
LBerger gravatar imageLBerger ( 2016-11-21 11:06:23 -0600 )edit

I have recompiled using Opencv.sln with cmake and with the option for opencv_dnn_WITH_BLAS and pointed the OpenBLAS bin, include and lib accordingly (I renamed the libopenblas.a.dll lib to libopenblas.lib), the issue I am running into now is that when I compile my code I get the error saying that libopenblas.lib is missing, all the other .libs are recognised. I have tried adding the .lib manually by using the property sheet in VS, I pointed to the lib folder of the OpenBLAS binary package in the "Additional Library Directories" field and adding the libopenblas.lib in the input. I am not sure what I am doing wrong, I feel like it might just be a linking issue.

Edit: I do apologise, I totally missed your last message, I'll give that a try.

Kingboom4 gravatar imageKingboom4 ( 2016-11-21 11:26:03 -0600 )edit

I am not getting the same options as you are in cmake, what might I be doing wrong?

These are the options I am getting

BLAS search

Edit: I don't have the following options:

  1. EIGEN_INCLUDE_DIR
  2. None of the LAPACK
  3. None of the BLAS options including BLAS_openblas_LIBRARY

Having said that, I do have the OpenBLAS_INCLUDE_DIR and OpenBLAS_LIB options.

Any help will be greatly appreciated.

Kingboom4 gravatar imageKingboom4 ( 2016-11-22 07:43:06 -0600 )edit

Just a little update, I managed to compile OpenCV with OpenBLAS (I believe) by just giving the path to the include and the .lib. Then I simply added the OpenBLAS bin directory to the path (environment variables) containing the .dll. That solved the problem for missing libopenblas.dll, now I am getting this error, I have tried adding the missing .dll into the project - which did fix the missing .dll problem but then gave me a new error which is this. Any idea what is going on?

Thought: Could it be that I need to compile OpenBLAS from source using CMake and specify that it's for VS 14 x64?

Kingboom4 gravatar imageKingboom4 ( 2016-11-22 10:43:35 -0600 )edit

I haven't got too much time today. About OpenBlas I have clone it from https://github.com/xianyi/OpenBLAS.git and after build using VS 2015. libgcc seems a cygwin dll.

Screenshot : click advanced and grouped in cmakegui

LBerger gravatar imageLBerger ( 2016-11-22 12:50:20 -0600 )edit

No problem, thanks for replying it is much appreciated. I did manage to run my code successfully yesterday - by simply compiling OpenBLAS from source for VS 2015 using CMake, which gave me a libopenblas.lib and libopenblas.dll which I used instead of the binary package .lib and .dll (did not change the include folder) - that seemed to do the trick and the program sucessfully compiled.

The concerning part is that I did not get a performance increase in regards to evaluation of the faces - it is still quite slow. I think it might be because I did not have all the options in CMake like you did, what are your thoughts? Additionally, I did use the options grouped and advanced but I still did not have the same options as you did - here is how my one looked like

Kingboom4 gravatar imageKingboom4 ( 2016-11-23 06:23:08 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2020-08-30 09:01:55 -0600

Hi I know that is too late but i write this for person who will encounter the same problem Just compile in release mode then it will be more fast

edit flag offensive delete link more
0

answered 2018-07-11 02:39:04 -0600

holger gravatar image

I don't know if this help - but most of my problems were gone when switching to a linux(ubuntu 16.04 LTS in the cloud) machine and compiling from the source.

I personally would no try on windows - too many setup problems imho.

edit flag offensive delete link more

Comments

just curious, do you have any "special" optimizations there ?

berak gravatar imageberak ( 2018-07-11 02:40:45 -0600 )edit
1

not at all - but i just got open cv compiling on linux pretty easy compared to the the clicking in VS Studio in Windows. And i think its just not worth putting any time to get it working on windows. I would rather invest the time installing an Ubuntu 16.04 LTS(have made good experience with this version) in a cloud or locally. Thats just my opinion after all the stuff i went through.

holger gravatar imageholger ( 2018-07-11 03:03:18 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-11-17 09:48:20 -0600

Seen: 2,105 times

Last updated: Jul 11 '18