bingykang / Fewshot_Detection

Few-shot Object Detection via Feature Reweighting
https://arxiv.org/abs/1812.01866
526 stars 111 forks source link

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 4 years ago

DL-Alva commented 4 years ago

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 commented 4 years ago

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

bingykang commented 4 years ago

Yes.

DL-Alva commented 4 years ago

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 commented 4 years ago

Are you using the cfg files in the instruction?

DL-Alva commented 4 years ago

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

PCH10507323 commented 4 years ago

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

DL-Alva commented 4 years ago

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 commented 4 years ago

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

DL-Alva commented 4 years ago

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

christegho commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

90000mileswind commented 4 years ago

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.runningmean.copy(torch.from_numpy(buf[start:start+num_b])); start = start + num_b 454 bn_model.runningvar.copy(torch.from_numpy(buf[start:start+num_b])); start = start + num_b --> 455 convmodel.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改成一致的 convmodel.weight.data.copy(torch.from_numpy(buf[start:start+num_w]).view(size_conv)); start = start + num_w

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

Fly-dream12 commented 4 years ago

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

MichaelXin commented 4 years ago

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 commented 3 years ago

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

NHW2017 commented 3 years ago

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 commented 3 years ago

It is OK using pytorch0.3.1-py2.7

VinhLoiIT commented 3 years ago

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 commented 2 years ago

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