Mazhar_Shaikh:

os.path.join(self.root_dir, str(self.data[‘ID’][idx])+’.npy’


I  have modified the line
   def __getitem__(self,idx):
       img_name = os.path.join(self.root_dir, str(self.data['ID'][idx])+'.npy')


       patches, p_id = np.load(img_name,allow_pickle= True)

       img_class = (self.data.iloc[idx,2])

       side = self.data.iloc[idx,1]

       if (self.data.iloc[idx,1]==1):
       # #if (self.data.iloc[idx,0]) ==1:
        image = np.array(patches['R'].astype('uint8'), 'L')                                              #[image['R':side]|image['L':side]]
       else:
        image = np.array(patches['L'].astype('uint8'), 'L')

        if self.transform is not None:
           image = self.transform(image)




       sample = {'image': image, 'grade':img_class}


       return sample


new error has occurred. @Mazhar_Shaikh ,
here is the error
runfile('/home/fatema/Downloads/practice1.py', wdir='/home/fatema/Downloads')
Traceback (most recent call last):
  File "/home/fatema/miniconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 3325, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-052e1fda1dc0>", line 1, in <module>
    runfile('/home/fatema/Downloads/practice1.py', wdir='/home/fatema/Downloads')
  File "/home/fatema/Downloads/pycharm-professional-2019.1.3/pycharm-2019.1.3/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "/home/fatema/Downloads/pycharm-professional-2019.1.3/pycharm-2019.1.3/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/fatema/Downloads/practice1.py", line 100, in <module>
    sample = train_data[i]
  File "/home/fatema/Downloads/practice1.py", line 63, in __getitem__
    img_name = os.path.join(self.root_dir, str(self.data['ID'][idx])+'.npy')
  File "/home/fatema/miniconda3/lib/python3.6/site-packages/pandas/core/series.py", line 868, in __getitem__
    result = self.index.get_value(self, key)
  File "/home/fatema/miniconda3/lib/python3.6/site-packages/pandas/core/indexes/base.py", line 4375, in get_value
    tz=getattr(series.dtype, 'tz', None))
  File "pandas/_libs/index.pyx", line 81, in pandas._libs.index.IndexEngine.get_value
  File "pandas/_libs/index.pyx", line 89, in pandas._libs.index.IndexEngine.get_value
  File "pandas/_libs/index.pyx", line 132, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/hashtable_class_helper.pxi", line 987, in pandas._libs.hashtable.Int64HashTable.get_item
  File "pandas/_libs/hashtable_class_helper.pxi", line 993, in pandas._libs.hashtable.Int64HashTable.get_item
KeyError: 0


sorry for asking again because I an very new in pytorch.