I would like to create a new tensor, which will have the shape (…original_shape…,4)
And will contain the 4 surrounding neighbors of each element, with a special index to the border.
The directions will be “hard coded” (top,right,down,left)
For example,
Create surround function that will return the 4 surrounding elements (including BORDER in the right places) and run it on all tensor elements, and then build a new tensor from the results. But, as you may think, this is not the most efficient thing to do…
(If you can live with 0.0 as your special border value, you can avoid
the cost in time and memory of constructing tpad by using Conv2d with padding_mode = 'zeros'.)
Actually I have to select some of the centers and not all of them.
I have 2 ways to do that:
Add them to the surround tensor above by 5 nonzero elements [add (1,1)] in the kernel, and looking for that value later
Use the original 2D tensor to find [for each sample] the i,j location of the argument passed (the value we are looking for). After, searching in that location on surr
The thing is that I have to locate a value in a 2D tensor on each sample in the batch…seems to be not so efficient