我像这样使用Conv1D
X_train_t = X_train.reshape(X_train.shape[0], 1,12)
X_test_t = X_test.reshape(X_test.shape[0], 1,12)
print(X_train_t.shape)
print(X_train_t)
K.clear_session()
model = Sequential()
model.add(Conv1D(12,1, activation='relu', input_shape=(1,12)))
#model.add(MaxPooling1D(pool_size = (6)))
model.add(LSTM(3))
model.add(Dense(1))
我添加了maxpooling来提高性能,比如在model.add行下(Conv1D ..
model.add(MaxPooling1D(pool_size = (6)))
但它显示这样的错误
ValueError: Negative dimension size caused by subtracting 6 from 1 for 'max_pooling1d_1/MaxPool' (op: 'MaxPool') with input shapes: [?,1,1,12].
如果我设置pool_size =(1)但它会增加更多的损失值 . 如果我想将pool_size更改为另一个值而不是1.如何编辑模型?
1 回答
MaxPooling1D需要一个3d Tensor作为其输入形状:
(batch_size, steps, features)
. 根据您的代码,X_train_t
和X_test_t
有1步(*.shape[0], 1, 12
) . 当Pooling将其窗口移动6步(pool_size=(6)
)时,它不能 . 结果它抛出了这样的例外 .Suggestion :尝试更改输入形状
Minimal example :以下是
Conv1D
的一种可能解决方案: