我已经在Keras中用以下图层对vgg16进行了微调:
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
vgg16 (Model) (None, 1, 1, 512) 14714688
_________________________________________________________________
flatten_1 (Flatten) (None, 512) 0
_________________________________________________________________
dense_1 (Dense) (None, 1024) 525312
_________________________________________________________________
dense_2 (Dense) (None, 512) 524800
_________________________________________________________________
dropout_1 (Dropout) (None, 512) 0
_________________________________________________________________
dense_3 (Dense) (None, 10) 5130
=================================================================
Total params: 15,769,930
Trainable params: 8,134,666
Non-trainable params: 7,635,264
但是我只能通过
flatten_1 , dense_1 ... , dense_3
从model.layers[1].output , model.layers[1].output , ... , model.layers[5].output
提取输入图像的特征。那么,如何提取vgg16中间层中的特征?
最佳答案
这是获取给定输入x_test
的中间层输出的常见模式:
import keras.backend as K
get_layer = K.function(
[model.layers[0].input, K.learning_phase()],
[model.layers[LAYER_DESIRED].output])
layer_output = get_layer([x_test, 0])[0]
其中
LAYER_DESIRED
是要输出的图层的索引。关于python - 访问keras的微调网络中的中间层的输出,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50241063/