我正在尝试用语音序列识别训练一个ctc丢失的blstm。我设法让代码运行但是训练在第二个时期的特定步骤失败,并出现以下错误:
W tensorflow/core/framework/op_kernel.cc:993] Invalid argument: slice index 0 of dimension 0 out of bounds.
[[Node: ctc/scan/strided_slice = StridedSlice[Index=DT_INT32, T=DT_INT32, begin_mask=0, ellipsis_mask=0, end_mask=0, new_axis_mask=0, shrink_axis_mask=1, _device="/job:localhost/replica:0/task:0/gpu:0"](ctc/scan/Shape, ctc/scan/strided_slice/stack, ctc/scan/strided_slice/stack_1, ctc/scan/strided_slice/stack_2)]]
Traceback (most recent call last):
File "speech_lstm_ctc.py", line 212, in <module>
callbacks=[earlystopping, checkpoint, data_gen])
File "/usr/local/lib/python2.7/dist-packages/keras/legacy/interfaces.py", line 88, in wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/training.py", line 1876, in fit_generator
class_weight=class_weight)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/training.py", line 1620, in train_on_batch
outputs = self.train_function(ins)
File "/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py", line 2073, in __call__
feed_dict=feed_dict)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 767, in run
run_metadata_ptr)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 965, in _run
feed_dict_string, options, run_metadata)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1015, in _do_run
target_list, options, run_metadata)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1035, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: slice index 0 of dimension 0 out of bounds.
[[Node: ctc/scan/strided_slice = StridedSlice[Index=DT_INT32, T=DT_INT32, begin_mask=0, ellipsis_mask=0, end_mask=0, new_axis_mask=0, shrink_axis_mask=1, _device="/job:localhost/replica:0/task:0/gpu:0"](ctc/scan/Shape, ctc/scan/strided_slice/stack, ctc/scan/strided_slice/stack_1, ctc/scan/strided_slice/stack_2)]]
[[Node: ctc/scan/while/Less_1/_77 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_981_ctc/scan/while/Less_1", tensor_type=DT_BOOL, _device="/job:localhost/replica:0/task:0/cpu:0"](^_cloopctc/scan/while/TensorArrayReadV3/_17)]]
Caused by op u'ctc/scan/strided_slice', defined at:
File "speech_lstm_ctc.py", line 189, in <module>
loss_out = Lambda(ctc_lambda_func, output_shape=(1,), name="ctc")([y_pred, labels, input_length, label_length])
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 554, in __call__
output = self.call(inputs, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/keras/layers/core.py", line 659, in call
return self.function(inputs, **arguments)
File "speech_lstm_ctc.py", line 141, in ctc_lambda_func
ctc_batch_loss = K.ctc_batch_cost(labels, y_pred, input_length, label_length)
File "/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py", line 3258, in ctc_batch_cost
sparse_labels = tf.to_int32(ctc_label_dense_to_sparse(y_true, label_length))
File "/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py", line 3222, in ctc_label_dense_to_sparse
initializer=init, parallel_iterations=1)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/functional_ops.py", line 524, in scan
n = array_ops.shape(elems_flat[0])[0]
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/array_ops.py", line 495, in _SliceHelper
name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/array_ops.py", line 653, in strided_slice
shrink_axis_mask=shrink_axis_mask)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 3688, in strided_slice
shrink_axis_mask=shrink_axis_mask, name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 763, in apply_op
op_def=op_def)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2327, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1226, in __init__
self._traceback = _extract_stack()
InvalidArgumentError (see above for traceback): slice index 0 of dimension 0 out of bounds.
[[Node: ctc/scan/strided_slice = StridedSlice[Index=DT_INT32, T=DT_INT32, begin_mask=0, ellipsis_mask=0, end_mask=0, new_axis_mask=0, shrink_axis_mask=1, _device="/job:localhost/replica:0/task:0/gpu:0"](ctc/scan/Shape, ctc/scan/strided_slice/stack, ctc/scan/strided_slice/stack_1, ctc/scan/strided_slice/stack_2)]]
[[Node: ctc/scan/while/Less_1/_77 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_981_ctc/scan/while/Less_1", tensor_type=DT_BOOL, _device="/job:localhost/replica:0/task:0/cpu:0"](^_cloopctc/scan/while/TensorArrayReadV3/_17)]]
实现ctc损失的功能如下:
def ctc_lambda_func(args):
y_pred, labels, input_length, label_length = args
# the 2 is critical here since the first couple outputs of the RNN
# tend to be garbage:
y_pred = y_pred[:, 2:, :]
ctc_batch_loss = K.ctc_batch_cost(labels, y_pred, input_length, label_length)
return ctc_batch_loss
我认为错误与特定输入无关,因为即使使用不同的输入,它也会出现在同一步骤中。
关于可能导致它的原因的任何想法?
答案 0 :(得分:0)
似乎导致问题的原因是批量生成器实际上在某个时刻给出了一个小批量的小批量,并导致张量流崩溃。通过使迷你批次始终大于1来纠正它。