I’m not sure I understand the use case completely.
Are test and train the two classes you would like to split or are they corresponding to the training and testing datasets and contain subfolders for each class inside of them?
In the latter case passing root=path_to_train_or_test to ImageFolder should work.
What kind of error are you seeing?