且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在keras中,给定隐藏层的输入,权重和偏差,如何获得隐藏层的输出?

更新时间:2023-12-02 11:57:58

最简单的方法是使用keras后端。使用keras后端,您可以定义一个函数,为您提供此处定义的keras模型的中间输出( https://keras.io/getting-started/faq/#how-can-i-obtain-the-output-of-an-中间层)。

The easiest way is to use the keras backend. With the keras backend you can define a function that gives you the intermediate output of a keras model as defined here (https://keras.io/getting-started/faq/#how-can-i-obtain-the-output-of-an-intermediate-layer).

所以本质上:

get_1st_layer_output = K.function([model.layers[0].input],
                                  [model.layers[1].output])
layer_output = get_1st_layer_output([X])