尝试在 Keras 模型中运行光束搜索时,我会收到令人困惑(和冲突?)的错误消息。我的模型有输入,例如
inputs = Input(name='spectrograms',
shape=(None, hparams["n_spectrogram"]))
input_length = Input(name='len_spectrograms',
shape=[1], dtype='int64')
CTC 损失函数需要[1]
输入和标签长度的形状。据我了解,应该通过类似的方式获得输出
# Stick connectionist temporal classification on the end of the core model
paths = K.function(
[inputs, input_length],
K.ctc_decode(output, input_length, greedy=False, top_paths=4)[0])
但按原样,这会导致对形状的抱怨input_length
ValueError: Shape must be rank 1 but is rank 2 for 'CTCBeamSearchDecoder' (op: 'CTCBeamSearchDecoder') with input shapes: [?,?,44], [?,1].
但如果我砍掉那个维度
K.ctc_decode(output, input_length[..., 0], greedy=False, top_paths=4)[0])
模型定义运行,但是当我运行y = paths([x, numpy.array([[30], [30]])])
时x.shape == (2, 30, 513)
我突然得到
tensorflow.python.framework.errors_impl.InvalidArgumentError: sequence_length is not a vector
[[{{node CTCBeamSearchDecoder}} = CTCBeamSearchDecoder[beam_width=100, merge_repeated=true, top_paths=4, _device="/job:localhost/replica:0/task:0/device:CPU:0"](Log, ToInt32)]]
我究竟做错了什么?