生活随笔
收集整理的這篇文章主要介紹了
【caffe-MATLAB】自己编译faster-rcnn的MATLAB版本
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
今天在自己的電腦上編譯MATLAB版本的faster-RCNN代碼,將過程在這作一記錄。
1.我的環(huán)境:Windows10 ,VS2013 , MATLAB2017a ,CUDA7.5
首先下載作者的源碼:https://github.com/ShaoqingRen/faster_rcnn
[html] view plaincopy
###?Preparation?for?Testing:??0.??Run?`fetch_data/fetch_caffe_mex_windows_vs2013_cuda65.m`?to?download?a?compiled?Caffe?mex?(for?Windows?only).??0.??Run?`faster_rcnn_build.m`??0.??Run?`startup.m`?? 上面是作者給出的運(yùn)行方法,但是他的環(huán)境是vs2013+cuda6.5,直接下載他的caffe mex在后面的build中會(huì)出錯(cuò)。
這里我們需要自己編譯caffe,在自己的環(huán)境下編譯好caffe之后,將build里面的matcaffe拷到G:\faster_rcnn-master\external\caffe\matlab\caffe_faster_rcnn下。
2.接下來就執(zhí)行2,3步了。
運(yùn)行第二步的時(shí)候經(jīng)常會(huì)出錯(cuò),原因大多是編譯器和cuda路徑不對。
錯(cuò)誤一般出在G:\faster_rcnn-master\functions\nms下面的nvmex.m文件中。
[html] view plaincopy
if?ispc?%?Windows???Host_Compiler_Location?=?'-ccbin?"C:\Program?Files?(x86)\Microsoft?Visual?Studio?12.0\VC\bin\x86_amd64"';???CUDA_INC_Location?=?['"'?getenv('CUDA_PATH')??'\include"'];??????CUDA_SAMPLES_Location?=['"'?getenv('NVCUDASAMPLES7_5_ROOT')??'\common\inc"'];??????PIC_Option?=?'';??????if?(?strcmp(computer('arch'),'win32')?==1)??????????machine_str?=?'?--machine?32?';??????????CUDA_LIB_Location?=?['"'?getenv('CUDA_PATH')??'\lib\Win32"'];??????elseif??(?strcmp(computer('arch'),'win64')?==1)??????????machine_str?=?'?--machine?64?';??????????CUDA_LIB_Location?=?['"'?getenv('CUDA_PATH')??'\lib\x64"'];??????end??????NVCC?=?'nvcc';?? 這是Windows下的配置,主要是選擇編譯器、包含庫、cuda庫。NVCUDASAMPLES7_5_ROOT本來是....6_5_ROOT,需要改成7.5版本。這些路徑可以在MATLAB里單步調(diào)試去看。
[html] view plaincopy
nvcc?--compile?-ccbin?"C:\Program?Files?(x86)\Microsoft?Visual?Studio?12.0\VC\bin\x86_amd64"?-o?nms_gpu_mex.o??--machine?64??...?? [html] view plaincopy
-I"E:\MATLAB2017a/extern/include?"?-I"C:\Program?Files\NVIDIA?GPU?Computing?Toolkit\CUDA\v7.5\include"?...?? [html] view plaincopy
-I"C:\ProgramData\NVIDIA?Corporation\CUDA?Samples\v7.5\common\inc"?"functions/nms/nms_gpu_mex.cu"??? 我的路徑是這樣的。
運(yùn)行build.m以后報(bào)錯(cuò):
[html] view plaincopy
Error?using?mex??LIBCMT.lib(crt0dat.obj)?:?error?LNK2005:?_amsg_exit?已經(jīng)在??MSVCRT.lib(MSVCR120.dll)?中定義??LIBCMT.lib(crt0dat.obj)?:?error?LNK2005:?_initterm_e?已經(jīng)在??MSVCRT.lib(MSVCR120.dll)?中定義??LIBCMT.lib(winapisupp.obj)?:?error?LNK2005:?__crtCaptureCurrentContext??已經(jīng)在?MSVCRT.lib(MSVCR120.dll)?中定義??LIBCMT.lib(winapisupp.obj)?:?error?LNK2005:?__crtCapturePreviousContext??已經(jīng)在?MSVCRT.lib(MSVCR120.dll)?中定義??LIBCMT.lib(winapisupp.obj)?:?error?LNK2005:?__crtTerminateProcess?已經(jīng)在??MSVCRT.lib(MSVCR120.dll)?中定義??LIBCMT.lib(winapisupp.obj)?:?error?LNK2005:?__crtUnhandledException?已經(jīng)??在?MSVCRT.lib(MSVCR120.dll)?中定義??LIBCMT.lib(hooks.obj)?:?error?LNK2005:?"void?__cdecl?terminate(void)"??(?terminate@@YAXXZ)?已經(jīng)在?MSVCRT.lib(MSVCR120.dll)?中定義??LIBCMT.lib(crt0init.obj)?:?error?LNK2005:?__xi_a?已經(jīng)在??MSVCRT.lib(cinitexe.obj)?中定義??LIBCMT.lib(crt0init.obj)?:?error?LNK2005:?__xi_z?已經(jīng)在??MSVCRT.lib(cinitexe.obj)?中定義??LIBCMT.lib(crt0init.obj)?:?error?LNK2005:?__xc_a?已經(jīng)在??MSVCRT.lib(cinitexe.obj)?中定義??LIBCMT.lib(crt0init.obj)?:?error?LNK2005:?__xc_z?已經(jīng)在??MSVCRT.lib(cinitexe.obj)?中定義??LIBCMT.lib(winxfltr.obj)?:?error?LNK2005:?__CppXcptFilter?已經(jīng)在??MSVCRT.lib(MSVCR120.dll)?中定義??LIBCMT.lib(mlock.obj)?:?error?LNK2005:?_lock?已經(jīng)在??MSVCRT.lib(MSVCR120.dll)?中定義??LIBCMT.lib(mlock.obj)?:?error?LNK2005:?_unlock?已經(jīng)在??MSVCRT.lib(MSVCR120.dll)?中定義?????正在創(chuàng)建庫?G:\faster_rcnn-master\bin\nms_gpu_mex.lib?和對象?????G:\faster_rcnn-master\bin\nms_gpu_mex.exp??LINK?:?warning?LNK4098:?默認(rèn)庫“MSVCRT”與其他庫的使用沖突;請使用??/NODEFAULTLIB:library??LINK?:?warning?LNK4098:?默認(rèn)庫“LIBCMT”與其他庫的使用沖突;請使用??/NODEFAULTLIB:library??G:\faster_rcnn-master\bin\nms_gpu_mex.mexw64?:?fatal?error?LNK1169:?找到??一個(gè)或多個(gè)多重定義的符號(hào)????????Error?in?nvmex?(line?48)??eval(mexCommandLine);????Error?in?faster_rcnn_build?(line?23)?????nvmex('functions/nms/nms_gpu_mex.cu',?'bin');??
這個(gè)錯(cuò)誤是lib庫沖突了,解決辦法是修改mex命令:
[html] view plaincopy
mexCommandLine?=?['mex?'?'-outdir?'?outDir?'?'?filename?'.o'???'?-L'?CUDA_LIB_Location???'?-lcudart'?'?LINKFLAGS="$LINKFLAGS?/NODEFAULTLIB:LIBCMT.LIB"'?];??
意思是忽略LIBCMT.lib庫,然后繼續(xù)編譯就可以過了。
3.第三步執(zhí)行startup.m,
[html] view plaincopy
mex?-outdir?bin?nms_gpu_mex.o?-L"C:\Program?Files\NVIDIA?GPU?Computing?Toolkit\CUDA\v7.5\lib\x64"?-lcudart?LINKFLAGS="$LINKFLAGS?/NODEFAULTLIB:LIBCMT.LIB"??Building?with?'Microsoft?Visual?C++?2013?Professional?(C)'.??MEX?completed?successfully.??>>?startup??fast_rcnn?startup?done?? 至此,基本環(huán)境已經(jīng)配置完成了。
4.運(yùn)行demo
下載final model,這個(gè)最好直接取上面的作者主頁下載,給出了百度云的地址。
[html] view plaincopy
If?the?automatic?"fetch_data"?fails,?you?may?manually?download?resouces?from:????Pre-complied?caffe?mex:??Windows-based?mex?complied?with?VS2013?and?Cuda6.5:?OneDrive,?DropBox,?BaiduYun??ImageNet-pretrained?networks:??Zeiler?&?Fergus?(ZF)?net?OneDrive,?DropBox,?BaiduYun??VGG-16?net?OneDrive,?DropBox,?BaiduYun??Final?RPN+FastRCNN?models:?OneDrive,?DropBox,?BaiduYun?? 下載最后一個(gè)。
然后需要在工程根目錄下面運(yùn)行 experiments/script_faster_rcnn_demo,剛開始運(yùn)行總是崩潰,修改模型以后就可以了:
[html] view plaincopy
%model_dir???????????????????=?fullfile(pwd,?'output',?'faster_rcnn_final',?'faster_rcnn_VOC0712_vgg_16layers');?%%?VGG-16??model_dir???????????????????=?fullfile(pwd,?'output',?'faster_rcnn_final',?'faster_rcnn_VOC0712_ZF');?%%?ZF?? 原因應(yīng)該是顯存不夠造成MATLAB崩潰,ZF模型要小一點(diǎn)。如果這部分出錯(cuò),可以在代碼里檢查一下你的模型路徑和圖片路徑是否與真實(shí)的一致,然后運(yùn)行就可以了??梢钥吹竭@個(gè)例子中作者給出了五張圖的測試。
2017.04.10修改:faster_rcnn_VOC0712_vgg_16layers模型在我嘗試的時(shí)候,將demo里的17行 ? ?
[html] view plaincopy
<span?style="font-size:14px;color:#ff0000;">?opts.test_scales????????????=?600;</span>?? 改為 ?= 300;之后居然神奇地跑通了??梢?#xff0c;之前MATLAB奔潰確實(shí)是因?yàn)轱@存不夠?qū)е碌摹?/span>
然后運(yùn)行就可以看到如下結(jié)果了:
[html] view plaincopy
fast_rcnn?startup?done??GPU?1:?free?memory?1686414131??Use?GPU?1??001763.jpg?(500x375):?time?0.230s?(resize+conv+proposal:?0.124s,?nms+regionwise:?0.105s)??004545.jpg?(500x375):?time?0.736s?(resize+conv+proposal:?0.604s,?nms+regionwise:?0.132s)??000542.jpg?(500x375):?time?0.246s?(resize+conv+proposal:?0.154s,?nms+regionwise:?0.092s)??000456.jpg?(500x375):?time?0.222s?(resize+conv+proposal:?0.088s,?nms+regionwise:?0.134s)??001150.jpg?(500x375):?time?0.165s?(resize+conv+proposal:?0.087s,?nms+regionwise:?0.077s)??mean?time:?0.320s??Cleared?0?solvers?and?2?stand-alone?nets??
總結(jié)
以上是生活随笔為你收集整理的【caffe-MATLAB】自己编译faster-rcnn的MATLAB版本的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。