前言:
膨脹卷積操作是指將卷積核擴張到指定尺寸,並將原卷積核中沒有佔用的區域用零填充(如下圖所示)。
膨脹卷積計算公式:
膨脹的卷積核尺寸 = 膨脹係數*(原始卷積核尺寸-1)+1
代碼實現:
import tensorflow as tf
import tensorflow.contrib.slim as slim
def conv_bn_relu(x,out_channel,kernel_size,stride=1,dilation=1):
with tf.variable_scope(None,'conv_bn_relu'):
x = slim.conv2d(x,out_channel,kernel_stride,rate=dilation,biases_initializer=None,
activation_fn=None)
x = slim.batch_norm(x,activate_fn=tf.nn.relu,fused=False)
return x
其中,參數dilation表示卷積核的膨脹係數,默認值爲1,表示不做膨脹卷積操作。