ShuangXieIrene / ssds.pytorch

Repository for Single Shot MultiBox Detector and its variants, implemented with pytorch, python3.
MIT License
571 stars 166 forks source link

trouble with dark2pth #12

Closed georgeokelly closed 5 years ago

georgeokelly commented 6 years ago

Hi, when I run the dark2pth.py, it turns out like this

convert yolov2...
Traceback (most recent call last):
  File "dark2pth.py", line 375, in <module>
    yolo_v2 = build_yolo_v2(darknet_19, feature_layer_v2, mbox_v2, 81)
  File "/home/georgeokelly/ssds.pytorch/lib/modeling/ssds/yolo.py", line 215, in build_yolo_v2
    return YOLO(base_, extras_, head_, feature_layer, num_classes)
  File "/home/georgeokelly/ssds.pytorch/lib/modeling/ssds/yolo.py", line 31, in __init__
    self.softmax = nn.Softmax(dim=-1)
TypeError: __init__() got an unexpected keyword argument 'dim'

and I don't know how to fix it.

foreverYoungGitHub commented 6 years ago

Umm. the dim is added in pytorch from 0.3.0. so check your pytorch version and update to the newest release one. Let me know whether it could fix this problem.

georgeokelly commented 6 years ago

thank you for your reply. now it's the newest one and there seem to be some mistakes when load the weightfile

convert yolov2...
layer     filters    size              input                output
    0 conv     32  3 x 3 / 1   416 x 416 x   3   ->   416 x 416 x  32
0 Conv2d(3, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
Traceback (most recent call last):
  File "dark2pth.py", line 378, in <module>
    yolo_v2 = yolo2pth(yolo_v2, './weights/yolov2.cfg', './weights/yolov2.weights')
  File "dark2pth.py", line 246, in yolo2pth
    start = load_conv_bn(buf, start, model[model_index].conv[model_sub*3], model[model_index].conv[model_sub*3+1])
  File "dark2pth.py", line 188, in load_conv_bn
    conv_model.weight.data.copy_(torch.from_numpy(buf[start:start+num_w])); start = start + num_w
RuntimeError: The expanded size of the tensor (3) must match the existing size (864) at non-singleton dimension 3

and the weightfile here is downloaded from the https://pjreddie.com/darknet/yolov2/

foreverYoungGitHub commented 6 years ago

which pytorch version are you used? I just test in my computer with pytorch 0.3.1. it looks ok.

The networks define looks good. The reason to generate this error is caused by mismatch between two weights. Seems weird.

georgeokelly commented 6 years ago

Hi, my pytorch is 0.4.0

print(torch.__version__)
0.4.0

and torchvision-cpu 0.2.1 The weightfile is the YOLOv2 544x544. Is there any difference between yours and that on website now?