OxfordPets
Classification of Pet's Real-Life Images
Lab Assignment from AI for Beginners Curriculum.
Now it's time to deal with more challenging task - classification of the original Oxford-IIIT Dataset. Let's start by loading and visualizing the dataset.
We will define generic function to display a series of images from a list:
You can see that all images are located in one directory called images, and their name contains the name of the class (breed):
To simplify classification and use the same approach to loading images as in the previous part, let's sort all images into corresponding directories:
Let's also define the number of classes in our dataset:
37
Preparing dataset for Deep Learning
To start training our neural network, we need to convert all images to tensors, and also create tensors corresponding to labels (class numbers). Most neural network frameworks contain simple tools for dealing with images:
- In Tensorflow, use
tf.keras.preprocessing.image_dataset_from_directory - In PyTorch, use
torchvision.datasets.ImageFolder
As you have seen from the pictures above, all of them are close to square image ratio, so we need to resize all images to square size. Also, we can organize images in minibatches.
Now we need to separate dataset into train and test portions:
Now define data loaders: