Machine learning Keras:将多个LSTM层与

Machine learning Keras:将多个LSTM层与,machine-learning,neural-network,deep-learning,keras,lstm,Machine Learning,Neural Network,Deep Learning,Keras,Lstm,我有以下工作正常的网络: output = LSTM(8)(output) output = Dense(2)(output) 现在,对于同一个模型,我尝试堆叠一些LSTM层,如下所示: output = LSTM(8)(output, return_sequences=True) output = LSTM(8)(output) output = Dense(2)(output) 但我犯了以下错误: TypeError Tra

我有以下工作正常的网络:

output = LSTM(8)(output)
output = Dense(2)(output)
现在,对于同一个模型,我尝试堆叠一些LSTM层,如下所示:

output = LSTM(8)(output, return_sequences=True)
output = LSTM(8)(output)
output = Dense(2)(output)
但我犯了以下错误:

TypeError                                 Traceback (most recent call last)
<ipython-input-2-0d0ced2c7417> in <module>()
     39 
     40 output = Concatenate(axis=2)([leftOutput,rightOutput])
---> 41 output = LSTM(8)(output, return_sequences=True)
     42 output = LSTM(8)(output)
     43 output = Dense(2)(output)

/usr/local/lib/python3.4/dist-packages/keras/layers/recurrent.py in __call__(self, inputs, initial_state, constants, **kwargs)
    480 
    481         if initial_state is None and constants is None:
--> 482             return super(RNN, self).__call__(inputs, **kwargs)
    483 
    484         # If any of `initial_state` or `constants` are specified and are Keras

/usr/local/lib/python3.4/dist-packages/keras/engine/topology.py in __call__(self, inputs, **kwargs)
    601 
    602             # Actually call the layer, collecting output(s), mask(s), and shape(s).
--> 603             output = self.call(inputs, **kwargs)
    604             output_mask = self.compute_mask(inputs, previous_mask)
    605 

TypeError: call() got an unexpected keyword argument 'return_sequences'
TypeError回溯(最近一次调用)
在()
39
40输出=串联(轴=2)([leftOutput,rightOutput])
--->41输出=LSTM(8)(输出,返回顺序=真)
42输出=LSTM(8)(输出)
43输出=密集(2)(输出)
/usr/local/lib/python3.4/dist-packages/keras/layers/recurrential.py in_u____调用____(self、输入、初始状态、常量、**kwargs)
480
481如果初始_状态为无且常数为无:
-->482返回超级(RNN,自我)。\调用(输入,**kwargs)
483
484#如果指定了`初始状态'或`常数'中的任何一个且为Keras
/usr/local/lib/python3.4/dist-packages/keras/engine/topology.py in___调用(self,input,**kwargs)
601
602#实际调用层,收集输出、掩码和形状。
-->603输出=自调用(输入,**kwargs)
604输出屏蔽=自计算屏蔽(输入,前一个屏蔽)
605
TypeError:call()获得意外的关键字参数“return\u sequences”
这是令人困惑的,因为return_序列是基于Keras文档的有效参数:
https://keras.io/layers/recurrent/#lstm


我做错了什么?谢谢

问题在于
return\u sequences
应该作为参数传递给层构造函数,而不是层调用。将代码更改为:

output = LSTM(8, return_sequences=True)(output)

解决了问题。

尝试:
output=LSTM(8,return\u sequences=True)(output)
有效。非常感谢。那么我可以给出答案吗?