Building a CNN for classifying real-world images
So far, we have learned how to perform image classification on the Fashion-MNIST dataset. In this section, we’ll do the same for a more real-world scenario, where the task is to classify images containing cats or dogs. We will also learn how the accuracy of the dataset varies when we change the number of images available for training.
We will be working on a dataset available in Kaggle at https://www.kaggle.com/tongpython/cat-and-dog:
The following code can be found in the Cats_Vs_Dogs.ipynb
file located in the Chapter04
folder on GitHub at https://bit.ly/mcvp-2e. Be sure to copy the URL from the notebook on GitHub to avoid any issues while reproducing the results.
- Import the necessary packages:
import torchvision import torch.nn as nn import torch import torch.nn.functional as F from torchvision import transforms,models,datasets from PIL import Image from torch import optim device = &apos...