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() to convert a 0-dim tensor to a Python number #34

Open
roshan-gopalakrishnan opened this issue Nov 20, 2019 · 3 comments

Comments

@roshan-gopalakrishnan
Copy link

Traceback (most recent call last):
File "main.py", line 166, in
train(epoch)
File "main.py", line 127, in train
avg_loss += loss.data[0]
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number

@Eric-mingjie
Copy link
Owner

Use torch v0.3.1.

@songheony
Copy link

If you want to use Pytorch >= 0.4.1, you have to edit some code.
Here is the source code I converted https://github.com/songheony/rethinking-network-pruning.
I've tested it with Pytorch 1.2, CUDA 10

@tejalal
Copy link

tejalal commented Feb 24, 2020

avg_loss += loss.data[0]

Replace avg_loss += loss.data[0] with avg_loss += loss.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

4 participants