Project - Build an Image Classifier with Deep Learning

1 minute read

Develop an AI Application

Build a flower image classifier with a Pytorch pre-trained deep learning model. This project is part of the deliverables for my AI Programming with Python Nanodegree (AIPND) with Udacity.

Dataset

The data set contains images of flowers from 102 different species in this dataset from Udacity AIPND program. Here are some example images from the dataset.

png

Visit here to read more about this dataset.

The dataset is split into three parts, training, validation, and testing. During training, we applied transformations such as random scaling, cropping, and flipping, to help the network generalize better and lead to better performance. The validation and testing sets were used to measure the model’s performance on data not seen by the model during training.

The input data was resized to 224x224 pixels in order to use a Pytorch pre-trained model to train the flower image classifier.

Process

Use one of the pretrained models from torchvision.models to get the image features. Built and trained a new feed-forward classifier using those features, as summarized by the following steps:

  • Load and preprocess the image dataset
  • Load a pre-trained network
  • Define a new, untrained feed-forward network as a classifier, using ReLU activations and dropout
  • Train the classifier layers using backpropagation using the pre-trained network to get the features
  • Track the loss and accuracy on the validation set to determine the best hyperparameters
  • Use the trained classifier to predict image content

First work through a Jupyter notebook to implement the steps to build the classifier. After that convert the notebook code into a pair of command line python applications, with one for training a new network then saving the model as a checkpoint file (.pt), and the other, utilizing the checkpoint file to predict the class for an input flower image.

Tool

Jupter Notebook (Python)

Programming library

torch, torchvision, numpy, PIL, python

Artifact

  • Image Classifier Project.ipynb
  • train.py
  • predict.py
  • imageClassifier.pt

See code here.

Updated: