MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ctc_batch_cost

Function ctc_batch_cost

tensorflow/python/keras/backend.py:5604–5632  ·  view source on GitHub ↗

Runs CTC loss algorithm on each batch element. Arguments: y_true: tensor `(samples, max_string_length)` containing the truth labels. y_pred: tensor `(samples, time_steps, num_categories)` containing the prediction, or output of the softmax. input_length: tens

(y_true, y_pred, input_length, label_length)

Source from the content-addressed store, hash-verified

5602
5603@keras_export('keras.backend.ctc_batch_cost')
5604def ctc_batch_cost(y_true, y_pred, input_length, label_length):
5605 """Runs CTC loss algorithm on each batch element.
5606
5607 Arguments:
5608 y_true: tensor `(samples, max_string_length)`
5609 containing the truth labels.
5610 y_pred: tensor `(samples, time_steps, num_categories)`
5611 containing the prediction, or output of the softmax.
5612 input_length: tensor `(samples, 1)` containing the sequence length for
5613 each batch item in `y_pred`.
5614 label_length: tensor `(samples, 1)` containing the sequence length for
5615 each batch item in `y_true`.
5616
5617 Returns:
5618 Tensor with shape (samples,1) containing the
5619 CTC loss of each element.
5620 """
5621 label_length = math_ops.cast(
5622 array_ops.squeeze(label_length, axis=-1), dtypes_module.int32)
5623 input_length = math_ops.cast(
5624 array_ops.squeeze(input_length, axis=-1), dtypes_module.int32)
5625 sparse_labels = math_ops.cast(
5626 ctc_label_dense_to_sparse(y_true, label_length), dtypes_module.int32)
5627
5628 y_pred = math_ops.log(array_ops.transpose(y_pred, perm=[1, 0, 2]) + epsilon())
5629
5630 return array_ops.expand_dims(
5631 ctc.ctc_loss(
5632 inputs=y_pred, labels=sparse_labels, sequence_length=input_length), 1)
5633
5634
5635@keras_export('keras.backend.ctc_decode')

Callers

nothing calls this directly

Calls 6

epsilonFunction · 0.85
transposeMethod · 0.80
castMethod · 0.45
logMethod · 0.45
expand_dimsMethod · 0.45

Tested by

no test coverage detected