vadimkantorov / caffemodel2pytorch

Convert Caffe models to PyTorch
389 stars 84 forks source link

When prototxt does not have operation in eltwise layer, it raises error #2

Closed eebeer closed 6 years ago

eebeer commented 6 years ago

When prototxt does not have operation in eltwise layer, it raises error (ex: https://github.com/KaimingHe/deep-residual-networks/blob/master/prototxt/ResNet-50-deploy.prototxt).

In caffe.proto, default operation is set as SUM.

    caffe_proto = 'https://raw.githubusercontent.com/BVLC/caffe/master/src/caffe/proto/caffe.proto'
  File "./caffemodel2pytorch/caffemodel2pytorch.py", line 83, in __init__    module = module_constructor(param)
  File "./caffemodel2pytorch/caffemodel2pytorch.py", line 291, in <lambda>
    Eltwise = lambda param: [torch.mul, torch.add, torch.max][param['operation']]
KeyError: 'operation'
vadimkantorov commented 6 years ago

Does it work if you replace this by Eltwise = lambda param: [torch.mul, torch.add, torch.max][param.get('operation', 1)]?

vadimkantorov commented 6 years ago

I put this in!

vadimkantorov commented 6 years ago

Also please mind that I do not support BatchNorm layer. But feel free to send a PR if you implement some support.