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, original_images, protect_images): l = int(len(original_images) * 0.7) self.original_images_test = original_images[l:] self.protect_images_train = protect_images[:l] other_classes = range(0, 20946) selected_classes = random.sample(other_classes, args.num_other_classes) print("Downloading additional data...") model_dir = os.path.join(os.path.expanduser('~'), '.fawkes') self.id2label = {-1: 0} self.id2path = {} self.id2pathtest = {} idx = 1 for target_data_id in selected_classes: image_dir = os.path.join(model_dir, "target_data/{}".format(target_data_id)) os.makedirs(os.path.join(model_dir, "target_data"), exist_ok=True) os.makedirs(image_dir, exist_ok=True) self.id2label[target_data_id] = idx idx += 1 for i in range(10): if os.path.exists( os.path.join( model_dir, "target_data/{}/{}.jpg".format(target_data_id, i))): continue try: get_file( "{}.jpg".format(i), "http://sandlab.cs.uchicago.edu/fawkes/files/target_data/{}/{}.jpg" .format(target_data_id, i), cache_dir=model_dir, cache_subdir='target_data/{}/'.format(target_data_id)) except Exception: print( "error getting http://sandlab.cs.uchicago.edu/fawkes/files/target_data/{}/{}.jpg" .format(target_data_id, i)) pass all_pathes = glob.glob( os.path.join(model_dir, 'target_data/{}/*.jpg'.format(target_data_id))) test_path = random.sample(all_pathes, 2) train_path = [p for p in all_pathes if p not in test_path] self.id2path[target_data_id] = train_path self.id2pathtest[target_data_id] = test_path self.num_classes = 1 + len(self.id2path) np.random.seed(12345) self.all_id = selected_classes + [-1]