繁体   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

我正在尝试使用小型测试数据集设置我的第一个深度学习顺序 model。

不幸的是,当我调用 model.fit() 时收到以下错误消息:

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

我的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'])

数据有以下维度

x_train.shape is (160, 4000)


y_train_cat is (160, 2)

有两个班。

感谢您阅读本文并提前提供帮助

当您为图层赋予形状时,应该与单个样本相同...更改

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

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

它应该可以正常工作

编辑:
您可能还需要重塑输入以添加维度:

x_train = np.expand_dims(x_train, 2)

解释:
考虑单个元素,一维卷积在您的一维元素上“滑动”一维过滤器,但是您可以假设有多个通道,因此输入形状中的前导“1”

在此处输入图像描述

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM