Tensorflow 如何在Keras中使用tile函数?

Tensorflow 如何在Keras中使用tile函数?,tensorflow,keras,Tensorflow,Keras,我想用Keras建立一个神经网络,但我得到了一个错误: AttributeError:“非类型”对象没有属性“\u inbound\u nodes”,这是我的示例代码: from keras.layers.merge import concatenate img = Input(shape=(64,64,3)) text_input = Input(shape=(192,)) text_emb = Reshape(target_shape=(1, 1, 256))(Dense(256, act

我想用Keras建立一个神经网络,但我得到了一个错误:
AttributeError:“非类型”对象没有属性“\u inbound\u nodes”
,这是我的示例代码:

from keras.layers.merge import concatenate

img = Input(shape=(64,64,3))
text_input = Input(shape=(192,))
text_emb = Reshape(target_shape=(1, 1, 256))(Dense(256, activation='relu')(text_input))
tiled_emb = keras.backend.tile(text_emb, (-1, 64, 64, 1))
img_feat = Conv2D(400,4,padding='same')(img)
con = concatenate([tiled_emb,img_feat])
conv4 = Conv2D(512, 1)(con)

flat = Flatten()(conv4)
validity = Dense(1, activation='sigmoid')(flat)

Model([img, text_input], validity)

发生此错误是因为keras.backend.tile是一个函数而不是一个层,使平铺的_emb成为张量。然后,当尝试构建网络时,遇到需要层的张量(因此未定义attr_inbound_节点),就会生成错误

您可以使用图层将任何功能转换为图层,例如:

tiled_emb = Lambda(keras.backend.tile, arguments={'n':(-1, 64, 64, 1)})(text_emb)