Error when checking target: expected dense_8 to have shape (2,) but got array with shape (28,)

在做深度学习的时候遇到的问题:

我是在做keras+自带的预训练模型+迁移学习自己的数据集,运行训练代码报错:

Error when checking target: expected dense_8 to have shape (2,) but got array with shape (28,)

原因是最后一层全连接层上面设置了二分类就是2类,但我要训练的数据集有28类,所以出错。

所以应该修改全连接层的最后一层的分类为28就好了。我是不用mobilnet自带的全连接层,而是自己设计的自定义全连接层。

Error when checking target: expected dense_8 to have shape (2,) but got array with shape (28,)_第1张图片
改成:

Error when checking target: expected dense_8 to have shape (2,) but got array with shape (28,)_第2张图片
如果是:
Error when checking target: expected dense_8 to have shape (28,) but got array with shape (1,)

记得把:

class_mode=‘binary’

改为:

class_mode=‘categorical’

因为要多分类。

你可能感兴趣的:(报错Bug解决方法,深度学习,tensorflow,神经网络,python,人工智能)