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

Can you offer converting code for converting yolov3 weight model to caffe format? #2

Open
xingyewuyu opened this issue Jun 23, 2018 · 8 comments

Comments

@xingyewuyu
Copy link

@makefile , Thank you for your codes. Can you offer converting code for converting yolov3 weight model to caffe format? What's more , yolov3 tiny model is more smaller, will you update it in the near future?

@makefile
Copy link
Owner

The script is in dir 'examples/YOLO'. I think the script also works for tiny yolo or needs some modification.

@moyans moyans mentioned this issue Jul 18, 2018
@claudehang
Copy link

Hi, dude! I tried to convert yolov3 darknet model using ./examples/YOLO/darknet2caffe.py but get this error:

unknow layer type yolo 
OrderedDict([('bottom', 'layer80-conv'), ('top', 'layer84-route'), ('name', 'layer84-route'), ('type', 'Concat')])
84
2
OrderedDict([('bottom', 'layer85-conv'), ('top', 'layer86-upsample'), ('name', 'layer86-upsample'), ('type', 'Module'), ('module_param', OrderedDict([('module', 'modules'), ('type', 'Upsample'), ('param_str', "{'scale': 2}")]))])
('upsample:', 86)
{1: 'layer1-conv', 2: 'layer2-conv', 3: 'layer3-conv', 4: 'layer4-conv', 5: 'layer5-shortcut', 6: 'layer6-conv', 7: 'layer7-conv', 8: 'layer8-conv', 9: 'layer9-shortcut', 10: 'layer10-conv', 11: 'layer11-conv', 12: 'layer12-shortcut', 13: 'layer13-conv', 14: 'layer14-conv', 15: 'layer15-conv', 16: 'layer16-shortcut', 17: 'layer17-conv', 18: 'layer18-conv', 19: 'layer19-shortcut', 20: 'layer20-conv', 21: 'layer21-conv', 22: 'layer22-shortcut', 23: 'layer23-conv', 24: 'layer24-conv', 25: 'layer25-shortcut', 26: 'layer26-conv', 27: 'layer27-conv', 28: 'layer28-shortcut', 29: 'layer29-conv', 30: 'layer30-conv', 31: 'layer31-shortcut', 32: 'layer32-conv', 33: 'layer33-conv', 34: 'layer34-shortcut', 35: 'layer35-conv', 36: 'layer36-conv', 37: 'layer37-shortcut', 38: 'layer38-conv', 39: 'layer39-conv', 40: 'layer40-conv', 41: 'layer41-shortcut', 42: 'layer42-conv', 43: 'layer43-conv', 44: 'layer44-shortcut', 45: 'layer45-conv', 46: 'layer46-conv', 47: 'layer47-shortcut', 48: 'layer48-conv', 49: 'layer49-conv', 50: 'layer50-shortcut', 51: 'layer51-conv', 52: 'layer52-conv', 53: 'layer53-shortcut', 54: 'layer54-conv', 55: 'layer55-conv', 56: 'layer56-shortcut', 57: 'layer57-conv', 58: 'layer58-conv', 59: 'layer59-shortcut', 60: 'layer60-conv', 61: 'layer61-conv', 62: 'layer62-shortcut', 63: 'layer63-conv', 64: 'layer64-conv', 65: 'layer65-conv', 66: 'layer66-shortcut', 67: 'layer67-conv', 68: 'layer68-conv', 69: 'layer69-shortcut', 70: 'layer70-conv', 71: 'layer71-conv', 72: 'layer72-shortcut', 73: 'layer73-conv', 74: 'layer74-conv', 75: 'layer75-shortcut', 76: 'layer76-conv', 77: 'layer77-conv', 78: 'layer78-conv', 79: 'layer79-conv', 80: 'layer80-conv', 81: 'layer81-conv', 82: 'layer82-conv', 83: 'layer82-conv', 84: 'layer84-route', 85: 'layer85-conv', 86: 'layer86-upsample'}
OrderedDict([('bottom', ['layer86-upsample', 'layer62-shortcut']), ('top', 'layer87-route'), ('name', 'layer87-route'), ('type', 'Concat')])
87
unknow layer type yolo 
OrderedDict([('bottom', 'layer92-conv'), ('top', 'layer96-route'), ('name', 'layer96-route'), ('type', 'Concat')])
96
2
OrderedDict([('bottom', 'layer97-conv'), ('top', 'layer98-upsample'), ('name', 'layer98-upsample'), ('type', 'Module'), ('module_param', OrderedDict([('module', 'modules'), ('type', 'Upsample'), ('param_str', "{'scale': 2}")]))])
('upsample:', 98)
{1: 'layer1-conv', 2: 'layer2-conv', 3: 'layer3-conv', 4: 'layer4-conv', 5: 'layer5-shortcut', 6: 'layer6-conv', 7: 'layer7-conv', 8: 'layer8-conv', 9: 'layer9-shortcut', 10: 'layer10-conv', 11: 'layer11-conv', 12: 'layer12-shortcut', 13: 'layer13-conv', 14: 'layer14-conv', 15: 'layer15-conv', 16: 'layer16-shortcut', 17: 'layer17-conv', 18: 'layer18-conv', 19: 'layer19-shortcut', 20: 'layer20-conv', 21: 'layer21-conv', 22: 'layer22-shortcut', 23: 'layer23-conv', 24: 'layer24-conv', 25: 'layer25-shortcut', 26: 'layer26-conv', 27: 'layer27-conv', 28: 'layer28-shortcut', 29: 'layer29-conv', 30: 'layer30-conv', 31: 'layer31-shortcut', 32: 'layer32-conv', 33: 'layer33-conv', 34: 'layer34-shortcut', 35: 'layer35-conv', 36: 'layer36-conv', 37: 'layer37-shortcut', 38: 'layer38-conv', 39: 'layer39-conv', 40: 'layer40-conv', 41: 'layer41-shortcut', 42: 'layer42-conv', 43: 'layer43-conv', 44: 'layer44-shortcut', 45: 'layer45-conv', 46: 'layer46-conv', 47: 'layer47-shortcut', 48: 'layer48-conv', 49: 'layer49-conv', 50: 'layer50-shortcut', 51: 'layer51-conv', 52: 'layer52-conv', 53: 'layer53-shortcut', 54: 'layer54-conv', 55: 'layer55-conv', 56: 'layer56-shortcut', 57: 'layer57-conv', 58: 'layer58-conv', 59: 'layer59-shortcut', 60: 'layer60-conv', 61: 'layer61-conv', 62: 'layer62-shortcut', 63: 'layer63-conv', 64: 'layer64-conv', 65: 'layer65-conv', 66: 'layer66-shortcut', 67: 'layer67-conv', 68: 'layer68-conv', 69: 'layer69-shortcut', 70: 'layer70-conv', 71: 'layer71-conv', 72: 'layer72-shortcut', 73: 'layer73-conv', 74: 'layer74-conv', 75: 'layer75-shortcut', 76: 'layer76-conv', 77: 'layer77-conv', 78: 'layer78-conv', 79: 'layer79-conv', 80: 'layer80-conv', 81: 'layer81-conv', 82: 'layer82-conv', 83: 'layer82-conv', 84: 'layer84-route', 85: 'layer85-conv', 86: 'layer86-upsample', 87: 'layer87-route', 88: 'layer88-conv', 89: 'layer89-conv', 90: 'layer90-conv', 91: 'layer91-conv', 92: 'layer92-conv', 93: 'layer93-conv', 94: 'layer94-conv', 95: 'layer94-conv', 96: 'layer96-route', 97: 'layer97-conv', 98: 'layer98-upsample'}
OrderedDict([('bottom', ['layer98-upsample', 'layer37-shortcut']), ('top', 'layer99-route'), ('name', 'layer99-route'), ('type', 'Concat')])
99
unknow layer type yolo 
[libprotobuf ERROR google/protobuf/text_format.cc:245] Error parsing text-format caffe.NetParameter: 2622:18: Message type "caffe.LayerParameter" has no field named "module_param".
WARNING: Logging before InitGoogleLogging() is written to STDERR
F0719 11:29:21.104534 49449 upgrade_proto.cpp:90] Check failed: ReadProtoFromTextFile(param_file, param) Failed to parse NetParameter file: my_yolov3.prototxt
*** Check failure stack trace: ***
Aborted

Not sure where is not correct. Could you give some suggestions? Many thanks!!

@makefile
Copy link
Owner

@claudehang Hi, you can remove the layer in yolov3.cfg file since it has no weight params. And yolo layer functions is implemented in test_yolov3.cpp

@claudehang
Copy link

You're just brilliant. Thanks a lot!

@claudehang
Copy link

My god, still one more error that confuses me:

I0719 15:40:28.297994 16478 net.cpp:243] This network produces output layer104-conv
I0719 15:40:28.298002 16478 net.cpp:243] This network produces output layer82-conv
I0719 15:40:28.298007 16478 net.cpp:243] This network produces output layer93-conv
I0719 15:40:28.298159 16478 net.cpp:256] Network initialization done.
Traceback (most recent call last):
  File "darknet2caffe.py", line 437, in <module>
    darknet2caffe(cfgfile, weightfile, protofile, caffemodel)
  File "darknet2caffe.py", line 59, in darknet2caffe
    start = load_conv_bn2caffe(buf, start, params[conv_layer_name], params[bn_layer_name], params[scale_layer_name])
  File "darknet2caffe.py", line 132, in load_conv_bn2caffe
    conv_param[0].data[...] = np.reshape(buf[start:start+conv_weight.size], conv_weight.shape); start = start + conv_weight.size
  File "/usr/lib64/python2.7/site-packages/numpy/core/fromnumeric.py", line 257, in reshape
    return _wrapfunc(a, 'reshape', newshape, order=order)
  File "/usr/lib64/python2.7/site-packages/numpy/core/fromnumeric.py", line 52, in _wrapfunc
    return getattr(obj, method)(*args, **kwds)
ValueError: cannot reshape array of size 135698 into shape (256,128,3,3)

What a strange shape (256, 128, 3, 3)!? I swear the .cfg and .weights files work just perfect in Darknet framework. How can I probably solve this? Many Thanks for your good advice and patience!!

@makefile
Copy link
Owner

@claudehang I'm not sure what caused this problem. Maybe your .weight file is mismatch with .cfg or there is some params in conv layer that the script cannot process correctly. And the shape (256, 128, 3, 3) is related to the input layer size. Hope this can give you some clue...

@claudehang
Copy link

Huge thanks for your sharing and supporting!!

@claudehang
Copy link

Finally figure it out :D by referring to the post here:
ChenYingpeng/caffe-yolov3#1
I rectified my .cfg file and it matched to its .weight friend now!

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

3 participants