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

Function _ctc_loss_impl

tensorflow/python/ops/ctc_ops.py:164–204  ·  view source on GitHub ↗
(labels,
                   inputs=None,
                   sequence_length=None,
                   preprocess_collapse_repeated=False,
                   ctc_merge_repeated=True,
                   ignore_longer_outputs_than_inputs=False,
                   time_major=True,
                   logits=None,
                   use_cudnn=False)

Source from the content-addressed store, hash-verified

162 use_cudnn=False)
163
164def _ctc_loss_impl(labels,
165 inputs=None,
166 sequence_length=None,
167 preprocess_collapse_repeated=False,
168 ctc_merge_repeated=True,
169 ignore_longer_outputs_than_inputs=False,
170 time_major=True,
171 logits=None,
172 use_cudnn=False):
173 # Helper function of ctc_loss with one additional param:
174 # use_cudnn: A bool to enable cuDNN CTC loss operation. If true, the blank
175 # index has to be 0.
176
177 # The second, third, etc output tensors contain the gradients. We use it in
178 # _CTCLossGrad() below.
179 if not isinstance(labels, sparse_tensor.SparseTensor):
180 raise TypeError("Expected labels (first argument) to be a SparseTensor")
181
182 # For internal calculations, we transpose to [time, batch, num_classes]
183 inputs = deprecation.deprecated_argument_lookup("logits", logits, "inputs",
184 inputs)
185 if not time_major:
186 inputs = array_ops.transpose(inputs, [1, 0, 2]) # (B,T,N) => (T,B,N)
187
188 # gen_ctc_ops.ctc_loss_v2 differs from gen_ctc_ops.ctc_loss. v2 assumes the
189 # blank index to be 0, but v1 views it as the last index.
190 if use_cudnn:
191 ctc_loss_func = gen_ctc_ops.ctc_loss_v2
192 else:
193 ctc_loss_func = gen_ctc_ops.ctc_loss
194
195 loss, _ = ctc_loss_func(
196 inputs,
197 labels.indices,
198 labels.values,
199 sequence_length,
200 preprocess_collapse_repeated=preprocess_collapse_repeated,
201 ctc_merge_repeated=ctc_merge_repeated,
202 ignore_longer_outputs_than_inputs=ignore_longer_outputs_than_inputs)
203
204 return loss
205
206# pylint: disable=unused-argument
207def _CTCLossGradImpl(op, grad_loss, _):

Callers 2

ctc_lossFunction · 0.85
ctc_loss_v2Function · 0.85

Calls 1

transposeMethod · 0.80

Tested by

no test coverage detected