输入密集与图层无效形状不兼容 [英] Input dense is incompatible with the layer invalid shape

查看:56
本文介绍了输入密集与图层无效形状不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的模型有这个简单的层

I have this simple layer for my model

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

这应该生成(328,None),但不知道为什么当我检查倒置时

This should generate a (328,None) but dunno why when I check is inverted

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 ?

推荐答案

指定输入形状时,只需指定要素数量.Keras不想知道样本数量,因为它可以接受任何大小.因此,当您执行此操作时:

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. So, when you do this:

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

您要告诉Keras,您的输入有328列,情况并非如此.当您输入输入时,Keras会意识到这一点,然后崩溃.

You're telling Keras that your input has 328 columns, which isn't the case. Keras realizes this when you feed the input, and crashes.

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

If inputFinal is a 2D NumPy array, try:

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

这篇关于输入密集与图层无效形状不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆