想象一个全连接的神经网络,其最后两层结构如下:
[Dense]
units = 612
activation = softplus
[Dense]
units = 1
activation = sigmoid
网络的输出值为 1,但我想知道 sigmoidal 函数的输入 x 是什么(必须是一些高数字,因为 sigm(x) 在这里是 1)。
按照 indraforyou的回答,我设法检索了 Keras 层的输出和权重:
outputs = [layer.output for layer in model.layers[-2:]]
functors = [K.function( [model.input]+[K.learning_phase()], [out] ) for out in outputs]
test_input = np.array(...)
layer_outs = [func([test_input, 0.]) for func in functors]
print layer_outs[-1][0] # -> array([[ 1.]])
dense_0_out = layer_outs[-2][0] # shape (612, 1)
dense_1_weights = model.layers[-1].weights[0].get_value() # shape (1, 612)
dense_1_bias = model.layers[-1].weights[1].get_value()
x = np.dot(dense_0_out, dense_1_weights) + dense_1_bias
print x # -> -11.7
x怎么可能是负数?在这种情况下,最后一层输出应该是一个比 1.0 更接近 0.0 的数字。是dense_0_out
或dense_1_weights
错误的输出或权重?