通过神经网络分类器计算图像显着性 [英] Computing Image Saliency via Neural Network Classifier

查看:96
本文介绍了通过神经网络分类器计算图像显着性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有一个经过训练的卷积神经网络,可以在 Tensor-Flow 中对图像进行分类(博客灰度)。

Assume that we have a Convolutional Neural Network trained to classify (w.l.o.g. grayscale) images, in Tensor-Flow.

网络和一幅测试图像,可以跟踪图像的哪些像素是显着的,或者等效地追踪哪些像素最负责图像的输出分类。 文章

Given the trained net and a test image one can trace which pixels of it are salient, or "equivalently" which pixels are most responsible for the output classification of the image. A nice, explanation and implementation details in Theano, are given in this article.

假设对于与输入图像直接链接的第一层卷积,对于每个卷积核-wrt的参数,我们确实具有梯度。分类功能。

Assume that for the first layer of convolutions that is directly linked with the input image, we do have the gradient for the parameters of every convolutional kernel-wrt. the classification function.

如何将梯度传播回输入层,以便计算图像的每个像素的偏导数?


  1. 传播并累积梯度,将为我们提供明显的像素(它们是幅值较大的像素)。

  1. Propagating and accumulating back the gradient, would give us the salient pixels (they are those with big in-magnitude derivative).

以找到渐变wrt。到目前为止,我已经完成了第一层的内核操作:

To find the gradient wrt. the kernels of the first layer, so far I did:


  1. 用输出层运算符代替了通常的损失运算符。

  2. 使用了 compute_gradient功能


全部全部看起来像这样:

All in all, it looks like:


  • opt = tf.train.GradientDescentOptimizer(1)

  • grads = opt.compute_gradients(输出)

  • grad_var = [(grad 1 )表示毕业的研究生]

  • g1 = sess.run([grad_var [0]])

  • opt = tf.train.GradientDescentOptimizer(1)
  • grads = opt.compute_gradients(output)
  • grad_var = [(grad1) for grad in grads]
  • g1 = sess.run([grad_var[0]])

其中,输出是NN输出层的最大值。
g1是一个(k,k,1,M)张量,因为我在第一层使用了M:k x k个卷积核。

Where, the "output" is the max of the output layer of the NN. And g1, is a (k, k, 1, M) tensor, since I used M: k x k convolutional kernels on the first layer.

现在,我需要找到在每个输入像素上传播g1的正确方法,以计算其导数wrt。

Now, I need to find the correct way to propagate g1 on every input pixel, as to compute their derivative wrt. the output.

推荐答案

要计算渐变,不需要使用优化器,可以直接使用 tf.gradients

使用此功能,您可以相对于图像输入直接计算输出的梯度,而优化器 compute_gradients 方法只能计算关于变量的梯度

To compute the gradients, you don't need to use an optimizer, and you can directly use tf.gradients.
With this function, you can directly compute the gradient of output with respect to the image input, whereas the optimizer compute_gradients method can only compute gradients with respect to Variables.

tf.gradients 的另一个优点是,您可以指定要反向传播的输出的梯度。

The other advantage of tf.gradients is that you can specify the gradients of the output you want to backpropagate.

这是相对于 output [1,1]


  • 我们必须将输出梯度设置为 0 ,除索引 [1,1]

  • we have to set the output gradients to 0 everywhere except at indice [1, 1]
input = tf.ones([1, 4, 4, 1])
filter = tf.ones([3, 3, 1, 1])
output = tf.nn.conv2d(input, filter, [1, 1, 1, 1], 'SAME')

grad_output = np.zeros((1, 4, 4, 1), dtype=np.float32)
grad_output[0, 1, 1, 0] = 1.

grads = tf.gradients(output, input, grad_output)

sess = tf.Session()
print sess.run(grads[0]).reshape((4, 4))
# prints [[ 1.  1.  1.  0.]
#         [ 1.  1.  1.  0.]
#         [ 1.  1.  1.  0.]
#         [ 0.  0.  0.  0.]]

这篇关于通过神经网络分类器计算图像显着性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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