简体   繁体   English

ValueError: Input 0 of layer "sequential_8" is in compatible with the layer - 深度学习 model

[英]ValueError: Input 0 of layer "sequential_8" is incompatible with the layer - deep learning model

I am attempting to setup my first deep learning sequential model with a small test dataset.我正在尝试使用小型测试数据集设置我的第一个深度学习顺序 model。

Unfortunately, I get the following error message when I call model.fit():不幸的是,当我调用 model.fit() 时收到以下错误消息:

ValueError: Input 0 of layer "sequential_8" is incompatible with the layer: expected shape=(None, 160, 4000), found shape=(32, 4000)

My model is as follows我的model如下

num_of_classes = 2
input_shape = (1,4000)

y_train_cat = keras.utils.to_categorical(y_train, num_of_classes)
y_test_cat = keras.utils.to_categorical(y_test, num_of_classes)



model = Sequential()
model.add(Conv1D(filters=10, kernel_size=5, input_shape=(160, 4000)))
model.add(MaxPool1D(pool_size=5))
model.add(Flatten())
model.add(Dense(1000, activation='relu'))
model.add(Dense(num_classes, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

The data is of the following dimensions数据有以下维度

x_train.shape is (160, 4000)


y_train_cat is (160, 2)

There are two classes.有两个班。

Thank you for reading this far and your help in advance感谢您阅读本文并提前提供帮助

When you give a layer the shape, is supposed to be the same of a single sample... change当您为图层赋予形状时,应该与单个样本相同...更改

model.add(Conv1D(filters=10, kernel_size=5, input_shape=(160, 4000)))

to

model.add(Conv1D(filters=10, kernel_size=5, input_shape=(4000,1)))

and it should work fine它应该可以正常工作

Edit:编辑:
You probably also need to reshape your input to add a dimension:您可能还需要重塑输入以添加维度:

x_train = np.expand_dims(x_train, 2)

Explanation:解释:
consider a single element, a 1D convolution "slides" a 1D filter over your 1D element, however you can assume to have multiple channels, thus the leading "1" in the shape of the input考虑单个元素,一维卷积在您的一维元素上“滑动”一维过滤器,但是您可以假设有多个通道,因此输入形状中的前导“1”

在此处输入图像描述

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

相关问题 ValueError: 层序号_3 的输入 0 与层不兼容: - ValueError: Input 0 of layer sequential_3 is incompatible with the layer: ValueError:“顺序”层的输入 0 与该层不兼容 - ValueError: Input 0 of layer "sequential" is incompatible with the layer "ValueError: Input 0 of layer "sequential" is in compatible with the layer" 在预测中 - "ValueError: Input 0 of layer "sequential" is incompatible with the layer" In prediction ValueError: 层序列 1 的输入 0 与层不兼容 - ValueError: Input 0 of layer sequential_1 is incompatible with the layer TensorFlow ValueError:层顺序的输入0与层不兼容 - TensorFlow ValueError: Input 0 of layer sequential is incompatible with the layer ValueError: 层序号_2 的输入 0 与层不兼容 - ValueError: Input 0 of layer sequential_2 is incompatible with the layer 由于输入层不兼容,深度学习模型没有给出预测 - Deep learning model not giving predictions as input layer is incompatible 当适合我的 model 时,我得到 ValueError: Input 0 of layer sequence is incompatible with the layer - When fit my model I obtain ValueError: Input 0 of layer sequential is incompatible with the layer ValueError:层顺序的输入0与层不兼容(重塑错误) - ValueError: Input 0 of layer sequential is incompatible with the layer(Reshape error) 层顺序的输入 0 与层不兼容: - Input 0 of layer sequential is incompatible with the layer:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM