본문 바로가기
728x90
반응형

RuntimeError7

[Pytorch] RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn - 전체 에러 문구 RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn ​ ​ - 해결 방법 requires_grad 함수가 False 값을 가진 채 backward 함수를 실행하면 발생하는 오류입니다. backward()함수를 통해 역전파를 실행하기 위해 네트워크의 뒤로 갔는데 gradient를 저장해 둔 공간이 없기 때문에 에러가 발생한다고 할 수 있습니다. import torch import torch.nn as nn loss = nn.CrossEntropyLoss() input = torch.FloatTensor([[-1.4922, -0.1335, 0.2527, 0.0334, 0.0705], [-0.. 2023. 1. 29.
[Pytorch] RuntimeError: Expected object of scalar type Long but got scalar type Float for argument # - 전체 에러 문구 RuntimeError: Expected object of scalar type Long but got scalar type Float for argument #2 ​ cross entropy loss를 사용할 때 발생하는 에러입니다. target(정답 라벨) 자리에 잘못된 데이터 타입이 왔을 때 발생합니다. ​ ​ ​ - 해결 방법 기존의 F.cross_entropy(logits, targets)를 아래처럼 변경해주면 됩니다. F.cross_entropy(logits, targets.to(device='cuda', dtype=torch.int64)) 2023. 1. 29.
[Pytorch] RuntimeError: DataLoader worker (pid(s) 19106, 19107, 19109, 19110) exited unexpectedly. - 전체 에러 문구 RuntimeError: DataLoader worker (pid(s) 19106, 19107, 19109, 19110) exited unexpectedly ​ 확실하지 않지만, dataloader에서 데이터를 불러올 때, 이미 tensor 형태로 데이터를 만들어 불러 오는 경우 발생하는 에러인 것으로 판단됩니다. 좀 더 구글링을 해보니 이미 tensor형태로 만들어진 데이터는 gpu에 들어가 있는 상태인데, 이를 다시 불러와 다른 gpu에 넣으려 할 때 발생하는 에러인 것 같습니다. ​ ​ ​ - 해결 방법 데이터를 넘겨줄 때 tensor로 만들어 넘겨 주는 방식 대신, numpy 형식으로 바꿔 넘겨주는 방식으로 해결하였습니다. 2023. 1. 28.
728x90
반응형