Interval equivalences convolution pooling

username: ymentha14
cooked: <p>Hi,</p>
<p>Given an input tensor (1x3xNxN) representing an image which undergoes many 2d convolutions/maxpool transformations, I obtain an output tensor (1xKxMxM) with K an arbitrary number of dimension (one per filter of the last layer) and M the side of the output tensor.</p>
<p>What I would like to do, is given a slice Z in the output generated by one of the K final filters<br>
Z=([x1,x2],[y1,y2]) with 0 &lt;= x1 &lt;= x2 &lt;= M, 0 &lt;= y1&lt;= y2 &lt;= M,<br>
recover the original input slice  Z’=([x1’,x2’],[y1’,y2’]) with<br>
0&lt;= x1’ &lt;= x2’ &lt;= N ,0&lt;= y1’&lt;=y2’&lt;=N<br>
which was the crop of the image which allowed to generate the area in the output layer. I already have a working code for a single convolutional layer and a “single-pixel” (x1’=x2’=x) output interval:</p>
<p>x1’ = max(x <em>S-P,0) x2’  = min(x</em>S +K-P,N)<br>
where S = stride size, P = padding, K = kernel size, N = input size</p>
<p>Is there a way to obtain this using pytorch code exclusively? The current approach would be far from ideal. Thank you for any help!</p>

username: ptrblck
cooked: <p>I’m not sure I understand the question completely, so please correct me if I’m wrong.</p>
<p>Based on the formulas it seems you would like to calculate the receptive field on the convolutions given a specific output activation?</p>

username: ymentha14
cooked: <p>Excuse me for the clumsy explanation: my goal is to calculate the receptive field in the original layer for a given field in the output one.</p>
<p>The figure represents an image (3x224 x 224) going through 17 Conv2d and Maxpool layers (one layer between each frame of the figure,please ignore the last 2 frames) I plot in orange the slice of interest in the output tensor: what I am looking for is a way to recover the white slices for each intermediate frame,i.e the portion of the previous tensor which will generate the next on,everything based on the slice of interest of the last tensor (orange)<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/8/1/813226eb0d68972127c15d2b1093a4bddbd02807.png" data-download-href="https://discuss.pytorch.org/uploads/default/813226eb0d68972127c15d2b1093a4bddbd02807" title="slices"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/8/1/813226eb0d68972127c15d2b1093a4bddbd02807_2_681x500.png" alt="slices" data-base62-sha1="iqV2ILyOZYD645W8jWXUBDDi9DN" width="681" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/8/1/813226eb0d68972127c15d2b1093a4bddbd02807_2_681x500.png, https://discuss.pytorch.org/uploads/default/original/3X/8/1/813226eb0d68972127c15d2b1093a4bddbd02807.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/8/1/813226eb0d68972127c15d2b1093a4bddbd02807.png 2x" data-dominant-color="D7D7D7"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">slices</span><span class="informations">954×700 38.6 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

username: ptrblck
cooked: <p>You could calculate the receptive field manually using the conv and pooling setup, but that is of course quite tedious.<br>
I’m not sure, if there are any libraries providing this functionality with this kind of visualization.</p>
<p>However, I found <a href="https://github.com/fornaxai/receptivefield">this repo</a> which uses a gradient based approach and could thus be suitable for more complex models.</p>

username: ymentha14
cooked: <p>Thank you very much! It looks like it should do!</p>