简体   繁体   English

ValueError:检查输入时出错:预期 lstm_6_input 具有形状 (87482, 1) 但得到的数组具有形状 (87482, 3)

[英]ValueError: Error when checking input: expected lstm_6_input to have shape (87482, 1) but got array with shape (87482, 3)

X_train data dimension is 87482, 3. X_train 数据维度为 87482, 3。

But I got an error on running with the below code.但是使用以下代码运行时出现错误。 The error is:错误是:

ValueError: Error when checking input: expected lstm_6_input to have shape (87482, 1) but got array with shape (87482, 3) ValueError:检查输入时出错:预期 lstm_6_input 具有形状 (87482, 1) 但得到的数组具有形状 (87482, 3)

My code is:我的代码是:

model = Sequential()
#model.add(Embedding(top_words, embedding_vecor_length, input_length=max_review_length))
model.add(LSTM(units=3, input_shape=(X_train_rnn.shape[1],1),return_sequences=True))
model.add(LSTM(3, return_sequences=True))  # returns a sequence of vectors of dimension 32
model.add(LSTM(3))

model.compile(loss='mean_squared_error', optimizer='adam', metrics=['accuracy'])
print(model.summary())
model.fit(X_train_rnn, y_train, epochs=2, batch_size=32)
# Final evaluation of the model
scores = model.evaluate(X_test_rnn, y_test, verbose=0)

input_shape=(X_train.shape[1], 1) should fix the error, but maybe not the entire problem: how long is each sequence ? input_shape=(X_train.shape[1], 1)应该修复错误,但可能不是整个问题:每个序列有多长

  • LSTM full input shape ( batch_shape ) is (batch_size, timesteps, channels) - or, equivalently, (samples, timesteps, features) LSTM 完整输入形状 ( batch_shape ) 是(batch_size, timesteps, channels) - 或者,等效地, (samples, timesteps, features)
  • batch_size=32 in your .fit() , but if X_train dimension is (87472, 3) , do you have 87472 samples (sequences) each of length 3 ( timesteps=3 )? batch_size=32在您的.fit()中,但如果X_train维度为(87472, 3) ,您是否有87472样本(序列),每个长度为 3 ( timesteps=3 )? If so, you'll need input_shape=(3, 1) (univariate data), which is what you get with (X_train.shape[1], 1)如果是这样,您将需要input_shape=(3, 1) (单变量数据),这就是您得到的(X_train.shape[1], 1)
  • If instead your timesteps=87462 , you'll need input_shape=(87462, 3) - but this is a pretty bad idea, as LSTMs struggle for timesteps > 0相反,如果您的timesteps=87462 ,您将需要input_shape=(87462, 3) -但这是一个非常糟糕的主意,因为 LSTM 为timesteps > 0而奋斗

I don't know what shapes X_train_rnn has, so I wrote the answer in terms of X_train .我不知道X_train_rnn有什么形状,所以我用X_train写了答案。 Feel free to clarify.随时澄清。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ValueError:检查输入时出错:预期 lstm_11_input 具有形状 (1, 1) 但得到形状为 (1, 3841) 的数组 - ValueError: Error when checking input: expected lstm_11_input to have shape (1, 1) but got array with shape (1, 3841) ValueError:检查输入时出错:预期 lstm_12_input 具有形状 (5793993, 7) 但得到形状为 (7, 1) 的数组 - ValueError: Error when checking input: expected lstm_12_input to have shape (5793993, 7) but got array with shape (7, 1) ValueError:检查输入时出错:预期lstm_1_input具有3个维,但数组的形状为(393613,50) - ValueError: Error when checking input: expected lstm_1_input to have 3 dimensions, but got array with shape (393613, 50) !! ValueError:检查输入时出错:预期lstm_2_input具有3个维,但数组的形状为(4982,12) - !! ValueError: Error when checking input: expected lstm_2_input to have 3 dimensions, but got array with shape (4982, 12) ValueError:检查输入时出错:预期lstm_1_input具有3个维,但数组的形状为(10,1) - ValueError: Error when checking input: expected lstm_1_input to have 3 dimensions, but got array with shape (10, 1) ValueError:检查输入时出错:预期lstm_1_input具有形状(973,215),但数组的形状为(61,215) - ValueError: Error when checking input: expected lstm_1_input to have shape (973, 215) but got array with shape (61, 215) ValueError:检查输入时出错:预期 input_1 具有形状 (50,),但使用 ELMo 嵌入和 LSTM 获得形状为 (1,) 的数组 - ValueError: Error when checking input: expected input_1 to have shape (50,) but got array with shape (1,) with ELMo embeddings and LSTM Keras LSTM输入-ValueError:检查输入时出错:预期input_1具有3维,但数组的形状为(1745,1) - Keras LSTM Input - ValueError: Error when checking input: expected input_1 to have 3 dimensions, but got array with shape (1745, 1) ValueError:检查输入时出错:预期density_1_input的形状为(24,),但数组的形状为(1,) - ValueError: Error when checking input: expected dense_1_input to have shape (24,) but got array with shape (1,) ValueError:检查输入时出错:预期dense_input具有形状(46,)但得到形状为(1,)的数组 - ValueError: Error when checking input: expected dense_input to have shape (46,) but got array with shape (1,)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM