擅长:python、mysql、java
<p><code>ignore_index</code>的值必须是<em>int</em>,这就是为什么默认值是<em>int</em>而不是<code>None</code>。默认值是任意的,它可以是任何负数,<em>即</em>任何不是“有效”类标签的值。该函数将忽略目标实例具有该类标签的所有元素。实际上,该选项可用于识别未标记的像素,例如在密集预测任务中</p>
<hr/>
<p><em>Edit</em>:追溯<a href="https://pytorch.org/docs/stable/generated/torch.nn.NLLLoss.html" rel="nofollow noreferrer">^{<cd3>}</a>的实现,我们可以在<a href="https://github.com/pytorch/pytorch/blob/aa5d2a8d867991fc8541e197112c35a8eba18182/torch/onnx/symbolic_opset12.py#L41" rel="nofollow noreferrer">^{<cd5>}</a>的<code>nll_loss</code>实现中找到以下注释:</p>
<pre><code># 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")
</code></pre>