pytorch/tnt

Replace loss[0] with loss.item() due to deprecation

sauercrowd opened this issue · 5 comments

When using tnt's meterlogger a deprecation warning by PyTorch does appear:

UserWarning: invalid index of a 0-dim tensor. This will be an error in PyTorch 0.
5. Use tensor.item() to convert a 0-dim tensor to a Python number

Issued by this line.

Replacing loss[0] with loss.item() should fix that without any further consequences

nbro commented

This also occurs with the MNIST with Visdom example. This is now an error in PyTorch 1.0.0.

Pytorch 1.1.0, error occurs with the mnist_with_meterlogger example
"IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number"
and it must fix This line

mnist_with_visdom example can be fixed
meter_loss.add(state['loss'].item())
# meter_loss.add(state['loss'].data[0])

@honghanchenchh wasn't it fixed by #113 ?

Yea it was, sorry forgot to close it.
Closing it for now

It fixed in repo but not in python package torchnet-0.0.4 (last version)