输出层的单元数(软最大)和数据中标签的数量不匹配?
我在用数据训练深度学习模型时遇到了以下问题。作为一个新手,我没有找到合适的答案。我希望你们能帮助我! !非常感谢!
对于第一张图像,我从数据集中提取了1,2,4,5,6,7,12,14,18(有20个标签)作为标签。通常情况下,我只需要在softmax层输入10,模型就可以正常运行;该错误表明我们需要将 softmax 层中的单元数设置为 19 才能使模型正常运行,而这正是发生的情况。对于第二张图片,我只将最后一个标签更改为16,然后我们需要将 softmax 中的单元数设置为 17 才能使模型正常运行。 那么为什么输出层(softmax)的单元数和数据中的标签数不匹配!! 虽然我可以改变softmax层中的单元数量来使模型正常工作,但我不确定这是否会对模型的准确性产生影响!
I encountered the following problems when training a deep learning model with data. As a novice, I didn't find a suitable answer. I hope you guys can help me out! ! Thank you very much!
For the first image, I extracted 1, 2, 4, 5, 6, 7, 12, 14, 18 from the dataset (there are 20 labels) as labels. Normally, I only need to enter 10 in the softmax layer and the model will function properly; the error shows that we need to set the number of units in the softmax layer to 19 for the model to function properly, and this is exactly what happened.For the second picture, I only changed the last labels to 16, then we need to set the number of units in the softmax to 17 for the model to function properly.
So why does the number of units of the output layer(softmax) and the number of labels in the data do not match!!
Although I can change the number of units in the softmax layer to make the model work properly, I'm not sure if this has an impact on the accuracy of the model!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
类的数量是从数据中出现的最大标签编号确定的。在您的情况下,由于最大标签为18,因此您将拥有0、1、2,...,18的类,因此总计19类(完全按错误中指定)。
要解决它,您需要将类标签重新映射
[1,2,4,5,6,7,12,14,18]
4,5,6,7,8] 。可以使用词典手动完成,也可以自动完成,例如可以使用:然后可以从
train_data1 ['FARFENNUMBER']
使用此答案,因为它现在具有类别
类型。The number of classes is determined from the maximum label number, that appears in your data. In your case since the maximum label was 18, you would have classes 0, 1, 2, ..., 18, so 19 classes in total (exactly as specified in the error).
To solve it, you need to remap the classes labels
[1,2,4,5,6,7,12,14,18]
to[0,1,2,3,4,5,6,7,8]
. It can be done manually using a dictionary, or automatically, e.g. this could work:The original labels could be then recovered from
train_data1['faultNumber']
using this answer, because it has nowcategory
type.