# SOAR: Second-Order Adversarial Regularization

## Requirements

To install requirements:

```setup
conda env create -f neurips.yml
```
Download [conda](https://www.anaconda.com/)

## Training

To train the model(s) in the paper, run this command:

```standard training
python main.py --method "standard"\
				--dataset "cifar10"\
				--epoch 200\
				--lr 0.1\
				--lr_update "multistep"\
				--seed 1\
				--pretrain ""
```
```soar training from a particular pretrained model
python main.py --method "soar"\
				--dataset "cifar10"\
				--epoch 200\
				--lr 0.004\
				--lr_update "100ep"\
				--pretrain "./pretrained/standard/model_sd0.pt"\
				--s_init pgd1\
				--s_eps 0.016\
				--s_step_size 0.01\
				--s_clip 10\
				--seed 1
```

You can play around with the hyperparameters in the .sh files for each training method. Some additional default hyperparameters are stored in options/default.yaml

## Evaluation

To evaluate my model on CIFAR10, run:

```standard accuracy
python eval.py --method "standard"\
				--dataset "cifar10"\
				--path "./pretrained/soar/model_sd0.pt"
```

```PGD20 accuracy
python eval.py --method "pgd"\
				--dataset "cifar10"\
				--pgd_step 20\
				--path "./pretrained/soar/model_sd0.pt"
```

```transferred pgd20 attack from a standard trained model
python eval.py --method "transfer"\
				--dataset "cifar10"\
				--pgd_step 20\
				--path "./pretrained/soar/model_sd0.pt"\
				--transfer_path "./pretrained/standard/model_sd0.pt"
```

```SimBA attack
python eval.py --method "simba"\
				--dataset "cifar10"\
				--path "./pretrained/soar/model_sd0.pt"
```

You can change the path to the new model you just trained. :D

## Pre-trained Models

Pre-trained models are stored in ./pretrained/ .

## Results

Our model achieves the following performance on :

### [CIFAR10](https://www.cs.toronto.edu/~kriz/cifar.html)

| Model name         |     Standard    | 		PGD20   |
| ------------------ |---------------- | -------------- |
|       SOAR  		 |     87.95%      |      56.06%    |

### [SVHN](http://ufldl.stanford.edu/housenumbers/)

| Model name         |     Standard    | 		PGD20   |
| ------------------ |---------------- | -------------- |
|       SOAR  		 |     91.23%      |      58.99%    |

