如何使用Tensorflow张量设置功能模型的Keras层的输入?

问题描述 投票:2回答:1

我有两个我想要使用的软件包,一个用Keras1.2编写,另一个用tensorflow编写。我想使用在张量流中构建到Keras模型中的体系结构的一部分。

建议使用部分解决方案here,但这是一个顺序模型。关于功能模型的建议 - 将预处理包装在Lambda层中 - 不起作用。

以下代码有效:

inp = Input(shape=input_shape)
def ID(x):
    return x
lam = Lambda(ID)  
flatten = Flatten(name='flatten')
output = flatten(lam(inp))
Model(input=[inp], output=output)

但是,当用预处理输出张量flatten(lam(inp))替换flatten(lam(TF_processed_layer))时,我得到:“模型的输出张量必须是Keras张量。发现:Tensor(”Reshape:0“,shape =(?,?),dtype = float32) “

tensorflow keras keras-layer
1个回答
0
投票

您可以尝试将输入张量包装到Keras输入层,然后从那里继续构建模型。像这样:

inp = Input(tensor=tftensor,shape=input_shape)
def ID(x):
    return x
lam = Lambda(ID)  
flatten = Flatten(name='flatten')
output = flatten(lam(inp))
Model(input=inp, output=output)
© www.soinside.com 2019 - 2024. All rights reserved.