Matconvnet介紹
MatConvNet是一個MATLAB工具箱,爲計算機視覺應用實現了卷積神經網絡(CNN)。它簡單,高效,並且可以運行和學習最新的CNN。提供了許多用於圖像分類,分割,面部識別和文本檢測的預訓練CNN。
基礎軟件
Windows 10
Visual Studio 2017 Communicity
Matlab2019b
RTX 2060
最新版Matconvnet
NVIDIA GPU Computing Toolkit\CUDA\v10.0
安裝
1.將庫源代碼下載並解壓縮到您選擇的目錄中(最好是項目的根目錄)。我這裏將庫源代碼命名爲matconvnet。其中最新版matconvnet下載地址:
配置
1.運行下列代碼進行編譯
mex -setup
選擇(點擊) mex -setup C++
2.進入到matconvet的matlab文件夾
cd matconvnet
addpath matlab
3.CPU編譯
vl_compilenn
4.GPU編譯
vl_compilenn('enableGpu',true,'cudaRoot','C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0','cudaMethod' ,'nvcc','enableCudnn',true,'cudnnRoot','C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA')
錯誤及解決方案
錯誤1
最新版本的MatConvNet中的vl_compilenn.m文件中在506行增加了這樣的判斷
if strcmp(arch, 'win64') && opts.enableCudnn
。這要求&&符號前後都是邏輯值,所以在運行vl_compilenn函數中’enableCudnn’後面要跟true,而不是跟’true’,即編譯語句爲:
vl_compilenn('enableGpu', true, ...
'cudaRoot', 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0', ...
'cudaMethod', 'nvcc',...
'enableCudnn', true, ...
'cudnnRoot', 'xxx\cuDNNv6'); % 這裏填寫你的cuDNN的路徑
否則會報Operands to the || and && operators must be convertible to logical scalar values
的錯誤
錯誤2
錯誤使用 mex’/home/pathto…/matconvnet-1.0-beta25_linux/matlab/mex/vl_nnconv.mexa64’ 使用了 ‘-R2018a’ 進行編譯並與 '-R2017b’鏈接在一起。有關詳細信息,請參閱 MEX 文件使用了一個 API 進行編譯並與另一個 API 鏈接在一起。
解決方案:
修改vl_compilenn.m
step1:從620行修改爲:
args = horzcat({'-outdir', mex_dir}, ...
flags.base, flags.mexlink, ...
'-R2018a',...
{['LDFLAGS=$LDFLAGS ' strjoin(flags.mexlink_ldflags)]}, ...
{['LDOPTIMFLAGS=$LDOPTIMFLAGS ' strjoin(flags.mexlink_ldoptimflags)]}, ...
{['LINKLIBS=' strjoin(flags.mexlink_linklibs) ' $LINKLIBS']}, ...
objs) ;
step2:修改359行爲:
flags.mexlink = {'-lmwblas'};
錯誤3
錯誤使用copyfilecopyfile(fullfile(opts.cudnnRoot,'bin', '*.dll'), flags.mex_dir)
解決方案
註釋掉vl_compilenn.m裏面的508行(註銷掉即可)
錯誤4
Warning: CL.EXE not found in PATH. Trying to guess out of mex setup.
> In vl_compilenn>check_clpath (line 650)
In vl_compilenn (line 426)
'cl.exe' is not recognized as an internal or external command,
operable program or batch file.
Error using vl_compilenn>check_clpath (line 656)
Unable to find cl.exe
Error in vl_compilenn (line 426)
cl_path = fileparts(check_clpath()); % check whether cl.exe in path
解決方案
把 C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64 的cl.exe複製到 matconvnet下
錯誤5
Error using vl_compilenn>nvcc_compile (line 615)
Command "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\nvcc" -c -o
"D:\Matlab\matconvnet-1.0-beta25\matconvnet-1.0-beta25\matlab\mex\.build\bits\data.obj"
"D:\Matlab\matconvnet-1.0-beta25\matconvnet-1.0-beta25\matlab\src\bits\data.cu" -DENABLE_GPU -DENABLE_DOUBLE
-DENABLE_CUDNN -I".local\cudnn\include" -O -DNDEBUG -D_FORCE_INLINES --std=c++11
-I"D:\Matlab\extern\include" -I"D:\Matlab\toolbox\distcomp\gpu\extern\include"
-gencode=arch=compute_52,code=\"sm_52,compute_52\" --compiler-options=/MD --compiler-bindir="C:\Program
Files (x86)\Microsoft Visual Studio\2017\Community\VC\bin" failed.
Error in vl_compilenn (line 487)
nvcc_compile(opts, srcs{i}, objfile, flags) ;
解決方案
在 C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC 下創建bin文件夾
錯誤6
0x00007FF64188ADD0 (0x0000000000000000 0x000001E56C1C7F18 0x000066BA00000001 0x00000004000304ED)
0x00007FF641886F3D (0x0000009EBEFFE798 0x0000000000000000 0x0000000000000000 0x000001E56C1DCE20)
0x00007FF641888713 (0xnvcc warning : The -std=c++11 flag is not supported with the configured host compiler. Flag will be ignored.
data.cu
nvcc error : 'cicc' died with status 0xC0000005 (ACCESS_VIOLATION)
Error using vl_compilenn>nvcc_compile (line 615)
Command "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\nvcc" -c -o
"D:\Matlab\matconvnet-1.0-beta25\matconvnet-1.0-beta25\matlab\mex\.build\bits\data.obj"
"D:\Matlab\matconvnet-1.0-beta25\matconvnet-1.0-beta25\matlab\src\bits\data.cu" -DENABLE_GPU -DENABLE_DOUBLE
-DENABLE_CUDNN -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\include" -O -DNDEBUG -D_FORCE_INLINES
--std=c++11 -I"D:\Matlab\extern\include" -I"D:\Matlab\toolbox\distcomp\gpu\extern\include"
-gencode=arch=compute_52,code=\"sm_52,compute_52\" --compiler-options=/MD --compiler-bindir="C:\Program
Files (x86)\Microsoft Visual Studio\2017\Community\VC\bin" failed.
Error in vl_compilenn (line 487)
nvcc_compile(opts, srcs{i}, objfile, flags) ;
解決方案
當使用Visual Studio 2017 Community時,CUDA使用 10.0版本。使用CUDA9.0可能會導致上述錯誤,即使用CUDA10.0
錯誤7(僅限CUDA9.0)
c:\program files\nvidia gpu computing toolkit\cuda\v9.0\include\crt/host_config.h(133): fatal error C1189: #error: -- unsupported Microsoft Visual Studio version! Only the versions 2012, 2013, 2015 and 2017 are supported!
nvcc warning : The -std=c++11 flag is not supported with the configured host compiler. Flag will be ignored.
data.cu
Error using vl_compilenn>nvcc_compile (line 615)
Command "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\nvcc" -c -o
"D:\Matlab\matconvnet-1.0-beta25\matconvnet-1.0-beta25\matlab\mex\.build\bits\data.obj"
"D:\Matlab\matconvnet-1.0-beta25\matconvnet-1.0-beta25\matlab\src\bits\data.cu" -DENABLE_GPU -DENABLE_DOUBLE
-DENABLE_CUDNN -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\include" -O -DNDEBUG -D_FORCE_INLINES
--std=c++11 -I"D:\Matlab\extern\include" -I"D:\Matlab\toolbox\distcomp\gpu\extern\include"
-gencode=arch=compute_52,code=\"sm_52,compute_52\" --compiler-options=/MD --compiler-bindir="C:\Program
Files (x86)\Microsoft Visual Studio\2017\Community\VC\bin" failed.
Error in vl_compilenn (line 487)
nvcc_compile(opts, srcs{i}, objfile, flags) ;
解決方案
cuda和vs版本不匹配。打開C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include\crt\host_config.h
,把#if _MSC_VER < 1600 || _MSC_VER > 1911
改爲:#if _MSC_VER < 1600 || _MSC_VER > 1920
,只要版本號夠高就行,隨便挑個數字
其他問題解決方案
https://www.cnblogs.com/qq552048250/p/7857122.html
https://zhuanlan.zhihu.com/p/57132601