【问题标题】:Can not use convolution 1D . error : expected conv1d_1 to have 3 dimensions [duplicate]不能使用一维卷积。错误:预期 conv1d_1 有 3 个维度 [重复]
【发布时间】:2018-01-16 07:03:00
【问题描述】:

我像这样使用一维卷积。

X_train[:, None].shape
X_train_t = X_train[:, None]
X_test_t = X_test[:, None]

K.clear_session()
model = Sequential()
model.add(Conv1D(39, 1, activation='relu', input_shape=(1,12)))

model.compile(loss='mean_squared_error', optimizer='adam' )

model.summary()

model.fit(X_train_t, y_train, epochs=200, batch_size=1, verbose=1)

y_pred = model.predict(X_test)

显示这样的错误

ValueError: Error when checking target: expected conv1d_1 to have 3 dimensions, but got array with shape (39, 1)

我使用此代码打印形状 print(X_train.shape) 它显示。

(39, 12)

如果我将 input_shape 模型更改为 1,1 。

model.add(Conv1D(39, 1, activation='relu', input_shape=(1,1)))

显示错误。

ValueError: Error when checking input: expected conv1d_1_input to have shape (None, 1, 1) but got array with shape (39, 1, 12)

如何使用卷积一维?

【问题讨论】:

    标签: tensorflow deep-learning keras convolution


    【解决方案1】:

    在您的代码中添加model.add(Flatten())

    model = Sequential()
    model.add(Flatten())
    model.add(Conv1D(39, 1, activation='relu', input_shape=(1,12)))
    
    model.compile(loss='mean_squared_error', optimizer='adam' )
    
    model.summary()
    
    model.fit(X_train_t, y_train, epochs=200, batch_size=1, verbose=1)
    
    y_pred = model.predict(X_test)
    

    【讨论】:

      猜你喜欢
      • 2017-08-31
      • 1970-01-01
      • 2017-07-03
      • 2017-01-06
      • 1970-01-01
      • 2016-07-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多