我一直在研究一个使用时间序列数据与天气数据相结合来估计交通流量的项目。我的时间序列使用了 30 个值的窗口,并且使用了 20 个与天气相关的特征。我已经使用函数式 API 来实现此目的,但我不断收到相同的错误,并且我不知道如何解决它。我看过其他类似的线程,例如这个层 conv1d_1 的输入 0 与该层不兼容:预期 ndim=3,发现 ndim=2。收到完整形状:[无,200] https://stackoverflow.com/questions/57430717/input-0-of-layer-conv1d-1-is-incompatible-with-the-layer-expected-ndim-3-found,但这并没有帮助。
这是我的模型,
series_input = Input(shape = (series_input_train.shape[1], ), name = 'series_input')
x = Conv1D(filters=32, kernel_size=5, strides=1, padding="causal", activation="relu")(series_input)
x = LSTM(32, return_sequences = True)(x)
x = LSTM(32, return_sequences = True)(x)
x = Dense(1, activation = 'relu')(x)
series_output = Lambda(lambda w: w * 200)(x)
weather_input = Input(shape = (weather_input_train.shape[1], ), name = 'weather_input')
x = Dense(32, activation = 'relu')(weather_input)
x = Dense(32, activation = 'relu')(x)
weather_output = Dense(1, activation = 'relu')(x)
concatenate = concatenate([series_output, weather_output], axis=1, name = 'concatenate')
output = Dense(1, name = 'output')(concatenate)
model = Model([series_input, weather_input], output)
的形状series_input_train
and weather_input_train
分别为 (34970, 30) 和 (34970, 20)。
我不断收到的错误是这个,
ValueError: Input 0 of layer conv1d is incompatible with the layer: : expected min_ndim=3, found ndim=2. Full shape received: (None, 30)
我究竟做错了什么?
老实说,我一直很难弄清楚输入的形状在 TensorFlow 中是如何工作的。如果您能指出正确的方向,我将不胜感激,但我现在需要的是修复我的模型。