连接层的 ValueError(Keras 函数 API)
ValueError with Concatenate Layer (Keras functional API)
在这里搜索了一番之后,我仍然找不到解决这个问题的方法。我是 Keras 的新手,如果有解决方案,我深表歉意,实际上我不明白它与我的问题有何关系。
我正在使用 Keras 2/Functional 制作一个小型 RNN API,但我无法让连接层正常工作。
这是我的结构:
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)
这里是错误:
ValueError: Unexpectedly found an instance of type `<class 'keras.layers.merge.Concatenate'>`. Expected a symbolic tensor instance.
完整的历史记录,如果有帮助的话:
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.
我在 Windows 7 上使用 Python 3.6 和 Spyder 3.1.4。我今天早上用 pip 升级了 TensorFlow 和 Keras。
感谢您提供的任何帮助!
尝试:
fusion = concatenate([sentenceMatrix, deletionMatrix])
Concatenate
用于 Sequential
模型,而 concatenate
用于 Functional API
.
尝试
fusion = Concatenate()([sentenceMatrix, deletionMatrix])
在这里搜索了一番之后,我仍然找不到解决这个问题的方法。我是 Keras 的新手,如果有解决方案,我深表歉意,实际上我不明白它与我的问题有何关系。
我正在使用 Keras 2/Functional 制作一个小型 RNN API,但我无法让连接层正常工作。
这是我的结构:
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)
这里是错误:
ValueError: Unexpectedly found an instance of type `<class 'keras.layers.merge.Concatenate'>`. Expected a symbolic tensor instance.
完整的历史记录,如果有帮助的话:
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.
我在 Windows 7 上使用 Python 3.6 和 Spyder 3.1.4。我今天早上用 pip 升级了 TensorFlow 和 Keras。
感谢您提供的任何帮助!
尝试:
fusion = concatenate([sentenceMatrix, deletionMatrix])
Concatenate
用于 Sequential
模型,而 concatenate
用于 Functional API
.
尝试
fusion = Concatenate()([sentenceMatrix, deletionMatrix])