windows环境下编译warp-ctc

最近在学习文本检测与识别

此次博文是一次失败的安装过程,最后用了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。

参考:

https://blog.csdn.net/qq_41895190/article/details/82818615

https://blog.csdn.net/fanhenghui/article/details/102745694

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
2016年新年伊始,百度硅谷实验室向 GitHub上传了 Warp-CTC C 代码库,并在一篇博客文章中鼓励开发者使用这些代码。据悉,CTC 代码结合了多个不同的神经网络设计,以处理不完美的数据集,并采用更复杂的数据模式,同时百度也在 CTC 的基础上开发了自己的系统。百度表示,Warp-CTC所需的存储空间较小,比普通 CTC 速度快数百倍。有业内人士认为,百度这么做是因为谷歌在去年11月开源了 TensorFlow 软件,而 Faceboo k也于去年12月公开了Big Sur人工智能硬件架构。百度担心,如果开发者开始学习竞争对手的技术,那么该公司将会落后WARP-CTC 是百度硅谷 AI 研究所 (SVAIL) 开源的百度关键人工智能 (AI) 软件。   connectionist temporal classification (CTC) 方法可以追溯到 2006 年,在 Swiss AI 研究所 IDSIA 论文上有记载。 百度研究所开发的 WARP-CTC 就基于 CTC 方案,但是改进了其自身的语音识别功能。GPU 性能基准测试基于单个 NVIDIA Titan X GPUT=150, L=40, A=28warp-ctcEesenTheanoN=13.1 ms.5 ms67 msN=163.2 ms6  ms94 msN=323.2 ms12 ms119 msN=643.3 ms24 ms153 msN=1283.5 ms49 ms231 msT=150, L=20, A=5000warp-ctcEesenTheanoN=17 ms40   ms120 msN=169 ms619  ms385 msN=3211 ms1238 ms665 msN=6416 ms2475 ms1100 msN=12823 ms4950 ms2100 msCPU 性能基准测试基于 2 个 Intel E5-2660 v3 处理器T=150, L=40, A=28warp-ctcEesenTheanoN=12.6 ms--15 msN=163.4 ms--180 msN=323.9 ms--375 msN=646.6 ms--700 msN=12812.2 ms--1340 msT=150, L=20, A=5000warp-ctcEesenTheanoN=121 ms--850 msN=1637 ms--10800 msN=3254 ms--22000 msN=64101 ms--42000 msN=128184 ms--86000 ms 标签:百度开源  人工智能

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值