Custom Dataset AttributeError:

I have created a custom Dataset but it is throwing AttributeError.

Error Logs

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-20-d59eb5edbfee> in <module>()
----> 1 print(len(mydataset))
      2 print(mydataset[2])

1 frames
<ipython-input-17-15b8607644ab> in __getattr__(self, attribute_name)
     18         return function
     19     else:
---> 20         raise AttributeError
     21 
     22   def __getitem__(self, idx):

AttributeError:

My DataSet:


class OCTDataset(Dataset):
  "OCT Scan data set"
  def __init__(self, images, references, transform = None):
    super(OCTDataset, self).__init__()
    self.images = images
    self.references = references
    self.transform = transform

  def __len__(self):
      return len(self.img)


  def __getitem__(self, idx):
    img = self.images[idx]
    label = self.references[idx]

    data_dict = {'image': img, 'label': label}

    if self.transform:
        data_dict = self.transform(data_dict)   

    return data_dict

Here I am initiating it, it does without any error.

mydataset = OCTDataset(train_oct_images, train_labels)

But when I am running this code to test, it is throwing an error:

print(len(mydataset))
print(mydataset[2])

In your __len__ method, it should be len(self.images) instead of len(self.img).