import logging


def eliminate_loaded_param(loaded_state, eliminate):
    """Remove all parameters that have a the name as part of string in eliminate list.
    :param loaded_state: An OrderDict after loaded parameters with torch.load()
    :param eliminate: A list of string that used to detect parameters for removing.
    :return loaded_state: An OrderDict after freeze and eliminated.
    """
    assert type(eliminate) == list
    eliminate_list = []
    kept_list = []
    for key, value in loaded_state.items():
        if any(i in key for i in eliminate):
            # Cannot remove key during this for loop.
            eliminate_list.append(key)
        else:
            kept_list.append(key)
            logging.info('{} was kept.'.format(key))
    for i in eliminate_list:
        del loaded_state[i]
        logging.info('{} was removed.'.format(i))
    logging.info('########################################################')
    return loaded_state, kept_list