bingykang / Fewshot_Detection

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

About the loading model #9

Open tjzjp opened 4 years ago

tjzjp commented 4 years ago

Traceback (most recent call last): File "train_meta.py", line 87, in model.load_weights(weightfile) File "/home/zjp/Fewshot_Detection/darknet_meta.py", line 381, in load_weights start = load_conv_bn(buf, start, model[0], model[1]) File "/home/zjp/Fewshot_Detection/cfg.py", line 461, in load_conv_bn convmodel.weight.data.copy(torch.from_numpy(buf[start:start+num_w])); start = start + num_w RuntimeError: The size of tensor a (3) must match the size of tensor b (864) at non-singleton dimension 3

sorry, When I loaded your pretrained model darknet19_448.conv.23, It came out the above problem. Thank you!

bingykang commented 4 years ago

Please check your PyTorchb (0.3.1) and Python (2.7) versions.

vasgaowei commented 4 years ago

For higher version pytorch (e.g. pytorch1.2), when loading weights for Conv2D, we can reshape the 1-D weights to 4-D weights. in cfg.py, in function load_conv_bn, we can conv.model.weight.data.copy_(torch.from_numpy(buff[start:start+num_w]).reshape(conv_model.weight.data.shape))