def __init__(self, feature_extractor, gpu, batch_size): self.feature_extractor = feature_extractor self.gpu = gpu self.batch_size = batch_size global sess sess = init_gpu(gpu) global graph graph = tf.get_default_graph() model_dir = os.path.join(os.path.expanduser('~'), '.fawkes') if not os.path.exists(os.path.join(model_dir, "mtcnn.p.gz")): os.makedirs(model_dir, exist_ok=True) get_file("mtcnn.p.gz", "http://mirror.cs.uchicago.edu/fawkes/files/mtcnn.p.gz", cache_dir=model_dir, cache_subdir='') self.fs_names = [feature_extractor] if isinstance(feature_extractor, list): self.fs_names = feature_extractor self.aligner = aligner(sess) self.feature_extractors_ls = [ load_extractor(name) for name in self.fs_names ] self.protector = None self.protector_param = None
def __init__(self, feature_extractor, gpu, batch_size, mode="low"): self.feature_extractor = feature_extractor self.gpu = gpu self.batch_size = batch_size self.mode = mode th, max_step, lr, extractors = self.mode2param(self.mode) self.th = th self.lr = lr self.max_step = max_step if gpu is not None: init_gpu(gpu) self.aligner = aligner() self.protector = None self.protector_param = None self.feature_extractors_ls = [load_extractor(name) for name in extractors]
def main(): sess = init_gpu(args.gpu) ali = aligner(sess) print("Build attacker's model") image_paths = glob.glob(os.path.join(args.directory, "*")) cloak_file_name = "low_cloaked" original_image_paths = sorted( [path for path in image_paths if "cloaked" not in path.split("/")[-1]]) protect_image_paths = sorted([ path for path in image_paths if cloak_file_name in path.split("/")[-1] ]) original_faces = Faces(original_image_paths, ali, verbose=1, eval_local=True) original_faces = original_faces.cropped_faces cloaked_faces = Faces(protect_image_paths, ali, verbose=1, eval_local=True) cloaked_faces = cloaked_faces.cropped_faces if len(original_faces) <= 10: raise Exception( "Must have more than 10 protected images to run the evaluation") num_classes = args.num_other_classes + 1 datagen = DataGenerator(original_faces, cloaked_faces) original_test_X, original_test_Y = datagen.test_original() print("{} Training Images | {} Testing Images".format( len(datagen.protect_images_train), len(original_test_X))) train_generator = datagen.generate() test_generator = datagen.generate(test=True) base_model = load_extractor(args.base_model) model = load_victim_model(teacher_model=base_model, number_classes=num_classes) cb = CallbackGenerator(original_imgs=original_test_X, protect_imgs=cloaked_faces, original_y=original_test_Y, original_protect_y=None, test_gen=test_generator) model.fit_generator(train_generator, steps_per_epoch=num_classes * 10 // 32, epochs=args.n_epochs, verbose=2, callbacks=[cb]) _, acc_original = model.evaluate(original_test_X, original_test_Y, verbose=0) print("Protection Success Rate: {:.4f}".format(1 - acc_original))
def __init__(self, feature_extractor, gpu, batch_size): global graph graph = tf.get_default_graph() self.feature_extractor = feature_extractor self.gpu = gpu self.batch_size = batch_size self.sess = init_gpu(gpu) self.aligner = aligner(self.sess) self.fs_names = [feature_extractor] if isinstance(feature_extractor, list): self.fs_names = feature_extractor self.feature_extractors_ls = [load_extractor(name) for name in self.fs_names]
def __init__(self, feature_extractor, gpu, batch_size, mode="low"): self.feature_extractor = feature_extractor self.gpu = gpu self.batch_size = batch_size self.mode = mode th, max_step, lr, extractors = self.mode2param(self.mode) self.th = th self.lr = lr self.max_step = max_step init_gpu(gpu) # model_dir = os.path.join(os.path.expanduser('~'), '.fawkes') # if not os.path.exists(os.path.join(model_dir)): # os.makedirs(model_dir, exist_ok=True) self.aligner = aligner() self.protector = None self.protector_param = None self.feature_extractors_ls = [ load_extractor(name) for name in extractors ]