最近在学习文本检测与识别
此次博文是一次失败的安装过程,最后用了pytorch中自带的CTCLoss,因为我的pytorch为1.1.0版本
如果版本为1.0以下,可以尝试以下方法,本人已经走到了最后一步,成功安装,但是却无法调用。
主要过程如下:
1.安装cmake;
2.下载warp-ctc,下载链接:https://github.com/amberblade/warp-ctc
以上链接是作者修改之后,可以在windows环境下编译
3.在命令行,进入warp-ctc,并建立文件目录build,进入该目录,执行cmake -G "Visual Studio 14 2015 Win64" ..
我需要到了一个错误,找不到vs编译器,后来查找了资料,在vs2015中,将SDK10添加安装后,编译成功。
到此编译成功,但是打不开sln文件,计算机重启后,重新编译了一次,打开sln,又需要安装适用于 Windows 桌面的 Visual C++ 2015 工具SDK8.1,安装之后,编译ALL_BUILD成功。
编译成功后,修改setup.py为以下内容:
# build.py import os import platform import sys from setuptools import setup, find_packages #from torch.utils.ffi import create_extension from torch.utils.cpp_extension import BuildExtension from torch.utils.cpp_extension import CppExtension import torch extra_compile_args = ['-std=c++11', '-fPIC', '-std=c99'] warp_ctc_path = "../build/release" if torch.cuda.is_available() or "CUDA_HOME" in os.environ: enable_gpu = True else: print("Torch was not built with CUDA support, not building warp-ctc GPU extensions.") enable_gpu = False lib_ext = ".dll" headers = ['src/cpu_binding.h'] # if enable_gpu: # extra_compile_args += ['-DWARPCTC_ENABLE_GPU'] # headers += ['src/gpu_binding.h'] if enable_gpu: from torch.utils.cpp_extension import CUDAExtension build_extension = CUDAExtension extra_compile_args += ['-DWARPCTC_ENABLE_GPU'] else: build_extension = CppExtension if not os.path.exists(os.path.join(warp_ctc_path, "warpctc" + lib_ext)): print(("Could not find libwarpctc.so in {}.\n" "Build warp-ctc and set WARP_CTC_PATH to the location of" " warpctc.dll (default is '../build/release')").format(warp_ctc_path)) sys.exit(1) include_dirs = [os.path.realpath('../include')] # ffi = BuildExtension( # name='warpctc_pytorch._warp_ctc', # package=True, # language='c++', # headers=headers, # sources=['src/binding.cpp'], # with_cuda=enable_gpu, # include_dirs=include_dirs, # library_dirs=[os.path.realpath(warp_ctc_path)], # libraries=['warpctc', 'caffe2_gpu', '_c', 'caffe2'], # extra_link_args=['-Wl,-rpath,' + os.path.realpath(warp_ctc_path)], # extra_compile_args=extra_compile_args) # ffi = ffi.distutils_extension() # setup( # name="warpctc_pytorch", # version="0.1", # description="PyTorch wrapper for warp-ctc", # url="https://github.com/baidu-research/warp-ctc", # author="Jared Casper, Sean Naren", # author_email="jared.casper@baidu.com, sean.narenthiran@digitalreasoning.com", # license="Apache", # packages=find_packages(), # ext_modules=[ffi], # ) ext_modules = [ build_extension( name='warpctc_pytorch._warp_ctc', package=True, language='c++', headers=headers, sources=['src/binding.cpp'], include_dirs=include_dirs, library_dirs=[os.path.realpath(warp_ctc_path)], libraries=['warpctc', 'caffe2_gpu', '_c', 'caffe2'], #libraries=['warpctc'], extra_link_args=['-Wl,-rpath,' + os.path.realpath(warp_ctc_path)], extra_compile_args=extra_compile_args ) ] setup( name="warpctc_pytorch", version="0.1", description="PyTorch wrapper for warp-ctc", url="https://github.com/baidu-research/warp-ctc", author="Jared Casper, Sean Naren", author_email="jared.casper@baidu.com, sean.narenthiran@digitalreasoning.com", license="Apache", packages=find_packages(), ext_modules=ext_modules, cmdclass={'build_ext': BuildExtension} )
在命令行输入:python setup.py install
安装成功后,将dll文件复制到安装目录下。
但是测试时仍然保存。不知道什么原因。
最后还是使用了pytorch自带的ctcloss。
参考: