# SAM-enhanced-PSD

## Installation

You can run the following script to configure the necessary environment.

```
conda create -n sam_psd python=3.8
conda activate sam_psd
sh ./sh/install.sh
```

## Quick Start

### SAM Training

Prepare poisoned dataset
```
python ./attack/badnet.py --save_folder_name badnet_0_05 --pratio 0.05 --model resnet18_cifar --dataset cifar10 --epochs 2
```

SAM training
```
python ./attack/sam_attack.py --result_file badnet_0_05 --save_folder_name samori_badnet_0_05_0_1 --model resnet18_cifar --dataset cifar10
```

### Get backdoor related feature

```
python ./detection_pretrain/samde.py --result_file samori_badnet_0_05_0_1 --model resnet18_cifar --dataset cifar10
```

### Detection with SAM-enhanced PSD

```
python ./detection_pretrain/ac_pca.py --result_file samori_badnet_0_05_0_1 --model resnet18_cifar --dataset cifar10 --variance True
```