结合Keras功能模型 [英] Combine to Keras functional models

查看:74
本文介绍了结合Keras功能模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试模仿此关于微调图像分类器的keras博客.我想使用在fchollet仓库中找到的Inceptionv3 .

I am trying to mimic this keras blog about fine tuning image classifiers. I would like to use the Inceptionv3 found on a fchollet repo.

Inception是一个Model(功能性API),所以我不能只是为Sequential保留的model.add(top_model).

Inception is a Model (functional API), so I can't just do model.add(top_model) which is reserved for Sequential.

如何将两个功能性Model相加?假设我有

How can I add combine two functional Models? Let's say I have

inputs = Input(shape=input_shape)
x = Flatten()(inputs)
predictions = Dense(4, name='final1')(x)

model1 = Model(input=inputs, output=predictions)

第一个模型和

inputs_2 = Input(shape=(4,))
y = Dense(5)(l_inputs)
y = Dense(2, name='final2')(y)
predictions_2 = Dense(29)(y)
model2 = Model(input=inputs2, output=predictions2)

第二个.我现在想要一个从inputspredicions_2并链接predictionsinputs_2的端到端.

for the second. I now want an end-to-end that goes from inputs to predicions_2 and links predictions to inputs_2.

我尝试使用model1.get_layer('final1').output,但是我与类型不匹配,因此无法正常工作.

I tried using model1.get_layer('final1').output but I had a mismatch with types and I couldn't make it work.

推荐答案

我没有尝试过,但是根据文档功能模型,因此您可以执行以下操作:

I haven't tried this but according to the documentation functional models are callable, so you can do something like:

y = model2(model1(x))

其中x是输入的数据,而ypredictions_2

where x is the data that goes to inputs and y is the result of predictions_2

这篇关于结合Keras功能模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆