无法获得ANN的隐藏层激活

Unable to get hidden layer activation of ANN

我正在使用 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,但也无法正常工作。

我应该怎么做才能从给定的层中获得激活值?

属性 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]