Source code for defense.ft

'''
This file implements the defense method called finetuning (ft), which is a standard fine-tuning that uses clean data to finetune the model.

basic sturcture for defense method:
    1. basic setting: args
    2. attack result(model, train data, test data)
    3. ft defense:
        a. get some clean data
        b. retrain the backdoor model
    4. test the result and get ASR, ACC, RC 
'''

from defense.base import defense

[docs]class ft(defense): r"""Basic class for ft defense method. basic structure: 1. config args, save_path, fix random seed 2. load the backdoor attack data and backdoor test data 3. load the backdoor model 4. ft defense: a. get some clean data b. retrain the backdoor model 5. test the result and get ASR, ACC, RC .. code-block:: python parser = argparse.ArgumentParser(description=sys.argv[0]) ft.add_arguments(parser) args = parser.parse_args() ft_method = ft(args) if "result_file" not in args.__dict__: args.result_file = 'one_epochs_debug_badnet_attack' elif args.result_file is None: args.result_file = 'one_epochs_debug_badnet_attack' result = ft_method.defense(args.result_file) .. Note:: Args: baisc args: in the base class ratio (float): the ratio of clean data loader index (str): index of clean data """