'Why is my custom dataset giving attribute error?

I am trying the create a custom dataset and if I call neither the getitem or len functions as object.len() or object.getitem(index) I get this error

File ~/Library/Python/3.9/lib/python/site-packages/torch/utils/data/dataset.py:83, in Dataset.__getattr__(self, attribute_name)
     81     return function
     82 else:
---> 83     raise AttributeError

the code itself is like the following,

class CustomDataset(Dataset):
def __init__(self,
             path_to_images,
             transform_extra=None,
             img_size=128):

    self.images= createimages(path, img_size)

def __len__(self):
    return len(self.images)
    
def __getitem__(self, idx):
    return self.images[idx][0], self.images[idx][1]

Images is a 2d list of Pillow images and string labels and the createimages function works outside of the class. I am not very familiar with Python so I was wondering what is going wrong here.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source