ValueError with Concatenate Layer (Keras Functional API)

After searching for a bit here, I still can't seem to find a solution for this. I am new to Keras, sorry if there is a solution and I didn't really understand how this relates to my problem.

I am creating a small RNN with Keras 2 / Functional API and I am having trouble getting it working in Concatenate Layer mode.

Here is my structure:

inputSentence = Input(shape=(30, 91))
sentenceMatrix = LSTM(91, return_sequences=True, input_shape=(30, 91))(inputSentence)

inputDeletion = Input(shape=(30, 1))
deletionMatrix = (LSTM(30, return_sequences=True, input_shape=(30, 1)))(inputDeletion)

fusion = Concatenate([sentenceMatrix, deletionMatrix])
fusion = Dense(122, activation='relu')(fusion)
fusion = Dense(102, activation='relu')(fusion)
fusion = Dense(91, activation='sigmoid')(fusion)

F = Model(inputs=[inputSentence, inputDeletion], outputs=fusion)

      

And here's the error:

ValueError: Unexpectedly found an instance of type `<class 'keras.layers.merge.Concatenate'>`. Expected a symbolic tensor instance.

      

Full story if it helps a little more:

Using TensorFlow backend.
    str(inputs) + '. All inputs to the layer '
ValueError: Layer dense_1 was called with an input that isn't a symbolic tensor. Received type: <class 'keras.layers.merge.Concatenate'>. Full input: [<keras.layers.merge.Concatenate object at 0x00000000340DC4E0>]. All inputs to the layer should be tensors.
self.assert_input_compatibility(inputs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py", line 425, in assert_input_compatibility
fusion = Dense(122, activation='relu')(fusion)
  File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py", line 552, in __call__
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py", line 419, in assert_input_compatibility
K.is_keras_tensor(x)
  File "C:\ProgramData\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py", line 392, in is_keras_tensor
raise ValueError('Unexpectedly found an instance of type `' + str(type(x)) + '`. '
ValueError: Unexpectedly found an instance of type `<class 'keras.layers.merge.Concatenate'>`. Expected a symbolic tensor instance.

      

I am using Python 3.6 with Spyder 3.1.4 on Windows 7. I updated TensorFlow and Keras with spike this morning.

Thanks for the help provided!

+6


source to share


2 answers


Try:

fusion = concatenate([sentenceMatrix, deletionMatrix])

      



Concatenate

used in the model Sequential

, while Concatenate

used in Functional API

.

+21


source


Try



fusion = Concatenate()([sentenceMatrix, deletionMatrix])

      

0


source







All Articles