PyTorch: Testing with torchvision.datasets.ImageFolder and DataLoader

后端 未结 2 1690
礼貌的吻别
礼貌的吻别 2021-01-11 15:42

I\'m a newbie trying to make this PyTorch CNN work with the Cats&Dogs dataset from kaggle. As there are no targets for the test images, I manually classified some of the

相关标签:
2条回答
  • 2021-01-11 16:15

    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.

    0 讨论(0)
  • 2021-01-11 16:15

    As per @Monster's comment above here is my folder structure for ImageFolder

    And this how I load the dataset:

        train_dataset=datasets.ImageFolder(root="./root/",transform=train_transforms)
    
    0 讨论(0)
提交回复
热议问题