def layer_to_index(target_layer, model):
    """
    Turns the identifier of an layer into a 
    layer index, regardless if it is a str or already index

    :param target_layer: <str or int> identifier for the target layer. None will return None
    :param model: <keras.Model> The model containing the target layer

    :returns: <int> index of target layer
    """
    if target_layer is None:
        return None
    if isinstance(target_layer, str):
        for idx, layer in enumerate(model.layers):
            if layer.name == target_layer:
                return idx
    elif isinstance(target_layer, int):
        return target_layer
    else:
        raise TypeError("layer has to be int or str")

    raise Exception("Layer %s could not be found"%(str(target_layer)))