Using the opencv_contrib dnn module (too slow)
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
just curious: "I am using a caffemodel (trained for gender classification)" -- is that gil levy's ? (it did not work with previous dnn versions)
Nope it's from this paper https://data.vision.ee.ethz.ch/cvl/rr... it works flawlessly but the implementation is just too slow.
What have you try? How can I know that's an answer ?
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.
Don't you use cmake ? here you can find results with opencv_perf_dnn.exe
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"
/SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"opencv_dnn.dir\Debug\opencv_dnn310d.dll.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /TLBID:1
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"
/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"
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?