Dynamically access patches from a batch of images

Hi All,

I have been struggling with a way to select patches in images. Currently I am using a for loop as a patch may vary from image to image in the batch. The patch location is decided by the model.

In short I would like to index separate locations in images in a batch. The batch is a 4d matrix. (128,3,128,128)
My output should be (128,3,x,y).

Any help is appreciated.
Thank you

What exactly do you mean by patch?

If you have x-coordinates in the tensor x and y-coordinates in the tensor y you can do the following:

batched_images[128, 3, x, y]

and then reshape it for your requirements.

Thanks richard. I wasn’t clear in my original post, what I wanted to do was apply the manipulation on the gpu. The issue was resolved by preparing a minibatch between calls.