输入密度与图层无效形状不兼容

2024-05-12 23:43:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我的模型有一个简单的图层

states = Input(shape=(len(inputFinal),))

这应该会产生一个(328,无),但不知道为什么当我检查是反向的

model.inputs
[<tf.Tensor 'input_1:0' shape=(None, 328) dtype=float32>]

当我试图将数据传递给模型时,层是不正确的

value.shape
(328,)

model.predict(value)

Input 0 of layer dense is incompatible with the layer: expected axis -1 of input shape to have value 328 but received input with shape [None, 1]

我找不到问题,有什么想法吗


Tags: of模型none图层layerinputmodellen
1条回答
网友
1楼 · 发布于 2024-05-12 23:43:59

指定输入形状时,只需指定特征的数量。Keras不想知道样本数量,因为它可以接受任何尺寸。因此,当您这样做时:

states = Input(shape=(len(inputFinal),))

你告诉Keras你的输入有328列,事实并非如此。Keras在输入时实现了这一点,然后崩溃

如果inputFinal是2D NumPy数组,请尝试:

Input(shape=inputFinal.shape[1:])

相关问题 更多 >