我在Keras中的ConvLSTM网络的输出是什么

时间:2019-05-26 00:09:51

标签: python keras conv-neural-network

我的输入是X_train.shape =(4291,1,278,29,1)的张量。我的输出是Y_train.shape =(4291,1,9)的张量。进行拟合(X_train,Y_train)时,显示给我

的错误
  

“ ValueError:检查目标时出错:预期density_1具有2维,但数组的形状为(4291,1,9)”

那我该如何处理输出的形状?

model = Sequential()
model.add(ConvLSTM2D(filters=8, kernel_size=5, strides=2,
                   input_shape=(1, 278, 29, 1),activation='relu',
                   padding='same',return_sequences=False))
model.add(Flatten())
model.add(Dense(9))
model.compile(loss="mse", optimizer="Adam", metrics=['mse'])
model.fit(X_train, Y_train,batch_size=batch_size, epochs=epochs, verbose=2, shuffle=False)

1 个答案:

答案 0 :(得分:0)

模型的输出的形状为(None, 9)。因此,目标数组(即Y_train)必须具有相同的形状,即(num_samples, 9)。尝试重塑它:

Y_train = Y_train.reshape(-1, 9)  # -1 indicates that the dimension of that axis should be automatically inferred.