The image path is defined as img_loc = self.data_path/f'{idx}.jpg', so it uses the passed idx to the __getitem__. By default this variable will be in the range [0, len(dataset)-1], so you should make sure that all these files exist.