How to sample a large image in a grid-like fashion?

Hi all,

So, I have developed an object detector model. It accepts images with a small dimension, let’s say 520x520. I want to infer with this model in a much larger image. Think an aerial or satellite image.

I’d want to sample batches of the large image in a grid-like fashion. Ideally, with some overlap between each image. I mean, I’d like to be able to select a patch size (like the 520x520) and a stride value.

I’ve used torchgeo before, and it has a class made just for this, the GridGeoSampler class. However, it only seems to work with georeferenced data, which the image I’m working with right now isn’t.

The docs for torchgeo mention that for nongeo data to use torchvision’s modules. However, I’m not finding anything that does this as cleanly. I could probably do it manually, but if there is something already made it’s sure to be better. Is there anything built-in that does this?

I’m not aware of any grid-like transformations in torchvision but to create (overlapping) patches of your input tensors you could use tensor.unfold.