로딩
요청 처리 중입니다...

[torch] IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)

 [torch] IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)

오늘의 에러 IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1) 발생 위치 torch의 crossentorpy loss에 predict와 target을 넣는 부분에서 발생 output = model(x) loss = criterion(output, target) # <- 여기서 발생 발생 원인 predict의 shape이 torch의 crossentropy 에서 요구하는 것과 맞지 않았음.. 해결 방법 torch에서는 아주 정확하게 input과 (=위 코드에서는 output) target의 shape의 명시하고 있다. document CrossEntropyLoss — PyTorch 1.12 documentation The input is expected to contain raw, unnormalized scores for each class. input has to be a Tensor...

# crossentropy # error # torch