是的,使用 Keras Functional API很容易做到这一点。
from keras.layers import Input
from keras.models import Model
densenet = DenseNet(....., include_top=False)
inp = Input(shape=(some_input_shape))
ds_features = densenet(inp)
out = Dense(10, activation="softmax")(ds_features)
model = Model(inp, out)
在这段代码中,你以某种方式实例化了一个 DenseNet,然后通过它(densenet(inp)
部分)传递了一个 keras 张量,你得到了一个可以提供给其他层的输出张量。然后构建一个指定输入和输出的模型。您可以使用不同的层多次执行此操作,构建不同的模型,并且将使用相同的 DenseNet 权重。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句