Best way to extract image patches around a set of landmarks

Gday all,

say I have

  • a batch of images (batch_size, channel, height, width).
  • a batch of landmarks (batch_size, n_landmarks, 2) (i.e. for each image, we have n_landmarks, each landmark is a (x,y) tuple of coordinates in the image)

For each image, I want to extract a patch of size (channel, patch_height, width_height) around each of the corresponding landmarks. The tensorflow equivalent is

I have a numpy implementation here:

This patch extraction occurs several times within the pipeline so I’d like to do it on the GPU side. Is there any smart way to do it without having to write tons of loops ?


:grinning: solution?

I’m also very interested!

Here is an implementation: