我使用了没有顶层的vgg模型并加载了'vggface'权重。我已将此模型用作特征提取器,并且冻结了其权重。然后,我创建了以下模型:
conv_base2 = VGG16(weights='vggface',
include_top=False,
input_shape=(64, 64, 3))
last_layer = conv_base2.output
x = Flatten(name='flatten')(last_layer)
x = Dense(4096, activation='relu', name='fc6')(x)
x = Dropout(0.25)(x)
x = Dense(4096, activation='relu', name='fc7')(x)
x = Dropout(0.25)(x)
out = Dense(n_classes, activation='softmax', name='fc8')(x)
custom_vgg_model = Model(conv_base2.input, out)
custom_vgg_model.trainable = True
custom_vgg_model.get_layer('conv1_1').trainable = False
custom_vgg_model.get_layer('conv1_2').trainable = False
custom_vgg_model.get_layer('conv2_1').trainable = False
custom_vgg_model.get_layer('conv2_2').trainable = False
custom_vgg_model.get_layer('conv3_1').trainable = False
custom_vgg_model.get_layer('conv3_2').trainable = False
custom_vgg_model.get_layer('conv3_3').trainable = False
custom_vgg_model.get_layer('conv4_1').trainable = False
custom_vgg_model.get_layer('conv4_2').trainable = False
custom_vgg_model.get_layer('conv4_3').trainable = False
custom_vgg_model.get_layer('conv5_1').trainable = False
custom_vgg_model.get_layer('conv5_2').trainable = False
custom_vgg_model.get_layer('conv5_3').trainable = False
我已经训练了模式。之后,我尝试微调模型。
custom_vgg_model.get_layer('conv4_1').trainable = True
custom_vgg_model.get_layer('conv4_2').trainable = True
custom_vgg_model.get_layer('conv4_3').trainable = True
custom_vgg_model.get_layer('conv5_1').trainable = True
custom_vgg_model.get_layer('conv5_2').trainable = True
custom_vgg_model.get_layer('conv5_3').trainable = True
然后我再次训练了模型,并遇到以下错误:
节点'dropout / rate'期望与未知节点'dropout_2 / cond'并置
通过删除辍学层,它可以正常工作,但是会发生过拟合。 有谁知道是什么问题吗?