带有连接层的ValueError(Keras功能API) [英] ValueError with Concatenate Layer (Keras functional API)

查看:155
本文介绍了带有连接层的ValueError(Keras功能API)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里进行搜索后,我仍然找不到解决方案。我是Keras的新手,如果有解决方案,我深表歉意,但实际上我不明白它与我的问题有何关系。

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 2 / Functional API,我很难使连接层正常工作。

I am making a small RNN with Keras 2/Functional API, and I have trouble to make the Concatenate Layer work.

这是我的结构:

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.

如果有更多帮助,请提供完整历史记录:

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.


$ b $类型的< class'keras.layers.merge.Concatenate'>`。 b

我在Windows 7上使用带有Spyder 3.1.4的Python 3.6。我升级了Tens

I'm using Python 3.6, with Spyder 3.1.4, on Windows 7. I upgraded TensorFlow and Keras with pip this morning.

感谢您提供的任何帮助!

Thank you for any help provided !

推荐答案

尝试:

fusion = concatenate([sentenceMatrix, deletionMatrix])

级联用于顺序模型,而串联用于功能API

这篇关于带有连接层的ValueError(Keras功能API)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆