alexcruz0202:

img = Image.open(img_path).convert("RGB")
img = self.aug(image=np.array(img))["image"]
img = self.transform(Image.fromarray(img))



Out of the overall code, this part seems much more computationally expensive, and could be made more efficient. If you don’t mind, could you clarify a few things?

Is it necessary to convert the images to RBG? If yes, you can probably do it beforehand.
What is the use of strong_aug function? Can’t it incorporated in self.transform? Also, you could use the library “albumentations” to make faster data augmentations on the fly
Conversion of PIL image to numpy array and back seems counter intuitive, if they are a part of same Data augmentation pipeline. You could make it more seemless somehow

Along with this, the part where you do random shuffling isn’t required if you rely on pytorch DataLoader’s “shuffle” argument
Hope this helps