python - 论文 "Deep inside convolutional networks: Visualising image classification models and saliency maps"的实现,Simonyan 等人

标签 python visualization gradient deep-learning caffe

在卷积神经网络中梯度数据的可视化中,使用 Caffe 框架,已经可视化了所有类的梯度数据,对特定类采用梯度很有趣。在“bvlc_reference_caffenet”模型的 deploy.prototxt 文件中,我设置了:

force_backward: true

并评论了最后一部分:

layer {
  name: "prob" 
  type: "Softmax"
  bottom: "fc8"
  top: "prob" 
}

,这是之前:

layer {
  name: "fc8"
  type: "InnerProduct"
  bottom: "fc7"
  top: "fc8"
  inner_product_param {
  num_output: 1000
 }
}

,并添加代替它:

 layer {
   name: "loss"
   type: "SoftmaxWithLoss"
   bottom: "fc8"
   bottom: "label"
   top: "prob"
}

,在python代码中通过调用:

out = net.forward()

,我们前进到最后一层,然后调用:

backout = net.backward()

,得到渐变的可视化。首先,我想问一下这叫做显着图,如果我想对特定类进行反向操作,例如281是给猫的。我该怎么办?

预先感谢您的指导。

附言受益于 Yangqing 为其笔记本在过滤器可视化方面的代码。

imagenetMeanFile = caffe_root  +'python/caffe/imagenet/ilsvrc_2012_mean.npy'
caffe.set_mode_cpu()
net = caffe.Net(caffe_root +   'models/bvlc_reference_caffenet/deploy.prototxt',
            caffe_root + 'models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel',
            caffe.TRAIN)
transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape})
transformer.set_transpose('data', (2,0,1))
transformer.set_mean('data', np.load(caffe_root + 'python/caffe/imagenet/ilsvrc_2012_mean.npy').mean(1).mean(1)) # mean pixel 
transformer.set_raw_scale('data', 255)  # the reference model operates on images in [0,255] range instead of [0,1]
transformer.set_channel_swap('data', (2,1,0))  # the reference model has channels in BGR order instead of RGB

最佳答案

另外,对于完整的可视化,您可以引用我的 github,它更完整并且可视化了显着图以及类模型的可视化和反向传播中的梯度可视化。

https://github.com/smajida/Deep_Inside_Convolutional_Networks

关于python - 论文 "Deep inside convolutional networks: Visualising image classification models and saliency maps"的实现,Simonyan 等人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31105548/

相关文章:

debugging - 如何可视化许多并发多阶段进程的行为?

flutter - 如何在 Flutter 中使用线性渐变创建模糊

matlab - 图像聚焦和 FFT

python - 如何使用 cv2 计算图像中的不同颗粒?

python - 更有效地到达最近的中心

javascript - 在 cytoscape.js 中使用网格布局时复合节点重叠

r - 此可视化的名称是什么?

css - 如何在绝对定位元素之上显示 li 内容?

python - 从被调用函数捕获异常

python - SQLAlchemy 中的楼层划分