简体   繁体   English

使用来自 keras 模型的预测作为另一个 keras 模型内的层

[英]Using prediction from keras model as a layer inside another keras model

Suppose we have a model already trained for some task can we use that models prediction as a lambda layer inside another model?假设我们已经为某个任务训练了一个模型,我们可以使用该模型预测作为另一个模型中的 lambda 层吗? I am thinking something in the following format:我正在考虑以下格式的内容:

pretrained_model=get_Model()    #Loaded from a different file
pretrained_model.load_weights('pretrained_model_weights.h5')

base_model = VGG16(weights = 'imagenet',include_top=False,input_shape (240,320,3))

for layer in base_model.layers:
    layer.trainable = True

img_input=base_model.input
encoded=base_model.output

pretrained_model_output=Lambda(lambda x: pretrained_model.predict(img_input))

#Then run pretrained_model_output through an architecture that gives same output size as base_model.output and then 

concat = Concatenate([img_input,Output_Convolutions_pretrained_model_output],axis=-1)

#then feed this through another block in the model

Is something like this viable in Keras?像这样的东西在 Keras 中可行吗?

这比您想象的要容易得多,您只需要执行以下操作:

pretrained_model_output= pretrained_model(img_input)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM