该层具有每侧的垫4像素,但是在张量流中它仅具有“相同”和“有效”填充模式。如何在tensorflow中实现这个层?
layer {
name: "conv3"
type: "Deconvolution"
bottom: "conv26"
top: "conv3"
param {
lr_mult: 0.1
}
param {
lr_mult: 0.1
}
convolution_param {
num_output: 1
kernel_size: 9
stride: 3
pad: 4
weight_filler {
type: "gaussian"
std: 0.001
}
bias_filler {
type: "constant"
value: 0
}
}
}
您可以使用tf.pad进行自定义填充。为每个空间维度填充一个名为my_tensor
的张量,其形状为(batch_size, height, width, channels)
,两侧有四个零:
my_padded_tensor = tf.pad(
tensor=my_tensor,
paddings=tf.constant([[0, 0,], [4, 4], [4,4], [0,0]], dtype=tf.int32),
mode='CONSTANT',
constant_values=0
)