Keras CTC损失输入

DNK*_*DNK 9 keras tensorflow

我试图用keras使用CTC语音识别和尝试了CTC例子在这里.在该示例中,CTC Lambda层的输入是softmax层(y_pred)的输出.该Lambda层调用ctc_batch_cost内部调用Tensorflow ctc_loss,但Tensorflow ctc_loss文档说该ctc_loss函数在内部执行softmax,因此您不需要首先softmax输入.我认为正确的用法是传递innerLambda图层,所以你只在ctc_loss内部函数中应用softmax .我试过这个例子,但它确实有效.我应该遵循示例还是Tensorflow文档?

Pro*_*ies 7

您发布的代码中使用的损失与您链接的代码不同.代码中使用的损失可在此处找到

keras代码在调用之前执行一些预处理ctc_loss,使其适合所需的格式.除了要求输入不是softmax-ed之外,tensorflow ctc_loss还要求dims是NUM_TIME, BATCHSIZE, FEATURES.Keras's 在这一行中ctc_batch_cost完成了这两件事.

它确实log()摆脱了softmax缩放,它也会使dim混乱,使其形状正确.当我说摆脱softmax缩放时,它显然不会恢复原始张量,而是softmax(log(softmax(x))) = softmax(x).见下文:

def softmax(x):
"""Compute softmax values for each sets of scores in x."""
e_x = np.exp(x - np.max(x))
return e_x / e_x.sum()


x = [1,2,3]
y = softmax(x)
z = np.log(y) # z =/= x (obviously) BUT
yp = softmax(z) # yp = y #####
Run Code Online (Sandbox Code Playgroud)