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
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.
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)