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

RuntimeError: The size of tensor a (13) must match the size of tensor b (70135) at non-singleton dimension 3 #42

Open
bahulkark opened this issue Jul 3, 2020 · 9 comments

Comments

@bahulkark
Copy link

I am trying to implement the code in Google Colab. I am getting this error, I had a similar issue in cgf.py but I solved it.
Below is the output and error that I am getting after running train_meta.py
!python train_meta.py cfg/metayolo.data cfg/darknet_dynamic.cfg cfg/reweighting_net.cfg darknet19_448.conv.23

/content/Fewshot_Detection/data/coco.names
('save_interval', 10)
['bird', 'bus', 'cow', 'motorbike', 'sofa']
('base_ids', [0, 1, 3, 4, 6, 7, 8, 10, 11, 12, 14, 15, 16, 18, 19])
logging to backup/metayolofix_novel0_neg1
('class_scale', 1)
layer filters size input output
0 conv 32 3 x 3 / 1 416 x 416 x 3 -> 416 x 416 x 32
1 max 2 x 2 / 2 416 x 416 x 32 -> 208 x 208 x 32
2 conv 64 3 x 3 / 1 208 x 208 x 32 -> 208 x 208 x 64
3 max 2 x 2 / 2 208 x 208 x 64 -> 104 x 104 x 64
4 conv 128 3 x 3 / 1 104 x 104 x 64 -> 104 x 104 x 128
5 conv 64 1 x 1 / 1 104 x 104 x 128 -> 104 x 104 x 64
6 conv 128 3 x 3 / 1 104 x 104 x 64 -> 104 x 104 x 128
7 max 2 x 2 / 2 104 x 104 x 128 -> 52 x 52 x 128
8 conv 256 3 x 3 / 1 52 x 52 x 128 -> 52 x 52 x 256
9 conv 128 1 x 1 / 1 52 x 52 x 256 -> 52 x 52 x 128
10 conv 256 3 x 3 / 1 52 x 52 x 128 -> 52 x 52 x 256
11 max 2 x 2 / 2 52 x 52 x 256 -> 26 x 26 x 256
12 conv 512 3 x 3 / 1 26 x 26 x 256 -> 26 x 26 x 512
13 conv 256 1 x 1 / 1 26 x 26 x 512 -> 26 x 26 x 256
14 conv 512 3 x 3 / 1 26 x 26 x 256 -> 26 x 26 x 512
15 conv 256 1 x 1 / 1 26 x 26 x 512 -> 26 x 26 x 256
16 conv 512 3 x 3 / 1 26 x 26 x 256 -> 26 x 26 x 512
17 max 2 x 2 / 2 26 x 26 x 512 -> 13 x 13 x 512
18 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024
19 conv 512 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 512
20 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024
21 conv 512 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 512
22 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024
23 conv 1024 3 x 3 / 1 13 x 13 x1024 -> 13 x 13 x1024
24 conv 1024 3 x 3 / 1 13 x 13 x1024 -> 13 x 13 x1024
25 route 16
26 conv 64 1 x 1 / 1 26 x 26 x 512 -> 26 x 26 x 64
27 reorg / 2 26 x 26 x 64 -> 13 x 13 x 256
28 route 27 24
29 conv 1024 3 x 3 / 1 13 x 13 x1280 -> 13 x 13 x1024
30 dconv 1024 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x1024
31 conv 30 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 30
32 detection

layer filters size input output
0 conv 32 3 x 3 / 1 416 x 416 x 4 -> 416 x 416 x 32
1 max 2 x 2 / 2 416 x 416 x 32 -> 208 x 208 x 32
2 conv 64 3 x 3 / 1 208 x 208 x 32 -> 208 x 208 x 64
3 max 2 x 2 / 2 208 x 208 x 64 -> 104 x 104 x 64
4 conv 128 3 x 3 / 1 104 x 104 x 64 -> 104 x 104 x 128
5 max 2 x 2 / 2 104 x 104 x 128 -> 52 x 52 x 128
6 conv 256 3 x 3 / 1 52 x 52 x 128 -> 52 x 52 x 256
7 max 2 x 2 / 2 52 x 52 x 256 -> 26 x 26 x 256
8 conv 512 3 x 3 / 1 26 x 26 x 256 -> 26 x 26 x 512
9 max 2 x 2 / 2 26 x 26 x 512 -> 13 x 13 x 512
10 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024
11 max 2 x 2 / 2 13 x 13 x1024 -> 6 x 6 x1024
12 conv 1024 3 x 3 / 1 6 x 6 x1024 -> 6 x 6 x1024
13 glomax 6 x 6 / 1 6 x 6 x1024 -> 1 x 1 x1024
1 14554 80200 32
10
===> Number of samples (before filtring): 4952
===> Number of samples (after filtring): 4952
('num classes: ', 15)
factor: 3.0
===> Number of samples (before filtring): 14554
===> Number of samples (after filtring): 14554
('num classes: ', 15)
2020-07-03 08:55:33 epoch 0/177, processed 0 samples, lr 0.000033
/usr/local/lib/python2.7/dist-packages/torch/nn/functional.py:1351: UserWarning: nn.functional.sigmoid is deprecated. Use torch.sigmoid instead.
warnings.warn("nn.functional.sigmoid is deprecated. Use torch.sigmoid instead.")
Traceback (most recent call last):
File "train_meta.py", line 328, in
train(epoch)
File "train_meta.py", line 223, in train
loss = region_loss(output, target)
File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py", line 532, in call
result = self.forward(*input, **kwargs)
File "/content/Fewshot_Detection/region_loss.py", line 294, in forward
pred_boxes[0] = x.data + grid_x
RuntimeError: The size of tensor a (13) must match the size of tensor b (70135) at non-singleton dimension 3

@risemeup
Copy link

risemeup commented Sep 7, 2020

@bahulkark hello,I met the same mistake with you. Have you fixed it ?

@bahulkark
Copy link
Author

bahulkark commented Sep 7, 2020 via email

@tailororrr
Copy link

I met the same mistake with you

@azharshaikh06
Copy link

Anyone have a fix for this?

@cgg99
Copy link

cgg99 commented Jan 26, 2021

Is the pytorch version wrong?

@azharshaikh06
Copy link

I am using torch 1.4 and can perform the forward pass through the model error is in the regionloss.py pred_boxes[0] = x.data + grid_x here x.data is a 4D tensor while grid_x is a 2D tensor

@zhanghao5
Copy link

I am using pytorch 1.7. With the view() method I can reshape and fit in the addition
pred_boxes[0] = x.data.view(nBnAnHnW) + grid_x
pred_boxes[1] = y.data.view(nB
nAnHnW)+ grid_y
pred_boxes[2] = torch.exp(w.data).view(nBnAnHnW) * anchor_w
pred_boxes[3] = torch.exp(h.data).view(nB
nAnHnW) * anchor_h

@SoonFa
Copy link

SoonFa commented Dec 14, 2021

pred_boxes[0] = x.data.view(nB*nA*nH*nW) + grid_x
pred_boxes[1] = y.data.view(nB*nA*nH*nW) + grid_y
pred_boxes[2] = torch.exp(w.data).view(nB*nA*nH*nW) * anchor_w
pred_boxes[3] = torch.exp(h.data).view(nB*nA*nH*nW) * anchor_h

@HeuristicLU
Copy link

change region_loss.py
294-297:
pred_boxes[0] = x.data.view(nBnAnHnW) + grid_x
pred_boxes[1] = y.data.view(nB
nAnHnW) + grid_y
pred_boxes[2] = torch.exp(w.data).view(nBnAnHnW) * anchor_w
pred_boxes[3] = torch.exp(h.data).view(nB
nAnHnW) * anchor_h

and this problem can be resolved

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

8 participants