【发布时间】:2020-11-07 07:29:54
【问题描述】:
我正在尝试使用序列到点 (seq2point) 架构在 keras 中拟合 CNN 1D 模型
我的数据是时间序列数据。
输入特征是一个传感器数据(每 6 秒 1 个值),输出也是一个连续数字。 这意味着我的问题是回归问题。
但我在运行模型时遇到错误
*ValueError: Error when checking input: expected conv1d_18_input to have 3 dimensions, but got array with shape (176526, 600)*
我知道我在弄乱尺寸但不知道在哪里。
非常感谢任何帮助。
Google Colab 中完整代码的链接 GoogleColab
创建模型
def create_model(n_timesteps, n_features,n_outputs):
'''Creates and returns the ShortSeq2Point Network
'''
model = Sequential()
# 1D Conv
model.add(Conv1D(filters=30, kernel_size=10, activation='relu', input_shape=(n_timesteps, n_features), padding="same", strides=1))
model.add(Dropout(0.5))
model.add(Conv1D(filters=30, kernel_size=8, activation='relu', padding="same", strides=1))
model.add(Dropout(0.5))
model.add(Conv1D(filters=40, kernel_size=6, activation='relu', padding="same", strides=1))
model.add(Dropout(0.5))
model.add(Conv1D(filters=50, kernel_size=5, activation='relu', padding="same", strides=1))
model.add(Dropout(0.5))
# Fully Connected Layers
model.add(Flatten())
model.add(Dense(1024, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(n_outputs, activation='linear'))
model.compile(loss='mse', optimizer='adam')
#plot_model(model, to_file='model.png', show_shapes=True)
return model
n_timesteps, n_features, n_outputs = x_train.shape[1], x_train.shape[2], y_train.shape[1]
# create model
model = create_model(num_time_periods, n_features,n_outputs)
model.summary()
型号
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv1d_18 (Conv1D) (None, 600, 30) 330
_________________________________________________________________
dropout_20 (Dropout) (None, 600, 30) 0
_________________________________________________________________
conv1d_19 (Conv1D) (None, 600, 30) 7230
_________________________________________________________________
dropout_21 (Dropout) (None, 600, 30) 0
_________________________________________________________________
conv1d_20 (Conv1D) (None, 600, 40) 7240
_________________________________________________________________
dropout_22 (Dropout) (None, 600, 40) 0
_________________________________________________________________
conv1d_21 (Conv1D) (None, 600, 50) 10050
_________________________________________________________________
dropout_23 (Dropout) (None, 600, 50) 0
_________________________________________________________________
flatten_5 (Flatten) (None, 30000) 0
_________________________________________________________________
dense_8 (Dense) (None, 1024) 30721024
_________________________________________________________________
dropout_24 (Dropout) (None, 1024) 0
_________________________________________________________________
dense_9 (Dense) (None, 600) 615000
=================================================================
Total params: 31,360,874
Trainable params: 31,360,874
数据集
Input_feature Output_Value
4 276
5 276
...
21 667
20 672
177126 rows × 2 columns
【问题讨论】:
-
你是
reshapingData两次,这就是错误的原因。请找到这篇文章 (machinelearningmastery.com/…),它有一个全面的End to End code用于Uni-Variate和Multi-Variate Time Series Analysis使用Conv-1D。谢谢!
标签: python tensorflow keras time-series conv-neural-network