Crop - Diagnosis - System
Crop - Diagnosis - System
Bachelor of Technology
in
Electronics and Communication Engineering
by
Mukkapati Venkatesh(S160976)
Mr.N.Ramesh Babu(M.Tech)
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
Page 2
Acknowledgement
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
3.Models
3.6 Inception-V 22
Page 4
3.6.1 Smaller convolutions 22
3.7 MobileNet V2 25
3.7.1 Arguments 27
4. Methodology
4.1 Dataset 28
5. Implementation 32
5.1.Preprocessing 32
5.1.1.Data augmentation 32
Page 5
5.7.1 Hardware Requirements 36
6 . Result 38
7.Discussion 40
8.Limitations 42
References 45
Appendix 46
Reference Code 46
Page 6
ABBREVATIONS
TN True Negative
TP True Positive
FP False Positive
FN False Negative
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.
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.
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:
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.
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.
Page 15
3.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 .
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.
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
Figure-2
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.
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.
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:
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.
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.
Figure-7
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.
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.
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.
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: 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
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.
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' )
Page 34
Loss Function & Optimizer:
optimizer=tf.keras.optimizers.Adam(lr=LEARNING_RATE),
loss='categorical_crossentropy'
Page 35
False Positive
Table:-4
Page 36
Figure-13 : Cross-Entropy for Neural network
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.
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.
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
Page 40
Figure-16 :Result of Random data-1
Page 41
7.Discussion
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
1.import tensorflow as tf
#tf.logging.set_verbosity(tf.logging.ERROR)
#tf.enable_eager_execution()
!unzip '/content/drive/MyDrive/CropDiagnosis/dataset.zip'
train_dir ='/content/dataset/val_ds'
validation_dir = '/content/dataset/train_ds'
import time
import os
from os.path import exists
Page 47
for pack in os.walk(dir):
for f in pack[2]:
counter += 1
return dir + " : " + str(counter) + "files"
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
print (classes)
print('Number of classes:',len(classes))
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)
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)
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])
else:
feature_extractor.trainable = False
model.summary()
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
"""
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
"""
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()
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)
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