简体   繁体   English

Keras LSTM 层序贯_10的输入0与层不兼容

[英]Keras LSTM Input 0 of layer sequential_10 is incompatible with the layer

My code for the LSTM is as follows:我的 LSTM 代码如下:

def myLSTM(i_shape, o_shape):
    input = keras.layers.Input(i_shape)
    model = Sequential()
    x = keras.layers.LSTM(128, return_sequences = True, input_shape = (x_train.shape[1], 1))(input)
    x = keras.layers.Dropout(0.2)(x)
    x = keras.layers.LSTM(128, return_sequences = True)(x)
    x = keras.layers.Dropout(0.2)(x)
    x = keras.layers.LSTM(64, return_sequences = True)(x)
    x = keras.layers.Dropout(0.2)(x)
    output = layers.Dense(units = 1, activation='softmax')(x)
    return Model(input, output)

my_lstm = myLSTM(x_train.shape[1:], y_train.shape[1:])
my_lstm.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['acc'])
my_lstm.summary()

I am getting the following error:我收到以下错误:

ValueError: Input 0 of layer lstm is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: (None, 20)

This error confuses me because I feel like a 3-dimensional shape is passed into the LSTM but it shows that a 2-dimensional shape is detected.这个错误让我感到困惑,因为我觉得一个 3 维形状被传递到 LSTM 中,但它表明检测到一个 2 维形状。

The dimensions of my data are as follows: x_train shape is (207, 20), y_train shape is (207, 5), x_test shape is (24, 20), y_test shape is (24, 5),我的数据的维度如下:x_train 形状是(207, 20),y_train 形状是(207, 5),x_test 形状是(24, 20),y_test 形状是(24, 5),

I'm also running this LSTM for a classification use case, as you can see in my code.正如您在我的代码中看到的那样,我还在为分类用例运行此 LSTM。

As @Andrey mention that, LSTM expects to have a 3D shape data [batch_size, time_steps, feature_size]正如@Andrey 提到的那样,LSTM 期望有一个 3D 形状数据[batch_size, time_steps, feature_size]

Example,If we provide for each of the 32 batch samples, for each of the 10 time steps, a 8 dimensional vector: Input data shape should be something like,例如,如果我们为 32 个批次样本中的每一个提供 10 个时间步长中的每一个,一个 8 维向量: 输入数据形状应该类似于,

X_train = tf.random.normal([32, 10, 8])

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

相关问题 ValueError: 层序列 10 的输入 0 与层不兼容:预期 ndim=5,发现 ndim=4。 Alexnet(cnn) + LSTM - ValueError: Input 0 of layer sequential_10 is incompatible with the layer: expected ndim=5, found ndim=4. Alexnet(cnn) + LSTM DNN 中的错误:层序贯_10 的输入 0 与层不兼容 - Error in DNN: Input 0 of layer sequential_10 is incompatible with the layer LSTM:层序的输入0与层不兼容 - LSTM: Input 0 of layer sequential is incompatible with the layer Keras:层顺序的输入 0 与层不兼容 - Keras: Input 0 of layer sequential is incompatible with the layer 在 Keras 中实现 LSTM。 ValueError:层顺序与层不兼容 - Implementing LSTM in Keras. ValueError: layer sequential is incompatible with the layer Keras LSTM ValueError:层“顺序”的输入 0 与层不兼容:预期形状 =(无,478405,33),找到形状 =(1、33) - Keras LSTM ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 478405, 33), found shape=(1, 33) 层顺序输入与层不兼容:LSTM 中的形状错误 - Input of layer sequential is incompatible with the layer: shapes error in LSTM 层序的输入0与层不兼容 - Input 0 of layer sequential is incompatible with the layer 层顺序的输入 0 与层不兼容: - Input 0 of layer sequential is incompatible with the layer: LSTM Keras 层中的维度不兼容 - Incompatible dimensions in LSTM Keras layer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM