且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何处理 tf.keras 中输出标签的“无效参数错误"

更新时间:2023-12-02 14:57:04

当模型顶部有 8 个层并且使用稀疏分类交叉熵损失时,它预计标签值为 0 到 7.当它的标签为 8 它会产生错误.当您从 8 个神经元更改为 9 个神经元时,它预计会看到 0 到 8 个范围内的标签,因此不会产生错误.由于没有一个样本的标签为 0,因此您的网络将正确分类.

When you have 8 layers at the top of the model and you are using sparse categorial cross entropy loss it expects the label values to be 0 up to 7. When it gets a label of 8 it creates an error. When you change from 8 neurons to 9 it expects to see labels in the range of 0 to 8 so it will not generate an error. Since none of the samples have a label of 0 your network will classify properly.