/IoTCourseProject

Users can take or upload any image of a flower and the type of flower is recognised and returned

Primary LanguageJava

Intenet of Things (IoT) Course Project - Flower Identification Application

Image Classification of Flowers using an Android Application

Users can take or upload any image of a flower and the type of flower is recognised and returned

Project Documents

  1. YouTube Video
  2. Presentation Slides
  3. Application Demonstration - Selecting a Photo of a Calendula Flower from Gallery
  4. Application Demonstration - Selecting a Photo of a Carnation Flower from Gallery
  5. Application Demonstration - Taking a Photo of a Sunflower Flower using Device Camera
  6. Application Demonstration - Taking a Photo of a Daisy Flower using Device Camera

Training of Model

Dataset

  • flowersDataset obtained from the following dataset found on Kaggle: Flower Dataset

Google Teachable Machine

  • The dataset contains the following 16 categories of flowers:

    • Astilbe (737 Images)
    • Bellflower (873 Images)
    • Black Eyed Susan (1000 Images)
    • Calendula (978 Images)
    • California Poppy (1022 Images)
    • Carnation (923 Images)
    • Coreopsis (1047 Images)
    • Daffodil (970 Images)
    • Daisy (980 Images)
    • Dandelion (1052 Images)
    • Iris (1054 Images)
    • Magnolia (1048 Images)
    • Rose (999 Images)
    • Sunflower (1027 Images)
    • Tulip (1048 Images)
    • Water Lily (982 Images)
  • Total Batch Size (Total number of images in the dataset): 15,740

  • Training Dataset - 85% (Used to train the models to correctly classify the image samples into the pre-existing classes): 13,379

  • Test Dataset - 15% (Not used to train the model; assess how well the model is performing on new, un-seen data): 2,361

  • Epoch (The number of times the training dataset has been fed through the model): 60

  • Batch Size (batch = set of samples used in one iteration of training): 16 --> Number of Batches = 13,379/16 = 837

  • Learning Rate (A tuning parameter in an optimization algorithm that determines the step size at each iteration while moving toward a minimum of a loss function): 0.001

Screenshot 2023-04-29 at 11 27 27 PM

Testing of the Image Classification Model

  • Test images used to test accuracy of the image classification model: testImages

Classification Results

  • Accuracy Per Class:

Accuracy Per Class

  • Accuracy Per Epoch:

Accuracy Per Epoch

  • Confusion Matrix:
    • 3 Classes Most Easiest to Identify Based on the Confusion Matrix:
      1. Dandelion - 154
      2. Tulip - 154
      3. Sunflower - 150
    • 3 Classes Most Difficult to Identify Based on the Confusion Matrix:
      1. Astilbe - 105
      2. Bellflower - 109
      3. Carnation - 118

Confusion Matrix

  • Loss Per Epoch:

Loss Per Epoch

Development of Android Application

  1. Install Android Studio Flamingo
  2. Download folder IoTAndroidApplication
  3. Open folder in Android Studio
  4. Change IP Address to your own in NetworkClient.java

NetworkClient java IP Address

  1. Run on either Emulated Device or Physical Device

Flask Server

Steps to Start & Run Flask Server

  1. Download folder FlaskServer and open in any IDE
  2. Ensure Python Version > 3.8 using the following command: python3 --version
  3. Ensure Pip Version > 20.3: pip3 --version
  4. Install Miniconda using the following command: curl https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -o Miniconda3-latest-MacOSX-x86_64.shbash Miniconda3-latest-MacOSX-x86_64.sh (specifically for MacOS; Choose according to your OS)
  5. Create a Conda Environment using the following command: conda create --name tf python=3.9
  6. Activate Conda Evironment using the following command: conda activate tf
  7. Upgrade Pip using the following command: pip install --upgrade pip
  8. Install TenserFlow using the following command: conda install -c conda-forge tensorflow
  9. Install all necessary packages: pillow, flask, etc
  10. Change IP Address to your own in test.py:

test py Water Lily Test File

  1. Change to an available port number to utilise in model.py:

model py Port Number

  1. Change directories to the FlaskServer folder using the following commad: cd FlaskServer
  2. Run python file, using the following command: python model.py
  3. To deativate the Conda Environment, run the following command: conda deactivate

test.py

  1. Add any flower image that you wish to test to the following folder: testImages
  2. Change the following file path in test.py: resp = requests.post("http://192.168.10.141:8000", files={'file': open('/Users/nikitabachhas/IoTCourseProject/IoTCourseProject/TestImages/water_lily.jpg', 'rb')})
  3. Execute the model.py in the FlaskServer folder
  4. Execute test.py file

test.py results

  • The following imges shows the results obtained when the test image of a water lily is used to test the integration of the flask server with the model and the accuracy of the model:

test py Water Lily Test File

test py Water Lily Test Results

Google Cloud Platform Virtual Machine

Steps to Create a VM Instance

  1. Click on Compute Engine
  2. Click on VM Instances
  3. Ensure that Region = asia-southeast1(Singapore)
  4. Click Create

Steps to Start & Run Flask Server on VM

  1. Use the command pwd to identify the directory that you are in and the command ls to get a list of all the files downloaded or uploaded into the virtual machine
  2. Install wget onto your virtual machine using the following command: sudo apt-get install wget
  3. Download Miniconda onto your virtual machine using the following command: wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh (specifically for those using a Debian/Linux VM)
  4. Execute the downloaded Miniconda file in your virtual machine by using the following command: bash Miniconda3-latest-Linux-x86_64.sh
  5. Restart your virtual machine
  6. Ensure python is installed by using the following command: python
  7. Exit from the python environment using the following command: exit()
  8. Upload these three files into the vritual machine: keras_model.h5, labels.txt and model.py
  9. Create a Conda Environment using the following command: conda create --name tf python=3.9
  10. Activate Conda Evironment using the following command: conda activate tf
  11. Upgrade Pip using the following command: pip install --upgrade pip
  12. Install TenserFlow using the following command: conda install -c conda-forge tensorflow
  13. Install all necessary packages: pillow, flask, etc
  14. Run python file, using the following command: python model.py
  15. To deativate the Conda Environment, run the following command: conda deactivate