如何在TensorFlow中使用图像和权重矩阵创建对抗图像? [英] How to use image and weight matrix to create adversarial images in TensorFlow?

查看:103
本文介绍了如何在TensorFlow中使用图像和权重矩阵创建对抗图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ImageNet上打破线性分类器博客文章,作者提出了一个非常简单的示例,说明如何通过修改图像来欺骗分类器.给出的技术非常简单:xad = x + 0.5w其中x是1d向量,w是1d权重.这一切都很好,也很清楚.但是,我试图用MNIST数据集来实现这一目标并陷入困境,却不知道如何将这个简单的想法变成实际的结果.我想知道如何使用已知的w矩阵修改给定的x矩阵(或简单地是一维的1d图像矢量).

In the Breaking Linear Classifiers on ImageNet blog post, the author presented a very simple example on how to modify an image to fool a classifier. The technique given is pretty simple: xad = x + 0.5w where x is the 1d vector and w is the 1d weight. This is all good and clear. However, I am trying to implement this with the MNIST dataset and got stuck, with no idea how to turn this simple idea into actual results. I'd like to know how to use the known w matrix to modify a given x matrix (or simply a flattened 1d image vector).

我的图像矩阵x的形状为(1032,784)(每个图像是具有784个数字的扁平向量),而我的权重矩阵w的形状为(784,10).那么问题是如何实现上述文章中介绍的思想?特别是,如何为所有图像添加一点权重?像这样:

My images matrix x is of the shape (1032, 784) (each image is a flattened vector with 784 numbers), and my weight matrix w has the shape (784, 10). So the question is how to implement the idea introduced in the above mentioned article? In particular, how to add a bit weight to all images? Something like this:

x + 0.5 * w

我的代码可以在GitHub上找到 .最好使用numpy解决方案,但使用TensorFlow也可以.谢谢!

My code can be found on GitHub. Solution with numpy is preferred, but using TensorFlow would be fine as well. Thanks!

推荐答案

找出方法:

因此,如果我们试图创建要错误分类为"6"的对抗图像,则只需从权重矩阵中获取"6"的权重:

So, if we're trying to create adversarial images to be falsely classified as "6", we need to grab the weights for "6" only from the weight matrix:

w_six = w[:, 6]

然后我们可以简单地进行矩阵加法:

Then we can simply do matrix addition:

images_fool = x + 1.5 * w_six

这篇关于如何在TensorFlow中使用图像和权重矩阵创建对抗图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆