简体   繁体   English

层 conv1d 的输入 0 与层不兼容::预期 min_ndim=3,发现 ndim=2。 收到的完整形状:(无,30)

[英]Input 0 of layer conv1d is incompatible with the layer: : expected min_ndim=3, found ndim=2. Full shape received: (None, 30)

I have been working on a project for estimating the traffic flow using time series data combine with weather data.我一直在做一个项目,使用时间序列数据和天气数据来估计交通流量。 I am using a window of 30 values for my time series and I am using 20 weather related features.我正在为我的时间序列使用 30 个值的 window,并且我正在使用 20 个与天气相关的功能。 I have used the functional API to implement this, but I keep getting the same error and I do not know how it can be solved.我已经使用功能 API 来实现这个,但我一直收到同样的错误,我不知道如何解决。 I have looked at other similar threads such as this one Input 0 of layer conv1d_1 is incompatible with the layer: expected ndim=3, found ndim=2.我查看了其他类似的线程,例如conv1d_1 层的输入 0 与该层不兼容:预期 ndim=3,发现 ndim=2。 Full shape received: [None, 200] , but it has not helped. 收到的完整形状:[None, 200] ,但没有帮助。

This is my model,这是我的 model,

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)

The shapes of series_input_train and weather_input_train are (34970, 30) and (34970, 20) respetively. series_input_trainweather_input_train的形状分别为 (34970, 30) 和 (34970, 20)。

The error I keep getting is this one,我不断得到的错误是这个,

ValueError: Input 0 of layer conv1d is incompatible with the layer: : expected min_ndim=3, found ndim=2. Full shape received: (None, 30)

What am I doing wrong?我究竟做错了什么?

Honestly, I have always had trouble figuring out how the shape of the inputs work in TensorFlow.老实说,我一直很难弄清楚 TensorFlow 中输入的形状是如何工作的。 If you could point me in the right direction, it would be appreciated but what I need right now is a fix for my model.如果您能指出正确的方向,我们将不胜感激,但我现在需要的是修复我的 model。

Problem问题

3+D tensor with shape: batch_shape + (steps, input_dim) https://keras.io/api/layers/convolution_layers/convolution1d/具有形状的 3+D 张量:batch_shape + (steps, input_dim) https://keras.io/api/layers/convolution_layers/convolution1d/

Solution解决方案

You don't specify "steps" parameters.您没有指定“步骤”参数。
If "steps" is 1, Use the following code:如果“步骤”为 1,请使用以下代码:

import numpy as np
series_input_train = np.expand_dims(series_input_train, axis=1)
weather_input_train = np.expand_dims(weather_input_train, axis=1)    

As Tao-Lung says, the first connection for a convolutional layer expects a 3-position form.正如 Tao-Lung 所说,卷积层的第一个连接需要 3 位形式。 1D convolution on sequences expects a 3D input.序列上的一维卷积需要 3D 输入。 In other words, for each element of the batch, for each time step, a single vector.换句话说,对于批次的每个元素,对于每个时间步,一个向量。 If you want the step to be unitary you solve your problem as follows:如果您希望步骤是单一的,您可以按如下方式解决您的问题:


series_input = Input(shape = (series_input_train.shape[1],1,) series_input = 输入(形状 = (series_input_train.shape[1],1,)

and


x = Conv1D(filters=32, kernel_size=5, strides=1, padding="causal", activation="relu",input_shape=[None,series_input]) x = Conv1D(filters=32, kernel_size=5, strides=1, padding="causal", activation="relu",input_shape=[None,series_input])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 层 conv1d_39 的输入 0 与层不兼容::预期 min_ndim=3,发现 ndim=2。 收到的完整形状:(无,64) - Input 0 of layer conv1d_39 is incompatible with the layer: : expected min_ndim=3, found ndim=2. Full shape received: (None, 64) Conv1D:ValueError:层序列_1 的输入 0 与层不兼容::预期 min_ndim=3,发现 ndim=2。 收到完整形状:(无,2) - Conv1D: ValueError: Input 0 of layer sequential_1 is incompatible with the layer: : expected min_ndim=3, found ndim=2. Full shape received: (None, 2) 层序的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=2。 收到的完整形状:(无,1) - Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=2. Full shape received: (None, 1) ValueError:层“conv2d_21”的输入 0 与层不兼容:预期 min_ndim=4,发现 ndim=2。 收到的完整形状:(无,19222) - ValueError: Input 0 of layer "conv2d_21" is incompatible with the layer: expected min_ndim=4, found ndim=2. Full shape received: (None, 19222) Keras Conv1d输入形状问题,conv1d层的输入0与层不兼容::预期min_ndim=3,发现ndim=2 - Keras Conv1d input shape problem, Input 0 of layer conv1d is incompatible with the layer: : expected min_ndim=3, found ndim=2 ValueError: 层顺序的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=2。 收到完整形状:[无,1] - ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=2. Full shape received: [None, 1] Keras 层顺序调谐器输入 0 与层不兼容::预期 min_ndim=3,发现 ndim=2。 收到的完整形状:(无,216) - Keras Tuner Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=3, found ndim=2. Full shape received: (None, 216) ValueError:layersequential_5 的输入 0 与 layer 不兼容::预期 min_ndim=4,发现 ndim=2。 收到的完整形状:[无,953] - ValueError: Input 0 of layer sequential_5 is incompatible with the layer: : expected min_ndim=4, found ndim=2. Full shape received: [None, 953] ValueError:顺序层的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=2。 收到完整形状:[无,2584] - ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=2. Full shape received: [None, 2584] ValueError:layersequential_32 的输入 0 与 layer 不兼容::预期 min_ndim=3,发现 ndim=2。 收到的完整形状:[无,256] - ValueError: Input 0 of layer sequential_32 is incompatible with the layer: : expected min_ndim=3, found ndim=2. Full shape received: [None, 256]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM