import tensorflow as tf

try:
    import cPickle
except:
    import _pickle as cPickle


def relu(x, name, alpha):
    if alpha > 0:
        return tf.maximum(alpha * x, x, name=name)
    else:
        return tf.nn.relu(x, name=name)


def get_variable(name, shape, dtype, initializer, trainable=True, regularizer=None):
    with tf.device('/cpu:0'):
        var = tf.get_variable(name, shape=shape, dtype=dtype,
                              initializer=initializer, regularizer=regularizer, trainable=trainable,
                              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]
