Я использую PyTorch, но получаю ошибку!Мой код ошибки следующий:
for train_data in trainloader:
example_count += 1
if example_count == 100:
break
optimer.zero_grad()
image, label = train_data
image = image.cuda()
label = label.cuda()
out = model(image)
_, out = torch.max(out, 1)
# print(out.cpu().data.numpy())
# print(label.cpu().data.numpy())
# out = torch.zeros(4, 10).scatter_(1, out.cpu(), 1).cuda()
# label= torch.zeros(4, 10).scatter_(1, label.cpu(), 1).cuda()
l = loss(out, label)
l.bakeward()
optimer.setp()
j += 1
count += label.size(0)
acc += (out == label).sum().item()
if j % 1000 == 0:
print(j + ' step:curent accurity is %f' % (acc / count))
трассировка:
Traceback (most recent call last):
File "VGG实现.py", line 178, in <module>
utils.train(testloader,model)
File "VGG实现.py", line 153, in train
l=loss(out,label)
File "/home/tang/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 489, in __call__
result = self.forward(*input, **kwargs)
File "/home/tang/anaconda3/lib/python3.7/site-packages/torch/nn/modules/loss.py", line 435, in forward
return F.mse_loss(input, target, reduction=self.reduction)
File "/home/tang/anaconda3/lib/python3.7/site-packages/torch/nn/functional.py", line 2156, in mse_loss
ret = torch._C._nn.mse_loss(expanded_input, expanded_target, _Reduction.get_enum(reduction))
RuntimeError: _thnn_mse_loss_forward is not implemented for type torch.cuda.LongTensor
Я получаю ответ, который здесь Pytorch RuntimeError: "host_softmax" не реализовано для torch.cuda.LongTensor '
Но я не знаю, как решить этот вопрос.