编译安装pytorch的 ctc loss 使用仓库:
https://github.com/SeanNaren/warp-ctc
会遇到问题:墙内没有解决方案:
src/binding.cpp:6:29: fatal error: torch/extension.h: No such file or directory
compilation terminated.
解决参考帖子:(我当时百度搜不出来。。。)
https://github.com/SeanNaren/warp-ctc/issues/101
OK, this seems to be related to PyTorch 1.0. If you are using PyTorch 0.4, just revert this repo to the previous commit:
git checkout ac045b6072b9bc3454fb9f9f17674f0d59373789
and then it will work.
最后放个测试代码:
import torch
from warpctc_pytorch import CTCLoss
ctc_loss = CTCLoss()
# expected shape of seqLength x batchSize x alphabet_size
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()
labels = torch.IntTensor([1, 2])
label_sizes = torch.IntTensor([2])
probs_sizes = torch.IntTensor([2])
probs.requires_grad_(True) # tells autograd to compute gradients for probs
cost = ctc_loss(probs, labels, probs_sizes, label_sizes)
cost.backward()