[英]ValueError with Concatenate Layer (Keras functional API)
After some search here, I still can't find a solution for this. 经过一些搜索,我仍然无法找到解决方案。 I'm new to Keras, apologies if there is a solution and I actually didn't understand how it was related to my problem.
我是Keras的新手,如果有解决方案我会道歉并且我实际上不明白它与我的问题有什么关系。
I am making a small RNN with Keras 2/Functional API, and I have trouble to make the Concatenate Layer work. 我正在使用Keras 2 / Functional API制作一个小型RNN,我无法使Concatenate Layer工作。
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 is the error: 这是错误:
ValueError: Unexpectedly found an instance of type `<class 'keras.layers.merge.Concatenate'>`. Expected a symbolic tensor instance.
Full History if it helps a bit 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'm using Python 3.6, with Spyder 3.1.4, on Windows 7. I upgraded TensorFlow and Keras with pip this morning. 我在Windows 7上使用Python 3.6和Spyder 3.1.4。我今天早上用pip升级了TensorFlow和Keras。
Thank you for any help provided ! 感谢您提供的任何帮助!
Try: 尝试:
fusion = concatenate([sentenceMatrix, deletionMatrix])
Concatenate
is used in a Sequential
model, whereas concatenate
is used in a Functional API
. Concatenate
用于Sequential
模型,而concatenate
用于Functional API
。
尝试
fusion = Concatenate()([sentenceMatrix, deletionMatrix])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.