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?
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
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.
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.
cmakegui1
cmakegui2
blas
end
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.
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:
Having said that, I do have the OpenBLAS_INCLUDE_DIR and OpenBLAS_LIB options.
Any help will be greatly appreciated.