OxfordPets

artificial-intelligencernnganmicrosoft-for-beginnerslessonsAImicrosoft-AI-For-Beginnersmachine-learning08-TransferLearningdeep-learninglab4-ComputerVisioncomputer-visioncnnNLP

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:

[1]

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:

[2]
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.

[3]

Now we need to separate dataset into train and test portions:

[4]

Now define data loaders:

[5]
[6]
OutputOutput