Plant Disease Detection App

Plant Disease Detection App

Code Availability

View on GitHub

Video Explanation & Demo

Built With

  • fastai - A deep learning library written in Python based off of PyTorch
  • Flask - Used as web framework for deployment
  • Docker Compose - Used to run application
  • WSGI - Web Server Gateway Interface to communicate with web application
  • AWS - For hosting ML models
  • Swift - For creating iOS app
  • Postman - For testing API
Resources

Project Plan

Flowchart

Model architecture

  • The power of convolutional neural networks (CNNs), specifically, ResNet-50 allows computer to detect patterns in the pixels of images that humans cannot see.

  • As opposed to other ResNet variants, ResNet-50 provides compromise of additional model layers (50) while keeping model storage relatively low (~100mb).

    ResNet50
  • Finally, skip connections helps mitigate vanishing gradient and model performance will perform at least as good as previous layer.

    SkipConnection

Deep Learning techniques used

  1. Model training with Learning rate (LR) scheduler using cosine annealing as opposed to more traditional LR scheduling from lr_max/div to lr_max where div is a number (100000.0 in my case & default for fastai library) for optimal learning rate for better training results

  2. Fine tuning model with freeze for freeze_epochs (transfer learning) then with unfreeze from epochs using discriminative LR (lower LR for earlier layers and greater LR for later layers)

CosineAnnealing

Results

My final models each achieved a validation accuracy of >= 99.2%.

Here are my results for tomatos:

TomatoTable TomatoGraph TomatoConfusionMatrix TomatoResults

Statistical Analysis:

  • The Matthews correlation coefficient (MCC) is in essence a correlation coefficient value between -1 and +1 commonly used in machine learning that considers class imbalances. A coefficient of +1 represents a perfect prediction, 0 an average random prediction and -1 an inverse prediction. It takes into consideration true and false positives and negatives. My model achieved a MCC of 0.991.
  • The F1 score can be interpreted as a weighted average of the precision and recall, where an F1 score reaches its best value at 1 and worst score at 0. This is also helpful in considering class imbalances. My model achieved an F1 score of 0.992.
  • As shown in the train loss and valid loss columns and the Epochs vs Training and Validation graph my model has a good fit after 12 epochs of training
    • A good fit is identified by a training and validation loss that decreases to a point of stability with a minimal gap between the two final loss values.
  • Therefore, based on the previous statistics it can be inferred that the validation accuracy from my results is reliable to diagnose and treat plant diseases.

Experiment for yourself:

In your terminal run:

pip install -r requirements.txt

Get the data from: https://www.kaggle.com/lavaman151/plantifydr-dataset

Points of Improvement:

  • In the future, I would like to add more plant types and diseases to my dataset.
  • Additionally, I want to add more features like plant nutritional deficiency recognition which can help provide insight into pesticide free and biological treatment of plants.
  • Something else I might have done differently was build my app in React Native or Flutter as it would have allowed me to bundle my iOS and Android app together which would be easier to do as the only developer.
  • Finally, I would like to implement and experiment with more state-of-the art models including XResNet and its variants for transfer learning on different datasets.

Final Words

I hope my experiences building this app can shed some light into someone who is looking to get started on a similar ML project. This project was my first experience with deep learning and sparked my passion for computer vision. I loved every bit of the four months I spent on this project.

Get my app

My app was available previously on the App Store and Google Play Store, however, it is no longer available since I wasn’t able to afford to renew my subscription and the cost of maintaining the services for the app was too high at the time.

👥 Collaborators

  • None