The ImageFolder will store the image paths and will lazily load the images, transform them if wanted, and will return the data as well as the target tensors. The Subset will store additionally passed indices and the underlying dataset will still contain all image paths. Since they are just paths, you usually wouldn’t care too much about them or the used memory, as it should be tiny compared to the real loaded images.


You could create a custom Dataset as described here 86 and e.g. use internally the ImageFolder as a class attribute. In this way you could pass indices or other arguments to your custom class, while you would still call the ImageFolder to load the data.


Yes, I think there is no limitation to allow flexible use cases, such as iterating the Dataset multiple times, filtering out or duplicating indices.