How to load a large image and split it into patches as a DataLoader

Hi longqi,

I think practically, preprocessing the images into small patches is usually good enough, as long as you don’t have a extreamly small dataset or the location of the patches matters. Based on your description, I assume you are dealing with a medical or remote sensing datasets? In this case, its commonly seen in papers that they cut patches with overlay.

I recently watched some fastai v2 walk-thru videos and I believe in fastai v2 (haven’t tried yet), splitting the images on the fly can be achieved by splitting the image into patches with a custom dataset class after loading it, and return the patches as tuples (like the siamese example), and finally batch them together in the after_batch callback. I remember these tuples are transformed independently so they are effectively

But one thing to note here is that if you cut it on the fly, the shuffling happens among whole images now instead of patches, so maybe you should experiment with your dataset to see if this (lack of) randomization affects training. Since your images are pretty big, I doubt you have enough GPUs to process an image in a single iteration, so you may need to throw some of the patches away to fit in GPU memory.

I’ll get into the new Pipeline API the next few days, if you are interested, I can give you more help after I watch more walk-thru videos :slight_smile:

In conclusion, I would recommend you just preprocess and save the patches.