defense.spectral
- class spectral[source]
Bases:
defense
Spectral Signatures in Backdoor Attacks
basic structure:
config args, save_path, fix random seed
load the backdoor attack data and backdoor test data
load the backdoor model
- spectral defense:
prepare the model and dataset
get the activation as representation for each data
detect the backdoor data by the SVD decomposition
retrain the model with remaining data
test the result and get ASR, ACC, RC
parser = argparse.ArgumentParser(description=sys.argv[0]) spectral.add_arguments(parser) args = parser.parse_args() spectral_method = spectral(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 = spectral_method.defense(args.result_file)
Note
@article{tran2018spectral, title={Spectral signatures in backdoor attacks}, author={Tran, Brandon and Li, Jerry and Madry, Aleksander}, journal={Advances in neural information processing systems}, volume={31}, year={2018}}
- Parameters:
args (baisc) – in the base class
percentile – the percentile of the singular value
target_label – the target label of the backdoor data(the default is None, which means all the labels are possible target labels)