deep features for text spotting 在windows上使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hjl240/article/details/52165748

         deep features for text spotting这篇文章中给的matlab代码eccv2014_textspotting,是作者在mac上编译好的,我们在Windows和linux下使用的时候需要自己编译mex文件。

         下面主要介绍如何在Windows下只编译CPU的版本,即不需要GPU支持。


          该matlab代码用的是Matconvnet这个是深度学习框架来做文本检测,故我们需要先去下载一个通用版本的 Matconvnet。

          github下载地址如下:https://github.com/vlfeat/matconvnet

         也可以在我上传在CSDN上下载:http://download.csdn.net/detail/hjl240/9470822

         然后用他提供的matconvnet-master\matlab\vl_compilenn.m 进行编译,修改 vl_compilenn 这个文件里面 193行至233行的代码,原本是这样:

         将193行至223行的代码


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') ;
lib_src{end+1} = fullfile(root,'matlab','src','bits','imread.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

然后把 jaderberg-eccv2014_textspotting\matlab\src\下 5个.cu文件gconv.cugnormalize.cu gpool.cu gsepconv.cu gsepconv2.cu,还有 jaderberg-eccv2014_textspotting\matlab\src\bits下的所有文件(除了mexutils.h),分别拷贝到拷贝到matconvnet-master\matlab\src\ 和 matconvnet-master\matlab\src\bits下。

接着,在matconvnet-master\matlab\src文件夹下新建5个.cpp文件,为gconv.cpp, gnormalize.cpp , gpool.cpp , gsepconv.cpp , gsepconv2.cpp ,在这5个cpp文件#include各自对应的.cu文件。   

比如,gconv.cpp内容为:

#if ENABLE_GPU
#error This file should not be compiled with GPU support enabled
#endif
#include "gconv.cu"

gnormalize.cpp内容为:

#if ENABLE_GPU
#error This file should not be compiled with GPU support enabled
#endif
#include " gnormalize.cu"

以此类推。


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

matlab切换到 vl_compilenn.m根目录,以下列参数运行(只编译CPU版本):

vl_compilenn('enableGpu'false)

运行结果如下:



编译GPU版本命令如下:

vl_compilenn('enableGpu', true, ...
'cudaRoot', 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5', ...
'cudaMethod', 'nvcc')

'cudaRoot' 设置为你 windows 上装 CUDA 的位置就行。


然后在mex目录下面就有.mexw64文件了。如下:



最后把这些.mexw64文件复制到jaderberg-eccv2014_textspotting\matconvnet\matlab\mex(即论文给的matlab代码文件下),便可以运行论文给的3个例子(fig_detmap.m,fig_charmap.m,reproduce_classifier_results.m)了。

         这是我编译的mexw64文件。环境:Win7 x64,matlab2015a。



参考文献:deep features for text spotting linuxwindows上使用


猜你喜欢

转载自blog.csdn.net/hjl240/article/details/52165748