Code Monkey home page Code Monkey logo

adversarial-face-attack's Introduction

Black-Box Adversarial Attack on Public Face Recognition Systems

Geekpwn CAAD (Competition on Adversarial Attacks and Defenses) 2018, is a competition that inherits the format of NIPS CAAD 2017, plus some new challenges. In October 2018, me and Cihang Xie were invited to Geekpwn CAAD CTF, a live competition with different types of adversarial attacks and defenses.

This CAAD CTF features a new challenge that asks teams to attack an unknown face recognition system. During the 30 minutes phase 1 competition, we were given an image of the competition moderator Chang-Jian Jiang. We need to make small modifications to the image, in order to fool the face recognition system to recognize it as Arnold Schwarzenegger. After the competition, we learned that the system we attacked was AWS Celebrity Recognition API.

This repo contains code and several results of such attacks.

Some Results

During the competition, we successfully attacked AWS to recognize Chang-Jian Jiang as Schwarzenegger:

AWS-JCJ

The following one is slightly harder (lower success rate with varying random seeds), probably because: (1) both source and target are American celebrities. (2) different gender

AWS-Trump

Apparently, Azure Vision API and Clarifai Celebrity Recognition can be fooled as well:

Azure-Trump

Clarifai-JCJ

Original and adversarial versions of the above images can be found at images/. You can download them and try on the public APIs.

Preparation to Use the Code

  1. Install 2 > TensorFlow ≥ 1.7, OpenCV, tqdm, scikit-learn

  2. Follow steps 1-4 in facenet wiki to setup facenet

  3. Clone this repo and uncompress the pre-trained model inside:

git clone https://github.com/ppwwyyxx/Adversarial-Face-Attack
cd Adversarial-Face-Attack
wget https://github.com/ppwwyyxx/Adversarial-Face-Attack/releases/download/v0.1/model-20180402-114759.tar.bz2
tar xjvf model-20180402-114759.tar.bz2

You can also download the model from facenet.

  1. Validate the model and the dataset:
./face_attack.py --data /path/to/lfw_mtcnnpy_160 --validate-lfw
# /path/to/lfw_mtcnnpy_160 is obtained above in step #4 in facenet wiki.

It should print a high accuracy on LFW, like:

Accuracy: 0.99517+-0.00361
Validation rate: 0.97467+-0.01454 @ FAR=0.00067

Run attack

./face_attack.py --data /path/to/lfw_mtcnnpy_160 \
	--attack images/clean-JCJ.png \
	--target Arnold_Schwarzenegger \
	--output JCJ-to-Schwarzenegger.png

--target has to be a person which has many images (the more the better) in the LFW dataset. Such person can be found by:

find /path/to/lfw_mtcnnpy_160/ -type f -printf "%h\0" | \
    xargs -0 -L1 basename | sort | uniq -c | sort -k1 -n

You can add new celebrities as victims in the LFW directory, or add additional images for existing celebrities in LFW. After adding new images, you'll need to repeat step 4 in facenet wiki, to crop and align the images you add.

Note that the attack contains randomness: you'll not get the same output every time.

Disclaimer

  1. This work is only for computer vision research. Please do not use it for illegal purposes.

  2. This work has no relationship with the authors' schools or employers.

  3. It turns out after a year, AWS is no longer vulnerable to my attack.

adversarial-face-attack's People

Contributors

cihangxie avatar ppwwyyxx avatar

Stargazers

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

Watchers

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

adversarial-face-attack's Issues

ValueError: Cannot feed value of shape (42, 250, 250, 3) for Tensor 'images:0', which has shape '(?, 160, 160, 3)'

按照教程配置了环境出现问题

Traceback (most recent call last):
  File "face_attack.py", line 216, in <module>
    victim = model.compute_victim(args.data, args.target)
  File "face_attack.py", line 44, in compute_victim
    embeddings = self.eval_embeddings(image_batch)
  File "face_attack.py", line 118, in eval_embeddings
    return self.sess.run(self.embeddings, feed_dict={self.image_batch: batch_arr})
  File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 905, in run
    run_metadata_ptr)
  File "D:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1116, in _run
    str(subfeed_t.get_shape())))
ValueError: Cannot feed value of shape (42, 250, 250, 3) for Tensor 'images:0', which has shape '(?, 160, 160, 3)'

请问怎么处理

Perturbation doesn't match eps

My environment is tensorflow 1.8.0, python 2.7.16. I run this code and get an adversarial image.

The adversarial image can successfully fool face classifier, but I found that the perturbation of some points in this adversarial image is larger than eps, which I set as 16.
I hope you can verify this issue.

I have a question

Can you explain why you use noise = 0.9 * grad + noise instead of grad = 0.9 * grad + noise in line 94 of face_attack.py?

Thank you!

How to understand the dist

dist = np.dot(emb, self.victim_embeddings.T).flatten()

how to understand the dist line, it's a somewhat formula?And whether I got wrong in the following steps ?:
I change the dist to calculate cosine similarity dist, but I found most dist of the original images results is close to 0, and most of most is lower than 0( I think I got wrong with this,normal image pair's cosine similarity is [0,0.5],and the dist result of adversarial examples is close to 0.8 or higher

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.