且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Keras使用Lambda图层错误和K.ctc_decode

更新时间:2023-12-02 16:40:28

一个棘手的部分是K.ctc_decode返回单个张量列表的元组,而不是单个张量,因此您不能直接创建层.而是尝试使用K.function:

One tricky part is that K.ctc_decode returns tuple of single list of tensors, not a single tensor, so you can't create a layer straightforwardly. Instead try creating a decoder with K.function:

top_k_decoded, _ = K.ctc_decode(y_pred, input_lengths)
decoder = K.function([input_data, input_lengths], [top_k_decoded[0]])

稍后您可以致电您的解码器:

Later you can call your decoder:

decoded_sequences = decoder([test_input_data, test_input_lengths])

您可能需要重新整形,因为K.ctc_decoder要求长度的形状像(样本),而长度张量是形状(样本1).

You may need some reshaping, as K.ctc_decoder requires lengths to have shape like (samples), while the lengths tensor was of shape (samples, 1).