Ssd.pytorch: Training error in multibox_loss.py, mismatch shape

Created on 28 Jan 2018  路  6Comments  路  Source: amdegroot/ssd.pytorch

When default setting, I use train.py, get the following error.

/work/ssd.py:33: UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
  self.priors = Variable(self.priorbox.forward(), volatile=True)
Loading base network...
Initializing weights...
Loading Dataset...
Training SSD on VOC0712
/work/train.py:179: UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
  targets = [Variable(anno.cuda(), volatile=True) for anno in targets]
Traceback (most recent call last):
  File "/work/train.py", line 236, in <module>
    train()
  File "/work/train.py", line 188, in train
    loss_l, loss_c = criterion(out, targets)
  File "/opt/conda/envs/pytorch-py3.5.2/lib/python3.5/site-packages/torch/nn/modules/module.py", line 357, in __call__
    result = self.forward(*input, **kwargs)
  File "/work/layers/modules/multibox_loss.py", line 97, in forward
    loss_c[pos] = 0  # filter out pos boxes for now
RuntimeError: The shape of the mask [16, 8732] at index 0 does not match the shape of the indexed tensor [139712, 1] at index 0
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/opt/conda/envs/pytorch-py3.5.2/lib/python3.5/multiprocessing/popen_fork.py", line 29, in poll
    pid, sts = os.waitpid(self.pid, flag)
  File "/opt/conda/envs/pytorch-py3.5.2/lib/python3.5/site-packages/torch/utils/data/dataloader.py", line 172, in handler
    _error_if_any_worker_fails()
RuntimeError: DataLoader worker (pid 15) is killed by signal: Terminated.

I guess the shape of "loss_c" mismatches the shape of "pos"
Can you help me to solve this problem? Thank you.

Most helpful comment

Well - I was able to start training by switching the following two lines, in multibox_loss.py (their order was reversed in the original code).

loss_c = loss_c.view(num, -1)
loss_c[pos] = 0  # filter out pos boxes for now

It works dimension-wise, and the loss seems to be decreasing for now, but I'm not sure if its the correct solution.
Any opinions?

All 6 comments

I have enter the same bug

Exactly the same for me.

I also have this error. Using PyTorch 0.4.0a0+52bd369 and Python 3.5.4

Well - I was able to start training by switching the following two lines, in multibox_loss.py (their order was reversed in the original code).

loss_c = loss_c.view(num, -1)
loss_c[pos] = 0  # filter out pos boxes for now

It works dimension-wise, and the loss seems to be decreasing for now, but I'm not sure if its the correct solution.
Any opinions?

Any news on this?

Any suggestion?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xinyu1214 picture xinyu1214  路  5Comments

Elyorcv picture Elyorcv  路  4Comments

JingpengSun picture JingpengSun  路  4Comments

chienyiwang picture chienyiwang  路  3Comments

isalirezag picture isalirezag  路  4Comments