Image Classification - Lab

Introduction

Now that you have a working knowledge of CNNs and have practiced implementing associated techniques in Keras, its time to put all of those skills together. In this lab, you'll work to complete a Kaggle competition on classifying dog breeds.

https://www.kaggle.com/c/dog-breed-identification

Objectives

You will be able to:

  • Independently design and build a CNN for image classifcation tasks
  • Compare and apply multiple techniques for tuning a model including data augmentation and adapting pretrained models

Download and Load the Data

Start by downloading the data locally and loading it into a Pandas DataFrame. Be forewarened that this dataset is fairly large and it is advisable to close other memory intensive applications.

The data can be found here:

https://www.kaggle.com/c/dog-breed-identification/data

We recommend downloading the data into this directory on your local computer. From there, be sure to uncompress the folder and subfolders.

#No code persay, but download and decompress the data.

Preprocessing

Now that you've downloaded the data, its time to prepare it for some model building! You'll notice that the current structure provided is not the same as our lovely preprocessed folders that we've been providing you. Instead, you have one large training folder with images and a csv file with labels associated with each of these file types.

Use this to create a directory substructure for a train-validation-test split as we have done previously. Also recall from our previous work that you'll also want to use one-hot encoding as we are now presented with a multi-class problem as opposed to simple binary classification.

#Your code here; open the labels.csv file stored in the zip file

We wish to create our standard directory structure:

  • train
    • category1
    • category2
    • category3 ...
  • val
    • category1
    • category2
    • category3 ...
  • test
    • category1
    • category2
    • category3 ...
#Your code here; transform the image files and then load them into Keras as tensors 
#(be sure to perform a train-val-test split)

Optional: Build a Baseline CNN

This is an optional step. Adapting a pretrained model will produce better results, but it may be interesting to create a CNN from scratch as a baseline. If you wish to, do so here.

#Create a baseline CNN model

Loading a Pretrained CNN

Feature Engineering with the Pretrained Model

Now that you've loaded a pretrained model, it's time to adapt that convolutional base and add some fully connected layers on top in order to build a classifier from these feature maps.

#Your code here; add fully connected layers on top of the convolutional base

Visualize History

Now fit the model and visualize the training and validation accuracy/loss functions over successive epochs.

#Your code here; visualize the training / validation history associated with fitting the model.
#Save model

Final Model Evaluation

#Your code here

Summary

Congratulations! In this lab, you brought all of your prior deep learning skills together from preprocessing including one-hot encoding, to adapting a pretrained model. There are always ongoing advancements in CNN architectures and best practices, but you have a solid foundation and understanding at this point.