Download as pdf or txt
Download as pdf or txt
You are on page 1of 53

CROP DIAGNOSIS SYSTEM

A project report submitted in partial fulfillment of the requirements for the


degree of

Bachelor of Technology
in
Electronics and Communication Engineering
by
Mukkapati Venkatesh(S160976)

T. Chaitanya Santosh Kumar(S160744)

Ramesh Nethi (S160738)

Under the Guidance Of

Mr.N.Ramesh Babu(M.Tech)

Department Of Electronics and Communication Engineering

Rajiv Gandhi University of Knowledge Technologies


SRIKAKULAM – 532410

MAY - 2022

Page 1
Certificate
This is to certify that the work entitled “crop diagnosis system” is a bonafide record of
authentic work carried out by S160976 – M.Venkatesh ,S160744 – T.Ch. Santosh Kumar
,S160738 – N .Ramesh under my supervision and guidance for the partial fulfillment of the
requirement of the award of the degree of Bachelor of Technology in the department of
Electronics and Communication Engineering at RGUKT- SRIKAKULAM.

The results embodied in this work have not been submitted to any other university or
institute for the award of any degree or diploma. This thesis, in our opinion, is worthy of
consideration for the award of the degree of Bachelor of Technology in accordance with the
regulations of the institute.

Mr.N.Ramesh Babu(M.Tech)

Assistant Professor,

Department of ECE,

RGUKT – Srikakulam

Head of the Department

Page 2
Acknowledgement

I would like to express my special thanks of gratitude to my project guide Mr.N.Rame sh


Babu(M.Tech), Asst.Professor, Dept. of ECE, who gave me the golden opportunity to do
this wonderful project on the topic “CROP DIAGNOSIS SYSTEM”, which also helped
me in doing a lot of research and I came to know about so many new things I am really
thankful to them.

Electronics and Communication Engineering


IIIT – SRIKAKULAM

Date : - 05/05/2022

Place : - Nuzvid

Page 3
TABLE OF CONTENTS

Title Page 1

Certificate 2

Acknowledgement 3

Abstract 7

1. Introduction
2. Literature Review
2.1 Past Research Techniques 10
2.2 Crop yields Development and crop diseases prediction with smart
agriculture 11
2.2.1 Round-the-clock crop monitoring . 11

2.2.2 Advanced fertilizer calculator 12

2.2.3 Effective plant health monitoring 12

3.Models

3.1 Deep Learning Models 14

3.2 Choosing Between Machine Learning and Deep Learning 15

3.3 Creating and Train Deep Learning Models 15

3.4 Feature Extraction 15

3.5 Convolution neural networks 16

3.5.1 Convolution Layer 16

3.5.2 Activation function 17

3.5.3 Pooling Layer 19

3.5.4 Fully Connected Layers 21

3.6 Inception-V 22

Page 4
3.6.1 Smaller convolutions 22

3.6.2 Asymmetric convolutions 24

3.6.3 Auxiliary classifier 24

3.6.4 Grid size reduction 24

3.7 MobileNet V2 25

3.7.1 Arguments 27

4. Methodology

4.1 Dataset 28

4.2. Experimental Configuration 30

4.2.1. Choice of deep learning architecture 30

4.2.2. Choice of training mechanism 30

4.2.3. Choice of dataset type 30

4.2.4. Choice of training-testing set distribution 30

5. Implementation 32

5.1.Preprocessing 32

5.1.1.Data augmentation 32

5.2 Model Parameters 33

5.3 Output Classes 33

5.4 Performace Matrics 33

5.4.1 Confusion Matrix 33

5.4.2. Classification Accuracy 34

5.4.3 Categorical cross-entropy 34

5.5 Functional Requirements 35

5.6 Non-Functional Requirements 35

5.7 System Requirements 36

Page 5
5.7.1 Hardware Requirements 36

5.7.2 Software Requirements 36

6 . Result 38

7.Discussion 40

8.Limitations 42

9. Conclusion and Future work 44

References 45

Appendix 46

Reference Code 46

Page 6
ABBREVATIONS

CNN Convolutional Neural Network

GPU Graphical Processing Unit

HCL Hardware Compatibility

TN True Negative

TP True Positive

FP False Positive

FN False Negative

ReLu Rectified Linear Unit

ANN Artificial Neural Network

DL Deep Learning

Page 7
LIST OF FIGURES

Figure-1 16
Figure-2 18
Figure-3 19

Figure-4 20
Figure-5 21
Figure-6 22
Figure-7 23
Figure-8 24
Figure-9 25
Figure-10 26
Figure-11 26
Figure-12 27
Figure-13 32

Figure-14 37
Figure-15 40
Figure-16 40
Figure-17 41
Figure-18 44

Page 8
LIST OF TABLES
Table-1 27

Table-2 28

Table-3 31

Table-4 36

Table-5 45

Page 9
Abstract

Crop diseases are a major threat to food security, but their rapid identification remains
difficult in many parts of the world due to the lack of the necessary infrastructure. The
combination of increasing global smartphone penetration and recent advances in computer
vision made possible by deep learning has paved the way for smartphone-assisted disease
diagnosis.

Agriculture is the most critical part of the Indian economy so to prevent production
loss, disease attacks must be predicted and treated early. In plants with different climatic
conditions, the disease is very normal and natural which decreases crop productivity. Study
into the use of image processing techniques for plant disease identification has become a hot
subject in order to address these issues. Deep learning (DL) is the golden age of machine
learning (ML), and it is now helping to identify and classify plant diseases early. This review
investigates and analyzed recent methods of Deep Learning, Transfer Learning, and
convolution neural networks for crop disease detection. First, a look at the deep learning
architectures, data sources, and various image processing techniques that were used to process
the imaging data. Many DL architectures have recently been adopted, along with visualization
tools, which are critical for identifying signs and classifying plant diseases.

Keywords: Machine Learning , Deep Learning , Convolution Neural


Network(CNN),Crop diseases.

Page 10
1. Introduction

Plant diseases have always been a significant concern in agriculture since they cause a
reduction in crop quality and consequently, production. The effects of plant diseases range
from minor symptoms to the serious damage of entire areas of planted crops, which causes
major financial costs and impacts heavily on the agricultural economy , especially in
developing countries that depend on a single crop or a few crops.

In order to prevent major losses, various methods have been developed to diagnose
disease. Methods established in molecular biology and immunology provide the precise
identification of causal agents. However, these methods are unavailable for many farmers and
require thorough domain knowledge or a great deal of money and resources to carry out.
According to the Food and Agriculture Organization of the United Nations, the majority of the
world’s farms are small and operated by families in developing countries. These families
produce food for a significant part of the world’s population. Despite this, poverty and food
insecurity are not uncommon and access to markets and services is limited. For the reasons
given above, a lot of research has been carried out in an effort to come up with methods that
will be accurate enough and accessible for the majority of farmers.

Precision agriculture uses the latest technology to optimize the decision-making process
. Thanks to contemporary digital technologies, a great amount of data are being collected in
real-time and various machine learning (ML) algorithms are used to provide optimal decisions,
which has led to a minimization in costs. However, this area is still open for improvements,
especially in the decision-support systems that help in turning massive amounts of data into
useful recommendations.

It has been found that various algorithms and methods such as linear regression, logistic
regression, random forest, clustering, Gaussian models, decision trees (DT), Naïve Bayes (NB),
K-nearest neighbors (KNN), and support vector machines (SVM) among others, can be used
for this purpose. A recent boom in deep learning (DL) methods have also expanded in the
agriculture area. Progression in computer vision and artificial intelligence can lead to new
solutions. These methods provide more accurate predictions than traditional methods, which
enable better decision-making. Owing to advances in hardware technology, DL methods are
now used for solving complex problems in a reasonably short amount of time. The results of
the research in this field are not trivial. DL is already a state-of-the-art technique for land cover
classification tasks, and could also prove useful for many other tasks. Various types of deep
neural networks (DNNs) have achieved remarkable results in the hyperspectral analysis .
Convolutional neural networks (CNNs) have performed well in crop classification tasks , fruit
counting, yield prediction , disease detection , and vision tasks in general . AlexNet and
GoogLeNet architectures have shown state-of-the-art performance in these experiments .
Additionally, it has been shown that better results are acquired if networks are pre-trained .

In order to obtain superior results in the detection of plant disease, DL methods require a greater
amount of data. This is a drawback since currently available datasets are usually small and do
not contain enough images, which is a necessity for high-quality decisions. A comprehensive
dataset must contain images captured in different conditions, as much as possible. When there
is a lack of examples in the training data, and traditional techniques do not improve the results
significantly, generative adversarial networks (GANs) could be used for generating synthetic

Page 11
data. Currently, available solutions with DL methods for plant disease detection have
somewhat been successful, however, there is still large room for improvement.

To develop such a precise image classifier aimed at the diagnosis of diseases in plants, we need
a large, processed, and verified dataset containing variously diseased and healthy plant images.
The Plant Village project has collected thousands of plant images and made them open and free
to use. The dataset is already processed and is available in three versions Colored, grayscale
and segmented.

The rest of this project documentation is organized as follows: Section 2 contains a brief review
of the currently known traditional DL techniques for plant disease detection. Section 3 contains
a series of experiments that cover all of the current methods for plant disease detection while
introducing new approaches that significantly improve the current state. Section 4 represents
the conclusions, followed by a list of the literature.

Page 12
2. Literature review
2.1 Past Research Techniques

In the paper ―Deep learning for Image-Based Plant detection” the authors Prasanna
Mohanty et al., have proposed an approach to detect disease in plants by training a
convolutional neural network. The CNN model is trained to identify healthy and diseased
plants of 14 species. The model achieved an accuracy of 99.35% on test set data. When using
the model on images procured from trusted online sources, the model achieves an accuracy of
31.4%, while this is better than a simple model of random selection, a more diverse set of
training data can aid to increase the accuracy. Also, some other variations of the model or
neural network training may yield higher accuracy, thus paving the path for making plant
disease detection easily available to everyone.

Malvika Ranjan et al. in the paper ―Detection, and Classification of leaf disease using
Artificial Neural Network” proposed an approach to detect diseases in plants utilizing the
captured image of the diseased leaf. Artificial Neural Network (ANN) is trained by properly
choosing feature values to distinguish between diseased plants and healthy samples. The ANN
model achieves an accuracy of 80%.

According to the paper ―Detection of the unhealthy region of plant leaves and
classification of plant leaf diseases using texture features” [3] by S. Arivazhagan, the disease
identification process includes four main steps as follows: first, a color transformation structure
is taken for the input RGB image, and then by means of a specific threshold value, the green
pixels are detected and uninvolved, which is followed by segmentation process, and for
obtaining beneficial segments the texture statistics are computed. At last, the classifier is used
for the features that are extracted to classify the disease..

Kulkarni et al. in the paper ―Applying image processing technique to detect plant
diseases” [4], a methodology for early and accurate plant diseases detection, using artificial
neural network (ANN) and diverse image processing techniques. As the proposed approach is
based on ANN classifier for classification and a Gabor filter for feature extraction, it gives
better results with a recognition rate of up to 91%.

In the paper ―Plant disease detection using CNN and GAN” [5], by Emaneul Cortes,
an approach to detect plant disease using Generative Adversarial networks has been proposed.
Background segmentation is used for ensuring proper feature extraction and output mapping.
It is seen that using Gans may hold promise to classify diseases in plants, however segmenting
based on background did not improve accuracy.

In the paper ―Convolutional Neural Network-based Inception v3 Model for Animal


Classification‖ [6], Jyotsna Bankar et al. have proposed the use of the inception v3 model in
classifying animals in different species. Inception v3 can be used to classify objects as well as
to categorize them, this capability of inception v3 makes it instrumental in various image
classifiers.

Page 13
2.2 Crop yields Development and crop diseases prediction with
smart agriculture :

Saving yields and protecting crops from diseases is a pressing concern for any farmer who
knowledge. Every farmer should be aware of the crop’s susceptibility to specific diseases, as
well as the abiotic agents that promote disease occurrence.

More importantly, one of the most effective practices is to employ preventative measures, such

as:

 Planting of resistant or tolerant varieties


 Managing optimal planting and harvesting times
 Plant quality and healthy material
 Disinfestation of equipment
 Rotating crops
 Plant nutrient management based on crop needs

There are a few other factors that could have a significant impact on the disease of field crops
and their management. Regular crop and field monitoring, as well as timely response, can be a
true lifesaver for any crop production. Here are three ways that smart agriculture can help with
pest crop diseases.

2.2.1. Round-the-clock crop monitoring

Farmers all over the world suffer significant food losses as a result of crop infection by
pathogens such as fungi, viruses, bacteria, and others. Farmers can use an advanced disease
detection and identification solution to reduce crop damage. Farmers can examine the moisture,
temperature, and humidity content of the leaf to detect nutrient deficiencies and disease
infections, which can spread in crops and reduce yield.

Page 14
2.2.2. Advanced fertilizer calculator
A smart solution that includes a fertilizer calculator can assist in calculating the appropriate
amount of fertilizer to use. This saves money on pesticides while also protecting the
environment from agrochemical pollution. Growers can also take preventive measures well in
advance to avoid harvest losses by identifying the region of a farm that is at high risk of disease
outbreaks.

2.2.3 Effective plant health monitoring


In large farms, identifying disease infections in plants through visual inspection can lead to an
incorrect diagnosis. This is where an AI-powered smart agricultural solution comes in. From a
captured image of a leaf, this smart agricultural solution can assist cultivators in determining
whether or not a disease persists in the plants. The technology is used for crop disease
prediction and can recommend tailored plant disease treatment based on fertilizers, triggers,
and symptoms using the captured images.
Plant
diseases pose a serious threat to the entire crop. As a result, it is critical for farmers to
effectively deal with them and control them through timely prevention. This task can be
difficult depending on the size of the agricultural area, especially since the list of harmful crop
diseases is quite long. Farmers can however benefit from modern technologies. Crop
monitoring enables you to identify risky areas and treat each crop individually, significantly
increasing disease control effectiveness.

Page 15
3.Models

3.1 Deep Learning Models

Deep learning is a machine learning technique that teaches computers to do what comes
naturally to humans. Most deep learning methods use neural network architectures, which is
why deep learning models are often referred to as deep neural networks.

The term “deep” usually refers to the number of hidden layers in the neural
network. Traditional neural networks only contain 2-3 hidden layers, while deep networks can
have as many as 150.

Deep learning models are trained by using large sets of labeled data and neural network
architectures that learn features directly from the data without the need for manual feature
extraction.

Figure-1

One of the most popular types of deep neural networks is known as convolutional neural
networks (CNN or ConvNet). A CNN convolves learned features with input data, and uses 2D
convolutional layers, making this architecture well suited to processing 2D data, such as
images.

CNNs eliminate the need for manual feature extraction, so you do not need to identify features
used to classify images. The CNN works by extracting features directly from images. The
relevant features are not pretrained; they are learned while the network trains on a collection
of images. This automated feature extraction makes deep learning models highly accurate for
computer vision tasks such as object classification.

Page 16
3.2 Choosing Between Machine Learning and Deep Learning
Machine learning offers a variety of techniques and models you can choose based on your
application, the size of data you're processing, and the type of problem you want to solve. A
successful deep learning application requires a very large amount of data (thousands of images)
to train the model, as well as GPUs, or graphics processing units, to rapidly process your data.

When choosing between machine learning and deep learning, consider whether you have a
high-performance GPU and lots of labeled data. If you don’t have either of those things, it may
make more sense to use machine learning instead of deep learning.

Deep learning is generally more complex, so you’ll need at least a few thousand images to get
reliable results. Having a high-performance GPU means the model will take less time to
analyze all those images .

3.3 Creating and Train Deep Learning Models


The three most common ways people use deep learning to perform object classification are:

Training from Scratch

To train a deep network from scratch, you gather a very large labeled data set and design a
network architecture that will learn the features and model. This is good for new applications,
or applications that will have a large number of output categories.

This is a less common approach because with the large amount of data and rate of learning,
these networks typically take days or weeks to train.

Transfer Learning

Most deep learning applications use the transfer learning approach, a process that involves
fine-tuning a pretrained model. You start with an existing network, such as AlexNet or
GoogLeNet, and feed in new data containing previously unknown classes.

After making some tweaks to the network, you can now perform a new task, such as
categorizing only dogs or cats instead of 1000 different objects. This also has the advantage of
needing much less data (processing thousands of images, rather than millions), so computation
time drops to minutes or hours.

3.4 Feature Extraction

A slightly less common, more specialized approach to deep learning is to use the network as
a feature extractor. Since all the layers are tasked with learning certain features from images,
we can pull these features out of the network at any time during the training process. These
features can then be used as input to a machine learning model such as support vector machines
(SVM).

Page 17
3.5 Convolution neural networks

A Convolutional Neural Network (ConvNet/CNN) is a Deep Learning algorithm which can


take in an input image, assign importance (learnable weights and biases) to various
aspects/objects in the image and be able to differentiate one from the other. The pre-processing
required in a ConvNet is much lower as compared to other classification algorithms. While in
primitive methods filters are hand-engineered, with enough training, ConvNets have the ability
to learn these filters/characteristics.

Figure-2

3.5.1 Convolution Layer

Convolutional neural networks are composed of multiple layers of artificial neurons. Artificial
neurons, a rough imitation of their biological counterparts, are mathematical functions that
calculate the weighted sum of multiple inputs and outputs an activation value. When you input
an image in a ConvNet, each layer generates several activation functions that are passed on to
the next layer.

The first layer usually extracts basic features such as horizontal or diagonal edges. This output
is passed on to the next layer which detects more complex features such as corners or
combinational edges. As we move deeper into the network it can identify even more complex
features such as objects, faces, etc.

Page 18
Figure-3

The above image shows what a convolution is. We take a filter/kernel(3×3 matrix) and apply
it to the input image to get the convolved feature. This convolved feature is passed on to the
next layer.

3.5.2 Activation function

Activation functions are mathematical equations that determine the output of a neural
network model. Activation functions also have a major effect on the neural network’s
ability to converge and the convergence speed, or in some cases, activation functions might
prevent neural networks from converging in the first place. Activation function also helps
to normalize the output of any input in the range between 1 to -1 or 0 to 1.

Activation function must be efficient and it should reduce the computation time because
the neural network sometimes trained on millions of data points.

Let’s consider the simple neural network model without any hidden layers.

Page 19
Figure-4

Y = ∑(weights*input + bias)

and it can range from -infinity to +infinity. So it is necessary to bound the output to get the
desired prediction or generalized results.

Y = Activation function (∑ (weights*input + bias))

So the activation function is an important part of an artificial neural network. They decide
whether a neuron should be activated or not and it is a non-linear transformation that can
be done on the input before sending it to the next layer of neurons or finalizing the output.

There are perhaps three activation functions you may want to consider for use in hidden layers;
they are:

 Rectified Linear Activation (ReLU)


 Logistic (Sigmoid)
 Hyperbolic Tangent (Tanh)
This is not an exhaustive list of activation functions used for hidden layers, but they are the
most commonly used.

Page 20
3.5.3 Pooling Layer

Similar to the Convolutional Layer, the Pooling layer is responsible for reducing the spatial
size of the Convolved Feature. This is to decrease the computational power required to
process the data by reducing the dimensions. There are two types of pooling average pooling
and max pooling. I’ve only had experience with Max Pooling so far I haven’t faced any
difficulties.

Figure-4

So what we do in Max Pooling is we find the maximum value of a pixel from a portion of the
image covered by the kernel. Max Pooling also performs as a Noise Suppressant. It discards
the noisy activations altogether and also performs de-noising along with dimensionality
reduction.

Page 21
On the other hand, Average Pooling returns the average of all the values from the portion of
the image covered by the Kernel. Average Pooling simply performs dimensionality reduction
as a noise suppressing mechanism. Hence, we can say that Max Pooling performs a lot better
than Average Pooling.

Figure-5

Limitations
Despite the power and resource complexity of CNNs, they provide in-depth results. At the root
of it all, it is just recognizing patterns and details that are so minute and inconspicuous that it
goes unnoticed to the human eye. But when it comes to understanding the contents of an
image it fails.

3.5.4 Fully Connected Layers

Neural networks are a set of dependent non-linear functions. Each individual function consists
of a neuron (or a perceptron). In fully connected layers, the neuron applies a linear
transformation to the input vector through a weights matrix. A non-linear transformation is then
applied to the product through a non-linear activation function f.

Page 22
Here we are taking the dot product between the weights matrix W and the input vector x. The
bias term (W0) can be added inside the non-linear function. I will ignore it in the rest of the
article as it doesn’t affect the output sizes or decision-making and is just another weight.

If we take as an example a layer in a FC Neural Network with an input size of 9 and an output
size of 4, the operation can be visualised as follows:

Figure-6

The activation function f wraps the dot product between the input of the layer and the weights
matrix of that layer. Note that the columns in the weights matrix would all have different
numbers and would be optimized as the model is trained.

The input is a 1x9 vector, the weights matrix is a 9x4 matrix. By taking the dot product and
applying the non-linear transformation with the activation function we get the output vector
(1x4)

Page 23
3.6 Inception-V

Inception v3 mainly focuses on burning less computational power by modifying the previous
Inception architectures. This idea was proposed in the paper [10] published in 2015. It was co-
authored by Christian Szegedy, Vincent Vanhoucke, Sergey Ioffe, and Jonathon Shlens.

In comparison to VGGNet, Inception Networks (GoogLeNet/Inception v1) have proved


to be more computationally efficient, both in terms of the number of parameters
generated by the network and the economical cost incurred (memory and other
resources). If any changes are to be made to an Inception Network, care needs to be
taken to make sure that the computational advantages aren’t lost. Thus, the adaptation
of an Inception network for different use cases turns out to be a problem due to the
uncertainty of the new network’s efficiency. In an Inception v3 model, several
techniques for optimizing the network have been put suggested to loosen the constraints
for easier model adaptation. The techniques include factorized convolutions,
regularization, dimension reduction, and parallelized computations.

Figure-7

The architecture of an Inception v3 network is progressively built, step-by-step, as explained


below:

Page 24
3.6.1 Factorized Convolutions: this helps to reduce the computational efficiency as it reduces
the number of parameters involved in a network. It also keeps a check on the network
efficiency.

3.6.2 Smaller convolutions: replacing bigger convolutions with smaller convolutions


definitely leads to faster training. Say a 5 × 5 filter has 25 parameters; two 3 × 3 filters replacing
a 5 × 5 convolution have only 18 (3*3 + 3*3) parameters instead.

In the middle, we see a 3x3 convolution and below a fully-connected layer. Since both 3x3
convolutions can share weights among themselves, the number of computations can be
reduced.

Figure:-8

Page 25
3.6.3 Asymmetric convolutions: A 3 × 3 convolution could be replaced by a 1 × 3 convolution
followed by a 3 × 1 convolution. If a 3 × 3 convolution is replaced by a 2 × 2 convolution, the
number of parameters would be slightly higher than the asymmetric convolution proposed.

Figure-9 : Asymmetric convolution operation

3.1.1.4. Auxiliary classifier: an auxiliary classifier is a small CNN inserted between layers during
training, and the loss incurred is added to the main network loss. In GoogLeNet auxiliary
classifiers were used for a deeper network, whereas in Inception v3 an auxiliary classifier acts
as a regularizer.

Figure-10 : Operation of Auxiliary Classifier

3.6.4 Grid size reduction:Grid size reduction is usually done by pooling operations. However,
to combat the bottlenecks of computational cost, a more efficient technique is proposed .

Page 26
Figure-11 : Grid size reduction using pooling operation

3.7 MobileNet V2
In MobileNetV2, there are two types of blocks. One is a residual block with a stride of 1. Another one
is blocked with a stride of 2 for downsizing. There are 3 layers for both types of blocks. This time, the
first layer is 1×1 convolution with ReLU6.The second layer is the depthwise convolution. The third
layer is another 1×1 convolution but without any non-linearity. It is claimed that if ReLU is used again,
the deep networks only have the power of a linear classifier on the non-zero volume part of the output
domain. And there is an expansion factor t. And t=6 for all main experiments. If the input got 64
channels, the internal output would get 64×t=64×6=384 channels.

Table:1

Table: Bottleneck residual block transforming from k to k 0 channels, with stride s, and expansion
factor.

The architecture of MobileNetV2 contains the initial fully convolution layer with 32 filters, followed
by 19 residual bottleneck layers described in Table 2. We use ReLU6 as the non-linearity because of

Page 27
its robustness when used with low-precision computation. We always use kernel size 3 × 3 as is
standard for modern networks, and utilize dropout and batch normalization during training. With the
exception of the first layer, we use a constant expansion rate throughout the network. In our
experiments, we find that expansion rates between 5 and 10 result in nearly identical performance
curves, with smaller networks being better off with slightly smaller expansion rates and larger
networks having slightly better performance with larger expansion rates. For all our main experiments
we use an expansion factor of 6 applied to the size of the input tensor. For example, for a bottleneck
layer that takes a 64-channel input tensor and produces a tensor with 128 channels, the intermediate
expansion layer is then 64 · 6 = 384 channels.

Table:2 Mobile Net V2 architectural operations

Table 2: MobileNetV2: Each line describes a sequence of 1 or more identical (modulo stride) layers,
repeated n times. All layers in the same sequence have the same number c of output channels. The
first layer of each sequence has a stride s and all others use stride 1. All spatial convolutions use 3 × 3
kernels. The expansion factor t is always applied to the input size as described in Table 1.

Page 28
3.7.1 Arguments
 Input_shape: Optional shape tuple, to be specified if you would like to use a model
with an input image resolution that is not (224, 224, 3). It should have exactly 3 input
channels (224, 224, 3). You can also omit this option if you would like to infer
input_shape from an input_tensor. If you choose to include both input_tensor and
input_shape then input_shape will be used if they match, if the shapes do not match
then we will throw an error. E.g. (160, 160, 3) would be one valid value.
 alpha: Float, larger than zero, controls the width of the network. This is known as the
width multiplier in the MobileNetV2 paper, but the name is kept for consistency with
applications.MobileNetV1 model in Keras.
o If alpha < 1.0, proportionally decreases the number of filters in each layer.
o If alpha > 1.0, proportionally increases the number of filters in each layer.
o If alpha = 1.0, default number of filters from the paper is used at each layer.
 include_top: Boolean, whether to include the fully-connected layer at the top of the
network. Defaults to True.
 weights: String, one of None (random initialization), 'imagenet' (pre-training on
ImageNet), or the path to the weights file to be loaded.
 input_tensor: Optional Keras tensor (i.e. output of layers.Input()) to use as image input
for the model.
 pooling: String, optional pooling mode for feature extraction when include_top is False.
o None means that the output of the model will be the 4D tensor output of the last
convolutional block.
o avg means that global average pooling will be applied to the output of the last
convolutional block, and thus the output of the model will be a 2D tensor.
o max means that global max pooling will be applied.
 classes: Optional integer number of classes to classify images into, only to be specified
if include_top is True, and if no weights argument is specified.
 classifier_activation: A str or callable. The activation function is to use on the "top"
layer. Ignored unless include_top=True. Set classifier_activation=None to return the
logits of the "top" layer. When loading pre-trained weights, classifier_activation can
only be None or "softmax".
 kwargs: For backward compatibility only.

Page 29
4. Methodology
 4.1 Dataset :
 One of the crucial drawbacks of the present study in the area of plant disease detection
is a major drop in classification performance of the models on real images taken in
fields compared to the images from a controlled environment. The reason for this is that
there is a lack of large public datasets of plant diseases and most of the present
achievements are based on the Plant Village dataset. Plant village consists of 54,323
images divided into 38 classes of diseased and healthy plants based on 14 different crop
species; it is available online from the crowd-sourced platform kaggle (Supplementary
Materials). All images are taken as a single leaf on a solid background labeled only by
a class name. Due to this, Plant Village is used as a performance metric in many papers,
which can be sometimes misleading when used in real on-field data, taking into account
the purity of the dataset.
 In our project, object detection algorithms were explored in the plant disease detection
task. Due to this, the Plan village dataset was additionally labeled generating metadata
holding two types of bounding boxes, one marking the entire leaf and the second one
marking only the infected areas. All additional labeling was performed and verified by
agricultural experts. In order to adapt the plant disease detection model for more
practical usage, a new dataset was introduced, the Plant disease dataset. This dataset is
a continuation of the author’s previous work .
 New images of healthy and diseased leaves have been taken in fields under various
weather conditions and at numerous angles during different daylight intensities.
Alongside this, all images have an inconsistent background, meaning that sometimes a
single leaf is in focus, and sometimes images hold many leaves of different crops
whether they are healthy or infected with different diseases. This way, the dataset
consists of images that mimic practical situations where the model could be potentially
used. All images from the dataset were manually labeled and verified by agricultural
experts. The dataset is publicly available for plant leaf disease detection called
PlantVillage curated by Sharada P. Mohanty et Al.The dataset consists of 87000 RGB
images of healthy and unhealthy plant leaves having 38 classes out of which We have
selected only 25 classes for experimentation of our algorithm These classes are shown
in Table below.

Page 30
Table : Dataset Specifications

Table:3

Page 31
Figure12 : Sample images in the dataset

4.2. Experimental Configuration:

4.2.1. Choice of deep learning architecture:


Inception V3,
MobileNet V2.

4.2.2. Choice of training mechanism:


Transfer Learning,
Training from Scratch.
4.2.3. Choice of dataset type:
Color,
Grayscale,
Leaf Segmented.

4.2.4. Choice of training-testing set distribution:


The train-test split procedure is used to estimate the performance of machine learning
algorithms when they are used to make predictions on data not used to train the model.It is a

Page 32
fast and easy procedure to perform, the results of which allow you to compare the performance
of machine learning algorithms for your predictive modeling problem.
Train: 80%, Test: 20%

Page 33
5. Implementation

5.1 Preprocessing:

processing is a process of preparing the raw data and making it suitable for a machine
learning model. It is the first and crucial step while creating a machine learning model. Real -
world data generally contains noises, and missing values, and may be in an unusable format
that cannot be directly used for machine learning models. Data preprocessing is a required task
for cleaning the data and making it suitable for a machine learning model which also increases
the accuracy and efficiency of a machine learning model.

5.1.1 Data augmentation:

Data augmentation is a strategy that enables practitioners to significantly increase the diversity
of data available for training models, without actually collecting new data. Data augmentation
techniques such as cropping, padding, and horizontal flipping are commonly used to train large
neural networks. It is also the process of modifying, or “augmenting” a dataset with additional
data. This additional data can be anything from images to text, and its use in machine learning
algorithms helps improve their performance.
tf.keras.preprocessing.image.ImageDataGenerator(
rescale = 1./255,
rotation_range=40,
horizontal_flip=True,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.2,
zoom_range=0.2,
fill_mode='nearest' )

5.2 Model Parameters

Solver type: Stochastic Gradient Descent,


• Base learning rate: 0.001,
• Momentum: 0.9,
• Weight decay: 0.0005,
• Gamma: 0.1,
• epochs : 10 , 20
• Batch size: 64 for both Inception V3 and MobileNet V2

Page 34
Loss Function & Optimizer:
optimizer=tf.keras.optimizers.Adam(lr=LEARNING_RATE),
loss='categorical_crossentropy'

5.3 Output Classes


['Apple___Apple_scab', 'Apple___Black_rot', 'Apple___Cedar_apple_rust',
'Apple___healthy', 'Blueberry___healthy', 'Cherry_(including_sour)___Powdery_mildew',
'Cherry_(including_sour)___healthy', 'Corn_(maize)___Cercospora_leaf_spot
Gray_leaf_spot', 'Corn_(maize)___Common_rust_', 'Corn_(maize)___Northern_Leaf_Blight',
'Corn_(maize)___healthy', 'Grape___Black_rot', 'Grape___Esca_(Black_Measles)',
'Grape___Leaf_blight_(Isariopsis_Leaf_Spot)', 'Grape___healthy',
'Orange___Haunglongbing_(Citrus_greening)', 'Peach___Bacterial_spot', 'Peach___healthy',
'Pepper,_bell___Bacterial_spot', 'Pepper,_bell___healthy', 'Potato___Early_blight',
'Potato___Late_blight', 'Potato___healthy', 'Raspberry___healthy', 'Soybean___healthy',
'Squash___Powdery_mildew', 'Strawberry___Leaf_scorch', 'Strawberry___healthy',
'Tomato___Bacterial_spot', 'Tomato___Early_blight', 'Tomato___Late_blight',
'Tomato___Leaf_Mold', 'Tomato___Septoria_leaf_spot', 'Tomato___Spider_mites Two-
spotted_spider_mite', 'Tomato___Target_Spot',
'Tomato___Tomato_Yellow_Leaf_Curl_Virus', 'Tomato___Tomato_mosaic_virus',
'Tomato___healthy']

5.4 Performance Metrics


We used accuracy and loss as the model metrics for both training ,validation and testing
the model.

5.4.1 Confusion Matrix


It is the easiest way to measure the performance of a classification problem where the
output can be of two or more type of classes. A confusion matrix is nothing but a table with
two dimensions viz. “Actual” and “Predicted” and furthermore, both the dimensions have
“True Positives (TP)”, “True Negatives (TN)”, “False Positives (FP)”, “False Negatives (FN)”
as shown below −

Page 35
False Positive

Table:-4

5.4.2. Classification Accuracy


It is most common performance metric for classification algorithms. It may be defined as the
number of correct predictions made as a ratio of all predictions made. We can easily calculate
it by confusion matrix with the help of following formula −

We can use accuracy_score function of sklearn.metrics to compute accuracy of our


classification model.

5.4.3 Categorical cross-entropy:


Categorical cross-entropy is a loss function that is used in multi-class classification
tasks. These are tasks where an example can only belong to one out of many possible
categories, and the model must decide which one. Formally, it is designed to quantify
the difference between two probability distributions.

Page 36
Figure-13 : Cross-Entropy for Neural network

5.5 Functional Requirements


In software engineering, a functional requirement defines a function of a software
system or its component. A function is described as a set of inputs, behavior, and outputs.
Functional requirements may be calculations, technical details, data manipulation and
processing, and other specific functionality that define what a system is supposed to
accomplish. Behavioral requirements describing all the cases where the system uses the
functional requirements are captured in use cases. Functional requirements are supported by
non-functional requirements (also known as quality requirements), which impose constraints
on the design or implementation (such as performance requirements, security, or reliability).

Functional Requirements for Present Project


1. Input: Leaf Image of the trained classes
2. Output: Deceased name
3. Process: AI System Trained on GPU
4. Training: GPU training

5.6 Non-Functional Requirements

In systems engineering and requirements engineering, a non-functional requirement is


a requirement that specifies criteria that can be used to judge the operation of a system, rather
than specific behaviors. This should be contrasted with functional requirements that define
specific behavior or functions In general; functional requirements define what a system is
supposed to do whereas non-functional requirements define how a system is supposed to be.
Non-functional requirements are often called qualities of a system. Other terms for non-

Page 37
functional requirements are "constraints", "quality attributes", "quality goals", "quality of
service requirements," and "non-behavioral requirements." Qualities, that is, non-functional
requirements, can be divided into two main categories one is Execution qualities, such as
security and usability, which are observable at run time, and Evolution qualities, such as
testability, maintainability, extensibility, and scalability, which are embodied in the static
structure of the software system.

Non-Functional Requirements for Present Project

Neat and quality data should be collected in order to train the data and which plays a very
important role in the accuracy and model performance.

5.7 System Requirements

To be used efficiently, all computer software needs certain hardware components or


other software resources to be present on a computer. These prerequisites are known as
(computer) system requirements and are often used as a guideline as opposed to an absolute
rule. Industry analysts suggest that this trend plays a bigger part in driving upgrades to exist
computer systems than technological advancements.

5.7.1 Hardware Requirements


The most common set of requirements defined by any operating system or software
application is the physical computer resources, also known as hardware, a hardware
requirements list is often accompanied by a hardware compatibility list (HCL), especially in
the case of operating systems. An HCL lists tested compatible, and sometimes incompatible
hardware devices for a particular operating system or application. The following subsections
discuss the various aspects of hardware requirements. T

Hardware Requirements for Present Project


1. Processor: Intel Core I3/ I5
2. RAM: 4GB
3. Storage: 20GB
4. Monitor with 1024*720 resolution

5.7.2 Software Requirements


Software Requirements deals with defining software resource requirements and
prerequisites that need to be installed on a computer to provide optimal functioning of an
application. These requirements or pre-requisites are generally not included in the software
installation package and need to be installed separately before the software is installed.

Page 38
Software Requirements for Present Project
1. Operating System: Windows 10
2. Platform & Languages: Google Colab, Python
3. AI Frameworks: Keras, Tensorflow, and Pytorch

Page 39
6.Result

Figure-14 Training epochs result of mobileNet V2:

Figure-15 : Graph of training and validation accuracy with epochs

Page 40
Figure-16 :Result of Random data-1

Figure:-17 Result of Random data-3

Page 41
7.Discussion

The performance of convolutional neural networks in object recognition and image


classification has made tremendous progress in the past few years. (Krizhevsky et al., 2012;
Simonyan and Zisserman, 2014; Zeiler and Fergus, 2014; He et al., 2015; Szegedy et al., 2015).
Previously, the traditional approach for image classification tasks has been based on hand-
engineered features, such as SIFT (Lowe, 2004), HoG (Dalal and Triggs, 2005), SURF (Bay
et al., 2008), etc., and then to use some form of learning algorithm in these feature spaces. The
performance of these approaches thus depended heavily on the underlying predefined features.
Feature engineering itself is a complex and tedious process which needs to be revisited every
time the problem at hand or the associated dataset changes considerably. This problem occurs
in all traditional attempts to detect plant diseases using computer vision as they lean heavily on
hand-engineered features, image enhancement techniques, and a host of other complex and
labor-intensive methodologies.
In addition, traditional approaches to disease classification via machine learning
typically focus on a small number of classes usually within a single crop. Examples include a
feature extraction and classification pipeline using thermal and stereo images in order to
classify tomato powdery mildew against healthy tomato leaves (Raza et al., 2015); the detection
of powdery mildew in uncontrolled environments using RGB images (Hernández-Rabadán et
al., 2014); the use of RGBD images for detection of apple scab (Chéné et al., 2012) the use of
fluorescence imaging spectroscopy for detection of citrus huanglongbing (Wetterich et al.,
2012) the detection of citrus huanglongbing using near infrared spectral patterns (Sankaran et
al., 2011) and aircraft-based sensors (Garcia-Ruiz et al., 2013) the detection of tomato yellow
leaf curl virus by using a set of classic feature extraction steps, followed by classification using
a support vector machines pipeline (Mokhtar et al., 2015), and many others. A very recent
review on the use of machine learning on plant phenotyping (Singh et al., 2015) extensively
discusses the work in this domain. While neural networks have been used before in plant
disease identification (Huang, 2007) (for the classification and detection of Phalaenopsis
seedling disease like bacterial soft rot, bacterial brown spot, and Phytophthora black rot), the
approach required representing the images using a carefully selected list of texture features
before the neural network could classify them.
Our approach is based on recent work Krizhevsky et al. (2012) which showed for the
first time that end-to-end supervised training using a deep convolutional neural network
architecture is a practical possibility even for image classification problems with a very large
number of classes, beating the traditional approaches using hand-engineered features by a
substantial margin in standard benchmarks. The absence of the labor-intensive phase of feature
engineering and the generalizability of the solution makes them a very promising candidate for
a practical and scaleable approach for computational inference of plant diseases.
Using the deep convolutional neural network architecture, we trained a model on
images of plant leaves with the goal of classifying both crop species and the presence and
identity of disease on images that the model had not seen before. Within the PlantVillage data
set of 54,306 images containing 38 classes of 14 crop species and 26 diseases (or absence
thereof), this goal has been achieved as demonstrated by the top accuracy of ___. Thus, without
any feature engineering, the model correctly classifies crop and disease from 38 possible
classes in 993 out of 1000 images. Importantly, while the training of the model takes a lot of
time (multiple hours on a high performance GPU cluster computer), the classification itself is
very fast (less than a second on a CPU), and can thus easily be implemented on a smartphone.
This presents a clear path toward smartphone-assisted crop disease diagnosis on a massive
global scale.

Page 42
However, there are a number of limitations at the current stage that need to be addressed in
future work. First, when tested on a set of images taken under conditions different from the
images used for training, the model's accuracy is reduced substantially, to just above 31%. It's
important to note that this accuracy is much higher than the one based on random selection of
38 classes (2.6%), but nevertheless, a more diverse set of training data is needed to improve
the accuracy. Our current results indicate that more (and more variable) data alone will be
sufficient to substantially increase the accuracy, and corresponding data collection efforts are
underway.
The second limitation is that we are currently constrained to the classification of single leaves,
facing up, on a homogeneous background. While these are straightforward conditions, a real
world application should be able to classify images of a disease as it presents itself directly on
the plant. Indeed, many diseases don't present themselves on the upper side of leaves only (or
at all), but on many different parts of the plant. Thus, new image collection efforts should try
to obtain images from many different perspectives, and ideally from settings that are as realistic
as possible.
At the same time, by using 38 classes that contain both crop species and disease status, we have
made the challenge harder than ultimately necessary from a practical perspective, as growers
are expected to know which crops they are growing. Given the very high accuracy on the
PlantVillage dataset, limiting the classification challenge to the disease status won't have a
measurable effect. However, on the real world datasets, we can measure noticeable
improvements in accuracy. Overall, the presented approach works reasonably well with many
different crop species and diseases, and is expected to improve considerably with more training
data.
Finally, it's worth noting that the approach presented here is not intended to replace existing
solutions for disease diagnosis, but rather to supplement them. Laboratory tests are ultimately
always more reliable than diagnoses based on visual symptoms alone, and oftentimes early-
stage diagnosis via visual inspection alone is challenging. Nevertheless, given the expectation
of more than 5 Billion smartphones in the world by 2020—of which almost a Billion in Africa
(GSMA Intelligence, 2016)—we do believe that the approach represents a viable additional
method to help prevent yield loss. What's more, in the future, image data from a smartphone
may be supplemented with location and time information for additional improvements in
accuracy. Last but not least, it would be prudent to keep in mind the stunning pace at which
mobile technology has developed in the past few years, and will continue to do so. With ever
improving number and quality of sensors on mobiles devices, we consider it likely that highly
accurate diagnoses via the smartphone are only a question of time.

Page 43
8.Limitations
Exhaustive surveys have been conducted where the limitations of current methods for plant
disease detection are summed up. Each of them listed the following challenges:
• Data scarcity
• Using images acquired in real conditions
• More accurate classification of the disease
• Disease stage identification

Figure-18

Page 44
Table-5: Limitation of DL methods for plant disease detection.

Page 45
9. Conclusion and Future work
In our project, we proposed Inception V3 and MobileNet V2 which can improve the
classification accuracy of the model on the plant leaf disease dataset. Moreover, the global
pooling layer can shorten the training time and parameter memory requirements, and also
improve the generalization ability of the model. We trained from scratch and as a result, our
model achieved average accuracy for Inception V3 and MobileNet V2. Compared with some
other CNN methods, it has better adaptability to the change of image spatial position, showing
better robustness to identify different diseases of various plant leaves, not limited to different
diseases of the same plant.
In the future, we develop a robust model for segmenting the deceased lesion of the leaf
which can be used to acknowledge the farmers visually the deceased part of the leaf. And also
we can deploy these models in the drone application used to surveillance the agricultural lands.

Page 46
Appendix
Reference code

# -*- coding: utf-8 -*-


"""Untitled17.ipynb

Automatically generated by Colaboratory.

Original file is located at


https://colab.research.google.com/drive/1npydZh7BTQY1WAKSEXicyyYZfN5FyJs
a

### Import Libraries


"""

from __future__ import absolute_import, division, print_function, unicode_literals

1.import tensorflow as tf
#tf.logging.set_verbosity(tf.logging.ERROR)
#tf.enable_eager_execution()

import tensorflow_hub as hub


import os
from tensorflow.keras.layers import Dense, Flatten, Conv2D
from tensorflow.keras import Model
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.optimizers import Adam
from tensorflow.keras import layers
#from keras import optimizers

from google.colab import drive


drive.mount('/content/drive')

!unzip '/content/drive/MyDrive/CropDiagnosis/dataset.zip'

"""### Prepare training and validation dataset


Create the training and validation directories
"""

train_dir ='/content/dataset/val_ds'
validation_dir = '/content/dataset/train_ds'

import time
import os
from os.path import exists

def count(dir, counter=0):


"returns number of files in dir and subdirs"

Page 47
for pack in os.walk(dir):
for f in pack[2]:
counter += 1
return dir + " : " + str(counter) + "files"

print('total images for training :', count(train_dir))


print('total images for validation :', count(validation_dir))

"""### Label mapping

You'll also need to load in a mapping from category label to category name. You can
find this in the file `categories.json`. It's a JSON object which you can read in with the
[`json` module](https://docs.python.org/2/library/json.html). This will give you a
dictionary mapping the integer encoded categories to the actual names of the plants
and diseases.
"""

!!wget https://github.com/obeshor/Plant-Diseases-Detector/archive/master.zip
!unzip master.zip;

import json

with open('Plant-Diseases-Detector-master/categories.json', 'r') as f:


cat_to_name = json.load(f)
classes = list(cat_to_name.values())

print (classes)

print('Number of classes:',len(classes))

"""###Select the Hub/TF2 module to use"""

module_selection = ("mobilenet_v2", 224, 1280) #@param ["(\"mobilenet_v2\", 224,


1280)", "(\"inception_v3\", 299, 2048)"] {type:"raw", allow-input: true}
handle_base, pixels, FV_SIZE = module_selection
MODULE_HANDLE ="https://tfhub.dev/google/tf2-
preview/{}/feature_vector/2".format(handle_base)
IMAGE_SIZE = (pixels, pixels)
print("Using {} with input size {} and output dimension {}".format(
MODULE_HANDLE, IMAGE_SIZE, FV_SIZE))

BATCH_SIZE = 64 #@param {type:"integer"}

"""### Data Preprocessing

Page 48
Let's set up data generators that will read pictures in our source folders, convert them
to `float32` tensors, and feed them (with their labels) to our network.

As you may already know, data that goes into neural networks should usually be
normalized in some way to make it more amenable to processing by the network. (It
is uncommon to feed raw pixels into a convnet.) In our case, we will preprocess our
images by normalizing the pixel values to be in the `[0, 1]` range (originally all values
are in the `[0, 255]` range).

"""

# Inputs are suitably resized for the selected module. Dataset augmentation (i.e.,
random distortions of an image each time it is read) improves training, esp. when fine-
tuning.

validation_datagen =
tf.keras.preprocessing.image.ImageDataGenerator(rescale=1./255)
validation_generator = validation_datagen.flow_from_directory(
validation_dir,
shuffle=False,
seed=42,
color_mode="rgb",
class_mode="categorical",
target_size=IMAGE_SIZE,
batch_size=BATCH_SIZE)

do_data_augmentation = True #@param {type:"boolean"}


if do_data_augmentation:
train_datagen = tf.keras.preprocessing.image.ImageDataGenerator(
rescale = 1./255,
rotation_range=40,
horizontal_flip=True,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.2,
zoom_range=0.2,
fill_mode='nearest' )
else:
train_datagen = validation_datagen

train_generator = train_datagen.flow_from_directory(
train_dir,
subset="training",
shuffle=True,
seed=42,
color_mode="rgb",
class_mode="categorical",
target_size=IMAGE_SIZE,

Page 49
batch_size=BATCH_SIZE)

"""###Build the model


All it takes is to put a linear classifier on top of the feature_extractor_layer with the Hub
module.

For speed, we start out with a non-trainable feature_extractor_layer, but you can also
enable fine-tuning for greater accuracy.
"""

feature_extractor = hub.KerasLayer(MODULE_HANDLE,
input_shape=IMAGE_SIZE+(3,),
output_shape=[FV_SIZE])

do_fine_tuning = False #@param {type:"boolean"}


if do_fine_tuning:
feature_extractor.trainable = True
# unfreeze some layers of base network for fine-tuning
for layer in base_model.layers[-30:]:
layer.trainable =True

else:
feature_extractor.trainable = False

print("Building model with", MODULE_HANDLE)


model = tf.keras.Sequential([
feature_extractor,
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(512, activation='relu'),
tf.keras.layers.Dropout(rate=0.2),
tf.keras.layers.Dense(train_generator.num_classes, activation='softmax',
kernel_regularizer=tf.keras.regularizers.l2(0.0001))
])
#model.build((None,)+IMAGE_SIZE+(3,))

model.summary()

"""### Specify Loss Function and Optimizer"""

#Compile model specifying the optimizer learning rate

LEARNING_RATE = 0.001 #@param {type:"number"}

model.compile(
optimizer=tf.keras.optimizers.Adam(lr=LEARNING_RATE),
loss='categorical_crossentropy',
metrics=['accuracy'])

Page 50
"""### Train Model
train model using validation dataset for validate each steps
"""

EPOCHS=2 #@param {type:"integer"}

history = model.fit_generator(
train_generator,
steps_per_epoch=train_generator.samples//train_generator.batch_size,
epochs=EPOCHS,
validation_data=validation_generator,
validation_steps=validation_generator.samples//validation_generator.batch_siz
e)

"""###Check Performance
Plot training and validation accuracy and loss
"""

import matplotlib.pylab as plt


import numpy as np

acc = history.history['accuracy']
val_acc = history.history['val_accuracy']

loss = history.history['loss']
val_loss = history.history['val_loss']

epochs_range = range(EPOCHS)

plt.figure(figsize=(8, 8))
plt.subplot(1, 2, 1)
plt.plot(epochs_range, acc, label='Training Accuracy')
plt.plot(epochs_range, val_acc, label='Validation Accuracy')
plt.legend(loc='lower right')
plt.title('Training and Validation Accuracy')
plt.ylabel("Accuracy (training and validation)")
plt.xlabel("Training Steps")

plt.subplot(1, 2, 2)
plt.plot(epochs_range, loss, label='Training Loss')
plt.plot(epochs_range, val_loss, label='Validation Loss')
plt.legend(loc='upper right')
plt.title('Training and Validation Loss')
plt.ylabel("Loss (training and validation)")
plt.xlabel("Training Steps")
plt.show()

"""### Random test

Page 51
Random sample images from validation dataset and predict
"""

# Import OpenCV
import cv2

# Utility
import itertools
import random
from collections import Counter
from glob import iglob

def load_image(filename):
img = cv2.imread(filename)
img = cv2.resize(img, (IMAGE_SIZE[0], IMAGE_SIZE[1]) )
img = img /255

return img

def predict(image):
probabilities = model.predict(np.asarray([img]))[0]
class_idx = np.argmax(probabilities)

return {classes[class_idx]: probabilities[class_idx]}

filename='/content/dataset/val_ds/Apple___Apple_scab/0395b847-2c73-4674-826f-
33a6afb5b4fe___FREC_Scab 3287.JPG'
img = load_image(filename)
prediction = predict(img)
print("PREDICTED: class: %s, confidence: %f" % (list(prediction.keys())[0],
list(prediction.values())[0]))
plt.imshow(img)
plt.figure(idx)
plt.show()

Page 52
References

[1] Mohanty, S. P., Hughes, D. P., & Salathé, M. (2016). Using deep learning for image-based
plant disease detection. Frontiers in Plant Science, 7(September),
[1419].https://doi.org/10.3389/fpls.2016.01419
[2] Mercelin Francis, and C. Deisy. Disease Detection and Classification in Agricultural Plants
Using Convolutional Neural Networks — A Visual Understanding. 2019 6th International
Conference on Signal Processing and Integrated Networks (SPIN).
[3] S.Arivazhagan, R. Newlin Shebiah, S.Ananthi, S.Vishnu Varthini. 2013. Detection of
unhealthy region of plant leaves and classification of plant leaf diseases using texture features.
Agric Eng Int: CIGR Journal.
[4] Huu Quan Cap, Katsumasa Suwa, Erika Fujita, Satoshi Kagiwada, Hiroyuki Uga, and
Hitoshi Iyatomi. A deep learning approach for on-site plant leaf detection. 2018 IEEE 14th
International Colloquium on Signal Processing & Its Applications (CSPA).
[5] Santhosh Kumar S, and B. K. Raghavendra. Diseases Detection of Various Plant Leaf Using
Image Processing Techniques: A Review. 2019 5th International Conference on Advanced
Computing & Communication Systems (ICACCS)
[6] Jyotsna Bankar, and Nitin R Gavai. Convolutional Neural Network based Inception v3
Model for Animal Classification. International Journal of Advanced Research in Computer and
communication Engineering, May 2018
[7] Abirami Devaraj, Karunya Rathan, Sarvepalli Jaahnavi, and K Indira. Identification of Plant
Disease using Image Processing Technique. 2019 International Conference on Communication
and Signal Processing (ICCSP).
[8] Hasan, Reem Ibrahim & Yusuf, Suhaila & Alzubaidi, Laith. (2020). Review of the State of
the Art of Deep Learning for Plant Diseases: A Broad Analysis and Discussion. Plants. 9.
10.3390/plants9101302.
[9]Mohanty SP, Hughes DP and Salathé M (2016) Using Deep Learning for Image-Based Plant
Disease Detection. Front. Plant Sci. 7:1419. doi: 10.3389/fpls.2016.01419.
[10] Rethinking the Inception Architecture for Computer Vision, Christian Szegedy et.al.
https://arxiv.Org/abs/1512.00567

Page 53

You might also like