我正在尝试使用这个博客https://brunolopezgarcia.github.io/2018/05/09/Crafting-adversarial-faces.html来生成对抗Facenet的面部图像。代码在这里,https://github.com/tensorflow/cleverhans/tree/master/examples/facenet_adversarial_faces,并且运行良好!我的问题是如何导出这些对抗性图像。这个问题是不是太简单了,所以博客没有提及,只给出了一些示例图片。
我认为这不是一个困难的问题,因为我知道生成的对抗性样本在"adv“中。但这个adv (float32)来自faces1,经过预白化和归一化后。要从adv(float32)恢复int8图像,我必须反向标准化和预白化过程。似乎如果我们想要从facenet输出一些图像,我们必须执行这个过程。
我是第一次接触Facenet和Cleverhans,我不确定这是最好的方式,还是人们从Facenet导出图像的常见方式(例如函数)。
在facenet_fgsm.py中,我们终于得到了对抗性样本。我需要将adv导出为纯int图像。adv = sess.run(adv_x, feed_dict=feed_dict)
在set_loader.py中。有一些标准化的东西。
def load_testset(size):
# Load images paths and labels
pairs = lfw.read_pairs(pairs_path)
paths, labels = lfw.get_paths(testset_path, pairs, file_extension)
# Random choice
permutation = np.random.choice(len(labels), size, replace=False)
paths_batch_1 = []
paths_batch_2 = []
for index in permutation:
paths_batch_1.append(paths[index * 2])
paths_batch_2.append(paths[index * 2 + 1])
labels = np.asarray(labels)[permutation]
paths_batch_1 = np.asarray(paths_batch_1)
paths_batch_2 = np.asarray(paths_batch_2)
# Load images
faces1 = facenet.load_data(paths_batch_1, False, False, image_size)
faces2 = facenet.load_data(paths_batch_2, False, False, image_size)
# Change pixel values to 0 to 1 values
min_pixel = min(np.min(faces1), np.min(faces2))
max_pixel = max(np.max(faces1), np.max(faces2))
faces1 = (faces1 - min_pixel) / (max_pixel - min_pixel)
faces2 = (faces2 - min_pixel) / (max_pixel - min_pixel)在facenet.py load_data函数中,有一个预白化过程。
nrof_samples = len(image_paths)
images = np.zeros((nrof_samples, image_size, image_size, 3))
for i in range(nrof_samples):
img = misc.imread(image_paths[i])
if img.ndim == 2:
img = to_rgb(img)
if do_prewhiten:
img = prewhiten(img)
img = crop(img, do_random_crop, image_size)
img = flip(img, do_random_flip)
images[i,:,:,:] = img
return images我希望一些专家能给我指出一些在facenet或cleverhans中的隐藏功能,可以直接导出adv图像,否则反向归一化和预白化过程似乎不太可能。非常感谢。
发布于 2019-06-09 08:56:03
我对Facenet代码了解不多。从您的讨论来看,您似乎必须保存min_pixel,max_pixelto reverse the normalization, and then look at theprewhiten`函数的值,以查看如何反转它。我会发邮件给Bruno,看看他是否有任何进一步的建议来帮助你。
发布于 2019-06-09 17:08:54
编辑:现在图像导出包含在Cleverhans的Facenet示例中:https://github.com/tensorflow/cleverhans/commit/08f6fb9cf2a7f199467d5ed60179fc3ae9140458
https://stackoverflow.com/questions/55431105
复制相似问题