Pre-Cropping Images Before DataLoader

Hello, I have a large set of images that only a small section of is relevant for training, so I was hoping to pre-crop the images.

I found I could crop the images using standard python cropping images such as this:

img = Image.open(‘file/path.png’)
img2 = img.crop((320,500,686,580)),

but I’m not sure how to implement it within a DataLoader for loading into my model?

Hey Jordan!

If you know that only a certain crop of your images is relevant for training, then I suggest writing a short script that goes through your entire image directory, crops each one and saves it all in a new directory - this process should only be done once and over the entire dataset so it makes more sense to do it before even using fastai for anything. Then, you can proceed to use fastai as usual (just make sure to point it at the directory of the cropped images).