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

This is because of what #327

Open
tom666tom666 opened this issue Apr 22, 2019 · 6 comments
Open

This is because of what #327

tom666tom666 opened this issue Apr 22, 2019 · 6 comments

Comments

@tom666tom666
Copy link

tom666tom666 commented Apr 22, 2019

Traceback (most recent call last):
File "train.py", line 275, in
train()
File "train.py", line 198, in train
loss_l, loss_c = criterion(out, targets)
File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py", line 491, in call
result = self.forward(*input, **kwargs)
File "/home/qiuyj/SSD/layers/modules/multibox_loss.py", line 101, in forward
loss_c[pos] = 0 # filter out pos boxes for now
RuntimeError: The shape of the mask [1, 8732] at index 0 does not match the shape of the indexed tensor [8732, 1] at index 0

use VOC dataset
`

@qigtang
Copy link

qigtang commented May 10, 2019

having the same problem here.

@wjourney
Copy link

I have the same problem. Have you solved it?

@qigtang
Copy link

qigtang commented May 20, 2019

I changed the code the following way, seems working fine for me.

@@ -95,8 +95,8 @@ class MultiBoxLoss(nn.Module):
         loss_c = log_sum_exp(batch_conf) - batch_conf.gather(1, conf_t.view(-1, 1))

         # Hard Negative Mining
-        loss_c[pos] = 0  # filter out pos boxes for now
         loss_c = loss_c.view(num, -1)
+        loss_c[pos] = 0  # filter out pos boxes for now
         _, loss_idx = loss_c.sort(1, descending=True)
         _, idx_rank = loss_idx.sort(1)
         num_pos = pos.long().sum(1, keepdim=True)

@yuanshengyu
Copy link

I changed the code the following way, seems working fine for me.

@@ -95,8 +95,8 @@ class MultiBoxLoss(nn.Module):
         loss_c = log_sum_exp(batch_conf) - batch_conf.gather(1, conf_t.view(-1, 1))

         # Hard Negative Mining
-        loss_c[pos] = 0  # filter out pos boxes for now
         loss_c = loss_c.view(num, -1)
+        loss_c[pos] = 0  # filter out pos boxes for now
         _, loss_idx = loss_c.sort(1, descending=True)
         _, idx_rank = loss_idx.sort(1)
         num_pos = pos.long().sum(1, keepdim=True)

it works fine for me too. But I meet another problem, Loss keeps NAN

@J0hannB
Copy link

J0hannB commented Dec 13, 2019

it works fine for me too. But I meet another problem, Loss keeps NAN

Same problem here.

Maybe we're doing something else wrong that causes the error in the first place? Moving the loss_c[pos] = 0 line might be fixing a symptom, not the original issue.

@J0hannB
Copy link

J0hannB commented Dec 13, 2019

I was able to fix my nan issue.

My solution: #173 (comment)

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

No branches or pull requests

5 participants