【发布时间】:2021-03-18 12:25:11
【问题描述】:
我正在尝试使用 conv1d 来预测时间序列,但是 conv1d 输入形状有问题。 我的数据按时间顺序包含 10 个值的 406 个样本。 目标是使用样本 N 作为输入来预测样本 N+1。
这是我的代码示例:
print(data_x.shape)
# (406, 10)
print(data_y.shape)
# (406, 10)
inputs = Input(10, 1)
x = Conv1D(64, 2, input_shape=(10,1))(inputs)
x = Dense(64, "relu")(x)
x = Dense(64, "relu")(x)
x = Dense(10, "sigmoid")(x)
model = Model(inputs, x)
model.compile(loss='mse', metrics=['accuracy'], optimizer='adam')
history = model.fit(data_x, data_y,
batch_size=10, epochs=EPOCHS)
但我收到此错误ValueError: Input 0 of layer conv1d is incompatible with the layer: : expected min_ndim=3, found ndim=2. Full shape received: (1, 10) 。
我不知道我错过了什么,我什至尝试过data_x = data_x.reshape(-1,10,1),但结果相同。
【问题讨论】:
-
如果你使用带注释的代码,它不会做太多......在你的最后一行是答案。
-
这只是一个复制/过去的错误。我试过
data_x = data_x.reshape(-1,10,1)。并与:python data_x = data_x.reshape(-1,10,1) inputs = Input(10, 1,1) x = Conv1D(64, 2, input_shape=(10,1,1))(inputs) -
完全使用帖子中的代码,但在CNN之前添加
data_x = data_x.reshape(-1,10,1) -
正如我之前所说,我尝试使用我在原始帖子中输入的确切代码并添加
data_x = data_x.reshape(-1, 10, 1),结果data_x的形状为(406, 10, 1)。这会导致完全相同的错误:ValueError: Input 0 of layer conv1d is incompatible with the layer: : expected min_ndim=3, found ndim=2. Full shape received: (1, 10) -
对,我的错..
标签: python tensorflow machine-learning keras