Python Keras LSTM输入与图层不兼容,预期ndim=3,发现ndim=4
我正在尝试嵌入LSTM,并在Keras中实现以下功能: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层期望(无,
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