我发现怎么做只需要找到分割复制第一层的点并将其输入引导到另一个模型,然后将所有层连接在一起
efficientnet = efn.EfficientNetB0()
retrained_model = load_model(model_path, custom_objects=get_custom_objects())
top_conv = efficientnet.get_layer('top_conv')
top_conv._name = top_conv._name + str("ef0")
top_bn = efficientnet.get_layer("top_bn")
top_bn._name = top_bn._name + str("ef0")
top_activation = efficientnet.get_layer('top_activation')
top_activation._name = top_activation._name + str("ef0")
avg_pool = efficientnet.get_layer('avg_pool')
avg_pool._name = avg_pool._name + str("ef0")
top_dropout = efficientnet.get_layer('top_dropout')
top_dropout._name = top_dropout._name + str("ef0")
probs = efficientnet.get_layer('probs')
probs(top_dropout(
avg_pool(top_activation(top_bn(top_conv(retrained_model.get_layer('block7a_project_bn').output))))))
model = Model(inputs=retrained_model.input,
outputs=[retrained_model.output, probs.get_output_at(0)])
model.summary()
model.save("/home/naor/projects/efficientnetretrainedmodel/bin/model-2-pred.h5")
新模型创建为模型 A 输入和输出 [A.output ,B.output]