我需要帮助来找出这段代码中缺少的内容。
这是模型:
def make_model(input_shape):
input_layer = keras.layers.Input(input_shape)
convLSTM1 = keras.layers.ConvLSTM1D(filters=32, kernel_size=sfreq, strides=2, padding="valid")(input_layer)
convLSTM1 = keras.layers.BatchNormalization()(convLSTM1)
convLSTM1 = keras.layers.ReLU()(convLSTM1)
convLSTM2 = keras.layers.ConvLSTM1D(filters=64, kernel_size=sfreq, strides=2,padding="valid")(conv1)
convLSTM2 = keras.layers.BatchNormalization()(convLSTM2)
convLSTM2 = keras.layers.ReLU()(convLSTM2)
convLSTM3 = keras.layers.ConvLSTM1D(filters=128, kernel_size=sfreq, strides=2,padding="valid")(conv2)
convLSTM3 = keras.layers.BatchNormalization()(convLSTM3)
convLSTM3 = keras.layers.ReLU()(convLSTM3)
gap = keras.layers.GlobalAveragePooling1D()(convLSTM3)
output_layer = keras.layers.Dense(num_classes, activation="softmax")(gap)
return keras.models.Model(inputs=input_layer, outputs=output_layer)
model = make_model(input_shape=X_train.shape[1:])
model.summary()
出现此错误:
ValueError: Input 0 of layer "conv_lstm1d" is incompatible with the layer: expected ndim=4, found ndim=3. Full shape received: (None, 300, 17)
您的代码中有一个类型
convLSTM2 = keras.layers.ConvLSTM1D(filters=64, kernel_size=sfreq, strides=2,padding="valid")(conv1)
应该是
convLSTM2 = keras.layers.ConvLSTM1D(filters=64, kernel_size=sfreq, strides=2,padding="valid")(conv1LSTM1)
第 3 层代码中也有类似的拼写错误