无法获得ANN的隐藏层激活

时间:2016-06-01 12:53:26

标签: python theano keras

我正在使用python2,而我正试图获取隐藏图层的激活。我使用以下代码给出了一个错误:

get_activations = theano.function([my_model.layers[0].input], my_model.layers[0].get_output(train=False),
                              allow_input_downcast=True)

当我运行代码时,它说:

AttributeError: 'Dense' object has no attribute 'get_output'

我尝试使用my_model.layers[0].output也无效。

如何从给定的图层中获取激活?

1 个答案:

答案 0 :(得分:2)

属性get_output仅针对旧版本的keras(0.3)定义。版本1.0中不再存在。

see new syntax (keras doc FAQ)

类似

get_activations = K.function([model.layers[0].input], [model.layers[1].output])

应该有效,因为隐藏图层是模型中的第二层(即model.layers[1]