简体   繁体   English

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

[英]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.

相关问题 层密集的输入 0 与层不兼容:输入形状的预期轴 -1 具有值 3,但收到的输入形状为 (None, 1) - Input 0 of layer dense is incompatible with the layer: expected axis -1 of input shape to have value 3 but received input with shape (None, 1) ValueError:密集层的输入 0 不兼容 - ValueError: Input 0 of layer dense is incompatible ValueError:密集层的输入 0 与层不兼容:预期轴 -1 的值为 8,但接收到形状为 [None, 1] 的输入 - ValueError: Input 0 of layer dense is incompatible with the layer: expected axis -1 to have value 8 but received input with shape [None, 1] “密集”层的输入 0 与该层不兼容:预期 min_ndim=2,发现 ndim=1。 完整形状收到:(32,) - Input 0 of layer "dense" is incompatible with the layer: expected min_ndim=2, found ndim=1. Full shape received: (32,) 自动编码器/Keras/Tensorflow:密集层与层不兼容:输入形状的预期轴 -1 的值为 64 - Autoencoder/Keras/Tensorflow: Dense layer is incompatible with the layer: expected axis -1 of input shape to have value 64 ValueError: 层密集的输入 0 与层不兼容 - ValueError: Input 0 of layer dense is incompatible with the layer ValueError:层 dense_2 的输入 0 与层不兼容 - ValueError: Input 0 of layer dense_2 is incompatible with the layer 密集层的输入 0 与该层不兼容:输入形状的预期轴 -1 具有值 8192,但接收到的输入具有形状(无,61608) - Input 0 of layer dense is incompatible with the layer: expected axis -1 of input shape to have value 8192 but received input with shape (None, 61608) ValueError: 层dense_1的输入0与层不兼容 - ValueError: Input 0 of layer dense_1 is incompatible with the layer 密集层的输入 0 与该层不兼容:输入形状的预期轴 -1 的值为 2700,但接收到的输入形状为 [None, 900] - Input 0 of layer dense is incompatible with the layer: expected axis -1 of input shape to have value 2700 but received input with shape [None, 900]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM