Giter Site home page Giter Site logo

dbd's Introduction

DBD

This a Pytorch implementation of our paper "Backdoor Defense via Decoupling the Training Process".

Table of Contents:

Setup

Environments

We recommend conda as the package manager to setup the environment used in our experiments. Create the environment dbd from the environment.yml file and activate it:

conda env create -f environment.yml && conda activate dbd

Datasets

Download CIFAR-10 dataset from its official website and extract it to dataset_dir specified in the YAML configuration files.

Note: Make sure dataset_dir contains the sub-string cifar.

Log and checkpoint directories

Create saved_dir and storage_dir specified in the YAML configuration files to save logs and checkpoints respectively:

mkdir saved_data && mkdir storage

Usage

We give examples to compare the standard supervised training (No Defense) and DBD on CIFAR-10 dataset under BadNets attack with ResNet-18. Other settings can also be found in the YAML configuration files. Please have an overview before running the codes.

No Defense

Run the following script to train a backdoored model:

python supervise.py --config config/supervise/badnets/cifar10_resnet18/example.yaml \
                    --resume False \
                    --gpu 0

DBD

  1. Self-Supervised Learning

    Run the following script to train a purified feature extractor:

    python simclr.py --config config/defense/simclr/badnets/cifar10_resnet18/example.yaml \
                     --resume False \
                     --gpu 0
    
  2. Semi-Supervised Fine-tuning

    Run the following script to finetune a clean model:

    python mixmatch_finetune.py --config config/defense/mixmatch_finetune/badnets/cifar10_resnet18/example.yaml \
                                --resume False \
                                --gpu 0
    

Pretrained Models

We provide pretrained models here.

Test

Run the following script to test No Defense under BadNets attack:

python test.py --config config/supervise/badnets/cifar10_resnet18/example.yaml \
               --ckpt-dir checkpoint/supervise/badnets/cifar10_resnet18/example \
               --resume latest_model.pt \
               --gpu 0

Run the following script to test DBD under BadNets attack:

python test.py --config config/supervise/badnets/cifar10_resnet18/example.yaml \
               --ckpt-dir checkpoint/defense/mixmatch_finetune/badnets/cifar10_resnet18/example \
               --resume latest_model.pt \
               --gpu 0

Run the following script to test No Defense under Blended attack:

python test.py --config config/supervise/blend/cifar10_resnet18/example.yaml \
               --ckpt-dir checkpoint/supervise/blend/cifar10_resnet18/example \
               --resume latest_model.pt \
               --gpu 0

Run the following script to test DBD under Blended attack:

python test.py --config config/supervise/blend/cifar10_resnet18/example.yaml \
               --ckpt-dir checkpoint/defense/mixmatch_finetune/blend/cifar10_resnet18/example \
               --resume latest_model.pt \
               --gpu 0

Results

Method BadNets BA (%) BadNets ASR (%) Blended BA (%) Blended ASR (%)
No Defense 95.13 100 94.26 98.15
DBD 92.50 0.88 92.60 0.31

License

Our codes is released under GNU General Public License v3.0.

Citation

If our work or this repo is useful for your research, please cite our paper as follows:

@inproceedings{huang2022backdoor,
  title={Backdoor Defense via Decoupling the Training Process},
  author={Kunzhe Huang, Yiming Li, Baoyuan Wu, Zhan Qin and Kui Ren},
  booktitle={ICLR},
  year={2022}
}

dbd's People

Contributors

hkunzhe avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.