The classes of these two ImageFolder should be identical. However, some folders in ./tr/<CLASSES>/*.jpg are empty. Then how to match the class index for these two ImageFolder.
If the class folder names of both ./train/ and /.tr/ are the same then the indices for each class should be identical by default. This is because the class names are sorted before the class to index map is built: