且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从预训练的Keras模型中删除图层可提供与原始模型相同的输出

更新时间:2023-12-02 14:22:22

解决@Koul答案.

我相信您不需要使用pop方法.相反,只需将输出层之前的层作为Model方法的输出参数的参数传递即可:

I believe you don't need to use the pop method. Instead just pass the layer before the output layer as the argument for the Model method's output parameter:

from keras.models import Model

model2 = Model(model.input, model.layers[-2].output)
model2.summary()