检查模型目标时发生错误:预期density_24具有形状...但在Keras中具有形状的数组... [英] Error when checking model target: expected dense_24 to have shape...but got array with shape... in Keras

查看:61
本文介绍了检查模型目标时发生错误:预期density_24具有形状...但在Keras中具有形状的数组...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白此错误消息试图告诉我什么.

I can't understand what this error message is trying to tell me.

查看我的模型摘要,我查看了最后几层.

Looking at the summary of my model, I am looking at the last few layers .

但是当我拟合模型时,我得到了这个:

But when I fit my model, I get the this:

我不明白.如果我仔细阅读,Keras似乎在说:我查看了验证集的标签(目标),明智地,这使我认为应该对模型的最后一层进行成形(无,2).但是,而不是在模型中实际获得最后一个形状的图层(无,2),该图层由一个实际的数组组成.该数组具有其他形状."

I don't understand. If I read this closely, Keras seems to be saying, "I looked at the labels (targets) for the validation set, and sensibly, this made me think the last layer in your model should be shaped (None, 2). But, instead of actually getting a last layer shaped (None, 2) in the model, the layer consisted of an actual array. Which was of some other shape."

这没有道理.

我认为我怀疑这个错误通常应该说是:

I think that I suspect that this error really should say, in general, is:

"ValueError: Error when checking model target: although dense_n has shape (x, y), the shape of the target, (a,b), in incompatible.".

有人愿意同意还是不同意?谢谢.

Does anyone care to agree or disagree? Thanks.

(有一个类似的问题

(There's a similar question here, but not very helpful.)

推荐答案

我不确定您期望的答案是否是这个,但是...

I'm not sure if the answer you expect is this, but...

首先:我同意-错误消息似乎很奇怪,它应该谈论一下density_24与目标数组之间的不兼容性.

First: I agree - the error message seems weird, it should talk about incompatibility between dense_24 and target array.

现在,要解决您的问题,您应该重塑目标数组的形状或在末尾创建另一个Dense以匹配您的数组.

Now, to solve your problem, you should either reshape your target array or create a different Dense at the end to match your array.

关于目标数组,对于两个类别的分类,其形状应为:

About your target array, for a classification in two classes, it should be shaped as:

  • (46000,2),如果您的分类使用两个值,一个用于A类的可能性,另一个用于B类的可能性
  • (46000,1),如果您的分类使用的单个值是0类A和1类B(在这种情况下,您的密集层应为(None,1))
  • 使用Dense(1, activation='sigmoid')代替模型末尾的Dense(2,...).
  • Instead of having Dense(2,...) at the end of your model, use Dense(1, activation='sigmoid').

为什么?因为目标数据的形状像(46000,1),这意味着您只有两个类别的一个数字. 0是一类,1是另一类.

Why? Because your target data is shaped like (46000,1), meaning you have only one number for two classes. 0 is one class, 1 is another.

这篇关于检查模型目标时发生错误:预期density_24具有形状...但在Keras中具有形状的数组...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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