我拟合了来自顶层(VGG16)的模型,没有顶层(我创建顶层并按顺序添加)。我将VGG16图层设置为不可训练,并通过检查点保存使模型适合我。
vgg16_net.trainable = False
model = Sequential()
model.add(vgg16_net)
model.add(Flatten())
model.add(Dense(1024, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(5, activation=softmax, name='predictions'))
checkpointer = ModelCheckpoint(monitor='val_acc',filepath='Keras_VGG16_Best_Weights.hpf5', verbose=1, save_best_only=True)
接下来,当我适合这些顶层时,我想适合最后的转化层:
i = 1
for layers in VGG16_net.layers:
if i <= 15:
layers.trainable = False
else:
layers.trainable = True
i += 1
model = Sequential()
model.add(VGG16_net)
model.add(Flatten())
model.add(Dense(1024, activation = 'relu'))
model.add(Dropout(0.5))
model.add(Dense(5, activation = softmax, name = 'predictions'))
从旧模型中保存权重并将训练后的权重加载到新模型中
model.load_weights('only_weights_VGG116.h5')
但是我有错误
Cannot feed value of shape (64, 3, 3, 3) for Tensor 'Placeholder_20:0', which has shape '(3, 3, 512, 512)'
我知道,在VGG16中有错误连接到可训练的位置,但是我现在不解决此问题。如果我将VGG16设置为不可训练,则所有层都将成功加载。请帮帮我,我想在我的新模型中加载此权重以进行火车最后一次转化图层。如果这不可能,请写下。对不起,我的英语!)