hunkim / PyTorchZeroToAll

Simple PyTorch Tutorials Zero to ALL!
http://bit.ly/PyTorchZeroAll
3.89k stars 1.2k forks source link

Lec11 bug fixed #61

Open jaewoogwak opened 6 months ago

jaewoogwak commented 6 months ago

I found some error

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

Then I changed,

In train function,

loss.data.item() # loss.data[0] -> loss.data.item()

In test function,

test_loss += F.nll_loss(output, target, size_average=False).item() # .data[0] -> .item()

It works well