rethinking-network-pruning icon indicating copy to clipboard operation
rethinking-network-pruning copied to clipboard

IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number

Open roshan-gopalakrishnan opened this issue 5 years ago • 3 comments

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

roshan-gopalakrishnan avatar Nov 20 '19 04:11 roshan-gopalakrishnan

Use torch v0.3.1.

Eric-mingjie avatar Nov 20 '19 06:11 Eric-mingjie

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

songheony avatar Jan 07 '20 13:01 songheony

avg_loss += loss.data[0]

Replace avg_loss += loss.data[0] with avg_loss += loss.item()

tejalal avatar Feb 24 '20 16:02 tejalal