在Keras中,在我自己的模型上使用include_top=False是否会删除所有最后的密集层,我是否可以定义;top";我的模特?
我可以定义我想要定义为“顶部”的层吗 据我所知,include_top=false将删除顶部的所有密度层。在Keras中,在我自己的模型上使用include_top=False是否会删除所有最后的密集层,我是否可以定义;top";我的模特?,keras,transfer-learning,Keras,Transfer Learning,我可以定义我想要定义为“顶部”的层吗 据我所知,include_top=false将删除顶部的所有密度层。 我想使用“include_top=False”来使用我自己的模型进行transfert学习,不想自动删除我最后的密集层。要访问最后的密集层,必须设置include_top=True。通过这种方式,可以创建包含所有所需中间层的子模型。下面是VGG16的一个示例 from tensorflow.keras.layers import * from tensorflow.keras.models
我想使用“include_top=False”来使用我自己的模型进行transfert学习,不想自动删除我最后的密集层。要访问最后的密集层,必须设置
include_top=True
。通过这种方式,可以创建包含所有所需中间层的子模型。下面是VGG16的一个示例
from tensorflow.keras.layers import *
from tensorflow.keras.models import *
from tensorflow.keras.applications import VGG16
vgg = VGG16(include_top = True, input_shape = (224,224,3))
new_layer = Dense(32)(vgg.layers[-3].output) # add new layer
sub_model = Model(vgg.input, new_layer)
在这种情况下,sub_模型的最后一层是:
block5_conv3 (Conv2D) (None, 14, 14, 512) 2359808
_________________________________________________________________
block5_pool (MaxPooling2D) (None, 7, 7, 512) 0
_________________________________________________________________
flatten (Flatten) (None, 25088) 0
_________________________________________________________________
fc1 (Dense) (None, 4096) 102764544
_________________________________________________________________
dense_6 (Dense) (None, 32) 131104