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

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,208 times

Last updated: Jul 11 '18