【问题标题】:Unable to get hidden layer activation of ANN无法获得 ANN 的隐藏层激活
【发布时间】:2016-06-01 12:53:26
【问题描述】:

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

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

【问题讨论】:

  • 能否提供模型定义和信息,您使用的是哪个版本的 Keras?
  • 我的 Keras 版本是 1.0.3。我的模型中有 1 个输入 1 个隐藏层和 1 个输出层。当我编写这段代码时,我使用的是 python3。现在我已经使用 py2 将它加载到 pycharm 中,这可能是个问题吗?

标签: python theano keras


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2016-09-09
    • 1970-01-01
    • 1970-01-01
    • 2013-11-10
    • 1970-01-01
    • 2021-08-16
    • 1970-01-01
    • 2018-03-25
    • 2011-07-18
    相关资源
    最近更新 更多