Python Can';t在keras中微调带有脱落层的预训练模型

Python Can';t在keras中微调带有脱落层的预训练模型,python,Python,我使用了没有顶层的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

我使用了没有顶层的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”共同定位

通过删除退出层,它可以正常工作,但会发生过拟合。
有人知道问题出在哪里吗

您使用的是什么Keras版本?您是否安装了TensorFlow和Keras?储罐以供回答。我使用了keras版本2.31和tensorflow版本2.0.0-alpha。请使用所有导入,如从tensorflow.keras.models导入,而不是从keras.models导入,替换所有位置,并告诉我问题是否仍然存在。我已经这样做了。它工作完美,没有脱落层。