【发布时间】:2021-11-06 14:16:06
【问题描述】:
我正在尝试为多类分类构建模型,但我不明白如何设置正确的输入形状。我有一个形状为(5420, 212) 的训练集,这是我构建的模型:
model = models.Sequential()
model.add(layers.Dense(64, activation='relu', input_shape = (5420,)))
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dense(5, activation='softmax'))
model.compile(optimizer='rmsprop', loss='categorical_crossentropy', metrics=['accuracy'])
model.summary()
history = model.fit(X_train, y_train, epochs=20, batch_size=512)
当我运行它时,我得到了错误:
ValueError: Input 0 of layer sequential_9 is incompatible with the layer: expected axis -1 of input shape to have value 5420 but received input with shape (None, 212)
为什么?输入的值不对吗?
【问题讨论】:
-
你应该设置
input_shape = (212,)。 -
刚试过,我得到了一个 ValueError: Shapes (None, 1) and (None, 5) are incompatible
标签: python tensorflow deep-learning neural-network sequential