Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Keras LSTM输入与图层不兼容,预期ndim=3,发现ndim=4_Python_Keras_Lstm - Fatal编程技术网

Python Keras LSTM输入与图层不兼容,预期ndim=3,发现ndim=4

Python Keras LSTM输入与图层不兼容,预期ndim=3,发现ndim=4,python,keras,lstm,Python,Keras,Lstm,我正在尝试嵌入LSTM,并在Keras中实现以下功能: inp = Input(shape=(20, 1)) x = Embedding(total_words, 256)(inp) x = LSTM(128)(x) output = Dense(1, activation ='softmax')(x) 但是,我不明白为什么在x=LSTM(128)(x)行中不断出现以下错误: 我遗漏了什么?尝试shape=(20,),这是因为嵌入的输出是shape(无,20,1256),但LSTM层期望(无,

我正在尝试嵌入LSTM,并在Keras中实现以下功能:

inp = Input(shape=(20, 1))
x = Embedding(total_words, 256)(inp)
x = LSTM(128)(x)
output = Dense(1, activation ='softmax')(x)
但是,我不明白为什么在
x=LSTM(128)(x)
行中不断出现以下错误:


我遗漏了什么?

尝试
shape=(20,)
,这是因为
嵌入的输出是shape
(无,20,1256)
,但LSTM层期望
(无,时间步,特性)
(无,20,256)
,DanielMöller是对的,你需要改变你的输入。@juliodanieleyes@DanielMöller如果我听起来很傻,很抱歉,我对这方面还不太熟悉。我尝试将输入形状设置为
input(shape=(20,0))
,但这也不起作用。如果嵌入层正在输出
(None,20,1,256)
,我仍然不确定如何将LSTM层的
(None,20,256)
重塑为
inp=Input(shape=(20,)
就足够了,或者您可以在输入之后添加一个重塑层。您是否将x设置为编译中的第一层?
ValueError: Input 0 is incompatible with layer lstm_12: expected ndim=3, found ndim=4