파이썬/파이썬 기초
RuntimeError: "nll_loss_forward_reduce_cuda_kernel_2d_index" not implemented for 'Int': Pytorch
Ninestar
2023. 1. 13. 13:06
반응형
손실함수에서 에러가 발생했습니다
데이터를 GPU에 저장하기 전에 대상 유형을 변환하면 됩니다.
아래와 같이 label을 LongTensorㅇ로 캐스팅 해주면 됩니다.
for inputs, targets in data_loader:
targets = targets.type(torch.LongTensor) # casting to long
inputs, targets = inputs.to(device), targets.to(device)
...
...
loss = self.criterion(output, targets)
for epoch in range(num_epochs):
for (words, labels) in train_loader:
words = words.to(device)
labels = labels.type(torch.LongTensor) # <---- Here (casting)
labels = labels.to(device)