Source code for defense.dbd

'''
This file is modified based on the following source:
link : https://github.com/SCLBD/DBD
The defense method is called dbd.
The license is bellow the code

The update include:
    1. data preprocess and dataset setting
    2. model setting
    3. args and config
    4. save process
    5. new standard: robust accuracy
    6. add some new backdone such as mobilenet efficientnet and densenet, reconstruct the backbone of vgg and preactresnet
    7. Different data augmentation (transform) methods are used
    8. rewrite the dateset
basic sturcture for defense method:
    1. basic setting: args
    2. attack result(model, train data, test data)
    3. dbd defense:
        a. self-supervised learning generates feature extractor
        b. learning model using extracted features
        c. the samples with poor confidence were excluded, and semi-supervised learning was used to continue the learning model
    4. test the result and get ASR, ACC, RA 
'''

from defense.base import defense

[docs]class dbd(defense): r"""Backdoor Defense Via Decoupling The Training Process basic structure: 1. config args, save_path, fix random seed 2. load the backdoor attack data and backdoor test data 3. dbd defense: a. self-supervised learning generates feature extractor b. learning model using extracted features c. the samples with poor confidence were excluded, and semi-supervised learning was used to continue the learning model 4. test the result and get ASR, ACC, RC with regard to the chosen threshold and interval .. code-block:: python parser = argparse.ArgumentParser(description=sys.argv[0]) dbd.add_arguments(parser) args = parser.parse_args() dbd_method = dbd(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 = dbd_method.defense(args.result_file) .. Note:: @article{huang2022backdoor, title={Backdoor defense via decoupling the training process}, author={Huang, Kunzhe and Li, Yiming and Wu, Baoyuan and Qin, Zhan and Ren, Kui}, journal={arXiv preprint arXiv:2202.03423}, year={2022}} Args: baisc args: in the base class epoch_self (int): the epoch of warmup during the self-supervised learning batch_size_self (int): the batch size of self-supervised learning temperature (float): the temperature in the loss function of self-supervised learning epsilon (float): the threshold of the presuppossed ratio of the backdoor data to separate the poisoned data in the semi-supervised learning (please be careful to choose the threshold) epoch_warmup (int): the epoch of warmup during the semi-supervised learning config_pretrain (str): the path of the config file of the self-supervised learning config_semi (str): the path of the config file of the semi-supervised learning """