Description: A python implementation of TA-LBF proposed in "Targeted Attack against Deep Neural Networks via Flipping Limited Weight Bits"


### Quick Start

Set the "cifar_root" in the "config.py" firstly.

Running the below command will attack a sample (3676-th sample in the CIFAR-10 validation set) into class 0.

> python attack_once.py --target-class 0 --attack-idx 3676 --lam 100 --k 5

You can set "target-class" and "attack-idx" to perform TA-LBF on a specific sample.



### Reproduce Our Results

Set the "cifar_root" in the "config.py" firstly.

Running the below command can reproduce our results in attacking the 8-bit quantized ResNet on CIFAR-10.

> python attack_reproduce.py 

"cifar_attack_info.txt" includes the 1,000 attacked samples and their target classes used in our experiments.
Format: [ [target-class, sample-index],
	      [target-class, sample-index],
	       ...
	      [target-class, sample-index] ]
where "sample-index" is the index the of this attacked sample in CIFAR-10 validation set.



### Others 

We provide the pretrained 8-bit quantized ResNet on CIFAR-10. -> cifar_resnet_quan_8/model.th

The main requirments is below:
	python==3.6.1
	pytorch==1.5.0
	numpy==1.18.1
	bitstring==3.1.7
	argparse==1.1
	torchvision==0.6.0

We also provide the following command to install dependencies before running the code:
> pip install -r requirements.txt