Pytorch Dataset class __getitem__() not being called

Really confused about why the __getitem__() method is not being called here:

class MaleFacesDataset(Dataset):
    def __init__(self, csv_file, root_dir):
        self.landmarks_frame = pd.read_csv(csv_file)
        self.root_dir = root_dir
        self.transform = transform

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

    def __getitem__(self, idx):


        if torch.is_tensor(idx):
            idx = idx.tolist()

        img_name = os.path.join(self.root_dir,
                                self.landmarks_frame.iloc[idx, 0])

        image = io.imread(img_name)
        sample = image

        sample = Image.fromarray(np.uint8(sample)).convert('RGB')
        sample = Image.fromarray(sample.astype('uint8'), 'RGB')

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

        return sample

Have tried rewriting the whole class a few times but still the same problem - any input is appreciated!

Can you show an example of how you are using the dataset class?

Yeah, here is how I am instantiating it:

male_dataset = MaleFacesDataset(csv_file = './attribute_dir', 
                                root_dir= './img_align_celeba', transform= transform)

But, there is no transform parameter in your __init__() constructor

Oh you’re right, i think that is the issue!