1

I cannot understand what is wrong. I need to have two sets of inputs so i divided them to give each one a name (serving purposes) and then concatenated them to link them to the next layer.

layer_input1  = tf.keras.Input(shape=(None, 1), name='layer1')
layer_input2  = tf.keras.Input(shape=(None, 1), name='layer2')

layer_input = tf.keras.layers.concatenate([layer_input1, layer_input2], name='inputs')
fc_1 = tf.keras.layers.Dense(2,
                             activation='relu')(layer_input)
fc_1 = tf.keras.layers.Dropout(0.5)(fc_1)
fc_2 = tf.keras.layers.Dense(10,
                             activation='relu')(fc_1)
output_layer = tf.keras.layers.Dense(1,
                             activation='relu', name='predictions')(fc_2)
model = tf.keras.Model(inputs=layer_input, outputs=output_layer)

AttributeError                            Traceback (most recent call last)
<ipython-input-430-b567199137e0> in <module>()
     10 output_layer = tf.keras.layers.Dense(1,
     11                              activation='relu', name='predictions')(fc_2)
---> 12 model = tf.keras.Model(inputs=layer_input, outputs=output_layer)

AttributeError: 'Model' object has no attribute '_name'

1 Answer 1

1

Just set your input layers as model inputs.

model = tf.keras.Model(inputs=[layer_input1, layer_input2], outputs=output_layer)

Note that concatenate is an operation, not Layer object. But even if you wrap it as Layer with Lambda it won't possess some attributes of keras.layers.Input

Sign up to request clarification or add additional context in comments.

3 Comments

Perfect, it worked thank you! so the concatenation of the layers is not equivalent to [layer_input1, layer_input2] apparently
concat op will be executed, it just can't be input node
@NoelSaade, if this answer was helpful, please consider accepting it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.