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

Function ctc_unique_labels

tensorflow/python/ops/ctc_ops.py:963–994  ·  view source on GitHub ↗

Get unique labels and indices for batched labels for `tf.nn.ctc_loss`. For use with `tf.nn.ctc_loss` optional argument `unique`: This op can be used to preprocess labels in input pipeline to for better speed/memory use computing the ctc loss on TPU. Example: ctc_unique_labels([[3, 4, 4

(labels, name=None)

Source from the content-addressed store, hash-verified

961
962@tf_export("nn.ctc_unique_labels")
963def ctc_unique_labels(labels, name=None):
964 """Get unique labels and indices for batched labels for `tf.nn.ctc_loss`.
965
966 For use with `tf.nn.ctc_loss` optional argument `unique`: This op can be
967 used to preprocess labels in input pipeline to for better speed/memory use
968 computing the ctc loss on TPU.
969
970 Example:
971 ctc_unique_labels([[3, 4, 4, 3]]) ->
972 unique labels padded with 0: [[3, 4, 0, 0]]
973 indices of original labels in unique: [0, 1, 1, 0]
974
975 Args:
976 labels: tensor of shape [batch_size, max_label_length] padded with 0.
977 name: A name for this `Op`. Defaults to "ctc_unique_labels".
978
979 Returns:
980 tuple of
981 - unique labels, tensor of shape `[batch_size, max_label_length]`
982 - indices into unique labels, shape `[batch_size, max_label_length]`
983 """
984
985 with ops.name_scope(name, "ctc_unique_labels", [labels]):
986 labels = ops.convert_to_tensor(labels, name="labels")
987
988 def _unique(x):
989 u = array_ops.unique(x)
990 y = array_ops.pad(u.y, [[0, _get_dim(u.idx, 0) - _get_dim(u.y, 0)]])
991 y = math_ops.cast(y, dtypes.int64)
992 return [y, u.idx]
993
994 return map_fn.map_fn(_unique, labels, dtype=[dtypes.int64, dtypes.int32])
995
996
997def _sum_states(idx, states):

Callers

nothing calls this directly

Calls 2

name_scopeMethod · 0.45
map_fnMethod · 0.45

Tested by

no test coverage detected