[英]Delete last layer and insert three Conv2D layers in Keras
我在Keras中有一個用於分類的模型,該模型是在一些數據集上訓練的。 將該模型稱為“ classification_model”。 該模型保存在“ classification.h5”中。 用於檢測的模型相同,除了我們刪除最后一個卷積層,並添加三個大小為(3,3)
Conv2D
層。 因此,我們的檢測模型“ detection_model”應如下所示:
detection_model =分類模型[:last_conv_index] + Conv2d + Conv2d + Conv2d。
我們如何在Keras中實現它?
好吧,加載您的分類模型並使用Keras功能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 ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.