attentioned-dual-stage-stock-prediction icon indicating copy to clipboard operation
attentioned-dual-stage-stock-prediction copied to clipboard

use item() to fix IndexError

Open ahmedengu opened this issue 5 years ago • 1 comments

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

ahmedengu avatar May 14 '19 00:05 ahmedengu

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

erjenkins29 avatar Jul 05 '20 08:07 erjenkins29