from keras import backend as K
get_3rd_layer_output = K.function(
[model.layers[0].input], # param 1 will be treated as layer[0].output
[model.layers[3].output]) # and this function will return output from 3rd layer
# here X is param 1 (input) and the function returns output from layers[3]
output = get_3rd_layer_output([X])[0]
Keras文档确实详细说明了如何做到这一点。如果您已经定义了模型
model_full
,那么您可以创建另一个模型,它只是模型的一部分-从输入层到您感兴趣的层然后,您应该能够使用以下方法从中间层获得输出:
为了做到这一点,您只需要定义一个
model_full
,我假设您已经定义了第二种方法
您还可以使用内置的Keras函数,我想您也已经在文档中看到了。一开始它可能看起来有点复杂,但它只是创建了一个具有绑定值的函数,即
显然,必须再次定义
model
。不确定除此之外是否还有其他要求相关问题 更多 >
编程相关推荐