Since there have been some requests on how to implement a dataset with libtorch, here 11 is a simple example. The dataset loads images of apples and bananas by their file names with OpenCV and converts them into a tensor. Furthermore, you can find a classifier in there, train it, and evaluate classification results.
Hope it helps
Martin