DataScience
728x90

손실함수에서 에러가 발생했습니다

 

데이터를 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)
profile

DataScience

@Ninestar

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!