Question on implement Excitation BackPropagation in Pytorch

username: mathkobe
cooked: <p>Hi, I’m trying to implement the following paper in pytorch.<br>
<a href="https://arxiv.org/abs/1608.00507" class="onebox" target="_blank" rel="nofollow noopener">https://arxiv.org/abs/1608.00507</a></p>
<p>It’s one way to construct saliency map.<br>
For a certain Conv2d layer, we need to truncate the weight W to W+ which only positive weights are remained. Then, they will do a Conv2d_back according to this new weight(together with normalized output). However, in pytorch,  the operator torch._C._functions.Conv2d is not allowed to use. Is there any suggestion on how to overcome this and implement this paper ?</p>
<p>Thanks a lot and happy new year !</p>

username: chenyuntc
cooked: <p>seems like guided backpropogation</p>
<aside class="onebox githubblob">
  <header class="source">
      <a href="https://github.com/utkuozbulak/pytorch-cnn-visualizations/blob/master/src/guided_backprop.py#L15" target="_blank" rel="nofollow noopener">github.com</a>
  </header>
  <article class="onebox-body">
    <h4><a href="https://github.com/utkuozbulak/pytorch-cnn-visualizations/blob/master/src/guided_backprop.py#L15" target="_blank" rel="nofollow noopener">utkuozbulak/pytorch-cnn-visualizations/blob/master/src/guided_backprop.py#L15</a></h4>
<pre class="onebox"><code class="lang-py"><ol class="start lines" start="5" style="counter-reset: li-counter 4 ;">
<li>"""</li>
<li>import torch</li>
<li>from torch.nn import ReLU</li>
<li>
</li>
<li>from misc_functions import (get_params,</li>
<li>                        convert_to_grayscale,</li>
<li>                        save_gradient_images,</li>
<li>                        get_positive_negative_saliency)</li>
<li>
</li>
<li>
</li>
<li class="selected">class GuidedBackprop():</li>
<li>"""</li>
<li>   Produces gradients generated with guided back propagation from the given image</li>
<li>"""</li>
<li>def __init__(self, model, processed_im, target_class):</li>
<li>    self.model = model</li>
<li>    self.input_image = processed_im</li>
<li>    self.target_class = target_class</li>
<li>    self.gradients = None</li>
<li>    # Put model in evaluation mode</li>
<li>    self.model.eval()</li>
</ol></code></pre>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>


username: yulongwang12
cooked: <p>For solving the inconsistent forward and backward functions in excitation backprop, I implemented two functions with pure conv functions by<br>
<aside class="onebox githubblob">
  <header class="source">
      <a href="https://github.com/yulongwang12/visual-attribution/blob/master/explainer/ebp/functions.py#L66-L69" target="_blank" rel="nofollow noopener">github.com</a>
  </header>
  <article class="onebox-body">
    <h4><a href="https://github.com/yulongwang12/visual-attribution/blob/master/explainer/ebp/functions.py#L66-L69" target="_blank" rel="nofollow noopener">yulongwang12/visual-attribution/blob/master/explainer/ebp/functions.py#L66-L69</a></h4>
<pre class="onebox"><code class="lang-py"><ol class="start lines" start="66" style="counter-reset: li-counter 65 ;">
<li>backend = type2backend[inp.type()]</li>
<li>f = getattr(backend, 'SpatialConvolutionMM_updateOutput')</li>
<li>f(backend.library_state, inp, output, weight, bias, columns, ones,</li>
<li>  kH, kW, ctx.stride[0], ctx.stride[1], ctx.padding[0], ctx.padding[1])</li>
</ol></code></pre>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
</p>
<p>Note that this is a temporal solution for pytorch 0.2 version. The full implementation can be found in <a href="https://github.com/yulongwang12/visual-attribution" rel="nofollow noopener">https://github.com/yulongwang12/visual-attribution</a>. Hope it helps</p>