Closed discort closed 3 years ago
But a simple example from docs works as expected
out = 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).requires_grad_(True)
print(out.shape)
labels = torch.IntTensor([1, 2])
label_lengths = torch.IntTensor([2])
input_lengths = torch.IntTensor([2])
warp_ctc = CTCLoss(size_average=True)
torch_ctc = nn.CTCLoss(reduction='sum')
loss1 = warp_ctc(out, labels, input_lengths, label_lengths)
print(loss1)
loss2 = torch_ctc(out.log_softmax(2), labels, input_lengths, label_lengths)
print(loss2)
out
torch.Size([2, 1, 5])
tensor([2.4629], grad_fn=<_CTCBackward>)
tensor(2.4629, grad_fn=<SumBackward0>)
@SeanNaren any ideas about the origins of double free or corruption (!prev)
(cpu) or zeros on cuda?
import torch import torch.nn as nn from warpctc_pytorch import CTCLoss
out = torch.randn(368, 2, 29) input_lengths = torch.IntTensor([119, 179]) labels = torch.randint(1, 27, size=(148,)).int() label_lengths = torch.IntTensor([59, 89])
warp_ctc = CTCLoss() torch_ctc = nn.CTCLoss(reduction='sum')
loss1 = warp_ctc(out, labels, input_lengths, label_lengths) print(loss1)
loss2 = torch_ctc(out.log_softmax(2), labels, input_lengths, label_lengths) print(loss2)
remember follows: torch.tensor([119, 179]) returns torch.int64 , not torch.int32 torch.randint(1, 27, size=(148,)) returns torch.int64 , not torch.int32
Background:
warpctc_pytorch.CTCLoss
resultsinf
loss howevertorch.nn.CTCLoss
calculates float value.Expected
I'm not sure what loss works correctly, but I suppose we should get the same result, right? Or did I miss something in terms of passing incorrect args to ctcloss?
To reproduce:
Version
UPD Ran the same code on
aarch64 GNU/Linux
on cpu:on cuda: