Home

Awesome

PatchBackdoor

The PatchBackdoor codebase is associated with the paper 'PatchBackdoor: Backdoor Attack against Deep Neural Networks without Model Modification'.

Prerequisite

We have not tested our code with other versions of torch/torchvision. However, since we do not utilize some sensitive functions from torch, it is likely that close versions will work as well. In most cases, as long as you can run

import torch
a=torch.rand((3,224,224),device='cuda')

, it is highly likely that your environment will be able to run our code successfully

Example Usage

python TrainPatchCifar10.py
or 
python TrainPatchImagenette.py

should work. It will keep printing the data of training. An example of data is shown below:

train loss: 
38614.067; 55173.612; sumLoss: 93787.679
train Top1: 
0.82;  0.87;  
vali Top1: 
0.78;  0.87;  
raio:
1.00;  1.21;    

The first column includes the clean accuracy and its corresponding ratio, while the second column represents the attack success rate and its ratio. For more information on ratios, please refer to the comment in PatchTrainer.

Running the code will generate a file named 'result.report'. By loading this file using torch.load, you will be able to view details such as the patch, trained model, testing data, and more

Data preparation (Optional)

  1. Download Imagenette from https://github.com/fastai/imagenette. Or precisely https://s3.amazonaws.com/fast-ai-imageclas/imagenette2-320.tgz
  2. If you are Windows user, simply unzip it with Bandizip or any other unzip tools
  3. If you are Linux or mac user,
tar -zxvf imagenette2-320.tgz

should work. Please remember the directory of dataset.

Content

Transformations(PatchApply.py)

PatchOnlyProtocol
<p > <img src="./markdown/pic.png" width=1024 title="First training image in Cifar 10"> </p> <p > <img src="./markdown/patch.png" width=1024 title="Just a patch, nothing more"> </p> <p > <img src="./markdown/patchOnly.png" width=1024 title="patched image"> </p>
import torchvision.transforms

torchvision.transforms.Resize((24,24))
PatchAndTriggerProtocol
patchedImage=patchOnly(pic,patch)
getTransformations
<p > <img src="./markdown/patchApply.PNG" width=883 title="How patch and trigger is applied"> </p>

Training and Testing(PatchTrainer.py)

CodeBook
Test
transformation(pic,patch)
train
<p > <img src="./markdown/train.PNG" title="training process"> </p>
patchedPic=transformation[i](pic,patch)

More

If you still have some question, please see TrainPatchCifar10 as a good example of using the code

If you still do not understand after that, please let me know by leaving an Issue or send me Email yuanyz21@mails.tsinghua.edu.cn

This is my first paper. If you think something could be improved, please let me know!

Personal

This paper took two years to finish. I know I am kind of Procrastination. I am pretty exciting when I know this paper is accepted. I want to share a quote with everyone here.

It is the time you have wasted for your rose that makes your rose so important

<p > <img src="./markdown/personal.jpg" title="My first rose"> </p>