xxradon / PytorchToCaffe

Pytorch model to caffe model, supported pytorch 0.3, 0.3.1, 0.4, 0.4.1 ,1.0 , 1.0.1 , 1.2 ,1.3 .notice that only pytorch 1.1 have some bugs
MIT License
782 stars 224 forks source link

caffe_analyser不支持反卷积 #80

Open bigbai0210 opened 4 years ago

bigbai0210 commented 4 years ago

analysis.layers中不包含Deconv这一类,这个补丁如何打呢?

bigbai0210 commented 4 years ago

补丁已经打上了,需要改动analysis/CaffeA.py,具体如下: 将源代码中的: if layer.type == 'Convolution': param = layer.convolution_param out = Conv(blob_dict[layer.bottom[0]], param.kernel_size, param.num_output, param.stride, param.pad, None, layer.name, group_size=param.group) 替换为: if layer.type in ['Convolution', 'Deconvolution']: param = layer.convolution_param out = Conv(blob_dict[layer.bottom[0]], param.kernel_size, param.num_output, param.stride, param.pad, None, layer.name, group_size=param.group, transpose=layer.type == 'Deconvolution') 即可

LightToYang commented 4 years ago

this repor already contains Deconv type

def _conv_transpose2d(raw,input, weight, bias=None, stride=1, padding=0, output_padding=0, groups=1, dilation=1):
    x=raw(input, weight, bias, stride, padding, output_padding, groups, dilation)
    name=log.add_layer(name='conv_transpose')
    log.add_blobs([x],name='conv_transpose_blob')
    layer=caffe_net.Layer_param(name=name, type='Deconvolution',
                                bottom=[log.blobs(input)], top=[log.blobs(x)])
    layer.conv_param(x.size()[1],weight.size()[2:],stride=_pair(stride),
                     pad=_pair(padding),dilation=_pair(dilation),bias_term=bias is not None, groups = groups)
    if bias is not None:
        layer.add_data(weight.cpu().data.numpy(),bias.cpu().data.numpy())
    else:
        layer.param.convolution_param.bias_term=False
        layer.add_data(weight.cpu().data.numpy())
    log.cnet.add_layer(layer)
    return x