Understand “Visualizing and Understanding Convolutional Networks”

Brent1: <p>I’m trying to understand “Visualizing and Understanding Convolutional Networks” <a href="https://arxiv.org/pdf/1311.2901.pdf" rel="noopener nofollow ugc">https://arxiv.org/pdf/1311.2901.pdf</a></p>
<p>The paper states: <code>the deconvnet uses transposed versions of the same filters, applied to the rectified maps</code></p>
<p>Is it possible to implement this step in a short example in pytorch? Given an unpooled, rectified map; how would the transposed filter be applied against it?</p>
<p>Thanks</p>

ptrblck: <p>I think this statement points towards reusing (trained) filters from convolutions in transposed convolutions at a later stage in the model:</p>
<pre><code class="lang-python">conv = nn.Conv2d(3, 6, 3, 1, 1, bias=False)
x = torch.randn(1, 3, 24, 24)
out = conv(x)
out = F.conv_transpose2d(out, conv.weight, stride=1, padding=1)
print(out.shape)
&gt; torch.Size([1, 3, 24, 24])
</code></pre>

Brent1: <p>Right; so seems pretty dead simple <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"> - but I might still be getting myself confused.</p>
<p>The paper says:<br>
<code> the deconvnet uses transposed versions of the same filters, but applied to the rectified maps, not the output of the layer beneath. In practice this means flipping each filter vertically and horizontally.</code></p>
<p>“the same filters” refer to the learnt filters from training.</p>
<p>The paper refers to the flipped vertically and horizontally filter as <code>transposed ... filters</code><br>
Is it correct that the term <code>transposed filters</code> has no semantic relation to the term <code>transposed convolution</code>?</p>
<p>Appreciated this is not pytorch related; so completely understand if its too far off topic for this forum; but any easy to share pointers would be fab!!</p>
<p>The paper says:<br>
<code>In the deconvnet, the unpooling operation uses these switches to place the reconstructions from the layer above into appropriate locations,</code><br>
So if the “layer above” had an output of</p>
<p>[<br>
[1,2],<br>
[3,4]<br>
]</p>
<p>And if; on the forward pass; before the pooling operation the <code>layer below</code> shape was 4x4.</p>
<p>Then instead of using “stride” to introduce spaces between the activations - would the process in the paper just place the activations in the original locations recorded on the forward pass; so for example could end up with something like</p>
<p>[<br>
[1,0,0,0],<br>
[0,0,2,0],<br>
[0,3,0,4],<br>
[0,0,0,0]<br>
]</p>
<p>And then the convolution operation would actually be a normal convolution as the resolution of the features has already been increased; and would convolve the transposed filters across the above feature map?</p>

ptrblck: <aside class="quote no-group" data-username="Brent1" data-post="3" data-topic="112953">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/brent1/48/33505_2.png" class="avatar"> Brent1:</div>
<blockquote>
<p>The paper refers to the flipped vertically and horizontally filter as <code>transposed ... filters</code><br>
Is it correct that the term <code>transposed filters</code> has no semantic relation to the term <code>transposed convolution</code>?</p>
</blockquote>
</aside>
<p>Oh, you might be right and it seems the authors might indeed meant to flip the kernel and apply a “standard” convolution?<br>
The transposed convolution is nicely explained <a href="https://arxiv.org/pdf/1603.07285.pdf">here</a>. In particular check chapter 4.2.<br>
Would it fit the paper better, if <code>nn.Conv2d</code> with a flipped kernel would be used?</p>

Brent1: <p>Great; thanks for the referenced explanation; I’ll look into it; and try to explore things further.</p>
<p>Really appreciate you input on something so non-pytorch!!</p>