我正在尝试使用caffe中的Deconvolution-Layer来进行ND-UnPooling。但是,不支持bilinear
重量填充。对于3D-Un-Poooling,我做了:
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(通道x深度x高度x宽度)中填充ND-Unpooling的权重。我可以省略重量填充物,否则会产生不良结果?
修改
他们在这里使用Python的二维双线性填充物:(链接)[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专家。这是正确的,还是可以有更简单的解决方案?