CTC 训练的调试bug记录

1.  InvalidArgumentError: Not enough time for target transition sequence (required: 21, available: 15)70You can turn this error into a warning by using the flag ignore_longer_outputs_than_inputs

原因:输入数据的标签长度大于数据序列的长度,即seq_len大于了time_step. 

解决办法:1)确保数据的前处理后label长度小于序列长度,通常发生在对数据做特征提取后长度变短小于label长度;

                  2)设置ignore_longer_outputs_than_inputs为True,此时遇到这类训练数据,CTCLoss会自动返回0梯度;

                        tf.nn.ctc_loss(targets, logits, seq_len,ignore_longer_outputs_than_inputs=True)

 The `ignore_longer_outputs_than_inputs` option allows to specify the behavior
  of the CTCLoss when dealing with sequences that have longer outputs than
  inputs. If true, the CTCLoss will simply return zero gradient for those
  items, otherwise an InvalidArgument error is returned, stopping training.

2. InvalidArgumentError: sequence_length(1) <= 132

原因:ctcloss计算要求所有sequence_length要小于max_time_step,通常max_time_step等于CTCLoss的输入序列数据的最大长度,即下面input_shape.dim_size(0),报错的是因为存在sequence_length大于了max_time_step。

解决办法:检查CTCLoss的输入数据和sequence_length是否对应,通常由于数据先进入了CNN导致输入到CTC的数据维度发生了变化,而sequence_length还对应CNN前的数据序列长度,故按照CNN结构缩放你的原始sequence_length即可。

inputs: 3-D `float` `Tensor`.
      If time_major == False, this will be a `Tensor` shaped:
        `[batch_size, max_time, num_classes]`.
      If time_major == True (default), this will be a `Tensor` shaped:
        `[max_time, batch_size, num_classes]`.
      The logits.

# From ctc_loss_op.cc
    for (int64 b = 0; b < batch_size; ++b) {
      OP_REQUIRES(
          ctx, seq_len_t(b) <= max_time,
          errors::InvalidArgument("sequence_length(", b, ") <= ", max_time));
    }

猜你喜欢

转载自blog.csdn.net/xcls2010/article/details/84472063
CTC