Ssd.pytorch: ValueError: not enough values to unpack (expected 2, got 0)

Created on 26 Apr 2018  ·  29Comments  ·  Source: amdegroot/ssd.pytorch

I am getting error when I try to use the pretrained model:
python demo/live.py --weights ./weights/ssd300_mAP_77.43_v2.pth

/home/cya/git_clones/ssd.pytorch/ssd.py:34: UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
  self.priors = Variable(self.priorbox.forward(), volatile=True)
/home/cya/git_clones/ssd.pytorch/layers/modules/l2norm.py:17: UserWarning: nn.init.constant is now deprecated in favor of nn.init.constant_.
  init.constant(self.weight,self.gamma)
[INFO] starting threaded video stream...
Traceback (most recent call last):
  File "demo/live.py", line 82, in <module>
    cv2_demo(net.eval(), transform)
  File "demo/live.py", line 55, in cv2_demo
    frame = predict(frame)
  File "demo/live.py", line 25, in predict
    y = net(x)  # forward pass
  File "/home/cya/anaconda3/envs/tensorflow/lib/python3.6/site-packages/torch/nn/modules/module.py", line 491, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/cya/git_clones/ssd.pytorch/ssd.py", line 103, in forward
    self.priors.type(type(x.data))                  # default boxes
  File "/home/cya/git_clones/ssd.pytorch/layers/functions/detection.py", line 54, in forward
    ids, count = nms(boxes, scores, self.nms_thresh, self.top_k)
ValueError: not enough values to unpack (expected 2, got 0)
FATAL: exception not rethrown
[1]    11209 abort (core dumped)  python demo/live.py --weights ./weights/ssd300_mAP_77.43_v2.pth

Most helpful comment

I changed the code as follows and worked for me.
In detection.py of line 62
from

if scores.dim() == 0:
    continue

to

if scores.size(0) == 0:
    continue

All 29 comments

I changed the code as follows and worked for me.
In detection.py of line 62
from

if scores.dim() == 0:
    continue

to

if scores.size(0) == 0:
    continue

Thanks a lot it worked now

After I change the code , it turns out to be
File "eval.py", line 438, in
thresh=args.confidence_threshold)
File "eval.py", line 395, in test_net
boxes = dets[:, 1:]
IndexError: too many indices for tensor of dimension 1
How can I solve it?

thanks

On Thu, May 10, 2018 at 9:17 PM, wynntw notifications@github.com wrote:

After I change the code , it turns out to be
File "eval.py", line 438, in
thresh=args.confidence_threshold)
File "eval.py", line 395, in test_net
boxes = dets[:, 1:]
IndexError: too many indices for tensor of dimension 1


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/amdegroot/ssd.pytorch/issues/154#issuecomment-388094838,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AcvYfpNMSq24xcE34SI6CiAeYF8DB0V0ks5txGELgaJpZM4TkVad
.

@wynntw
just do as commented by @mkx1925 , change the "if" condition "dim()==0" to "size(0)==0"
after pytorch 0.4, the dim of an empty tensor is 1, and dim of a scalar tensor (e.g, x=tensor(0.1)) is 0

I meet the error as wynntw too. How can I solve it ?
Traceback (most recent call last):
File "eval.py", line 438, in
thresh=args.confidence_threshold)
File "eval.py", line 395, in test_net
boxes = dets[:, 1:]
IndexError: too many indices for tensor of dimension 1

if dets.dim() == 1
to
if dets.size(0) == 1

@dongfengxijian just do like @KeyKy .
change the code in the eval.py line 393

@ivansong1988 @mkx1925
thanks

Thanks. @mkx1925 @ivansong1988 I am using pytorch=0.4.0. And your answers help me out.

I changed the code as follows and worked for me.
In detection.py of line 62
from

if scores.dim() == 0:
    continue

to

if scores.size(0) == 0:
    continue

Excuse me, I changed the demo of 'if scores.dim() == 0:' to 'if scores.size(0) == 0:', but still got the error that ValueError: not enough values to unpack (expected 2, got 0). I am using pytorch=0.4.0, The error will miss if I install a version of 0.3.1. Can you help me with that? Thanks a lot

Thanks. @mkx1925 @ivansong1988 I am using pytorch=0.4.0. And your answers help me out.

Hello,sir. Did your test the demo successly in the version of 0.4.0? Did you changed other place? I got the same error and thy to solve it by changing the demo of 'if scores.dim() == 0:' to 'if scores.size(0) == 0:' ,but failed. Can you help me with that please? Thanks a lot.

I just did what they said above and did not remember clearly whether I encountered other errors. If you met other errors, you may refer to other issues.

I just did what they said above and did not remember clearly whether I encountered other errors. If you met other errors, you may refer to other issues.

your pytorch version is also 0.4.0+?

Yes, and Cuda version 8.0.

moyan007 notifications@github.com 于2018年11月22日周四 下午8:52写道:

I just did what they said above and did not remember clearly whether I
encountered other errors. If you met other errors, you may refer to other
issues.

your pytorch version is also 0.4.0+?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/amdegroot/ssd.pytorch/issues/154#issuecomment-441021554,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AVtsB-D-BwQtFbZudUW-MeKHrpAB6h02ks5uxp3zgaJpZM4TkVad
.

--
Best Regards,
Wang Jiahua

Thanks. @mkx1925 @ivansong1988 I am using pytorch=0.4.0. And your answers help me out.

Hello,sir. Did your test the demo successly in the version of 0.4.0? Did you changed other place? I got the same error and thy to solve it by changing the demo of 'if scores.dim() == 0:' to 'if scores.size(0) == 0:' ,but failed. Can you help me with that please? Thanks a lot.

just the same question, you can restart jupyter notebook to run again , then its work.

I had this problem and I changed
scores.dim()
to
scores.size(0)
but here is the problem:
I can't detect anything in the video? what should I do? Should I change the BaseTransform initialization? Now it's like this:
transform = BaseTransform(net.size, (104/256.0, 117/256.0, 123/256.0))

I have edited the detection.py file by
from

if scores.dim() == 0:
continue
to

if scores.size(0) == 0:
continue
Restarted Spyder. Now Its showing me this error:

File "", line 4, in
from data import BaseTransform, VOC_CLASSES as labelmap

ImportError: No module named 'data'

I had this problem and I changed
scores.dim()
to
scores.size(0)
but here is the problem:
I can't detect anything in the video? what should I do? Should I change the BaseTransform initialization? Now it's like this:
transform = BaseTransform(net.size, (104/256.0, 117/256.0, 123/256.0))

i have the same problem!!

I have edited the detection.py file by
from

if scores.dim() == 0:
continue
to

if scores.size(0) == 0:
continue
Restarted Spyder. Now Its showing me this error:

File "", line 4, in
from data import BaseTransform, VOC_CLASSES as labelmap

ImportError: No module named 'data'

open the directory in which the files are placed
this can be done from the top right corner using file explorer

I had this problem and I changed
scores.dim()
to
scores.size(0)
but here is the problem:
I can't detect anything in the video? what should I do? Should I change the BaseTransform initialization? Now it's like this:
transform = BaseTransform(net.size, (104/256.0, 117/256.0, 123/256.0))

I have the same problem , by changing scores.dim() to scores.size(0) , I can't detect aything in video , how to solve that ?

I had this problem and I changed
scores.dim()
to
scores.size(0)
but here is the problem:
I can't detect anything in the video? what should I do? Should I change the BaseTransform initialization? Now it's like this:
transform = BaseTransform(net.size, (104/256.0, 117/256.0, 123/256.0))

I have same issue too, please suggest what is wrong going on.

I had this problem and I changed
scores.dim()
to
scores.size(0)
but here is the problem:
I can't detect anything in the video? what should I do? Should I change the BaseTransform initialization? Now it's like this:
transform = BaseTransform(net.size, (104/256.0, 117/256.0, 123/256.0))

Same problem :(

I had this problem and I changed
scores.dim()
to
scores.size(0)
but here is the problem:
I can't detect anything in the video? what should I do? Should I change the BaseTransform initialization? Now it's like this:
transform = BaseTransform(net.size, (104/256.0, 117/256.0, 123/256.0))

Same problem :(

apparently I downgraded my torchvision version and it worked

I had this problem and I changed
scores.dim()
to
scores.size(0)
but here is the problem:
I can't detect anything in the video? what should I do? Should I change the BaseTransform initialization? Now it's like this:
transform = BaseTransform(net.size, (104/256.0, 117/256.0, 123/256.0))

Same problem :(

apparently I downgraded my torchvision version and it worked

seems like that's the only way :(
well, can you tell the command ?

I had this problem and I changed
scores.dim()
to
scores.size(0)
but here is the problem:
I can't detect anything in the video? what should I do? Should I change the BaseTransform initialization? Now it's like this:
transform = BaseTransform(net.size, (104/256.0, 117/256.0, 123/256.0))

Same problem :(

apparently I downgraded my torchvision version and it worked

seems like that's the only way :(
well, can you tell the command ?
Can you please give details what you are trying to achieve and what are other libs you are using
Because if you are using Anaconda then in the particular environment you can select pytorch and uninstall then install the desired version. If I can help, you can connect with me on ssj.[email protected]

I had this problem and I changed
scores.dim()
to
scores.size(0)
but here is the problem:
I can't detect anything in the video? what should I do? Should I change the BaseTransform initialization? Now it's like this:
transform = BaseTransform(net.size, (104/256.0, 117/256.0, 123/256.0))

Same problem :(

apparently I downgraded my torchvision version and it worked

seems like that's the only way :(
well, can you tell the command ?
Can you please give details what you are trying to achieve and what are other libs you are using
Because if you are using Anaconda then in the particular environment you can select pytorch and uninstall then install the desired version. If I can help, you can connect with me on ssj.[email protected]

Sir I have mailed you.

I have edited the detection.py file by
from

if scores.dim() == 0:
continue
to

if scores.size(0) == 0:
continue
Restarted Spyder. Now Its showing me this error:

File "", line 4, in
from data import BaseTransform, VOC_CLASSES as labelmap

ImportError: No module named 'data'

Switch to proper working directory

if dets.dim() == 1
to
if dets.size(0) == 1

Thanks. It worked.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sxyxf66 picture sxyxf66  ·  4Comments

kouyichi picture kouyichi  ·  5Comments

xinyu1214 picture xinyu1214  ·  5Comments

mikejmills picture mikejmills  ·  6Comments

lmingyin picture lmingyin  ·  5Comments