[英]Input dense is incompatible with the layer invalid shape
I have this simple layer for my model我的模型有这个简单的层
states = Input(shape=(len(inputFinal),))
This should generate a (328,None) but dunno why when I check is inverted这应该生成一个 (328,None) 但不知道为什么当我检查时被反转
model.inputs
[<tf.Tensor 'input_1:0' shape=(None, 328) dtype=float32>]
And when I try to pass data to the model the layer is not correct当我尝试将数据传递给模型时,图层不正确
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]
I cannot find the problem, any ideas ?我找不到问题,有什么想法吗?
When specifying the input shape, you only need to specify the number of features.在指定输入形状时,您只需要指定特征的数量。 Keras doesn't want to know the number of sample because it can accept any size. Keras 不想知道样本数量,因为它可以接受任何大小。 So, when you do this:所以,当你这样做时:
states = Input(shape=(len(inputFinal),))
You're telling Keras that your input has 328 columns, which isn't the case.您告诉 Keras 您的输入有 328 列,但事实并非如此。 Keras realizes this when you feed the input, and crashes.当您输入输入时,Keras 意识到这一点,并崩溃了。
If inputFinal
is a 2D NumPy array, try:如果inputFinal
是 2D NumPy 数组,请尝试:
Input(shape=inputFinal.shape[1:])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.