Flower Image Classification

Flower Image Classification Project: A Journey into Deep Learning

Introduction

In the realm of artificial intelligence and computer vision, image classification is a fundamental task. It involves training a model to recognize and categorize images into predefined classes. The Flower Image Classification is a project from Udacity’s AI Programming with Python Nanodegree program which i graduated Nov 2023 . In this blog post, we’ll explore the key aspects of this project, from data preparation to model training and deployment.

Project Overview

The goal of the Flower Image Classification project is to build an image classifier capable of identifying different species of flowers. The dataset comprises 102 flower categories, each with its unique characteristics. Our journey involves creating a robust model that can accurately predict the species of a flower based on input images.

Steps Involved

1. Data Preparation

  • The first step is to gather and preprocess the data. The dataset contains images of various flowers, and we split it into three subsets: training, validation, and testing.
  • Each image is labeled with the corresponding flower category.

2. Model Architecture

  • For this project, i employed deep learning techniques. Specifically, with the use PyTorch, a popular deep learning framework.
  • I choose a pre-trained convolutional neural network (CNN) as our base model. In this my  case pretrained   VGG16.
  • The pre-trained model serves as a feature extractor, capturing relevant features from the images.

3. Custom Classifier

  • On top of the pre-trained model, we add a custom classifier. This classifier is a feed-forward neural network with ReLU activations and dropout layers.
  • The classifier’s purpose is to map the extracted features to the 102 flower categories.
  • fine-tune the classifier using backpropagation and track loss and accuracy on the validation set.

4. Training and Hyperparameter Tuning

  • During training, i had to optimize hyperparameters such as learning rate, hidden units, and the number of epochs.
  • Monitor the model’s performance on the validation set and adjust hyperparameters accordingly.

5.Model Training

  • I trained the model for approximately 2,5 hours could have been faster with better internet connectivity , cutting batch size from 64 to 32 also helped model train faster
  •   A PIL to load the image (documentation). It’s best to write a function that preprocesses the image so it can be used as input for the model. This function should process the images in the same manner used for training. Below is plot of a image from process_image  function  that shows it should return the original image (except for the cropped out portions):

 Sanity Checking

Using a trained model for predictions, predictions should  makes sense. Even if the testing accuracy is high, it’s always good to check that there aren’t obvious bugs.  matplotlib can plot the probabilities for the top 5 classes as a bar graph, along with the input image:

 

5. Command Line Applications

  • The second part involves converting  the  trained model into two command line applications:
    • train.py: Used for training the model. It accepts arguments such as data directory, model architecture ( VGG13), learning rate, hidden units, and GPU usage.
    • predict.py: Used for making predictions on new flower images. It takes the path to an image file, a saved checkpoint, and optional parameters like top K most likely classes and category names mapping.

Conclusion

The Flower Image Classification project exemplifies the power of deep learning in solving real-world problems. By combining pre-trained models with custom classifiers, we create an accurate flower species identifier. Link to github project.

 

4 thoughts on “Flower Image Classification”

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top