import grain.python as grain class MyImageSource(grain.RandomAccessDataSource): def __init__(self, file_paths, labels): self._file_paths = file_paths self._labels = labels def __len__(self): return len(self._file_paths) def __getitem__(self, index): # Return raw, unprocessed data. Keep this fast and simple. return { 'path': self._file_paths[index], 'label': self._labels[index], } source = MyImageSource(file_paths=my_paths, labels=my_labels) __ __