CROP DISEASE DETECTION USING IMAGE PROCESSING TECHNIQUE AND CNN NETWORKS : Part 1

B.Thushar Marvel
7 min readApr 9, 2022

--

In this article, I have given a detailed explanation on crop disease detection using deep learning and image processing.

Totally 3 different approaches were conducted in this research.

  1. Plant disease detection using image classification model.
  2. Plant disease detection using real time object detection models(YOLO, SSD, Faster R CNN) [ Part 2 ]
  3. Quantification of plant disease severity using OpenCV image processing technique. [ Part 3 ]

Introduction

Automatic object localization and image classification has been one of the major research areas which is in trend nowadays. As we all know that our national economy is highly dependent on our agricultural productivity. If any negligence in this field may result in serious effects on crops, which directly affects our nation.

Every time experts are not available to monitor the crop growth. So developing an automated system for real time disease detection will be very much effective in reducing the time as well as cost for the farmers.

Before moving to core model development part, its better to know the basic functionalities/concepts of neural networks, optimization, loss functions and model metrics which are used in this research.
The detailed explanation of basics are given Basics of Artificial Neural Network and Convolutional Neural Network

Classification and Object Detection

Both classification and object detection uses convolutional neural networks to perform the task

Classification is the technique of classifying the image into classes. This method only classifies the image, it won’t detect any object. The task of classifying the digits, classifying cat and dog are some of the examples for classification. Examples — CNN model, SVM classifier etc

Object detection is the technique of identifying the location of the object present in the image and classify the objects present in that location. The input for object detection model is images with annotation files (bounding box co-ordinate and its class label).The output of the trained object detection model is image enclosed with rectangular boxes along with class label and its confidence. Plant disease detection, fruit counting, face detection are some examples for object detection task. Examples- R-CNN,YOLO, SSD etc

Plant disease detection using image classification model.

Dataset

The data has been taken from the Plant Village Disease Classification Challenge (Plant Village Dataset). I have used only potato plant images for this research. For the image classification model, 2101 training images and 311 test images were used. Augmentation technique is implemented to overcome overfitting and to increase the accuracy of the model.

Data set

Tools used.

  1. Jupyter notebook
  2. Keras (Python Library)
  3. Google colab

Image classification using CNN

Import necessary libraries

Here, we imported all necessary python libraries which will be required in developing the project. Numpy library is imported to perform numerical operations in image. Keras library to build the model. Sklearn library is used to calculate confusion matrix and other evaluation metrics.

Load dataset

Data pre-processing

Image pre-processing using image data generators is done and is also as important as training the model because without proper pre-processing the model may learn the input incorrectly and may start producing improper results. Thus, in order to get correct and accurate results pre-processing needs to be done

Model building

In this step the model is being built, the layers of the model are defined. And the final model is made up of a combination of convolution, pooling and fully connected layers. Here, in this model there are 3 convolution layers, 2 average pooling layers, 1 max pooling layer, 2 fully connected neural network layers and final output softmax layer.

Training the model

The model is trained in a jupyter notebook. The model is compiled as a one using “model.fit.generator”. The model starts to build after this statement which takes some time to completely train and build. The parameters used for training are learning rate=0.001, batch =16, optimizer=adam , loss= cross entropy, epochs=15

CNN architecture for classification model

Results

The classification accuracy is calculated by providing an unseen dataset to the developed CNN model. The model is trained for 15 epochs.

It has been observed in the above figure that the training accuracy increases with increase in the number of epochs. During training it was found that for above 13 epochs, validation accuracy of the model remained almost constant. Further increase in training results in overfitting of the model. Therefore the training process was stopped at 15 epochs. The model training, validation and test accuracy is 97.4%, 96.9% and 97.1% respectively

The performance of the classification model is given in the above table. As shown in table the trained model when tested with a test dataset (311 images) achieved 100 % accuracy in predicting the healthy image. 4 images got misclassified which are of late blight and early blight image. Best precision is for early blight class.

Flow chart of CNN model deployed in app

Build an application and deploy the model.

Build Application

Android application is built using Android studio in kotlin

Before creating the app, first convert the developed CNN model to tensorflow lite model.

APP development

Steps to install Android studio and creating android project

Install Android Studio

Install the android studio software tool. Android Studio is an open source IDE used to build android apps. It has all built in functions to generate apps. In addition to this it also contains built in tools to develop, debug and test the performance of the application in a much faster and easier way.

Install development tool kit

Install the required developer tool kit by following the guidelines in android studio

After installing all the requirements ,the software will

∙ Creates a folder for the current project.

∙ It builds all necessary requirements along with the gradle system.

∙ Opens the code editor with project files.

The Gradle build system

Gradle is used as a build system in android studio. Gradle is used to build our own android projects. It also helps in syncing the libraries into the project. It is an open source custom tool which is used to build android packages. These gradle files are required during building the app.

App layout design

Android studio has built in functions to create the required app layout system. Add 3 push buttons which work as detect, access to camera and access to file manager (photos). Add tensorflow lite model and labels file in assets folder and access these files when push button is pressed by editing the main code. Write the code to import the images and to classify the imported images.

Create a emulator

This task is optional, Android studio has a built in android operating systems.It is possible to test the app in android studio itself by downloading the emulator. Emulators are used to run the developed app in android studio.

Deploy apps on mobile devices.

Finally deploy the built app in android mobile phone by enabling the developer option in mobile.

The built android app is capable of classifying the potato leaf images above 98% accuracy.

The app consists of 3 push buttons. Out of which 2 are for capturing the images and one for detecting. The below shown figure consists of app dashboard image and detected image

Source code for the above classification model is provided here.

Part 2 [Implement object detection models]
CROP DISEASE DETECTION USING IMAGE PROCESSING TECHNIQUE AND CNN NETWORKS : Part2 | by B.Thushar Marvel | Medium

Part 3 [Plant disease severity quantification using Image processing]
CROP DISEASE DETECTION USING IMAGE PROCESSING TECHNIQUE AND CNN NETWORKS : Part 3 | by B.Thushar Marvel | Medium

Please a clap/follow if the content is useful
Thank you

--

--