I am trying to use Kfold on image classification task
/data/
class1/ image1
/image2
…
class2/image1
/image2
…
…
class6/image1
/image2
…
My code is as follows

dsets = torchvision.datasets.ImageFolder(data_dir)

for i_fold, (train_idx, valid_idx) in enumerate(folds.split(dsets))
   dataset_train = Subset(dsets, train_idx,transforms = transforms_train)
   dataset_valid = Subset(dsets, valid_idx,transforms=transforms_valid )
 ` trainloader = torch.utils.data.DataLoader( train, batch_size = batch_size, shuffle =True)`

 ` testloader = torch.utils.data.DataLoader(test, batch_size=batch_size,
     shuffle=True)`


for the subset  I copied a new Subset to keep the transform in the Subset (not the parent).
the error i m getting is :
RecursionError: maximum recursion depth exceeded
the labels are the names of the folders
can someone please tell me what s wrong with my code?