简体   繁体   English

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]

I am building a Conv1D model with train data (28659, 257) and test data (5053, 257), but I am facing a value error that says: expected min_ndim=3, found ndim=2.我正在构建一个带有训练数据(28659、257)和测试数据(5053、257)的 Conv1D model,但我遇到了一个值错误,上面写着:预期 min_ndim=3,发现 ndim=2。 Full shape received: [None, 256]收到的完整形状:[无,256]

size of datasets数据集的大小

print(train_data.shape)
print(test_data.shape)

model model

model = Sequential()
model.add(Conv1D(filters=64, kernel_size=5, activation='relu', input_shape=(256,1)))
model.add(Conv1D(filters=64, kernel_size=3, activation='relu'))
model.add(Dropout(0.5))
model.add(MaxPooling1D(pool_size=2))
model.add(Flatten())
model.add(Dense(8, activation='relu'))
model.add(Dense(2, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='Adam', metrics=['accuracy'])
model.summary()

opt = keras.optimizers.Adam(learning_rate=0.01)
model.compile(loss='CategoricalCrossentropy', optimizer=opt, metrics=['accuracy'])

history = model.fit(train_data.values[:, 0:256], to_categorical(train_data.values[:, 256]), epochs=180, batch_size=500)
y_pred = model.predict(test_data.values[:, 0:256])

testing accuracy测试精度

y_pred = model.predict(test_data.values[:,0:256])
y_pred = (y_pred > 0.5)
accuracy = metrics.accuracy_score(to_categorical(test_data.values[:,256]),y_pred)
print(f'Testing accuracy of the model is {accuracy*100:.4f}%')

The error is from the fit(), but I cannot figure my mistake with the calculation!错误来自 fit(),但我无法计算出我的计算错误! Any help is appreciated!任何帮助表示赞赏!

try to reshape your train and test data:尝试重塑您的训练和测试数据:

X_train=np.reshape(train_data,(train_data.shape[0], train_data.shape[1],1))
X_test=np.reshape(test_data,(test_data.shape[0], test_data.shape[1],1))

You can't feed values like: [1,2,3,4] , you have to feed your values like [[1],[2],[3],[4]]您不能提供诸如[1,2,3,4]类的值,您必须提供诸如[[1],[2],[3],[4]]类的值

暂无
暂无

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

相关问题 层序的输入 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: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。 收到完整形状:[无,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:顺序层的输入 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_4 的输入 0 与 layer 不兼容::预期 min_ndim=3,发现 ndim=2。 收到的完整形状:(无,5000) - ValueError: Input 0 of layer sequential_4 is incompatible with the layer: : expected min_ndim=3, found ndim=2. Full shape received: (None, 5000) 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] ValueError:层顺序的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=3。 收到的完整形状:[None, 32, 32] - ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None, 32, 32] 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: 层序贯_1 的输入 0 与层不兼容: : 预期 min_ndim=4,发现 ndim=2。 收到的完整形状:(32768, 1) - ValueError: Input 0 of layer sequential_1 is incompatible with the layer: : expected min_ndim=4, found ndim=2. Full shape received: (32768, 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)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM