pytorch 转 caffe

目录

一 工具

二 修改pytorch2caffe

三 调用工具,将pytorch模型转为caffe

四 测试转换的caffe模型


一 工具

使用pytorch2caffe(稍加修改)

原作者的:https://github.com/longcw/pytorch2caffe

环境:pytoch 0.2.0_0, python 2.7

修改的:

二 修改pytorch2caffe

  1. ' nn.ConvTranspose2d':-->'Deconvolution',

      nn.ConvTranspose2d(
                in_channels=self.inplanes,
                out_channels=self.inplanes,
                kernel_size=kernel,
                stride=2,
                padding=padding,
                groups=self.inplanes,
                output_padding=output_padding,
                bias=self.deconv_with_bias)

具体实现:

elif parent_type == 'ConvNdBackward':
    # Only for UpsamplingCaffe
    if func.transposed is True and func.next_functions[1][0] is None:
        # UpsamplingBilinear2d 
    elif func.transposed is True and func.next_functions[1][0] is not None:
        # Deconvolution, w is not none

2、DepthwiseConvolution

        elif parent_type == 'ConvNdBackward':
           ...
            else:
                ...
                if func.groups!=1:
                    layer['type'] = 'DepthwiseConvolution'

nn.Conv2d(plane, plane,
                                     kernel_size=1, stride=1, groups=plane,
                                     padding=0, dilation=1, bias=False) 

!然而当 空洞卷积时(dilation!=1)计算出错

三 调用工具,将pytorch模型转为caffe

 转换特定的模型在文件夹“hrnet2caffe”中实现

例如:hrnet2caffe/lpn_liteseg_simple2caffe.py

四 测试转换的caffe模型

CUDA_VISIBLE_DEVICES=1 python tools/test_seg_pose.py --cfg experiments/lip/LightPose_res50.yaml TEST.BATCH_SIZE_PER_GPU 1

 

你可能感兴趣的:(pytorch 转 caffe)