You are on page 1of 35

CASSAVA LEAF DISEASE DETECTION

A PROJECT REPORT

Submitted by

Sweda P
17CSR212

Swetha P
17CSR213

Vidyalakshimi P
17CSR222

in partial fulfilment of the requirements for the award

of the degree

of

BACHELOR OF ENGINEERING

IN

COMPUTER SCIENCE AND ENGINEERING DEPARTMENT OF


COMPUTER SCIENCE AND ENGINEERING SCHOOL OF

COMMUNICATION AND COMPUTER SCIENCES

KONGU ENGINEERING COLLEGE


(Autonomous)

PERUNDURAI ERODE – 638 060

DECEMBER 2020
ii

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING KONGU

ENGINEERING COLLEGE
(Autonomous)

PERUNDURAI ERODE – 638060 DECEMBER 2020

BONAFIDE CERTIFICATE

This is to certify that the Project report entitled Cassava Leaf Disease Detection is the bonafide record of
project work done by SWEDA P (17CSR212), SWETHA P (17CSR213) and VIDYALAKSHIMI
P(17CSR222) in partial fulfillment of the requirements for the award of the Degree of Bachelor of
Engineering in Computer Science and Engineering of Anna University, Chennai during the year 2019 -
2020.

SUPERVISOR HEAD OF THE DEPARTMENT

(Signature with seal)


Date:

Submitted for the end semester viva voce examination held on

INTERNAL EXAMINER EXTERNAL EXAMINER


iii

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING KONGU


ENGINEERING COLLEGE
(Autonomous)

PERUNDURAI, ERODE – 638060


DECEMBER 2020

DECLARATION

We affirm that the Project Report titled Cassava Leaf Disease Detection being submitted in partial
fulfilment of the requirements for the award of Bachelor of Engineering is the original work carried out by
us. It has not formed the part of any other project report or dissertation on the basis of which a degree or
award was conferred on an earlier occasion on this or any other candidate.

Date: (Signature of the candidate)


SWEDA P
(Reg. No.: 17CSR212)
SWETHA P
(Reg. No.:17CSR213)
VIDYALAKSHI P (Reg. No.:
17CSR222)

We certify that the declaration made by the above candidates is true to the best of our
knowledge.

Date: Name and Signature of the Supervisor with seal


iv

ABSTRACT

Cassava plants are a key food security crop grown by local farmers in Africa and in some other parts of the
world due to the plant's ability to withstand harsh outdoor elements. When Cassava plants incur disease, it can
devastate a local farmer's crops and income that drastically affects their source of food and quality of life. There
are variety of diseases found in cassava plants. We have to detect or identify these diseases . Traditionally, this
detection is done mostly through physical inspection and supervision of cassava plants in the garden by farmers or
agricultural extension workers. However, this can be tiresome, capital intensive, and lacks the ability to detect
cassava infection timely to help farmers apply preventive techniques to the non-infected cassava plants in order to
improve on yields.

So, our project is to identify the kind of viral disease infected on the cassava plant as it will be easy for the
farm workers to take a preventive measure on time. We have identified 4 different types of viral diseases namely
Cassava Mosaic Disease(CMD) , Cassava Green Mite (CGM) , Cassava Brown streak Disease (CBSD) ,Cassava
Bacterial Blight (CBB) attempt to expedite disease identification. In this project, We have 21,375 images of
Cassava plants that we will use to train a disease classification model and we give different images to test the
model using convolutional neural network (CNN). We have collected the dataset from Kaggle.80% of our images
is used for training and 20% is used for testing the model. We have been using Convolutional neural network for
image processing considering its advantage over others.

The main advantage of CNN compared to its predecessors is that it automatically detects the important features
without any human supervision. In the existing system, we have acquired the accuracy rate of 92% and in the
proposed system, we have acquired the accuracy of 94.95%.
v

ACKNOWLEDGEMENT

We express our sincere thanks and gratitude to our beloved correspondent Thiru.P.Sachithanandan

for giving us the opportunity to pursue this course.

We are extremely thankful with no words of formal nature to the dynamic principal
Dr.V.Balusamy M.Tech., Ph.D., for providing the necessary facilities to complete our work.

We would like to express our sincere gratitude to our respected Head of the Department
Dr.N.Shanthi M.E., Ph.D., for providing necessary facilities.

Our debt is owed to Dr.E.Gothai PhD., the project coordinator for her encouragement and
valuable advice that made us to carry out the project work successfully.

We extend our gratitude to our supervisor, Ms.M.K.Dharani M.E., for her valuable ideas and
suggestions, which have been very helpful in the project. We are grateful to all the faculty members of the
Computer Science and Engineering Department, for their support.
vi

TABLE OF CONTENTS

CHAPTER No. TITLE PAGE No.

ABSTRACT iv
LIST OF FIGURES viii
LIST OF ABBREVIATIONS ix

1. INTRODUCTION 1
1.1 OVERVIEW OF PROJECT 1
1.2 DEEP LEARNING 2
1.3 CONVOLUTIONAL NEURAL NETWORK 2
1.4 CASSAVA DISEASE DETECTION 4

2. LITERATURE REVIEW 5

3. REQUIREMENTS SPECIFICATION 7
3.1 HARDWARE REQUIREMENT 7
3.2 SOFTWARE REQUIREMENT 7
3.3 SOFTWARE DESCRIPTION 7

4. PROPOSED SYSTEM 11
4.1 INTRODUCTION 11
4.2 MODULE DESCRIPTION 12
5 CONCLUSION AND FUTURE WORK 19

6 APPENDIX 1 20

7 APPENDIX 2 25
REFERENCES 27
LIST OF FIGURES

FIGURE No. TITLE PAGE No.

4.1 Module Diagram 12

4.2 Different types of diseased image 13

4.3 Convolutional Neural Network 15


4.4 Confusion matrix 18
A2.1 Dataset Count 26

A2.2 Labelling 26

A2.3 Training Graph 27


LIST OF ABBREVIATIONS

CNN Convolution Neural Network


ReLu Rectified Linear Unit
ANN Artificial Neural Network
EEG Electro Encephalo Graph
RBM Restricted Boltzmann Machine
WFE Weighted Feature Extraction
SVM Support Vector Machine
GPL General Public License
GUI Graphical User Interface
VGG Visual Geometry Group
DCNN Deep Convolutional Neural Network
DBN-GC Deep Belief Networks with Glia Chains
CBB Cassava Bacterial Blight
CBSD Cassava Brown Streak Disease
CMD Cassava Mosaic Disease
CGM Cassava Green Mottle
1

CHAPTER 1

INTRODUCTION

1.1 OVERVIEW OF PROJECT

Cassava plants are a key food security crop grown by local farmers in Africa due to the plant's ability
to withstand harsh outdoor elements. As one of the biggest providers of carbohydrates in Africa after rice
and maize and at least 80% of household farms in Sub-Saharan Africa grow this starchy root, We have
been tasked with building a model that can identify viral diseases on the plants as this is a major reason of
poor crop yields.

As it stands today, these diseases are transmitted by the whitefly Bemisia tabaci and can quickly
dessimate an entire crop's bounty. If farmers require help to detect disease within their crops, they must go
through an arduous task of soliciting the help of government-funded agricultural experts, leading to delays
in assessing crop damage and risk of destroying their entire crop base due to the spread of disease. As an
added challenge, any image detection solution must perform well under low quality images, since African
farmers may only have access to mobile-quality cameras with low-bandwidth.It classify each Cassava plant
image into four disease categories or a fifth category indicating a healthy plant. With the help of this
model, farmers may be able to quickly identify diseased plants, potentially saving their crops before they
inflict irreparable damage.In this project, we will train a convolutional neural network (CNN) that must
have an accuracy score higher than the baseline accuracy. We demonstrate that by utilizing transfer
learning, applying an EfficientNetB4 architecture and callbacks for early stopping and learning rate
reduction.
1.1 DEEP LEARNING

Deep learning is part of a broader family of machine learning methods based on learning data
representations, as opposed to task-specific algorithms. Learning can be supervised, semi- supervised or
unsupervised. Deep learning architectures such as deep neural networks, deep belief networks and
recurrent neural networks have been applied to fields including computer vision, speech recognition,
object detection, natural language processing, audio recognition, social network filtering, machine
translation, bioinformatics, drug design and board game programs, where they have produced results
comparable to and in some cases superior to human experts. Deep learning models are vaguely inspired
by information processing and communication patterns in object detection yet have various differences
from the structural properties of objects.

1.2 CONVOLUTIONAL NEURAL NETWORK

A convolutional neural network (CNN) is a type of artificial neural network used in image
recognition and processing that is specifically designed to process pixel data. CNNs are like traditional
neural network, but with deeper layers. The innovation of convolutional neural networks is the ability
to automatically learn a large number of filters in parallel specific to a training dataset under the
constraints of a specific predictive modeling problem, such as image classification.

1.2.1 Convolution

Convolution is the first layer to extract features from an input image. Convolution preserves the
relationship between pixels by learning image features using small squares of input data. It is a
mathematical operation that takes two inputs such as image matrix and a filter or kernel.
1.2.2 ReLu (Rectified Linear Unit)

In this step, the rectifier function is applied to increase non-linearity in the CNN. Images are
made of different objects that are not linear to each other. Without applying this function, the image
classification will be treated as a linear problem while it is actually a non- linear one.

1.2.3 Pooling

Pooling layers’ section would reduce the number of parameters when the images are too large.
Spatial pooling also called subsampling or down sampling which reduces the dimensionality of each
map but retains the important information.Max pooling takes the largest element from the rectified
feature map. Taking the largest element could also take the average pooling. Sum of all elements in the
feature map call as sum pooling.

1.2.4 Flattening

Once the pooled featured map is obtained, the next step is to flatten it. Flattening involves
transforming the entire pooled feature map matrix into a single column which is then fed to the neural
network for processing.

1.2.5 Full connection

After flattening, the flattened feature map is passed through a neural network. This step is made
up of the input layer, the fully connected layer, and the output layer. The fully connected layer is
similar to the hidden layer in ANNs but in this case it’s fully connected. The output layer is where we
get the predicted classes. The information is passed through the network and the error of prediction is
calculated. The error is then back propagated through the system to improve the prediction.
1.3 CASSAVA DISEASE DETECTION

Cassava is the third largest source of carbohydrates for human food in the world but is vulnerable to
virus diseases, which threaten to destabilize food security in sub-Saharan Africa. Novel methods of cassava
disease detection are needed to support improved control which will prevent this crisis. Image recognition
offers both a cost effective and scalable technology for disease detection. New deep learning models offer
an avenue for this technology to be easily deployed on mobile devices. Using a dataset of cassava disease
images taken in the field in Tanzania, we applied transfer learning to train a deep convolutional neural
network to identify three diseases and two types of pest damage.

The main goal for the future work will be developing a complete system consisting of server side
components containing a trained model and an application for smart mobile devices with features such as
displaying recognized diseases in this plant, based on leaf images captured by the mobile phone camera.
This application will serve as an aid to farmers (regardless of the level of experience), enabling fast and
efficient recognition of plant diseases and facilitating the decision- making process when it comes to the
use of chemical pesticides.
CHAPTER 2

LITERATURE REVIEW

Cassava Disease detection aimed at detecting cassava diseases using five fine-grained cassava leaf
disease categories with 10,000 labeled images. An emotion-aware personalized music recommendation . To
achieve this correlation, the combined outputs of two approaches is used, the deep convolutional neural
networks (DCNN) approach and the weighted feature extraction (WFE) approach

The paper demonstrate Cassava (Manihot esculenta Crantz) is one of the most common staple
food crops. The leaves and tender shoots are a rich source of proteins and vitamins and contributing to food
security and industrial crop, but the major challenge is that cassava plants are vulnerable to a broad range of
diseases as well as less known viral strains.A approach aims to detect cassava disease by training CNNs
from scratch using an imbalanced dataset. This work presents our techniques used to achieve an accuracy
score of over 93% with a very limited image dataset of 5 fine grained cassava leaf disease categories
having 10000, labeled images. Additionally, these images were highly imbalanced, being heavily biased
towards classes – CMD and CBSD.

Another approach have demonstrated that there are four of the most common cassava diseases .
Each has unique signs and symptoms that appear on the leaf, these can be used to differentiate and
categorize the infections both visually by human eyes and automatically by deep learning algorithms. CGM
causes white spots on the leaves. It starts with small spots which then enlarges to cover the whole leaf
surface leading to loss of chlorophyll hence affecting photosynthesis. CBB causes exhibited are black leaf
spots and blights. The affected leaves dry.
This method explore deep learning for plant disease diagnosis in the early works by using all
used leaf images as a data source. Spectroscopy is to detect and curb infection at early stages.It
introduced a practical and applicable solution for detecting the class and location of diseases. The goal
was to find more suitable deep learning architecture processing units rather than the method of
collecting physical samples (leaves, plants).

Several model architectures such as AlexNet, AlexNetOWTBn, GoogLeNet, Overfeat and VGG
(Solid State Drive) were trained on an open database containing 87,848 images, having 25 different plants
in a set of 58 distinct classes of plant disease combinations, including healthy plant., with the best
performance reaching a 99.53% success rate. Our experiment builds on these previous works as discussed
above but using a small dataset with high class imbalanced.

Convolutional Neural Networks to build a low-cost method to detect cassava infections through
deep-learning. Specific CNN architectures were trained and assessed,to form an automated plant disease
detection and diagnosis system,based on simple images of leaves of healthy and diseased plants. The
available dataset contained images captured in both experimental (laboratory) setups and real cultivation
conditions in the field. The proposed deep learning approach may find more general solutions than shallow
approaches, which learn with less data.

Synthetic Aperture Radar (SAR) is an important mean to obtain information, and it is used
geological survey,topographic mapping, utilization of marine resources, and so on. The reason why it is
worthy to explore in the future is due to its vast practical applications. SAR image recognition always is
seemed as research hotpot, in the process of obtaining information, while feature extraction is one key
factor in the success of an image target recognition system

This model can be integrated into mobile applications for use by farmers or agricultural extension
workers in mobile devices such as smartphones or other unmanned aerial vehicles to be used for real-time
monitoring and early warning of cassava infections so that necessary prevention methods be applied or
large scale implementation can be deployed via satellite imagery analysis to detect areas with infestation
and recommend prevention techniques
CHAPTER 2

REQUIREMENTS SPECIFICATION

3.1 HARDWARE REQUIREMENT

Processor : Intel Processor


Speed : 2.40GHz Hard
Disk : 1 TB
RAM : 8 GB

3.1 SOFTWARE REQUIREMENT

Language : Python
Software : GoogleColab
Operating System : Windows 10

3.2 SOFTWARE DESCRIPTION

3.2.1 Python

Python is a general-purpose interpreted, interactive, object-oriented, and high-level


programming language. Python source code is also available under the General Public License (GPL).
It provides constructs that enable clear programming on both small and large scales. Python feature a
dynamic type system and automatic memory management. It supports
multiple programming paradigms, including object-oriented, imperative, functional and procedural, and
has a large and comprehensive standard library. Python is open source software and has a community-
based development model. Python and Cpython are managed by the non- profit Python Software
Foundation.

The features of python include the below mentioned


 Easy-to-learn :Python has few keyword, simple structure, and a clearly defined syntax. This allows the
student to pick up the language quickly.
 Easy-to-read : Python code is more clearly defined and visible to the eyes.
 Easy-to-maintain :Python’s source code is fairly easy to maintain.
 A broad standard library :Python’s source code is fairly easy to maintain.
 Interactive Mode : Python has a support for an interactive mode which allows interactive testing and
debugging of snippets of code.
 Portable : Python can run on a wide variety of hardware platforms and has the same interface on all
platforms.
 Databases : Python provides interfaces to all major commercial databases.
 GUI Programming : Python supports GUI applications that can be created and ported to many system
calls, libraries and windows systems, such as Windows MFC, Macintosh, and the X Window system of
Unix
 Scalable : Python provides a better structure and support for large programs than shell scripting.

The support of NumPy makes the task easier. NumPy is a highly optimized library for numerical
operations. It gives a MATLAB-style syntax. All the OpenCV array structures are converted to-and-from
NumPy arrays. Increases number of weapons. The several other libraries like SciPy, Matplotlib which
supports NumPy can be used with OpenCV.
3.2.2 Google Colab

Colaboratory, or “Colab” for short, is a product from Google Research. Colab allows anybody to
write and execute arbitrary python code through the browser, and is especially well suited to machine
learning, data analysis and education . It is a free and open source distribution of the Python and
Rprogramming languages for data science and machine learning related applications. Colab allows to use
and share jupyter notebooks with others without having to . download, install or run anything. Colab
notebooks are stored in Google Drive, or can be loaded from GitHub. Colab notebooks can be shared just
as you would with Google Docs or Sheets.

Google Colab is free to use a web that allows to create and share documents that contain:
• code (e.g. Python code)
• Output and comments(can also omit code cell output from being shared)
• Explanatory text

Google Colab is great for the following use cases:


• Learn and try out python
• Data processing / Transformation
• Numeric Simulation
• Statistical Modelling
• Machine Learning

In Google Colab , existing Jupyter notebooks or python code is imported into colab by choosing “Upload
file” from the file menu. It also allows absolutely anyone to develop deep learning applications using
popular libraries such as PyTorch, TensorFlow, Keras, and OpenCV.

3.2.2 Applications of Google Colab

Google Colab is a free cloud service and now it supports free GPU and improve Python
programming language coding skills. develop deep learning applications using popular libraries such as
Keras, TensorFlow, PyTorch, and OpenCV. Uses include, data cleaning and transformation, numerical
simulation, statistical modelling, data visualization, machine learning.
3.2.2 OpenCV

OpenCV is an open source computer vision and machine learning software library. OpenCV
provide a common infrastructure for computer vision applications and to accelerate the use of machine
perception in the commercial products. The library has more than 2500 optimized algorithms, which
includes a comprehensive set of both classic and state-of-the-art computer vision and machine learning
algorithms. These algorithms can be used to detect and recognize faces, identify objects, classify human
actions in videos, track camera movements, track moving objects, extract 3D models of objects, produce
3D point clouds from stereo cameras, stitch images together to produce a high resolution image of an entire
scene, find similar images from an image database, remove red eyes from images taken using flash, follow
eeye movements, recognize scenery and establish markers to overlay it with augmented problems.
OpenCV-Python makes use of NumPy, which is a highly optimized library for numerical operations with a
MATLAB-style syntax. All the OpenCV array structure convets to and from NumPy arrays.
CHAPTER 4

PROPOSED SYSTEM

4.1 INTRODUCTION

Cassava is one of the most common staple food crops grown in sub-Saharan Africa. Common parts
of the plant that can be eaten are leaves and starchy roots; the starchy roots are by far the most commonly
consumed because they are a valuable source of energy and can be eaten raw, roasted on a char-coal stove,
boiled or processed in different ways for human consumption . The leaves and tender shoots are a rich
source of proteins and vitamins and are consumed as a vegetable in many regions . Farmers across Africa
are growing cassava in small, medium to large scale under a wide range of environmental and climatic
conditions contributing to food security and industrial crop, but the major challenge is that cassava plants
are vulnerable to a broad range of diseases as well as less known viral strains. In Uganda, the most common
are CMD which shows symptoms of yellowing and wrinkled leaves and CBB which leads to root rot are
among the serious threats to Sub-Saharan Africa’s food security.

Cassava Mosaic infection was first reported in Tanzania towards the end of the 19th century and
from that time, the epidemic has spread throughout Sub-Saharan Africa resulting in great economic loss
and devastating famine because they are the major constraints to cassava production. This means we need
better-automated approaches that can assist farmers in early detection and prevention of cassava diseases
because conventional plant disease diagnosis by human experts is tiresome, capital intensive, and lacks the
ability to detect cassava infection timely. Our model performance showed promising results and to the best
of our knowledge, there is still no experimentation done for classification of cassava mosaic and other
cassava disease detection by training CNNs from scratch using an imbalanced dataset. This work presents
our techniques used to achieve an accuracy with a very limited image dataset of 5 fine grained cassava leaf
disease categories having 1000, labeled images. Additionally, these images were highly imbalanced, being
heavily biased towards classes – CMD and CBSD.

4.1 MODULE DESCRIPTION

The project has four modules –Collection of Dataset,Image processing, Training the
model,Testing the model
.
CMD

CBB
Extracting features
using CNN and
categorising
diseases CGM

Data Set CBSD

Figure 4.1 Module Diagram

4.1.1 Image Module

Image detection is done with the help of CNN. The features are extracted with the help of CNN
module.

Dataset Description

The dataset used for training is from a Kaggle Cassava Leaf Disease Detection. The dataset consists of 48x
48 pixel grayscale images of cassava diseased plants . The image of the cassava plants are classified into
different types of cassava classes such as Cassava Bacterial Blight (CBB), Cassava Brown Streak Disease
(CBSD), Cassava Green Mottle (CGM) and Cassava
Mosaic Disease (CMD). It consists of nearly 1000 example images corresponding to these classes.
These images are breakdown into Cassava Bacterial Blight(CBB) with 200 samples, Cassava Brown Streak
Disease (CBSD) with 200 samples, Cassava Green Mottle (CGM) with 200 samples and Cassava Mosaic
Disease (CMD) with 200 samples.

4.1.1 Training Module

For image detection, Cascading classifier is used along with the dataset. Using these disease is
identified . The diseases are classified into four categories as shown in Figure 4.3.

Figure 4.3 Different types of diseased images


4.1.1.1 Model Description

The disease of the plant is identified using their feature which is extracted during the process. First
an image is captured. The feature of the diseased plant image is extracted using the Convolutional Neural
Network (CNN). It is an artificial neural network and helps in processing the pixel data. It consists of
deeper layers which are used as filters and is used in image extraction. Some of the convolutional layers are
ReLu layers, pooling layers and some dense layers.This model pre-processed our training images and
performed a validation split where 20% of our images test the model and 80% of images train our model.
We also augment our images by horizontal flips, vertical flips, shifts in ranges, and rotations.

After our images are preprocessed, we then create a CNN by first applying transfer learning,
importing the EfficientNetB4 architecture, and then adding a GlobalAveragePooling2D() and Dense layers
to denote the 5 image classifications. Note our batch size is 16, we run 10 epochs, and the target size of
each image passed into the CNN is 299x299x3. Our steps per epoch & validation are separated like our
training & testing images (20-80 split) and the CNN takes approximately ~50 minutes to run.

It also apply callbacks to make sure our model can stop completely and/or reduce its learning speed
when the model does not improve its validation loss. We also tell our model in a call to save the model
when the model validation loss improves so we have the best model available for future fine tuning.After
completing 10 epochs, the models finishes with an average validation loss of 38% and an average
validation accuracy of 88%. It also identified early stopping on the 10th epoch so no further epochs were
required.
4.1.1.1 Convolutional Layer

Convolution Layer is the first layer to extract features from an input image. It takes two inputs such
as image matrix and a filter or kernel. Different filters are used to enhance the pixel values of the input
image. A set of feature maps are created by applying the filters over the entire image. Each convolutional
layer generates 256 feature maps. It is followed by ReLu, Pooling, MaxPooling layers which are useful to
reduce the dimension of feature maps. After every convolution operation, Rectified Linear Unit (ReLu) is
used. After the completion of convolutional layers, the dimensionality of the featured map has been
reduced using the pooling layer particularly with the help of Max Pooling. Dense layer uses the output
from both the convolutional and pooling layers to represent the high-level features of the input image. At
the output of the dense layer, softmax is used as the activation function. Finally the leaf image is
identified using the CNN . The identified image is then converted into grayscale image and is given as
input to the cascading classifier which helps in identifying the diseases.

Figure 4.3 Convolutional Neural Network


The leaf color, contour, texture, and shape were used to classify plants. The color image was
transformed into a grayscale image , the grayscale image was then converted to a binary one through
binarization, and the contour then extracted. The features are extracted using the characteristics of the
contour line . Using these features, the recognition rate will be increased when classified through machine
learning. Because the shape of the leaf outlines are similar to each other, the features alone make it difficult
to classify the plant.

Input layer is used for preprocessing the image by using OpenCV for detecting the feature in the
image. This layer has predetermined dimensions and the pre-trained filters from the Cascading classifier,
which is used to find and crop the leaf. Then it is converted into grayscale and resized to 48 pixels. It is
used to reduce the dimensions so that it can be easily fed as numpy array into the input layer.

After this process the image is fed into numpy array that is into the input layer, after passing
through the input layer feature extraction is done in the deep neural networks that is in the hidden layer,
after the feature extraction done in the hidden layer and then the images which is assigned for training in
the jason file which is labelled using numbers for the different diseases is trained as if the input is given it is
processed and gives the output as the labeled diseases corresponding to the numbers. After the training
phase the model is trained and it will be tested using different images apart from the images which is used
in the training phase to get the maximum accuracy.

4.1.2 Testing Module

In the last section, we implemented a neural network or created a model which classifies the
different kinds of diseased images in cassava plant. Now, we test our model by grabbing an image apart
from the images in the training model to find the accuracy of the result.
4.1.1.2Experimental Analysis

Precision-Recall is a very useful measure of success of prediction In Data Science, evaluating


model performance is so important that the most commonly used performance metrics in classification are;
confusion matrix [normalized, non-normalized], accuracy, precision, F- Measure, etc…
Precision

Precision is the measure of accurately predicted true positive values to the total number of
positive predicted observations as below.

True positive
Precision =
True positive + False positive
Recall

Recall is the measure of number of positive class predictions made with the all positive
predictions as below.

True positive
Recall =
True positive + False positive
F-Measure

F-Measure is the measure which balances both the precision and recall as below.
Precision

Precision * Recall
F - Measure =
2* Precision + Recall
Accuracy

Accuracy is one metric for evaluating classification models. Informally, accuracy is the
fraction of predictions our model got right. Formally, accuracy has the following definition: Accuracy
= Number of correct predictions Total number of predictions.
True Positive + True Negative
Accuracy =
True Positive + True Negative + False Positive + False Negative

After testing the images using the model that we have designed accuracy is calculated. Accuracy is
calculated using the above given formula with the help of confusion matrix which is designed with the
output which we have obtained when testing the data of different images. After testing we have acquired
the accuracy rate of 94.95% .

Confusion Matrix

A Confusion matrix is an N x N matrix used for evaluating the performance of a classification


model, where N is the number of target classes. The matrix compares the actual target values with those
predicted by the machine learning model. The rows represent the predicted values
of the target variable.

Figure 4.4: Confusion matrix


CHAPTER 5

CONCLUSION AND FUTURE WORKS

In this work, the CNNs model was developed and trained with a very limited dataset having high
class imbalanced. The data was heavily biased towards CMD and CBSD classes, hence, necessitated for
various techniques to counter class imbalanced. Our model performance showed promising results and to
the best of our knowledge, there is still no experimentation done for classification of cassava mosaic and
other cassava disease detection by training CNNs from scratch using an imbalanced dataset. Techniques
applied were class weight, focal loss, SMOTE and different image dimensions which we found input shape
of a vector (448, 448, 3) giving the best performance. Therefore, this model can be integrated into mobile
applications for use by farmers or agricultural extension workers in mobile devices such as smartphones or
other unmanned aerial vehicles to be used for real-time monitoring and early warning of cassava infections
so that necessary prevention methods be applied or large scale implementation can be deployed via satellite
imagery analysis to detect areas with infestation and recommend prevention techniques since most
subsistence farmers in Sub-Saharan Africa cannot afford smartphones due to low level of income.
In our project it is very interesting how the model performance for the imbalanced dataset can be
highly improved by class-weight, SMOTE, focal loss techniques and large input shape dimensions of
images. In the existing model we have the accuracy of 92% and . One key area that still needs further
research though is multiple co-occurring diseases on the same plant. So in upcoming work we will be
proposing a model with a recommendation of fertilizer with respective to its diseases. .
APPENDIX 1 CODING

!pip install --upgrade --force-reinstall --no-deps kaggle # Load


the TensorBoard notebook extension
%load_ext tensorboard import
numpy as np import pandas as pd
import matplotlib.pyplot as plt import
seaborn as sns
import datetime import
random import os, cv2, json
from PIL import Image
from sklearn.model_selection import train_test_split from
sklearn.metrics import accuracy_score
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import models, layers from
keras.models import Model
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from keras.callbacks import ModelCheckpoint, EarlyStopping, ReduceLROnPlateau, TensorBoard from
tensorflow.keras.applications import EfficientNetB4
from keras.optimizers import Adam #
ignoring warnings
import warnings warnings.simplefilter("ignore")
!rm -rf ./logs/
log_dir = "logs/fit/" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S") from
google.colab import files
data_to_load = files.upload()
!mkdir -p ~/.kaggle
!cp kaggle.json ~/.kaggle/
!chmod 600 ~/.kaggle/kaggle.json
!kaggle competitions download -c cassava-leaf-disease-classification import
zipfile
zip_ref = zipfile.ZipFile('cassava-leaf-disease-classification.zip', 'r')
zip_ref.extractall('cassava-leaf-disease-classification') zip_ref.close()
WORK_DIR = os.getcwd()+'/cassava-leaf-disease-classification'
os.listdir(WORK_DIR)
with open(os.path.join(WORK_DIR, "label_num_to_disease_map.json")) as file:
print(json.dumps(json.loads(file.read()), indent=4))
train_labels = pd.read_csv(os.path.join(WORK_DIR, "train.csv"))
train_labels.head()
# Image sample from 5 different classes
sample_images =
['1000015157.jpg','1000723321.jpg','1000910826.jpg','1000201771.jpg','1003442061.jpg']
sample_images_df = train_labels[train_labels.image_id.isin(sample_images)]
plt.figure(figsize=(10,10))
for ind, (image_id, label) in enumerate(zip(sample_images_df.image_id, sample_images_df.label)): plt.subplot(3,
2, ind + 1)
image = cv2.imread(os.path.join(WORK_DIR, "train_images", image_id)) image =
cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
plt.title('{}\n{}'.format(image_id,label))
plt.imshow(image)
plt.axis("off")

plt.show()
sns.countplot(train_labels.label, edgecolor = 'black', palette =
sns.color_palette("viridis", 5))
plt.show()

sample = train_labels[train_labels.label == 3].sample(6)


plt.figure(figsize=(16, 8))
for ind, (image_id, label) in enumerate(zip(sample.image_id, sample.label)):
plt.subplot(2, 3, ind + 1)
image = cv2.imread(os.path.join(WORK_DIR, "train_images", image_id)) image =
cv2.cvtColor(image, cv2.COLOR_BGR2RGB) plt.imshow(image)
plt.axis("off")

plt.show()

sample = train_labels[train_labels.label == 4].sample(6)


plt.figure(figsize=(16, 8))
for ind, (image_id, label) in enumerate(zip(sample.image_id, sample.label)):
plt.subplot(2, 3, ind + 1)
image = cv2.imread(os.path.join(WORK_DIR, "train_images", image_id)) image =
cv2.cvtColor(image, cv2.COLOR_BGR2RGB) plt.imshow(image)
plt.axis("off")

plt.show()
y_pred = [3] * len(train_labels.label) print('The
baseline accuracy: %.3f'
%accuracy_score(y_pred, train_labels.label,normalize=True))
BATCH_SIZE = 16
STEPS_PER_EPOCH = len(train_labels)*0.8 / BATCH_SIZE
VALIDATION_STEPS = len(train_labels)*0.2 / BATCH_SIZE EPOCHS
= 10
TARGET_SIZE = 299

train_labels.label = train_labels.label.astype('str')
#validation_split parameter allows for us to split 20% of the data into the validation set automatically without
train test split
#Then you can allow .flow_from_dataframe to breakout the train versus validation in the data
train_generator = ImageDataGenerator(validation_split = 0.2,
preprocessing_function = None,
zoom_range = 0.2,
cval = 0.2, horizontal_flip =
True, vertical_flip = True,
rotation_range = 5, fill_mode =
'constant', shear_range = 0.2,
height_shift_range = 0.2,
width_shift_range = 0.2) \
.flow_from_dataframe(train_labels,
directory = os.path.join(WORK_DIR, "train_images"), subset
= "training",
x_col = "image_id", y_col =
"label",
target_size = (TARGET_SIZE, TARGET_SIZE),
batch_size = BATCH_SIZE,
class_mode = "sparse")

validation_generator = ImageDataGenerator(validation_split = 0.2) \


.flow_from_dataframe(train_labels,
directory = os.path.join(WORK_DIR, "train_images"), subset
= "validation",
x_col = "image_id", y_col =
"label",
target_size = (TARGET_SIZE, TARGET_SIZE),
batch_size = BATCH_SIZE,
class_mode = "sparse") def
create_model():
model = models.Sequential()

model.add(EfficientNetB4(include_top = False, weights = 'imagenet',


input_shape = (TARGET_SIZE, TARGET_SIZE, 3)))

model.add(layers.GlobalAveragePooling2D())
model.add(layers.Dense(5, activation = "softmax"))

model.compile(optimizer = Adam(lr = 0.001), loss =


"sparse_categorical_crossentropy", metrics =
["acc"])
return model
model = create_model()
model.summary()
log_dir = "logs/fit/" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S")

tensorboard_callback=tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=1)
model_save = ModelCheckpoint('./best_baseline_model.h5',
save_best_only = True,
save_weights_only = True, monitor
= 'val_loss',
mode = 'min', verbose = 1)

early_stop = EarlyStopping(monitor = 'val_loss', min_delta = 0.001,


patience = 5, mode = 'min', verbose = 1,
restore_best_weights = True)
reduce_lr = ReduceLROnPlateau(monitor = 'val_loss', factor = 0.3,
patience = 2, min_delta = 0.001,
mode = 'min', verbose = 1) history
= model.fit(
train_generator,
steps_per_epoch = STEPS_PER_EPOCH, epochs
= EPOCHS,
validation_data = validation_generator,
validation_steps = VALIDATION_STEPS,
callbacks = [tensorboard_callback,model_save, early_stop, reduce_lr]
)
accuracy = history.history['acc'] val_accuracy =
history.history['val_acc'] loss =
history.history['loss']
val_loss = history.history['val_loss'] epochs

= range(1, len(accuracy) + 1)

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(15, 5))


sns.set_style("white")
plt.suptitle('Train history', size = 15)
ax1.plot(epochs, accuracy, "bo", label = "Training acc")
ax1.plot(epochs, val_accuracy, "b", label = "Validation acc")
ax1.set_title("Training and validation acc")
ax1.legend()
ax2.plot(epochs, loss, "bo", label = "Training loss", color = 'red')
ax2.plot(epochs, val_loss, "b", label = "Validation loss", color = 'red')
ax2.set_title("Training and validation loss")
ax2.legend()
plt.show()
model.save('./baseline_model.h5')
ss = pd.read_csv(os.path.join(WORK_DIR, "sample_submission.csv")) ss
reds = []
for image_id in ss.image_id:
image = Image.open(os.path.join(WORK_DIR, "test_images", image_id)) image =
image.resize((TARGET_SIZE, TARGET_SIZE))
image = np.expand_dims(image, axis = 0)
preds.append(np.argmax(model.predict(image)))

ss['label'] = preds ss
APPENDIX 2

OUTPUT

Figure A2.1: Dataset Count


Figure A2.2: Labeling

Figure A2.3: Training Graph


REFERENCES

[1] G. Sambasivam, A predictive machine learning application in agriculture: Cassava disease


detection and classification with imbalanced dataset using convolutional neural network”(2019)

[2] Yang Lua,b, Shujuan Yi a, Nianyin Zengc, Yurong Liude, Yong Zhangf,” Identification of
cassava diseases using deep convolutional neural networks”,(2017

[3] Lei Chen and Yuan Yuan(B),” Agricultural Disease Image Dataset for Disease Identification
Based on Machine Learning”.263-274 (2019)

[4] Konstantinos P. Ferentinos, Hellenic Agricultural Organization “Demeter”, ” Deep learning


models for plant disease detection and diagnosis”, 311–318(2018)

[5] Muhammad Hammad Saleem , Johan Potgieter and Khalid Mahmood Arif,” Plant Disease
Detection and Classification by Deep Learning”,(2019)

[6] Yusuke Kawasaki, Hiroyuki Uga, Satoshi Kagiwada, and Hitoshi Iyatomi,” Basic Study of
Automated Diagnosis of Viral Plant Diseases Using Convolutional Neural Networks”,

[7] Mónica Pineda, María L. Pérez-Bueno and Matilde Barón ,”Infection in plants by
classification method based on imaging data”,(2018)

[8] Rabia Masood Shaheed Zulfikar Ali Bhutto Institute of Science and Technology and
S.A.Khan, M.M.A.Khan Shaheed Zulfikar Ali Bhutto Institute of Science and
Technology,” Plants Disease Segmentation using Image Processing(2017)

[9] Peng Wang , Xiaomin Zhang, and Yan Hao,” A Method Combining CNN and ELM for Feature
Extraction and Classification of SAR Image”,(2019)

You might also like