tensorflow - Keras 密集层输出为 'nan'

标签 tensorflow keras deep-learning

我正在使用 Keras 构建具有 CTC 损失的 RNN 模型。

我发现当使用activation=None 将张量传递给 Dense 层时,该层的输出都是nan

但是当设置 activation='softmax' 时,输出是normal 而不是 nan

问题代码(logits的元素都是nan):

logits = Dense(out_shape, activation = None, name="logits")(x_permute)#x_permute is a tensor with shape (?,1876,96)
loss_ctc = Lambda(ctc_lambda_func, name='ctc_my')(
    [logits, labels, x_len, lab_len])
model = Model(inputs=[x, labels, x_len, lab_len], outputs=[loss_ctc])
model.compile(loss={'ctc_my': lambda y_true,y_pred: y_pred}, optimizer='adadelta')

普通代码(logits的元素不是nan):

logits = Dense(out_shape, activation = None, name="logits")(x_permute)#x_permute is a tensor with shape (?,1876,96)
output = Activation(activation="softmax", name="softmax")(logits)
loss_ctc = Lambda(ctc_lambda_func, name='ctc_my')(
    [output, labels, x_len, lab_len])
model = Model(inputs=[x, labels, x_len, lab_len], outputs=[loss_ctc])
model.compile(loss={'ctc_my': lambda y_true,y_pred: y_pred}, optimizer='adadelta')

def ctc_lambda_func(args):

    y_pred, y_true, input_length, label_length = args

    return ctc_batch_cost(y_true, y_pred,input_length,label_length)

有人帮忙吗?非常感谢。

最佳答案

我可能会误解你,但你为什么要激活=“无”? 也许您想使用的是线性激活?

看看Keras Activation Functions

关于tensorflow - Keras 密集层输出为 'nan',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51607153/

相关文章:

machine-learning - 多层感知器 (MLP) 架构 : criteria for choosing number of hidden layers and size of the hidden layer?

python - TensorFlow 2.0 : Eager execution of training either returns bad results or doesn't learn at all

python - AdamOptimizer 的随机性如何?

python - Keras - [0-100] 范围内数字的目标函数

python - 为什么TensorFlow训练过程中变量值没有改变?

Tensorflow镜像策略和Horovod分布策略

python - 如何从数据帧在 keras flow 中提供一个热编码矢量数据帧

tensorflow - Keras 未导入 : TypeError: can only concatenate str (not "list") to str?

python - 神经网络攻击傻瓜盒(FGSM)

python - Keras 加载彩色图像