every time you index or call retrieve an item from your data class, your code processes all the images again. which i think would be a mistake while training.
shift the data retrieving part in init, and then just return what you have to return in  getitem .  and shouldnt it be def getitem( self, index) ?