Source code for defense.nab

'''
This file is modified based on the following source:
link : https://github.com/SCLBD/DBD & https://github.com/damianliumin/non-adversarial_backdoor
The defense method is called nab.
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. nab defense:
        a. self-supervised learning generates feature extractor
        b. LGA from ABL method to detect poison samples
        c. relabel the detected samples
        d. train the model using the relabelled dataset
    4. test the result and get ASR, ACC, RA 
    
Note:
    The original code use an additional clean dataset to train a auxiliary classifier for relabeling. 
    To make a fair comparison, we use the SSL model from DBD for relabeling as described in the paper.
'''

from defense.base import defense



[docs]class nab(defense): r'''Beating Backdoor Attack at Its Own Game basic structure: 1. config args, save_path, fix random seed 2. load the backdoor attack data and backdoor test data 3. NAB a. self-supervised learning generates feature extractor b. LGA from ABL method to detect poison samples c. relabel the detected samples d. train the model using the relabelled dataset 4. test the result and get ASR, ACC, RC .. code-block:: python nab = nab() parser = argparse.ArgumentParser(description=sys.argv[0]) parser = nab.set_args(parser) args = parser.parse_args() nab.add_yaml_to_args(args) args = nab.process_args(args) nab.prepare(args) nab.defense() .. Note:: @inproceedings{liu2023beating, title={Beating Backdoor Attack at Its Own Game}, author={Liu, Min and Sangiovanni-Vincentelli, Alberto and Yue, Xiangyu}, booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision}, pages={4620--4629}, year={2023}} Args: baisc args: in the base class epoch_warmup(int): epoch number of warm up for SSL batch_size_self(int): batchsize for SSL temperature(int): temperature for SSL epsilon(int): epsilon for SSL epoch_self(int): self train epochs for SSL epoch_lga(int): epochs for Poisoned Sample Detection (LGA) Phase gamma(float): gamma for Poisoned Sample Detection (LGA) Phase at "(loss - args.gamma).abs() + args.gamma" batch_size_lgd(int): batch_size for LGA '''