PyTorch: Testing With Torchvision.datasets.ImageFolder And DataLoader
Solution 1:
Looking at the data from Kaggle and your code, it seems that there are problems in your data loading, both train and test set. First of all, the data should be in a different folder per label for the default PyTorch ImageFolder
to load it correctly. In your case, since all the training data is in the same folder, PyTorch is loading it as one class and hence learning seems to be working. You can correct this by using a folder structure like - train/dog
, - train/cat
, - test/dog
, - test/cat
and then passing the train and the test folder to the train and test ImageFolder
respectively. The training code seems fine, just change the folder structure and you should be good. Take a look at the official documentation of ImageFolder which has a similar example.
Solution 2:
As per @Monster's comment above here is my folder structure for ImageFolder
- Runtimeerror: Given Groups=1, Weight Of Size [64, 3, 7, 7], Expected Input[3, 1, 224, 224] To Have 3 Channels, But Got 1 Channels Instead
- Randomly Set Some Elements In A Tensor To Zero (with Low Computational Time)
- Why The Model Is Training On Only 1875 Training Set Images If There Are 60000 Images In The Mnist Dataset?
And this how I load the dataset:
train_dataset=datasets.ImageFolder(root="./root/",transform=train_transforms)
Post a Comment for "PyTorch: Testing With Torchvision.datasets.ImageFolder And DataLoader"