输出层的单元数(软最大)和数据中标签的数量不匹配?

发布于 2025-01-20 19:48:17 字数 865 浏览 1 评论 0原文

我在用数据训练深度学习模型时遇到了以下问题。作为一个新手,我没有找到合适的答案。我希望你们能帮助我! !非常感谢!

对于第一张图像,我从数据集中提取了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.
enter image description here
enter image description here
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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫卆 2025-01-27 19:48:17

类的数量是从数据中出现的最大标签编号确定的。在您的情况下,由于最大标签为18,因此您将拥有0、1、2,...,18的类,因此总计19类(完全按错误中指定)。

要解决它,您需要将类标签重新映射[1,2,4,5,6,7,12,14,18] 4,5,6,7,8] 。可以使用词典手动完成,也可以自动完成,例如可以使用:

train_data1['faultNumber'] = train_data1['faultNumber'].astype("category").cat.codes

然后可以从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:

train_data1['faultNumber'] = train_data1['faultNumber'].astype("category").cat.codes

The original labels could be then recovered from train_data1['faultNumber'] using this answer, because it has now category type.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文