shivam2298:

I want to construct a random dataset.


Based on your description, if sounds rather as if you would like to just load images randomly.
If that’s the case, just swap by Dataset for ImageFolder and the code should work nevertheless.