简体   繁体   English

二进制信号数据:keras ValueError:层顺序的输入 0 与层不兼容::预期 min_ndim=3,发现 ndim=2

[英]binary signal data: keras ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=3, found ndim=2

I'm attempting to train models for RF fingerprinting, and have captured samples from a number of devices at a length of 1 million each.我正在尝试训练用于射频指纹识别的模型,并从多个设备中捕获了每个长度为 100 万个的样本。 I've converted the samples into a variety of images, and have successfully trained models using that form of data by means of:我已将样本转换为各种图像,并通过以下方式成功地使用该数据形式训练了模型:

imageSize = 224
x_train = np.array(x_train) / 255
x_train.reshape(-1, imageSize, imageSize, 1)                
x_val = np.array(x_val) / 255
x_val.reshape(-1, imageSize, imageSize, 1)
y_train = np.array(y_train)
y_val = np.array(y_val)

model = Sequential()
model.add(Conv2D(96, 7, padding="same", activation="relu", input_shape = (224, 224, 3)))
model.add(MaxPool2D())

model.add(Conv2D(96, 7, padding="same", activation="relu"))
model.add(MaxPool2D())

model.add(Conv2D(192, 7, padding="same", activation="relu"))
model.add(MaxPool2D())
model.add(Dropout(0.4))

model.add(Flatten())
model.add(Dense(384, activation="relu"))
model.add(Dense(6, activation="softmax"))

opt = Adam(learning_rate=0.000001)
model.compile(optimizer = opt, loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True), metrics=["accuracy"])                        
                    
model.summary()
                    
history = model.fit(x_train, y_train, epochs = 500, validation_data = (x_val, y_val))

However, attempting to do the same to the array data (shape (60, 4000)) which was used to create the images yields the "ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=3, found ndim=2" issue listed in the title.但是,尝试对用于创建图像的数组数据(形状 (60, 4000))执行相同操作会产生“ValueError:层顺序的输入 0 与层不兼容::预期 min_ndim=3,找到 ndim =2" 标题中列出的问题。 My code for that is:我的代码是:

x_train = np.array(x_train)    
x_train.reshape(-1, 4000, 1)
                                            
x_val = np.array(x_val)
x_val.reshape(-1, 4000, 1)
                    
y_train = np.array(y_train)                        
                    
y_val = np.array(y_val)
                    
model = Sequential()
model.add(Conv1D(96, 7, padding="same", activation="relu", input_shape=(4000, 1)))
model.add(MaxPooling1D())

model.add(Conv1D(96, 7, padding="same", activation="relu"))
model.add(MaxPooling1D())

model.add(Conv1D(192, 7, padding="same", activation="relu"))
model.add(MaxPooling1D())
model.add(Dropout(0.4))

model.add(Flatten())
model.add(Dense(384, activation="relu"))
model.add(Dense(6, activation="softmax"))
                    
opt = Adam(learning_rate=0.000001)                                                                      
model.compile(optimizer = opt, loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True), metrics=["accuracy"])

model.summary()                       

history = model.fit(x_train, y_train, epochs = 500, validation_data = (x_val, y_val))

Like many it seems, I'm unable to figure out why this input shape isn't working for the array data.就像许多看起来一样,我无法弄清楚为什么这个输入形状不适用于数组数据。 Any clarifications will be helpful.任何澄清都会有所帮助。

The error: expected min_ndim=3, found ndim=2 clearly explains all.错误:expected min_ndim=3, found ndim=2 清楚地说明了一切。 The first problem, you used input shape is in three dimension (224, 224, 3), while for the second one the input shape changed to 1 dimensional array of shape (4000, 1).第一个问题,您使用的输入形状是三维的 (224, 224, 3),而对于第二个问题,输入形状更改为形状 (4000, 1) 的一维数组。 You should reshape the dimension of your input to the sequential model.您应该将输入的维度重塑为顺序 model。

暂无
暂无

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

相关问题 Keras Conv1D ValueError:层顺序的输入 0 与层不兼容::预期 min_ndim=3,发现 ndim=2 - Keras Conv1D ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=3, found ndim=2 Keras Conv2D - ValueError:层序的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=3 - Keras Conv2D - ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=3 ValueError:层顺序的输入0与层不兼容::预期的min_ndim = 4,发现ndim = 3 - ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=3 Keras Lambda层给出ValueError:输入0与层xxx不兼容:预期的min_ndim = 3,找到的ndim = 2 - Keras Lambda layers gives ValueError: Input 0 is incompatible with layer xxx: expected min_ndim=3, found ndim=2 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=3。 收到完整形状:[8, 28, 28] - ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [8, 28, 28] 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] ValueError: 层序列 9 的输入 0 与层不兼容:预期 min_ndim=4,发现 ndim=3。 收到的完整形状:[无,无,无] - ValueError: Input 0 of layer sequential_9 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None, None, None] ValueError:层顺序的输入 0 与层不兼容::预期 min_ndim=3,发现 ndim=2。 收到的完整形状:(10, 24) - ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=3, found ndim=2. Full shape received: (10, 24) ValueError:layersequential_1 的输入 0 与 layer 不兼容::预期 min_ndim=4,发现 ndim=3。 收到的完整形状:[无、256、256] - ValueError: Input 0 of layer sequential_1 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None, 256, 256]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM