This problem was solved by modifying the line of code  img_name = os.path.join(self.root_dir, str(self.data['ID'].iloc[idx])+'.npy') from   img_name = os.path.join(self.root_dir, str(self.data['ID'][idx])+'.npy') in the   def __getitem__(self,idx):