1

我正在尝试使用 caffe 中的反卷积层来进行 ND-UnPooling。但是,bilinear不支持权重填充。对于 3D-Un-Pooling,我会:

layer {
  name: "name"
  type: "Deconvolution"
  bottom: "bot"
  top: "top"
  param {
    lr_mult: 0
    decay_mult: 0
  }
  convolution_param {
    num_output: #output
    bias_term: false
    pad: 0
    kernel_size: #kernel
    group: #output
    stride: #stride
    weight_filler {
      type: "bilinear"
    }
  }
}

如何像 4D-Unpooling 一样填充 ND-Unpooling 的权重(通道 x 深度 x 高度 x 宽度)。我可以省略重量填充物还是会产生不好的结果?

编辑

在这里,他们使用 Python 的 2D 双线性填充:(链接)[ https://github.com/shelhamer/fcn.berkeleyvision.org/blob/master/surgery.py]

def upsample_filt(size):
    """
    Make a 2D bilinear kernel suitable for upsampling of the given (h, w) size.
    """
    factor = (size + 1) // 2
    if size % 2 == 1:
        center = factor - 1
    else:
        center = factor - 0.5
    og = np.ogrid[:size, :size]
    return (1 - abs(og[0] - center) / factor) * \
           (1 - abs(og[1] - center) / factor)

def interp(net, layers):
    """
    Set weights of each layer in layers to bilinear kernels for interpolation.
    """
    for l in layers:
        m, k, h, w = net.params[l][0].data.shape
        if m != k and k != 1:
            print 'input + output channels need to be the same or |output| == 1'
            raise
        if h != w:
            print 'filters need to be square'
            raise
        filt = upsample_filt(h)
        net.params[l][0].data[range(m), range(k), :, :] = filt

我将其转换为 3D 的方法如下:

def upsample_filt(size):
        """
        Make a 2D bilinear kernel suitable for upsampling of the given (h, w) size.
        """
        factor = (size + 1) // 2
        if size % 2 == 1:
            center = factor - 1
        else:
            center = factor - 0.5
        og = np.ogrid[:size, :size, :size]
        return (1 - abs(og[0] - center) / factor) * \
               (1 - abs(og[1] - center) / factor) * \
               (1 - abs(og[2] - center) / factor)

    def interp(net, layers):
        """
        Set weights of each layer in layers to bilinear kernels for interpolation.
        """
        for l in layers:
            m, k, d, h, w = net.params[l][0].data.shape
            if m != k and k != 1:
                print 'input + output channels need to be the same or |output| == 1'
                raise
            if h != w or h != d or w != d:
                print 'filters need to be square'
                raise
            filt = upsample_filt(h)
            net.params[l][0].data[range(m), range(k), :, :, :] = filt

但是,我不是 Python 专家。这是正确的,还是可能有更简单的解决方案?

4

0 回答 0