Fewshot_Detection icon indicating copy to clipboard operation
Fewshot_Detection copied to clipboard

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]

Open DL-Alva opened this issue 5 years ago • 20 comments

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 avatar Oct 22 '19 02:10 DL-Alva

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

DL-Alva avatar Oct 22 '19 02:10 DL-Alva

Yes.

bingykang avatar Oct 22 '19 02:10 bingykang

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.

DL-Alva avatar Oct 22 '19 03:10 DL-Alva

Are you using the cfg files in the instruction?

bingykang avatar Oct 22 '19 03:10 bingykang

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

DL-Alva avatar Oct 22 '19 04:10 DL-Alva

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

PCH10507323 avatar Oct 22 '19 04:10 PCH10507323

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.

DL-Alva avatar Oct 23 '19 06:10 DL-Alva

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

bingykang avatar Oct 23 '19 06:10 bingykang

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

DL-Alva avatar Oct 23 '19 06:10 DL-Alva

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 avatar Nov 20 '19 14:11 christegho

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.

christegho avatar Nov 20 '19 14:11 christegho

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

shenglih avatar Dec 07 '19 06:12 shenglih

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的版本能解决问题!

90000mileswind avatar Mar 05 '20 11:03 90000mileswind

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

Fly-dream12 avatar May 13 '20 15:05 Fly-dream12

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

MichaelXin avatar Aug 31 '20 11:08 MichaelXin

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

JakeZDK avatar Sep 13 '20 15:09 JakeZDK

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?

NHW2017 avatar Sep 14 '20 12:09 NHW2017

It is OK using pytorch0.3.1-py2.7

mountain111 avatar Nov 25 '20 08:11 mountain111

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

VinhLoiIT avatar Jan 03 '21 18:01 VinhLoiIT

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!!!!!!

binbinlan avatar Oct 12 '21 04:10 binbinlan