def clean_layer_name(input_name: str,
                     strip_right_of_last_backslash: bool=True,
                     strip_numerics_after_underscores: bool=True):
    """
    There exist cases when layer names need to be concatenated in order to create new, unique
    layer names. However, the indices added to layer names designating the ith output of calling
    the layer cannot occur within a layer name apart from at the end, so this utility function
    removes these.

    Parameters
    ----------

    input_name: str, required
        A Keras layer name.
    strip_right_of_last_backslash: bool, optional, (default = True)
        Should we strip anything past the last backslash in the name?
        This can be useful for controlling scopes.
    strip_numerics_after_underscores: bool, optional, (default = True)
        If there are numerical values after an underscore at the end of the layer name,
        this flag specifies whether or not to remove them.
    """
    # Always strip anything after :, as these will be numerical
    # counts of the number of times the layer has been called,
    # which cannot be included in a layer name.
    if ':' in input_name:
        input_name = input_name.split(':')[0]
    if '/' in input_name and strip_right_of_last_backslash:
        input_name = input_name.rsplit('/', 1)[0]
    if input_name.split('_')[-1].isdigit() and strip_numerics_after_underscores:
        input_name = '_'.join(input_name.split('_')[:-1])

    return input_name