Computes CTC (Connectionist Temporal Classification) loss. This op implements the CTC loss as presented in the article: [A. Graves, S. Fernandez, F. Gomez, J. Schmidhuber. Connectionist Temporal Classification: Labeling Unsegmented Sequence Data with Recurrent Neural Networks. ICML 2006, P
(labels,
logits,
label_length,
logit_length,
logits_time_major=True,
unique=None,
blank_index=None,
name=None)
| 640 | |
| 641 | @tf_export("nn.ctc_loss", v1=["nn.ctc_loss_v2"]) |
| 642 | def ctc_loss_v2(labels, |
| 643 | logits, |
| 644 | label_length, |
| 645 | logit_length, |
| 646 | logits_time_major=True, |
| 647 | unique=None, |
| 648 | blank_index=None, |
| 649 | name=None): |
| 650 | """Computes CTC (Connectionist Temporal Classification) loss. |
| 651 | |
| 652 | This op implements the CTC loss as presented in the article: |
| 653 | |
| 654 | [A. Graves, S. Fernandez, F. Gomez, J. Schmidhuber. |
| 655 | Connectionist Temporal Classification: Labeling Unsegmented Sequence Data |
| 656 | with Recurrent Neural Networks. ICML 2006, Pittsburgh, USA, |
| 657 | pp. 369-376.](http://www.cs.toronto.edu/~graves/icml_2006.pdf) |
| 658 | |
| 659 | Notes: |
| 660 | |
| 661 | - Same as the "Classic CTC" in TensorFlow 1.x's tf.compat.v1.nn.ctc_loss |
| 662 | setting of preprocess_collapse_repeated=False, ctc_merge_repeated=True |
| 663 | - Labels may be supplied as either a dense, zero-padded tensor with a |
| 664 | vector of label sequence lengths OR as a SparseTensor. |
| 665 | - On TPU and GPU: Only dense padded labels are supported. |
| 666 | - On CPU: Caller may use SparseTensor or dense padded labels but calling with |
| 667 | a SparseTensor will be significantly faster. |
| 668 | - Default blank label is 0 rather num_classes - 1, unless overridden by |
| 669 | blank_index. |
| 670 | |
| 671 | Args: |
| 672 | labels: tensor of shape [batch_size, max_label_seq_length] or SparseTensor |
| 673 | logits: tensor of shape [frames, batch_size, num_labels], if |
| 674 | logits_time_major == False, shape is [batch_size, frames, num_labels]. |
| 675 | label_length: tensor of shape [batch_size], None if labels is SparseTensor |
| 676 | Length of reference label sequence in labels. |
| 677 | logit_length: tensor of shape [batch_size] Length of input sequence in |
| 678 | logits. |
| 679 | logits_time_major: (optional) If True (default), logits is shaped [time, |
| 680 | batch, logits]. If False, shape is [batch, time, logits] |
| 681 | unique: (optional) Unique label indices as computed by |
| 682 | ctc_unique_labels(labels). If supplied, enable a faster, memory efficient |
| 683 | implementation on TPU. |
| 684 | blank_index: (optional) Set the class index to use for the blank label. |
| 685 | Negative values will start from num_classes, ie, -1 will reproduce the |
| 686 | ctc_loss behavior of using num_classes - 1 for the blank symbol. There is |
| 687 | some memory/performance overhead to switching from the default of 0 as an |
| 688 | additional shifted copy of the logits may be created. |
| 689 | name: A name for this `Op`. Defaults to "ctc_loss_dense". |
| 690 | |
| 691 | Returns: |
| 692 | loss: tensor of shape [batch_size], negative log probabilities. |
| 693 | """ |
| 694 | if isinstance(labels, sparse_tensor.SparseTensor): |
| 695 | if blank_index is None: |
| 696 | raise ValueError( |
| 697 | "blank_index must be given when using SparseTensor labels.") |
| 698 | |
| 699 | _ctc_use_cudnn = os.environ.get("TF_CUDNN_CTC_LOSS", "0") |
nothing calls this directly
no test coverage detected