Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to build a neural network with Keras,but I got a error: AttributeError: 'NoneType' object has no attribute '_inbound_nodes',and this is my example code:

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
955 views
Welcome To Ask or Share your Answers For Others

1 Answer

This error occurs because keras.backend.tile is a function and not a layer, making tiled_emb a tensor. The error is then generated when trying to construct the network and encountering just a tensor where it expects a layer (so the attr _inbound_nodes is not defined).

You can turn any function into a layer by using the keras.layers.lambda layer, eg:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...