NVIDIA / flownet2-pytorch

Pytorch implementation of FlowNet 2.0: Evolution of Optical Flow Estimation with Deep Networks
Other
3.09k stars 739 forks source link

class_correct[label] +=( c[i].item()) IndexError: invalid index of a 0-dim tensor. Use tensor.item(.. #219

Closed Codewyf-top closed 4 years ago

Codewyf-top commented 4 years ago

image Who can help me fix this issue? image

Codewyf-top commented 4 years ago

fixed

` python for n_iter, (images, labels) in enumerate(dataloaders['test']):

print("iteration: {}\ttotal {} iterations".format(n_iter + 1, len(dataloaders['test'])))

    images = images.to(device)
    labels = labels.to(device)
    output = net(images)
    _, predicted = torch.max(output, 1)
    c = (predicted == labels).squeeze()
    label = labels.item()
    if c.item():
        class_correct[label] +=1
    class_total[label] += 1
for i in range(10):
    print('Accuracy of %5s : %2d %%' % (classes[i], 100 * class_correct[i] / class_total[i]))

` image