Research Notes

[Solved] IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number 본문

Programming Language/Python

[Solved] IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number

jiachoi 2022. 9. 22. 11:18

문제상황: pytorch에서 model을 돌리다가 해당 에러가 뜸 

이유: pytorch 이전 버전(0.5)에서 작성된 코드를 돌릴 때 뜨는 에러, pytorch의 데이터 자료 구조가 변경되었다고 함

코드에서 변수명.data[0] --> 변수명.data로 바꾸면 해결됨