gpt4 book ai didi

python - pytorch:NLLLoss ignore_index 默认值

转载 作者:行者123 更新时间:2023-12-04 12:30:38 24 4
gpt4 key购买 nike

在 pytorch 中 NLLLoss doc ignore_index 的默认值是 -100 而不是通常的 None ,有什么特别的原因吗?似乎任何负值都是等价的。
顺便说一句,我想忽略索引的原因可能是什么?谢谢!

最佳答案

ignore_index 的值必须是 int,这就是为什么默认值是 int 而不是 None .默认值是任意的,它可以是任何负数,即任何不是“有效”类标签的东西。该函数将忽略目标实例具有该类标签的所有元素。在实践中,此选项可用于识别未标记的像素,例如在密集预测任务中。

编辑:追溯 nn.NLLLoss 的实现,我们可以在 nll_loss 中找到此评论 torch/onnx/symbolic_opset12.py 的实现:

# in onnx NegativeLogLikelihoodLoss specification, ignore_index is optional without default value.
# therefore we need to set ignore_index attribute even if it is not specified (e.g. ignore_index=-100).
ignore_index = sym_help._maybe_get_const(ignore_index, "i")

关于python - pytorch:NLLLoss ignore_index 默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69346001/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com