参考:https://blog.csdn.net/g11d111/article/details/101781549
在做deconvolution的时候,因为kernel size和stride各种值组合可能会出现uneven overlap的情况,这样会导致失真,并且这种情况是很容易发生的。下图中黑色点和灰色点即为uneven overlap的点。
并且在网络中,它不仅不会避免这类问题,还甚至会学习导致导致相似失真的卷积核。
那么要解决这样的问题有两种方法:(1)确保kernel size能被strides整除,产生的效果如下
这样overlap的点也是均匀分布的
(2)另一种方式是two-stage: 1) 用一般的upsample方法(最近邻, 双线性插值等)进行resize, 对特征图进行放大 2) 在第1)步得到的放大的特征图基础上进行卷积.。
实验表明,最近邻上采样+卷积效果是最好的,用resize_conv2d代替转置卷积计算,代码如下:
def resize_conv2d(x, input_filters, output_filters, kernel, strides, training):
with tf.variable_scope('conv_transpose'):
height = x.get_shape()[1].value if training else tf.shape(x)[1]
width = x.get_shape()[2].value if training else tf.shape(x)[2]
new_height = height * strides * 2
new_width = width * strides * 2
x_resized = tf.image.resize_images(x, [new_height, new_width], tf.image.ResizeMethod.NEAREST_NEIGHBOR)
# shape = [kernel, kernel, input_filters, output_filters]
# weight = tf.Variable(tf.truncated_normal(shape, stddev=0.1), name='weight')
return conv2d(x_resized, input_filters, output_filters, kernel, strides)