Hi,
I ran your code and it works just fine. But I have changed few things that I cannot have a clear thought on them:

Is Subset the classes from torch.utils.data.Subset or you have created your own class?
In 2 last lines, you have passed train and test as datasets to data loaders. Is it typo?




 Maryam_M:

trainloader = torch.utils.data.DataLoader( train ###??, batch_size = batch_size, shuffle =True)
testloader = torch.utils.data.DataLoader(test ###?, batch_size=batch_size, shuffle=True)



Here is the code I ran:

from sklearn.model_selection import KFold

!wget https://download.microsoft.com/download/3/E/1/3E1C3F21-ECDB-4869-8368-6DEBA77B919F/kagglecatsanddogs_3367a.zip
!unzip kagglecatsanddogs_3367a.zip

folds = KFold(shuffle=True)
dsets = torchvision.datasets.ImageFolder('PetImages')

for i_fold, (train_idx, valid_idx) in enumerate(folds.split(dsets)):
    dataset_train = data.Subset(dsets, train_idx)
    dataset_valid = data.Subset(dsets, valid_idx)
    trainloader = torch.utils.data.DataLoader(dataset_train, batch_size=256, shuffle =True)
    testloader = torch.utils.data.DataLoader(dataset_valid, batch_size=256, shuffle=True)

bests