TransForm_Kit/ModelConvert/pytorch2caffe/code/ConvertLayer_caffe.py
def UpsampleBilinear(self,pytorch_layer):
        layer = pb2.LayerParameter()
        layer.type = "Deconvolution"

        assert pytorch_layer.scale_factor[0] == pytorch_layer.scale_factor[1]
        factor = int(pytorch_layer.scale_factor[0])
        c = int(pytorch_layer.input_size[1])
        k = 2 * factor - factor % 2

        layer.convolution_param.num_output = c
        layer.convolution_param.kernel_size.extend([k])
        layer.convolution_param.stride.extend([factor])
        layer.convolution_param.pad.extend([int(math.ceil((factor - 1) / 2.))])
        layer.convolution_param.group = c
        layer.convolution_param.weight_filler.type = 'bilinear'
        layer.convolution_param.bias_term = False

        learning_param = pb2.ParamSpec()
        learning_param.lr_mult = 0
        learning_param.decay_mult = 0
        layer.param.extend([learning_param])

        """ Init weight blob of filter kernel """
        blobs_weight = FillBilinear(c, k)
        layer.blobs.extend([self.as_blob(blobs_weight)])

        return layer
 Init weight blob of filter kernel 
Init weight blob of filter kernel
Init weight blob of filter kernel
def UpsampleBilinear(self,pytorch_layer):
        layer = pb2.LayerParameter()
        layer.type = "Deconvolution"
        assert pytorch_layer.scale_factor[0] == pytorch_layer.scale_factor[1]
        factor = int(pytorch_layer.scale_factor[0])
        c = int(pytorch_layer.input_size[1])
        k = 2 * factor - factor % 2
        layer.convolution_param.num_output = c
        layer.convolution_param.kernel_size.extend([k])
        layer.convolution_param.stride.extend([factor])
        layer.convolution_param.pad.extend([int(math.ceil((factor - 1) / 2.))])
        layer.convolution_param.group = c
        layer.convolution_param.weight_filler.type = 'bilinear'
        layer.convolution_param.bias_term = False
        learning_param = pb2.ParamSpec()
        learning_param.lr_mult = 0
        learning_param.decay_mult = 0
        layer.param.extend([learning_param])
        blobs_weight = FillBilinear(c, k)
        layer.blobs.extend([self.as_blob(blobs_weight)])
        return layer
def UpsampleBilinear ( self , pytorch_layer ) : layer = pb2 . LayerParameter ( ) layer . type = "Deconvolution" assert pytorch_layer . scale_factor [ 0 ] == pytorch_layer . scale_factor [ 1 ] factor = int ( pytorch_layer . scale_factor [ 0 ] ) c = int ( pytorch_layer . input_size [ 1 ] ) k = 2 * factor - factor % 2 layer . convolution_param . num_output = c layer . convolution_param . kernel_size . extend ( [ k ] ) layer . convolution_param . stride . extend ( [ factor ] ) layer . convolution_param . pad . extend ( [ int ( math . ceil ( ( factor - 1 ) / 2. ) ) ] ) layer . convolution_param . group = c layer . convolution_param . weight_filler . type = 'bilinear' layer . convolution_param . bias_term = False learning_param = pb2 . ParamSpec ( ) learning_param . lr_mult = 0 learning_param . decay_mult = 0 layer . param . extend ( [ learning_param ] ) blobs_weight = FillBilinear ( c , k ) layer . blobs . extend ( [ self . as_blob ( blobs_weight ) ] ) return layer
Init weight blob of filter kernel
Init weight blob of filter kernel
""" Init weight blob of filter kernel """
self
pytorch_layer