【发布时间】:2018-01-11 12:53:50
【问题描述】:
想象一个全连接的神经网络,其最后两层的结构如下:
[Dense]
units = 612
activation = softplus
[Dense]
units = 1
activation = sigmoid
net 的输出值为 1,但我想知道 sigmoidal 函数的输入 x 是什么(必须是一些大数字,因为这里 sigm(x) 是 1)。
按照indraforyou's 的回答,我设法检索了 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 是错误的输出或权重吗?
【问题讨论】:
-
不应该是
x = np.dot(dense_0_out, dense_1_weights) + dense_1_bias吗? -
@MarcinMożejko 你是对的,我更正了。自从偏差被训练到 0.0 后没有改变任何东西。
-
但是该层的输出被馈送到softmax - 然后你获得的值被压缩到
[0, 1]间隔。 -
@MarcinMożejko 你是说最后一层吗?它被喂给 sigmoid,是的。因此,如果该值为 -11.7,则将其输入 sigmoid 并获得一些接近零的值。
layer_outs[-1]改为 1... -
啊——不应该是
x = np.dot(dense_1_weights, dense_0_out.transpose())吗?
标签: python neural-network keras keras-layer sigmoid