Libtorch: A custom (e.g. NOT mnist) Image dataset in C++

Dear All,
I am trying to migrate the python based ImageList and PilImageList from here to Libtorch C++:

Most of the examples I found in C++ are for MNIST and not a custom dataset.
Has anyone done something like this before? or is there a build in ImageFolder in C++?


Anyone … breaking my head on this.

This is what I am looking for in C++:

class ImageList(
    def __init__(self, image_paths, preprocess=None, image_transform=None):
        self.image_paths = image_paths
        self.image_transform = image_transform or transforms.image_transform
        self.preprocess = preprocess

    def __getitem__(self, index):
        image_path = self.image_paths[index]
        with open(image_path, 'rb') as f:
            image ='RGB')

        if self.preprocess is not None:
            image = self.preprocess(image, [])[0]

        original_image = torchvision.transforms.functional.to_tensor(image)
        image = self.image_transform(image)

        return image_path, original_image, image

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