'Returns a variable given its layer and name.
The variable must already exist.'

def get_variable(self, layer, name):

    scope = self._get_layer_str(layer)
    collection = tf.get_collection(tf.GraphKeys.VARIABLES, scope=scope)
    for var in collection:
        if (var.name[:(-2)] == ((scope + '/') + name)):
            return var
    return None
