Could you check if the current class to index mapping is the same in both approaches?
Based on your code it looks like you are using ind to get the class folder.
You can check if with printing dataset.class_to_idx.
Let me know, if the mapping is the same, and I’ll have another look at your code.