我在Keras中有一个用于分类的模型,该模型是在一些数据集上训练的。将该模型称为“ classification_model”。该模型保存在“ classification.h5”中。除了删除最后一个卷积层,并添加三个大小为Conv2D(3,3)层外,检测模型是相同的。因此,我们的检测模型“ detection_model”应如下所示:

detection_model =分类模型[:last_conv_index] + Conv2d + Conv2d + Conv2d。

我们如何在Keras中实现它?

最佳答案

好了,加载您的分类模型并使用Keras functional API来构建新模型:

model = load_model("classification.h5")

last_conv_layer_output = model.layers[last_conv_index].output
conv = Conv2D(...)(last_conv_layer_output)
conv = Conv2D(...)(conv)
output = Conv2D(...)(conv)

new_model = Model(model.inputs, output)

# compile the new model and save it ...

关于python - 删除最后一层并在Keras中插入三个Conv2D层,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52441919/

10-12 21:37