Code Monkey home page Code Monkey logo

lafeat's Introduction

LAFEAT attack

Paper

This is the official repository for our paper "LAFEAT: Piercing Through Adversarial Defenses with Latent Features". The paper is available on:

Please feel free to cite our paper with the following bibtex entry:

@InProceedings{Yu_2021_CVPR,
    author    = {Yu, Yunrui and Gao, Xitong and Xu, Cheng-Zhong},
    title     = {{LAFEAT}: Piercing Through Adversarial Defenses With Latent Features},
    booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
    month     = {June},
    year      = {2021},
    pages     = {5735-5745}
}

Introduction

We introduce LAFEAT, a unified $\ell^\infty$-norm white-box attack algorithm which harnesses latent features in its gradient descent steps. Our results show that not only is it computationally much more efficient for successful attacks, but it is also a stronger adversary than the current state-of-the-art across a wide range of defense mechanisms. This suggests that model robustness could be contingent on the effective use of the defender's hidden components, and it should no longer be viewed from a holistic perspective.

Requirements

  • Python 3 (>= 3.6)
  • PyTorch (>= 1.2.0)

Instructions for reproducing attacks on TRADES

Note that for reproducibility, the scripts are made to be completely deterministic, your runs should hopefully produce exactly the same results as ours.

  1. Download the original TRADES CIFAR-10 model_cifar_wrn.pt model provided by the authors, and place it in the models/ folder.

  2. To train logits for intermediate features, run the following command:

    python3 train.py --max-epoch=100 --save-model=trades_new

    It will run for 100 epochs and save the final logits model at models/trades_new.pt. We have also included trained logits named models/trades.pt with the code, so you can skip this step.

  3. To perform a multi-targeted attack on the TRADES model with trained intermediate logits, run:

    python3 attack.py \
        --verbose --batch-size=${your_batch_size:-2000} \
        --multi-targeted --num-iterations=1000 \
        --logits-model=models/trades_new.pt  # your trained logits

    It will run a multi-targeted LAFEAT attack and save the adversarial images at attacks/lafeat.{additional_info}.pt.

  4. For testing with the original TRADES evaluation script, we need to first convert the adversarial examples for their script with the following command:

    python3 convert.py --name=lafeat.{additional_info}.pt

    By default, it converts the .pt file to a cifar10_X_adv.npy file and performs additional range clipping to ensure correct L-inf boundaries under the effect of floating-point errors. It also generates a new attacks/cifar10_X_adv.npy file. We ran multi-targeted LAFEAT with 1000 iterations, and generated the adversarial examples with a 52.94% accuracy for the CIFAR-10 test set, which places it at the top of the TRADES CIFAR-10 white-box leaderboard. For convenience, we uploaded the file anonymously, and you can download it from:

  5. Download the CIFAR-10 datasets for TRADES’s testing script, and place them in the attacks/ folder:

  6. Evaluate with the original TRADES script (with minor modifications to make it work with our paths) using:

    python3 eval_trades.py

    and you should be able to test the accuracy of LAFEAT adversarial examples on the TRADES model.

lafeat's People

Contributors

admk avatar yunduanzhineng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

lafeat's Issues

Acutually the PyTorch version needed to run your codes is higher than 1.2.0

I am very interested in your paper, so I want to reproduce your experiments yesterday. My Python version is 3.7.9 and my PyTorch version is exactly 1.2.0 When I ran
python3 attack.py
--verbose --batch-size=${your_batch_size:-2000}
--multi-targeted --num-iterations=1000
--logits-model=models/trades_new.pt # your trained logits
It reported a bug in /lafeat/lafeat/attack.py line 113: logits_prev = scale_17 * out_adv_256_17 * mask_256_17 + (1 - scale_17 * mask_256_17) * out_adv, saying that I should have used torch.float to do this calculation other than Char.
It turned out that the variable "mask_256_17" is in type "torch.int8", which was interpreted as Char in PyTorch 1.2.0
To fix this bug, we have two choices: (1) Change the return type of the function "check_right_index(self, output, labels)". We can modify /lafeat/lafeat/attack.py line 42: from "mask = output_index.to(dtype=torch.int8)" to "mask = output_index.to(dtype=torch.float)". (2) Upgrade our PyTorch version. I found that at least in PyTorch 1.5.1, the type torch.in8 can be automatically converted to torch.float when it is going to be operated with torch.float

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.