deep features for text spotting 在linux,windows上使用

做文本检测这个方向的同学应该都知道 deep features for text spotting 这篇ECCV14的文章。

用的是Matconvnet这个是深度学习框架来做文本检测,同时他还提供了代码:  eccv2014_textspotting

不过这个代码里的Matconvnet不同于原版本Matconvnet,原版本的内容比较全,而这个repository里的算是阉割版,同时还新加入了几个cpp,cu文件。。。

不幸的是,新加入的几个文件只在mac上有编译好的mex文件,linux上,windows上都需要自己编译。接下来就讲讲如何在linux和windows下编译这几个cpp,cu的mex文件。


 linux 上的编译方法已经在repository中提到

1. Edit matconvnet/Makefile to ensure MEX points to your matlab mex binary. Optinally ENABLE_GPU.
2. cd matconvnet/ && make

已经提供了编译的模板,主要是要修改好matconvnet/Makefile_Linux中几个变量的路径,就可以直接编译了。

比如 我是Ubuntu上装的CUDA7.0就修改如下:

MEX ?= /usr/local/MATLAB/R2014b/bin/mex
MEXARCH = mexa64
NVCC ?= /usr/local/cuda-7.0/bin/nvcc
ENABLE_GPU = true
MEXOPTS_GPU= $(MEXOPTS) -DENABLE_GPU -L /usr/local/cuda-7.0/targets/x86_64-linux/lib -lcudart -lcublas -lcudadevrt -f matlab/src/mex_CUDA_glnxa64.sh

然后重命名Makefile_linux为Makefile,然后 cd matconvnet/,然后 make

这里提供我编译好的 .mexa64文件,:linux_version 。     注意:我在Ubuntu下用cuda7.0编译的,matlab版本是2014b。

把这些mex文件放在 matconvnetmatlabmex下就能跑整个代码了。


 linux下用还是有点不方便,接下来主要讲一下windows下的编译

说来惭愧,本来想自己看明白makefile,然后逐个逐个编译的,但是在不知道nvcc和mex这两编译器该怎么个顺序,用啥编译参数,后来只能偷懒了。

Makefile里面说道了,主要是编译一下几个文件

cpp_src:=matlab/src/bits/im2col.cpp
cpp_src+=matlab/src/bits/pooling.cpp
cpp_src+=matlab/src/bits/normalize.cpp
mex_src:=matlab/src/gconv.cu
mex_src+=matlab/src/gpool.cu
mex_src+=matlab/src/gnormalize.cu
mex_src+=matlab/src/gsepconv.cu
mex_src+=matlab/src/gsepconv2.cu
cpp_src+=matlab/src/bits/im2col_gpu.cu
cpp_src+=matlab/src/bits/pooling_gpu.cu
cpp_src+=matlab/src/bits/normalize_gpu.cu

用过通用版的Matconvnet会有记得那边的windows编译很方便很简单,所以就直接用那边的程序编译了。

首先去下载一个通用版本的 Matconvnet : 通用版Matconvnet

然后用他提供的 matconvnet-mastermatlabvl_compilenn.m 进行编译,修改 vl_compilenn 这个文件里面 185来行的代码,原本是这样:

if opts.enableGpu, ext = 'cu' ; else ext='cpp' ; end
lib_src{end+1} = fullfile(root,'matlab','src','bits',['data.' ext]) ;
lib_src{end+1} = fullfile(root,'matlab','src','bits',['datamex.' ext]) ;
lib_src{end+1} = fullfile(root,'matlab','src','bits',['nnconv.' ext]) ;
lib_src{end+1} = fullfile(root,'matlab','src','bits',['nnfullyconnected.' ext]) ;
lib_src{end+1} = fullfile(root,'matlab','src','bits',['nnsubsample.' ext]) ;
lib_src{end+1} = fullfile(root,'matlab','src','bits',['nnpooling.' ext]) ;
lib_src{end+1} = fullfile(root,'matlab','src','bits',['nnnormalize.' ext]) ;
lib_src{end+1} = fullfile(root,'matlab','src','bits',['nnbnorm.' ext]) ;
lib_src{end+1} = fullfile(root,'matlab','src','bits',['nnbias.' ext]) ;
mex_src{end+1} = fullfile(root,'matlab','src',['vl_nnconv.' ext]) ;
mex_src{end+1} = fullfile(root,'matlab','src',['vl_nnconvt.' ext]) ;
mex_src{end+1} = fullfile(root,'matlab','src',['vl_nnpool.' ext]) ;
mex_src{end+1} = fullfile(root,'matlab','src',['vl_nnnormalize.' ext]) ;
mex_src{end+1} = fullfile(root,'matlab','src',['vl_nnbnorm.' ext]) ;

% CPU-specific files
lib_src{end+1} = fullfile(root,'matlab','src','bits','impl','im2row_cpu.cpp') ;
lib_src{end+1} = fullfile(root,'matlab','src','bits','impl','subsample_cpu.cpp') ;
lib_src{end+1} = fullfile(root,'matlab','src','bits','impl','copy_cpu.cpp') ;
lib_src{end+1} = fullfile(root,'matlab','src','bits','impl','pooling_cpu.cpp') ;
lib_src{end+1} = fullfile(root,'matlab','src','bits','impl','normalize_cpu.cpp') ;
lib_src{end+1} = fullfile(root,'matlab','src','bits','impl','bnorm_cpu.cpp') ;
lib_src{end+1} = fullfile(root,'matlab','src','bits','impl','tinythread.cpp') ;

% GPU-specific files
if opts.enableGpu
  lib_src{end+1} = fullfile(root,'matlab','src','bits','impl','im2row_gpu.cu') ;
  lib_src{end+1} = fullfile(root,'matlab','src','bits','impl','subsample_gpu.cu') ;
  lib_src{end+1} = fullfile(root,'matlab','src','bits','impl','copy_gpu.cu') ;
  lib_src{end+1} = fullfile(root,'matlab','src','bits','impl','pooling_gpu.cu') ;
  lib_src{end+1} = fullfile(root,'matlab','src','bits','impl','normalize_gpu.cu') ;
  lib_src{end+1} = fullfile(root,'matlab','src','bits','impl','bnorm_gpu.cu') ;
  lib_src{end+1} = fullfile(root,'matlab','src','bits','datacu.cu') ;
end

改成这样:

if opts.enableGpu, ext = 'cu' ; else ext='cpp' ; end
mex_src{end+1} = fullfile(root,'matlab','src',['gconv.' ext]) ;
mex_src{end+1} = fullfile(root,'matlab','src',['gnormalize.' ext]) ;
mex_src{end+1} = fullfile(root,'matlab','src',['gpool.' ext]) ;
mex_src{end+1} = fullfile(root,'matlab','src',['gsepconv.' ext]) ;
mex_src{end+1} = fullfile(root,'matlab','src',['gsepconv2.' ext])

% CPU-specific files
lib_src{end+1} = fullfile(root,'matlab','src','bits','im2col.cpp') ;
lib_src{end+1} = fullfile(root,'matlab','src','bits','pooling.cpp') ;
lib_src{end+1} = fullfile(root,'matlab','src','bits','normalize.cpp') ;

% GPU-specific files
if opts.enableGpu
  lib_src{end+1} = fullfile(root,'matlab','src','bits','im2col_gpu.cu') ;
  lib_src{end+1} = fullfile(root,'matlab','src','bits','pooling_gpu.cu') ;
  lib_src{end+1} = fullfile(root,'matlab','src','bits','normalize_gpu.cu') ;
end

然后把 matconvnet-max-versionmatlabsrc 下 5个.cu文件 gconv.cu gnormalize.cu gpool.cu gsepconv.cu gsepconv2.cu ,还有 matconvnet-max-versionmatlabsrcits下的所有文件(除了mexutils.h),分别拷贝到拷贝到 matconvnet-mastermatlabsrc 和 matconvnet-mastermatlabsrcits下。

把vl_compilenn里的 opts.enableImreadJpeg 改为false, 其他不变。

matlab切换到 vl_compilenn.m根目录,以下列参数运行 

vl_compilenn('enableGpu', true, ...
'cudaRoot', 'C:Program FilesNVIDIA GPU Computing ToolkitCUDAv6.5', ...
'cudaMethod', 'nvcc')
'cudaRoot'设置为你windows上装CUDA的位置就行。

 然后在mex目录下面就有.mexw64文件了。 就这么简单。

这里给我自己编译的  : window64位cuda6.5

 环境: x64,matlab2014b,cuda 6.5

原文地址:https://www.cnblogs.com/jugg1024/p/5131679.html