How to perform shift operation from ShiftNet image inpainting paper

Bhavesh_Patil: <p>Hi,<br>
I am facing difficulty in implementing a <strong>shift layer</strong> from <strong>shiftnet</strong> image inpainting paper.  the link for the paper is <a href="https://arxiv.org/pdf/1801.09392.pdf" rel="noopener nofollow ugc">shiftnet image inpainting paper</a>.<br>
I want to perform cross-correlation operation in the third last layer of the U-Net type architecture given in this paper.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/1/6/16ed2b552e67c4d0323aee4c50ff4a4744a6477c.png" data-download-href="https://discuss.pytorch.org/uploads/default/16ed2b552e67c4d0323aee4c50ff4a4744a6477c" title="Screenshot from 2020-04-28 17-49-07"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/1/6/16ed2b552e67c4d0323aee4c50ff4a4744a6477c_2_690x466.png" alt="Screenshot from 2020-04-28 17-49-07" data-base62-sha1="3gODvg45e2qzAEfuNJs7cDIjFxi" width="690" height="466" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/1/6/16ed2b552e67c4d0323aee4c50ff4a4744a6477c_2_690x466.png, https://discuss.pytorch.org/uploads/default/original/3X/1/6/16ed2b552e67c4d0323aee4c50ff4a4744a6477c.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/1/6/16ed2b552e67c4d0323aee4c50ff4a4744a6477c.png 2x" data-dominant-color="ECE9E7"><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">Screenshot from 2020-04-28 17-49-07</span><span class="informations">940×635 58.1 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>
<p>could someone please help me figure out how can I performs this shift operation in PyTorch?<br>
Thanks in advance</p>

Bhavesh_Patil: <p>The shift vector is computed in the paper as given below<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/0/7/075bbea51828964be53cffde256219e535540af6.png" data-download-href="https://discuss.pytorch.org/uploads/default/075bbea51828964be53cffde256219e535540af6" title="Screenshot from 2020-04-28 17-52-24"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/0/7/075bbea51828964be53cffde256219e535540af6_2_690x384.png" alt="Screenshot from 2020-04-28 17-52-24" data-base62-sha1="135U4AKrWQXDhXRK6NAncHcjMAS" width="690" height="384" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/0/7/075bbea51828964be53cffde256219e535540af6_2_690x384.png, https://discuss.pytorch.org/uploads/default/original/3X/0/7/075bbea51828964be53cffde256219e535540af6.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/0/7/075bbea51828964be53cffde256219e535540af6.png 2x" data-dominant-color="EEEEEE"><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">Screenshot from 2020-04-28 17-52-24</span><span class="informations">830×462 52.8 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>
<p>the idea is basically to perform the nearest neighbour search for each pixel in the corrupted region and then replace the nearest neighbour element inplace and further concatenating with the already upsampled and skip connected feature map.<br>
But I am unable to figure out a way to do so in pytorch!</p>