2
0
mirror of https://github.com/Shawn-Shan/fawkes.git synced 2024-12-22 07:09:33 +05:30
This commit is contained in:
Shawn-Shan 2020-06-29 11:14:48 -05:00
parent 95a0d5efc0
commit 1d13a85276
23 changed files with 41 additions and 78 deletions

View File

@ -1,57 +0,0 @@
# Fawkes
Code implementation of the paper "[Fawkes: Protecting Personal Privacy against Unauthorized Deep Learning Models](https://arxiv.org/pdf/2002.08327.pdf)", at *USENIX Security 2020*.
### BEFORE YOU RUN OUR CODE
We appreciate your interest in our work and for trying out our code. We've noticed several cases where incorrect configuration leads to poor performances of protection. If you also observe low detection performance far away from what we presented in the paper, please feel free to open an issue in this repo or contact any of the authors directly. We are more than happy to help you debug your experiment and find out the correct configuration.
### ABOUT
This repository contains code implementation of the paper "[Fawkes: Protecting Personal Privacy against Unauthorized Deep Learning Models](https://arxiv.org/pdf/2002.08327.pdf)", at *USENIX Security 2020*.
### DEPENDENCIES
Our code is implemented and tested on Keras with TensorFlow backend. Following packages are used by our code.
- `keras==2.3.1`
- `numpy==1.18.4`
- `tensorflow-gpu==1.13.1`
Our code is tested on `Python 3.6.8`
### HOWTO
#### Download and Config Datasets
The first step is to download several datasets for protection and target selection.
1. Download the following dataset to your local machine. After downloading the datasets, restructure it the same way as the FaceScrub dataset downloaded.
- FaceScrub -- used for protection evaluation (link)
- VGGFace1 -- used for target select (link)
- VGGFace2 -- used for target select (link)
- WebFace -- used for target select (link)
2. Config datasets
open `fawkes/config.py` and update the `DATASETS` dictionary with the path to each dataset. Then run `python fawkes/config.py`. Every time the datasets are updated or moved, remember to rerun the command with the updated path.
3. Calculate embeddings using feature extractor.
Run `python3 fawkes/prepare_feature_extractor.py --candidate-datasets scrub vggface1 vggface2 webface`. This will calculate and cache the embeddings using the default feature extractor we provide. To use a customized feature extractor, please look at the Advance section at the end.
#### Generate Cloak for Images
To generate cloak, run
`python3 fawkes/protection.py --gpu 0 --dataset scrub --feature-extractor webface_dense_robust_extract`
For more information about the detailed parameters, please read `fawkes/protection.py`.
The code will output a directory in `results/` with `cloak_data.p` inside. You can check the cloaked images or inspect the changes in `this notebook`.
#### Evaluate Cloak Effectiveness
To evaluate the cloak, run `python3 fawkes/eval_cloak.py --gpu 0 --cloak_data PATH-TO-RESULT-DIRECTORY --transfer_model vggface2_inception_extract`.
The code will print out the tracker model accuracy on uncloaked/original test images of the protected user, which should be close to 0.
### Citation
```
@inproceedings{shan2020fawkes,
title={Fawkes: Protecting Personal Privacy against Unauthorized Deep Learning Models},
author={Shan, Shawn and Wenger, Emily and Zhang, Jiayun and Li, Huiying and Zheng, Haitao and Zhao, Ben Y},
booktitle="Proc. of USENIX Security",
year={2020}
}
```

View File

@ -37,19 +37,34 @@ def generate_cloak_images(sess, feature_extractors, image_X, target_X=None, th=0
return cloaked_image_X return cloaked_image_X
def get_mode_config(mode):
if mode == 'low':
args.feature_extractor = "low_extract"
args.th = 0.001
elif mode == 'mid':
args.feature_extractor = "mid_extract"
args.th = 0.001
elif mode == 'high':
args.feature_extractor = "high_extract"
args.th = 0.005
elif mode == 'ultra':
args.feature_extractor = "high_extract"
args.th = 0.007
elif mode == 'custom':
pass
else:
raise Exception("mode must be one of 'low', 'mid', 'high', 'ultra', 'custom'")
def extract_faces(img): def extract_faces(img):
# foo # wait on Huiying
return preprocess_input(resize(img, (224, 224))) return preprocess_input(resize(img, (224, 224)))
def fawkes(): def fawkes():
assert os.path.exists(args.directory) get_mode_config(args.mode)
assert os.path.isdir(args.directory)
sess = init_gpu(args.gpu) sess = init_gpu(args.gpu)
print("Loading {} for optimization".format(args.feature_extractor))
feature_extractors_ls = [load_extractor(args.feature_extractor)] feature_extractors_ls = [load_extractor(args.feature_extractor)]
image_paths = glob.glob(os.path.join(args.directory, "*")) image_paths = glob.glob(os.path.join(args.directory, "*"))
@ -70,10 +85,6 @@ def fawkes():
else: else:
target_images = select_target_label(orginal_images, feature_extractors_ls, [args.feature_extractor]) target_images = select_target_label(orginal_images, feature_extractors_ls, [args.feature_extractor])
# file_name = args.directory.split("/")[-1]
# os.makedirs(args.result_directory, exist_ok=True)
# os.makedirs(os.path.join(args.result_directory, file_name), exist_ok=True)
protected_images = generate_cloak_images(sess, feature_extractors_ls, orginal_images, protected_images = generate_cloak_images(sess, feature_extractors_ls, orginal_images,
target_X=target_images, th=args.th) target_X=target_images, th=args.th)
@ -85,18 +96,20 @@ def fawkes():
def parse_arguments(argv): def parse_arguments(argv):
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--gpu', type=str,
help='GPU id', default='0')
parser.add_argument('--directory', type=str, parser.add_argument('--directory', type=str,
help='directory that contain images for cloaking', default='imgs/') help='directory that contain images for cloaking', default='imgs/')
parser.add_argument('--gpu', type=str,
help='GPU id', default='0')
parser.add_argument('--mode', type=str,
help='cloak generation mode', default='mid')
parser.add_argument('--feature-extractor', type=str, parser.add_argument('--feature-extractor', type=str,
help="name of the feature extractor used for optimization", help="name of the feature extractor used for optimization",
default="webface_dense_robust_extract") default="mid_extract")
parser.add_argument('--th', type=float, default=0.005) parser.add_argument('--th', type=float, default=0.005)
parser.add_argument('--sd', type=int, default=1e9) parser.add_argument('--sd', type=int, default=1e9)
parser.add_argument('--protect_class', type=str, default=None)
parser.add_argument('--lr', type=float, default=1) parser.add_argument('--lr', type=float, default=1)
parser.add_argument('--result_directory', type=str, default="../results") parser.add_argument('--result_directory', type=str, default="../results")

View File

@ -46,6 +46,13 @@ To evaluate the cloak, run `python3 fawkes/eval_cloak.py --gpu 0 --cloak_data PA
The code will print out the tracker model accuracy on uncloaked/original test images of the protected user, which should be close to 0. The code will print out the tracker model accuracy on uncloaked/original test images of the protected user, which should be close to 0.
#### Exisiting Feature extractors
We shared three different feature extractors under feature_extractors/
1. low_extract.h5: trained on WebFace dataset with DenseNet architecture.
2. mid_extract.h5: VGGFace2 dataset with DenseNet architecture. Trained with PGD adversarial training for 5 epochs.
3. high_extract.h5: WebFace dataset with DenseNet architecture. Trained with PGD adversarial training for 20 epochs.
### Citation ### Citation
``` ```
@inproceedings{shan2020fawkes, @inproceedings{shan2020fawkes,

View File

@ -3,8 +3,8 @@ import json
import os import os
DATASETS = { DATASETS = {
"pubfig": "../data/pubfig",
"scrub": "/home/shansixioing/cloak/fawkes/data/scrub/", "scrub": "/home/shansixioing/cloak/fawkes/data/scrub/",
# "vggface1": "/mnt/data/sixiongshan/data/vggface/",
"vggface2": "/mnt/data/sixiongshan/data/vggface2/", "vggface2": "/mnt/data/sixiongshan/data/vggface2/",
"webface": "/mnt/data/sixiongshan/data/webface/", "webface": "/mnt/data/sixiongshan/data/webface/",
"youtubeface": "/mnt/data/sixiongshan/data/youtubeface/keras_flow_data/", "youtubeface": "/mnt/data/sixiongshan/data/youtubeface/keras_flow_data/",

View File

@ -207,8 +207,7 @@ class FawkesMaskGeneration:
# we're creating # we're creating
start_vars = set(x.name for x in tf.global_variables()) start_vars = set(x.name for x in tf.global_variables())
self.learning_rate_holder = tf.placeholder(tf.float32, shape=[]) self.learning_rate_holder = tf.placeholder(tf.float32, shape=[])
# optimizer = tf.train.AdadeltaOptimizer(self.learning_rate_holder) optimizer = tf.train.AdadeltaOptimizer(self.learning_rate_holder)
optimizer = tf.train.AdamOptimizer(self.learning_rate_holder)
self.train = optimizer.minimize(self.loss_sum, self.train = optimizer.minimize(self.loss_sum,
var_list=[self.modifier]) var_list=[self.modifier])

View File

@ -44,7 +44,7 @@ def main():
for k, v in path2emb.items(): for k, v in path2emb.items():
path2emb[k] = normalize(v) path2emb[k] = normalize(v)
pickle.dump(path2emb, open("../feature_extractors/embeddings/{}_emb_norm.p".format(args.feature_extractor), "wb")) pickle.dump(path2emb, open("../feature_extractors/embeddings/{}_emb.p".format(args.feature_extractor), "wb"))
def parse_arguments(argv): def parse_arguments(argv):

View File

@ -83,9 +83,9 @@ def parse_arguments(argv):
help="name of the feature extractor used for optimization", help="name of the feature extractor used for optimization",
default="webface_dense_robust_extract") default="webface_dense_robust_extract")
parser.add_argument('--th', type=float, default=0.007) parser.add_argument('--th', type=float, default=0.007)
parser.add_argument('--sd', type=int, default=1e5) parser.add_argument('--sd', type=int, default=1e9)
parser.add_argument('--protect_class', type=str, default=None) parser.add_argument('--protect_class', type=str, default=None)
parser.add_argument('--lr', type=float, default=0.1) parser.add_argument('--lr', type=float, default=1)
return parser.parse_args(argv) return parser.parse_args(argv)

View File

@ -13,7 +13,7 @@ from keras.models import Model
from keras.preprocessing import image from keras.preprocessing import image
from keras.utils import to_categorical from keras.utils import to_categorical
from sklearn.metrics import pairwise_distances from sklearn.metrics import pairwise_distances
# from keras.utils import get_file
def clip_img(X, preprocessing='raw'): def clip_img(X, preprocessing='raw'):
X = reverse_preprocess(X, preprocessing) X = reverse_preprocess(X, preprocessing)
@ -172,6 +172,7 @@ def imagenet_reverse_preprocessing(x, data_format=None):
return x return x
def build_bottleneck_model(model, cut_off): def build_bottleneck_model(model, cut_off):
bottleneck_model = Model(model.input, model.get_layer(cut_off).output) bottleneck_model = Model(model.input, model.get_layer(cut_off).output)
bottleneck_model.compile(loss='categorical_crossentropy', bottleneck_model.compile(loss='categorical_crossentropy',