我正在按照this教程尝试使用VGG16模型进行微调,我训练了模型并使用.h5
和
model.save_weights
文件
vgg_conv = VGG16(include_top=False,weights='imagenet',input_shape=(image_size,image_size,3))
# Freeze the layers except the last 4 layers
for layer in vgg_conv.layers[:-4]:
layer.trainable = False
model = Sequential()
model.add(vgg_conv)
model.add(flatten())
model.add(Dense(256,activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(11,activation='softmax'))
然后我尝试使用以下内容重建架构和负载权重
def create_model(self):
model = Sequential()
vgg_model = VGG16(include_top=False,input_shape=(150,150,3))
model.add(vgg_model)
model.add(flatten())
model.add(Dense(256,activation='softmax'))
model.load_weights(self.top_model_weights_path) # throws error
return model
但是它会引发此错误
ValueError: Cannot feed value of shape (512,512,3,3) for Tensor 'Placeholder:0',which has shape '(3,64)'
我在做什么错了?