I am trying to use the Deconvolution-Layer in caffe to do ND-UnPooling. However, bilinear
weight filling is not supported. For 3D-Un-Poooling I do:
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"
}
}
}
How do you fill the weights for ND-Unpooling as in 4D-Unpooling (channels x depth x height x width). Can I just ommit the weight filler or will this produce bad results?
EDIT
Here they are using a 2D bilinear filler with Python: (link)[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
My approach to transfer this to 3D is following:
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
However, I am not a Python expert. Is that correct, or might there be an easier solution?