Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexError: invalid index of a 0-dim tensor. Use tensor.item() in Python or tensor.item<T>() in C++ to convert a 0-dim tensor to a number #12

Open
GeneralJing opened this issue Oct 10, 2020 · 2 comments

Comments

@GeneralJing
Copy link

Traceback (most recent call last):
File "main.py", line 152, in
train(epoch)
File "main.py", line 120, in train
100. * batch_idx / len(train_loader), loss.data[0]))
IndexError: invalid index of a 0-dim tensor. Use tensor.item() in Python or tensor.item<T>() in C++ to convert a 0-dim tensor to a number

@shine0801
Copy link

I have the same problem. Has it been solved?

@1337Eddy
Copy link

1337Eddy commented Jan 7, 2022

That's a version problem. Replace 100. * batch_idx / len(train_loader), loss.data[0])) in line 120 with 100. * batch_idx / len(train_loader), loss.data.item())) and test_loss += F.cross_entropy(output, target, size_average=False).data[0] in line 131 with test_loss += F.cross_entropy(output, target, size_average=False).data.item()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants