https://blog.csdn.net/zcgyq/article/details/83085028
訪問本站觀看效果更佳
在pytorch中遇到如下錯誤:
libraries/torch/extra/cunn/lib/THCUNN/ClassNLLCriterion.cu:52: void
cunn_ClassNLLCriterion_updateOutput_kernel(Dtype *, Dtype *, Dtype *, long *,
Dtype *, int, int, int, int) [with Dtype = float, Acctype = float]: block:
[0,0,0], thread: [2,0,0] Assertiont >= 0 && t < n_classesfailed.
造成這個問題的原因就是在做分類任務時,訓練數據中存在超出分類數目的標籤。比如我一共設置了8個類,但是訓練數據中的標籤裏出現了9,就會報這個錯誤。
那麼問題來了,這裏有一個陷阱。
訓練數據中的標籤含0也會報上述錯誤。這個就非常詭異了。一般我們都從0開始數,但是在pytorch裏0以下的類別標籤都是要報錯的。所以如果類別標籤從0開始,要給所有類別標籤都加上一。