pytorch编译配置warp-CTC,warpctc_pytorch 编译

warp_ctc源码地址为:https://github.com/SeanNaren/Warp-ctc

1.下载压缩包并解压,或直接git clone源码。

git clone https://github.com/SeanNaren/warp-ctc.git

2.运行如下指令进行编译:


 
 
  1. mv warp-ctc-pytorch_bindings/ warp-ctc
  2. cd warp-ctc
  3. mkdir build; cd build
  4. cmake ..
  5. make

3.开始安装:


 
 
  1. cd pytorch_binding
  2. python setup .py install

4. 安装结束后,在warp-ctc/pytorch_binding/build目录下新建一个test.py文件进行测试。目录结构如下:

文件内容为:


 
 
  1. import torch
  2. from warpctc_pytorch import CTCLoss
  3. ctc_loss = CTCLoss()
  4. # expected shape of seqLength x batchSize x alphabet_size
  5. probs = torch.FloatTensor([[[ 0.1, 0.6, 0.1, 0.1, 0.1], [ 0.1, 0.1, 0.6, 0.1, 0.1]]]).transpose( 0, 1).contiguous()
  6. labels = torch.IntTensor([ 1, 2])
  7. label_sizes = torch.IntTensor([ 2])
  8. probs_sizes = torch.IntTensor([ 2])
  9. probs.requires_grad_( True) # tells autograd to compute gradients for probs
  10. cost = ctc_loss(probs, labels, probs_sizes, label_sizes)
  11. cost.backward()

执行python test.py,若没有报错,则证明编译及运行成功。

6.将其应用于其他项目中。若某项目存在一py格式文件,存在如下调用方式:

则将warp-ctc/pytorch_binding/build/warpctc_pytorch 目录拷贝至与该py文件同级的目录下。

cp -r ~/warp-ctc/pytorch_binding/build/warpctc_pytorch .
 
 

再执行该py文件即可成功。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值