-
Notifications
You must be signed in to change notification settings - Fork 22
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
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number #6
Comments
I guess you're using pytorch version >= 1.0 which was released after this package was developed. According to this issue could you try to change from
to
thanks. |
Thanks, I changed it accordingly, here is the error after that. raceback (most recent call last): |
I have tried pytorch version 1.1.0 and it works well without error. Are you using CPU or GPU and what's your pytorch and cuda version? You may check pytorch version in python using
and check cuda version in command line using
you may also try
|
Thank you very much again, after changing to "meter_loss.add(state['loss'].data.cpu())" as suggested and it seems working. Here is the pytorch and cuda version I am using here pytorch: v1.1.0 cuda: |
I am trying to train a model using same config.py provided from the package but got the error shown below. Do you know what might have gone wrong? Thank you very much
parameters: 2869764
0 -> *
1 -> 1
2 -> 2
3 -> 3
4 -> 4
5 -> A
6 -> C
7 -> D
8 -> E
9 -> F
10 -> G
11 -> H
12 -> I
13 -> K
14 -> L
15 -> M
16 -> N
17 -> P
18 -> Q
19 -> R
20 -> S
21 -> T
22 -> V
23 -> W
24 -> Y
C:\Users\cct\AppData\Local\Continuum\anaconda3\lib\site-packages\torch\nn_reduction.py:46: UserWarning: size_average and reduce args will be deprecated, please use reduction='sum' instead.
warnings.warn(warning.format(ret))
0%| | 0/192 [00:00<?, ?it/s]Traceback (most recent call last):
File "capsule_network_emb.py", line 738, in
engine.train(processor, get_rt_iterator(True), maxepoch=NUM_EPOCHS, optimizer=optimizer)
File "C:\Users\cct\AppData\Local\Continuum\anaconda3\lib\site-packages\torchnet\engine\engine.py", line 63, in train
state['optimizer'].step(closure)
File "C:\Users\cct\AppData\Local\Continuum\anaconda3\lib\site-packages\torch\optim\adam.py", line 58, in step
loss = closure()
File "C:\Users\cct\AppData\Local\Continuum\anaconda3\lib\site-packages\torchnet\engine\engine.py", line 56, in closure self.hook('on_forward', state)
File "C:\Users\cct\AppData\Local\Continuum\anaconda3\lib\site-packages\torchnet\engine\engine.py", line 31, in hook
self.hooksname
File "capsule_network_emb.py", line 575, in on_forward
meter_loss.add(state['loss'].data[0])
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python `number
The text was updated successfully, but these errors were encountered: