import tensorflow as tf

                              collections=[tf.GraphKeys.WEIGHTS, tf.GraphKeys.GLOBAL_VARIABLES])
    return var


def conv(inp, name, size, out_channels, strides=[1, 1, 1, 1],
         dilation=None, padding='SAME', apply_relu=True, alpha=0.0,bias=True,
         initializer=tf.contrib.layers.xavier_initializer_conv2d()):
    
    batch_size = inp.get_shape().as_list()[0]
    res1 = inp.get_shape().as_list()[1]
    res2 = inp.get_shape().as_list()[1]
    in_channels = inp.get_shape().as_list()[3]
    
    with tf.variable_scope(name):
        W = get_variable("W", shape=[size, size, in_channels, out_channels], dtype=tf.float32,
                         initializer=initializer, regularizer=tf.nn.l2_loss)
        b = get_variable("b", shape=[1, 1, 1, out_channels], dtype=tf.float32,
                         initializer=tf.zeros_initializer(),trainable=bias)
        
        if dilation:
            assert(strides == [1, 1, 1, 1])
            out = tf.add(tf.nn.atrous_conv2d(inp, W, rate=dilation, padding=padding), b, name='convolution')
            out.set_shape([batch_size, res1, res2, out_channels])
        else:
            out = tf.add(tf.nn.conv2d(inp, W, strides=strides, padding=padding), b, name='convolution')
        
