How to compute l2 norm between every pixel and its 8-pixel neighborhood?

I want to compute a pixel-wise loss by summing up distances to pixels neighbors. Is there a “sliding window” manner to do that with Pytorch?

You could probably use unfold to get the image patches and calculate the loss on these.
Have a look at this post for an example.

1 Like

Thank u so much! :))

1 Like