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