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

use item() to fix IndexError #4

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

ahmedengu
Copy link

Greetings,

I got the following error when i tried to run the code:

Traceback (most recent call last):
  File "trainer.py", line 142, in <module>
    trainer.train_minibatch(num_epochs, batch_size, interval)
  File "trainer.py", line 51, in train_minibatch
    loss_sum += loss.data[0]
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number

And as it described using item() fixed the problem and it's training now

Best Regards,
Ahmed

@erjenkins29
Copy link

The code in this pull request is similar to what I needed in order to make the code work.

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

Successfully merging this pull request may close these issues.

2 participants