0

Use the Tensorflow's internal method "tf.nn.ctc_loss(labels, inputs,sequence_length, preprocess_collapse_repeated=False, ctc_merge_repeated=True)" to calculate the loss, however, i occur an error.

Caused by op 'CTCLoss', defined at:
  File "/home/liu/PythonCode/single_deepspeech/util/data_process.py", line 175, in <module>
    total_loss = tf.nn.ctc_loss(labels=result, inputs=logits, sequence_length=source_lengths)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/ctc_ops.py", line 145, in ctc_loss
    ctc_merge_repeated=ctc_merge_repeated)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/gen_ctc_ops.py", line 164, in _ctc_loss
    name=name)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py", line 768, in apply_op
    op_def=op_def)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 2336, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 1228, in __init__
    self._traceback = _extract_stack()

InvalidArgumentError (see above for traceback): Saw a non-null label (index >= num_classes - 1) following a null label, batch: 0 num_classes: 29 labels: 
     [[Node: CTCLoss = CTCLoss[ctc_merge_repeated=true, preprocess_collapse_repeated=false, _device="/job:localhost/replica:0/task:0/cpu:0"](Reshape_7, ToInt64, Gather, CTCLoss/sequence_length)]

The labels is a SparseTensor,

  1. indices.shape=[327,2]

  2. values.shape=[327]

  3. dense_shape.shape=[3,130]

The inputs is the RNN's output:logit

logit.shape = [447, 3, 29]

The sequence_length is the RNN's input sequence_len,

 sequence_length.shape=[408,432,494]

This question has been bothering me for many days, and it will be appreciated.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Zhen Liu
  • 1
  • 1

1 Answers1

0

In the CTC model there is a blank label with value "num_classes", if that value or a higher value is included in the label you will get this error. Check your labels, and remember that a white space between words is not your blank label, but just another class (normal label).

Lorenzo D'Arsiè
  • 125
  • 1
  • 10
  • I'm sorry,I don't quite understand what you mean. Can you make it clear – Zhen Liu Aug 10 '17 at 06:15
  • Sorry if I haven't been clear. Try to read the following links [StackOverflow](https://stackoverflow.com/questions/41737992/connectionist-temporal-classification-ctc-blank-label) and [Blog page](https://gab41.lab41.org/speech-recognition-you-down-with-ctc-8d3b558943f0). I hope these are going to be more clear than my explanation. – Lorenzo D'Arsiè Aug 10 '17 at 08:33