ValueError: Input 0 is incompatible with layer lstm_13: expected ndim=3, found ndim=4
ValueError: Input 0 is incompatible with layer lstm_13: expected ndim=3, found ndim=4
我正在尝试进行多class class化,这里是我的训练输入和输出的详细信息:
train_input.shape= (1, 95000, 360) (95000 length input array with each
element being an array of 360 length)
train_output.shape = (1, 95000, 22) (22 Classes are there)
model = Sequential()
model.add(LSTM(22, input_shape=(1, 95000,360)))
model.add(Dense(22, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
print(model.summary())
model.fit(train_input, train_output, epochs=2, batch_size=500)
错误是:
ValueError: Input 0 is incompatible with layer lstm_13: expected ndim=3, found ndim=4
in line:
model.add(LSTM(22, input_shape=(1, 95000,360)))
请帮帮我,我无法通过其他答案解决。
input_shape 应该是(时间步长,n_features)。删除第一个维度。
input_shape = (95000,360)
输出相同。
我通过
解决了这个问题
input size: (95000,360,1) and
output size: (95000,22)
并在定义模型的代码中将 输入形状更改为 (360,1):
model = Sequential()
model.add(LSTM(22, input_shape=(360,1)))
model.add(Dense(22, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
print(model.summary())
model.fit(ml2_train_input, ml2_train_output_enc, epochs=2, batch_size=500)
好吧,我认为主要问题在于 network.This 超参数中的 return_sequences
参数应该为 最后一层设置为 False
和 true
其他 前一层 .
综合以上答案,
return_sequences
不要所有层都设置True,最后一层不要设置即可,省略return_sequences=True
在人工神经网络 (ANN) 中,输入的形状为 (N,D),其中 N 是样本数,D 是特征数。
在RNN、GRU和LSTM中,输入的形状为(N,T,D),其中N为样本数,T为时间序列长度,D为特征数。
因此,在添加图层时
ANN 的输入(shape = (D,)) 和
RNN、GRU 和 LSTM 的输入(形状 = (T,D))
我正在尝试进行多class class化,这里是我的训练输入和输出的详细信息:
train_input.shape= (1, 95000, 360) (95000 length input array with each element being an array of 360 length)
train_output.shape = (1, 95000, 22) (22 Classes are there)
model = Sequential()
model.add(LSTM(22, input_shape=(1, 95000,360)))
model.add(Dense(22, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
print(model.summary())
model.fit(train_input, train_output, epochs=2, batch_size=500)
错误是:
ValueError: Input 0 is incompatible with layer lstm_13: expected ndim=3, found ndim=4 in line: model.add(LSTM(22, input_shape=(1, 95000,360)))
请帮帮我,我无法通过其他答案解决。
input_shape 应该是(时间步长,n_features)。删除第一个维度。
input_shape = (95000,360)
输出相同。
我通过
解决了这个问题input size: (95000,360,1) and output size: (95000,22)
并在定义模型的代码中将 输入形状更改为 (360,1):
model = Sequential()
model.add(LSTM(22, input_shape=(360,1)))
model.add(Dense(22, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
print(model.summary())
model.fit(ml2_train_input, ml2_train_output_enc, epochs=2, batch_size=500)
好吧,我认为主要问题在于 network.This 超参数中的 return_sequences
参数应该为 最后一层设置为 False
和 true
其他 前一层 .
综合以上答案,
return_sequences
不要所有层都设置True,最后一层不要设置即可,省略return_sequences=True
在人工神经网络 (ANN) 中,输入的形状为 (N,D),其中 N 是样本数,D 是特征数。
在RNN、GRU和LSTM中,输入的形状为(N,T,D),其中N为样本数,T为时间序列长度,D为特征数。
因此,在添加图层时
ANN 的输入(shape = (D,)) 和 RNN、GRU 和 LSTM 的输入(形状 = (T,D))