An operator integrating the open source Warp-CTC library (https://github.com/baidu-research/warp-ctc)
An operator integrating the open source Warp-CTC library (https://github.com/baidu-research/warp-ctc)
to compute Connectionist Temporal Classification (CTC) loss.
to compute Connectionist Temporal Classification (CTC) loss.
It can be aliased as softmax with CTC, since a native softmax activation
It can be aliased as softmax with CTC, since a native softmax activation
is interated to the Warp-CTC library to normalize values for each row of the input tensor.
is interated to the Warp-CTC library to normalize values for each row of the input tensor.
Parameters:
Parameters:
...
@@ -695,7 +801,7 @@ class CTCLoss(fluid.dygraph.Layer):
...
@@ -695,7 +801,7 @@ class CTCLoss(fluid.dygraph.Layer):
Returns:
Returns:
Tensor, The Connectionist Temporal Classification (CTC) loss between ``log_probs`` and ``labels``. If attr:`reduction` is ``'none'``, the shape of loss is [batch_size], otherwise, the shape of loss is [1]. Data type is the same as ``log_probs``.
Tensor, The Connectionist Temporal Classification (CTC) loss between ``log_probs`` and ``labels``. If attr:`reduction` is ``'none'``, the shape of loss is [batch_size], otherwise, the shape of loss is [1]. Data type is the same as ``log_probs``.
Examples:
Examples:
.. code-block:: python
.. code-block:: python
...
@@ -739,13 +845,13 @@ class CTCLoss(fluid.dygraph.Layer):
...
@@ -739,13 +845,13 @@ class CTCLoss(fluid.dygraph.Layer):
input_lengths = paddle.to_variable(input_lengths)
input_lengths = paddle.to_variable(input_lengths)
label_lengths = paddle.to_variable(label_lengths)
label_lengths = paddle.to_variable(label_lengths)
loss = paddle.nn.CTCLoss(blank=0, reduction='none')(log_probs, labels,
loss = paddle.nn.CTCLoss(blank=0, reduction='none')(log_probs, labels,
input_lengths,
input_lengths,
label_lengths)
label_lengths)
print(loss.numpy()) #[3.9179852 2.9076521]
print(loss.numpy()) #[3.9179852 2.9076521]
loss = paddle.nn.CTCLoss(blank=0, reduction='mean')(log_probs, labels,
loss = paddle.nn.CTCLoss(blank=0, reduction='mean')(log_probs, labels,