Keras报错—Error when checking target: expected fc15 to have shape (5,) but got array with shape(1,)

在Keras中经常出现一种错误:

ValueError:Error when checking target: expected fc15 to have shape (5,) but got array with shape(1,)

这是一种常见错误,数据形状不匹配错误。它可以总结出来一套更加通用的模式:

ValueError:Error when checking target: expected xxx to have shape (xx,) but got array with shape(x,)

xxx:表示某一层
xx:表示期望得到的数据形状
x:表示实际的数据形状

解决方法有两种:
1.添加

keras.utils.to_categorical(label)

2.添加

更改loss='categorical_crossentropy'
为loss='sparse_categorical_crossentropy'

Tips:解决的两种方法详情,在我的以前博客里,请戳这里:解决方法

我好像之前写过一篇类似的博客,再来大致纪录一遍;bug天天有,隔一段时间再犯错,又忘了以前是怎么解决的了,甚至有时候都想不起来以前也犯过这样的错误,脑子真是不好了。大家可要注意保护大脑,保护我们的头发呀~~

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值