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 expanded size of the tensor (3) must match the existing size (864) at non-singleton dimension 3. Target sizes: [32, 3, 3, 3]. Tensor sizes: [864] #7

Open
DL-Alva opened this issue Oct 22, 2019 · 20 comments

Comments

@DL-Alva
Copy link

DL-Alva commented Oct 22, 2019

Sorry for troubling you. When I run train_meta.py and load weightfile, a runtimeerror occured:

logging to backup/metayolo_novel0_neg1
class_scale 1

RuntimeErrorTraceback (most recent call last)
in ()
14 region_loss = model.loss
15
---> 16 model.load_weights(weightfile)
17 model.print_network()

~/lkj项目/FSD_yolo/darknet_meta.py in load_weights(self, weightfile)
376 batch_normalize = int(block['batch_normalize'])
377 if batch_normalize:
--> 378 start = load_conv_bn(buf, start, model[0], model[1])
379 else:
380

~/lkj项目/FSD_yolo/cfg.py in load_conv_bn(buf, start, conv_model, bn_model)
453 bn_model.running_mean.copy_(torch.from_numpy(buf[start:start+num_b])); start = start + num_b
454 bn_model.running_var.copy_(torch.from_numpy(buf[start:start+num_b])); start = start + num_b
--> 455 conv_model.weight.data.copy_(torch.from_numpy(buf[start:start+num_w])); start = start + num_w
456 return start
457

RuntimeError: The expanded size of the tensor (3) must match the existing size (864) at non-singleton dimension 3. Target sizes: [32, 3, 3, 3]. Tensor sizes: [864]

Do you know what's wrong with this? Thank you so much.

@DL-Alva
Copy link
Author

DL-Alva commented Oct 22, 2019

The folder "backup" is created manually. Is that right?

@bingykang
Copy link
Owner

Yes.

@DL-Alva
Copy link
Author

DL-Alva commented Oct 22, 2019

Hi, thank you for your quickly reply. But I haven't solved the error mentioned above till now. Is it related with Broadcasting semantics in Pytorch? Thanks a lot.

@bingykang
Copy link
Owner

Are you using the cfg files in the instruction?

@DL-Alva
Copy link
Author

DL-Alva commented Oct 22, 2019

Yes, I use cfg files and change the path of train set and val set.

@PCH10507323
Copy link

Maybe you can refer to this.
https://github.com/marvis/pytorch-yolo3/issues/15

@DL-Alva
Copy link
Author

DL-Alva commented Oct 23, 2019

Thank you for your opinions. I have tried these methods mentioned in the link above but solutions didn't work.My torch version is 1.3.0.

@bingykang
Copy link
Owner

Our code is implemented with PyTorch 0.3.1 and Python 2.7. You may want to try this version.

@DL-Alva
Copy link
Author

DL-Alva commented Oct 23, 2019

Thank you for your suggestion! I think I should try it.

@christegho
Copy link

I had the same issue, so I switched to PyTorch 0.3.1 but now I get

    import torch.utils.checkpoint as cp
ImportError: No module named checkpoint

@DL-Alva Were you able to resolve the error with the The expanded size of the tensor (3) ?

if yes, how and what version of Torch did you end up using?

@christegho
Copy link

This ended up working, although not sure what I did to resolve the issue.

I did install torchvision==0.4.2, and installed torch 0.4.0 then reinstalled torch 0.3.1.

@shenglih
Copy link

shenglih commented Dec 7, 2019

torch==0.3.1, python2.7, torchvision==0.2.0 work

@90000mileswind
Copy link

Sorry for troubling you. When I run train_meta.py and load weightfile, a runtimeerror occured:

logging to backup/metayolo_novel0_neg1

class_scale 1
RuntimeErrorTraceback (most recent call last)
in ()
14 region_loss = model.loss
15
---> 16 model.load_weights(weightfile)
17 model.print_network()

~/lkj项目/FSD_yolo/darknet_meta.py in load_weights(self, weightfile)
376 batch_normalize = int(block['batch_normalize'])
377 if batch_normalize:
--> 378 start = load_conv_bn(buf, start, model[0], model[1])
379 else:
380

~/lkj项目/FSD_yolo/cfg.py in load_conv_bn(buf, start, conv_model, bn_model)
453 bn_model.running_mean.copy_(torch.from_numpy(buf[start:start+num_b])); start = start + num_b
454 bn_model.running_var.copy_(torch.from_numpy(buf[start:start+num_b])); start = start + num_b
--> 455 conv_model.weight.data.copy_(torch.from_numpy(buf[start:start+num_w])); start = start + num_w
456 return start
457

RuntimeError: The expanded size of the tensor (3) must match the existing size (864) at non-singleton dimension 3. Target sizes: [32, 3, 3, 3]. Tensor sizes: [864]

Do you know what's wrong with this? Thank you so much.

这个问题我觉得可以修改,cfg.py第456行.copy_()如下:
size_conv = conv_model.weight.data.size() # 这两行改过,将被复制的shape改成一致的
conv_model.weight.data.copy_(torch.from_numpy(buf[start:start+num_w]).view(size_conv)); start = start + num_w

copy_()复制和被复制的shape不一样,所有如果改了应该就可以。但是,我还遇到其他一些问题,或许换了pytorch的版本能解决问题!

@Fly-dream12
Copy link

Have you solved this problem? @DL-Alva @90000mileswind
I also met this problem. Thanks for your help.

@MichaelXin
Copy link

Same errors. I use cuda8, pytorch 0.3.1, python 2.7 and torchvision 0.2.0.
Have you solved this problem? @DL-Alva

@JakeZDK
Copy link

JakeZDK commented Sep 13, 2020

@90000mileswind
你好,我也是同样的问题。view(size_conv)是否与存储的预训练数据顺序一致呢?

@NHW2017
Copy link

NHW2017 commented Sep 14, 2020

Our code is implemented with PyTorch 0.3.1 and Python 2.7. You may want to try this version.

Hello, can you tell me the CUDA version you used in the test?

@mountain111
Copy link

It is OK using pytorch0.3.1-py2.7

@VinhLoiIT
Copy link

Open cfg.py file at line 455 and change to

conv_model.weight.data.copy_(torch.from_numpy(buf[start:start+num_w]).reshape_as(conv_model.weight.data)); start = start + num_w 

worked for me

@binbinlan
Copy link

Open cfg.py file at line 455 and change to

conv_model.weight.data.copy_(torch.from_numpy(buf[start:start+num_w]).reshape_as(conv_model.weight.data)); start = start + num_w 

worked for me
that really works!! thanks!!!!!!

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