본문 바로가기
파이썬/오류모음

[파이썬 오류] Expected object of scalar type Long but got scalar type Int for argument #2 'target' in call to _thnn_nll_loss_forward

by 욱찡이 2022. 10. 10.
반응형

 

loss = criterion(model_pred, label)

에서 loss 계산할 때 

 

"Expected object of scalar type Long but got scalar type Int for argument #2 'target' in call to _thnn_nll_loss_forward"

오류가 뜸

 

해석 : 스칼라 유형의 개체가 Long이어야 하지만 _thnn_nll_loss_forward에 호출된 #2 'target' 인수에 대한 스칼라 유형 Int가 있습니다.

label의 값을 쳐보니 

 

"int32"로 나옴.

 

 

해결방법 : label.to(device) => label.to(device).long()

반응형

댓글