1. 程式人生 > >keras獲取中間層輸出

keras獲取中間層輸出

https://keras-cn.readthedocs.io/en/latest/for_beginners/FAQ/#intermediate_layer

from keras import backend as K
get_3rd_layer_output = K.function([model.layers[0].input, K.learning_phase()],
                                  [model.layers[5].output])
X = x_test
# output in test mode = 0
layer_output = get_3rd_layer_output([X
, 0])[0] print(layer_output.shape) # output in train mode = 1 layer_output = get_3rd_layer_output([X, 1])[0]