在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天天有,隔一段时间再犯错,又忘了以前是怎么解决的了,甚至有时候都想不起来以前也犯过这样的错误,脑子真是不好了。大家可要注意保护大脑,保护我们的头发呀~~