Well, I know this question might be not very suitable to ask here, but I really need some help.
Well, I copy the code from the tutorial of pytorch website:https://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html#sphx-glr-beginner-blitz-cifar10-tutorial-py
I ran this code and it worked perfectly. Because I have already download the CIFR-10 data set, I decided to load the data directly from my computer. However, I only changed the data loading method and the neural network stopped working. And the most interesting thing is that I used the same data loading method to train another NN to identify the MNIST data set and it worked perfectly. But it did not work on CIFR-10.
And I downloaded the CIFR-10 data set, found a code to transform those data into .JPG images and classified them into 10 different files with names like “cat”,“airplane” and so on… I do not know why, but this is my code about data loading, I wrote them as 3 functions:
def load_train_dataset():
data_path = ‘C:\Users\…\CIFR-10\train’
train_dataset = torchvision.datasets.ImageFolder(
root=data_path,
transform=torchvision.transforms.ToTensor()
)
train_loader = torch.utils.data.DataLoader(
train_dataset,
batch_size=64,
num_workers=0,
shuffle=True
)
return train_loader
def load_test_dataset():
data_path = ‘C:\Users\…\CIFR-10\test’
test_dataset = torchvision.datasets.ImageFolder(
root=data_path,
transform=torchvision.transforms.ToTensor()
)
test_loader = torch.utils.data.DataLoader(
test_dataset,
batch_size=64,
num_workers=0,
shuffle=False
)
return test_loader
def test_dataset():
data_path = ‘C:\Users\…\CIFR-10\test’
test_dataset = torchvision.datasets.ImageFolder(
root=data_path,
transform=torchvision.transforms.ToTensor()
)
return test_dataset