LEAF DISEASE PREDICTION USING CLASSIFICATION IN
MACHINE LEARNING AND GUI
ABSTRACT
In agriculture, timely detection and classification of leaf diseases play a
crucial role in ensuring crop health and yield optimization. With the
advent of machine learning (ML) techniques, automated systems have
emerged as effective tools for disease identification, aiding farmers in
making informed decisions regarding crop management. This project
presents a novel approach for leaf disease classification using ML
algorithms, coupled with the prediction of suitable fertilizers and the
season during which the disease is likely to affect the crop. The proposed
system leverages image processing techniques to extract features from
leaf images, which are then used as input for ML models. Various
classifiers such as Convolutional Neural Networks (CNN) are trained on
a dataset comprising images of healthy and diseased leaves to classify
different types of leaf diseases accurately. Overall, the integration of
ML-based disease classification, fertilizer recommendation, and season
prediction offers a comprehensive solution for addressing leaf diseases in
crops, empowering farmers with actionable insights for efficient crop
management. Finally we get a output through Graphical User Interface.It
is one of the user interface that allows users to interact with electronic
devices through graphical icons.
CHAPTER – 1
INTRODUCTION
1.1 Introduction to Leaf Disease Prediction using Machine Learning
The United Nations estimated 2 billion increase in the worlds‘ population
by next 30 years, a significant increase of nearly 25% [1]. According to
the report of the Food and Agricultural Organization (FAO), to feed this
population, about 70-90% more food will be required. Of the total
agricultural crop production worldwide, damage of nearly 16% has been
caused by the microbial diseases. In order to minimize the occurrence of
diseases as well as maximizing the productivity and ensuring agricultural
sustainability, there is a need for advanced disease detection in preventing
damages to crops. Hence, predetermining plant diseases and their
prevention have raised a great interest in researchers. Diseases prediction
in crops depends on various environmental and weather conditions, under
which a pathogen can survive. When pathogen comes in contact with a
susceptible host, it can infect and can cause severe losses to the
agriculture production. The diseases in plants causes a drop in the quality
and quantity of the agricultural output [2]. One of the most common
diseases is fungi, present in the plant leaves. Fungi is the most diverse
group of plant pathogens, accounting for over 70-80% of plant diseases .
There are over 20,000 species of fungi that are parasitic and responsible
for infections in crops and plants, thereby the quality of leaves, fruits,
stem, vegetables, and their products gets suffered. There are two key
factors ‘Disease‘ and ‘Disorder‘ that affect the crops and their products.
Disease, the biotic factors, are caused either by fungi or by bacteria or
algae, and the disorder are the abiotic factors caused by the atmospherics
conditions ( temperature, rainfall, moisture etc.) [4]. These infectious
crop diseases, if not treated timely, can significantly reduce the yield, thus
endangering global food security. Early disease diagnosis and providing
the control measures can help the farmers to save the crops. These
measures include direct or indirect disease identification methods. Direct
detection methods mainly include laboratory-based techniques, while
indirect methods use optical sensors for thermography, fluorescence
imaging, and hyper spectral techniques. The limitation of various optical
sensing techniques is the large amount of data acquired and the
complexity of the data collected. In order to effectively utilize these
techniques, it requires high setup and computational costs along with the
knowledge of data analytics and statistical methods Manual prediction of
potato disease is time-consuming, hard and expensive, while the
computerized system is cost effective and more efficient. Recently,
machine Learning (ML) system are extensively used to automate the
processes. Machine learning can be an efficient way to monitor plant
health status and early plant disease predictions. Every disease has some
noticeable symptoms on the plants‘ leaves. These symptoms, for
example, a visible pattern of the affected leaves help to predict the
disease. In this way, machine learning (ML) provides a solution to
agricultural productivity issues and guarantees food safety
1.2 Importance of Early Disease Detection:
The occurrence of plant diseases has a negative impact on agricultural
production. If plant diseases are not discovered in time, food insecurity
will increase [1]. Early detection is the basis for effective prevention and
control of plant diseases, and they play a vital role in the management and
decision making of agricultural production. In recent years, plant disease
identification has been a crucial issue. Disease-infected plants usually
show obvious marks or lesions on leaves, stems, flowers, or fruits.
Generally, each disease or pest condition presents a unique visible pattern
that can be used to uniquely diagnose abnormalities. Usually, the leaves
of plants are the primary source for identifying plant diseases, and most
of the symptoms of diseases may begin to appear on the leaves .The best
solution to the problem is to identify the disease of the plant so that
precautionary steps can be taken to safeguard the same. This paper
implements the concept of applying convolutional neural network
implementation to the detection of leaf disease in the plant and suggests a
suitable solution to the farmer to recover the same.
Farmers with less experience may misjudgment and use drugs blindly
during the identification process. Quality and output will also bring
environmental pollution, which will cause unnecessary economic losses.
To counter these challenges, research into the use of image processing
techniques for plant disease recognition has become a hot research topic.
1.3 Challenges in Current Detection Methods
Deep learning models became an attractive and efficient alternative for
leaf disease detection when compared with traditional models. The
rationale behind this is that the deep models could handle large datasets
and support for pre-trained models. For image-based detection of diseases
and classification using leafs as input, deep learning models explored
different crops in agriculture. This study has assumed significance in the
wake of Precision Agriculture (PA) efforts across the globe. Technology
driven approach in detection of crop diseases lead to innovations in early
identification of problems in agricultural crops and take necessary steps.
Many researchers. Most of the research papers use Convolutional Neural
Network (CNN) architectures for deep learning-based disease detection.
CNN is used in [5] and [6] for disease detection in Paddy and Tomato
plants. In and also CNN is used for disease detection using plant leaves‘
images. There are some research pertaining to leaf disease datasets and
the impact of size as explored in [8]. Deep CNN is used in for rice
diseases prediction. From the literature, it is understood that the existing
methods are based on CNN for deep learning. However, there is need for
novel architectures with pre-trained models and the existing models have
not used transfer learning. This paper uses transfer learning with a deep
learning framework with pre-trained deep models to classify diseases of
crop.
CHAPTER – 2
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING
BASICS
2.1 ARTIFICIAL INTELLIGENCE
Artificial Intelligence(AI), digital computer or computer-
controlled robot to perform tasks commonly associated with intelligent
beings. The term is frequently applied to the project of developing
systems endowed with the intellectual processes characteristic of humans,
such as the ability to reason, discover meaning, generalize, or learn from
past experience. Since the development of the digital computer in the
1940s, it has been demonstrated that computers can be programmed to
carry out very complex tasks—as, for example, discovering proofs for
mathematical theorems or playing chess—with great proficiency. Still,
despite continuing advances in computer processing speed and memory
capacity, there are as yet no programs that can match human flexibility
over wider domains or in tasks requiring much everyday knowledge. On
the other hand, some programs have attained the performance levels of
human experts and professionals in performing certain specific tasks, so
that artificial intelligence in this limited sense is found in applications
as diverse as medical diagnosis, computer search engines, and voice or
handwriting recognition.
BASICS
A typical AI analyzes its environment and takes actions that
maximize its chance of success. An AI's intended utility function (or
goal) can be simple ("1 if the AI wins a game of Go, 0 otherwise") or
complex ("Do mathematically similar actions to the ones succeeded in the
past"). Goals can be explicitly defined, or induced. If the AI is
programmed for "reinforcement learning", goals can be implicitly
induced by rewarding some types of behavior or punishing
others. Alternatively, an evolutionary system can induce goals by using a
"fitness function" to mutate and preferentially replicate high-scoring AI
systems, similarly to how animals evolved to innately desire certain goals
such as finding food. Some AI systems, such as nearest-neighbor, instead
of reason by analogy, these systems are not generally given goals, except
to the degree that goals are implicit in their training data. Such systems
can still be benchmarked if the non-goal system is framed as a system
whose "goal" is to successfully accomplish its narrow classification task.
AI often revolves around the use of algorithms. An algorithm is a set of
unambiguous instructions that a mechanical computer can execute. A
complex algorithm is often built on top of other, simpler, algorithms. A
simple example of an algorithm is the following (optimal for first player)
recipe for play at tic-tac-toe
Many AI algorithms are capable of learning from data; they can
enhance themselves by learning new heuristics (strategies, or "rules of
thumb", that have worked well in the past), or can themselves write other
algorithms. Some of the "learners" described below, including Bayesian
networks, decision trees, and nearest-neighbor, could theoretically, (given
infinite data, time, and memory) learn to approximate any function,
including which combination of mathematical functions would best
describe the world. These learners could therefore, derive all possible
knowledge, by considering every possible hypothesis and matching them
against the data. In practice, it is almost never possible to consider every
possibility, because of the phenomenon of "combinatorial explosion",
where the amount of time needed to solve a problem grows exponentially.
Much of AI research involves figuring out how to identify and avoid
considering broad range of possibilities that are unlikely to be
beneficial. For example, when viewing a map and looking for the shortest
driving route from Denver to New York in the East, one can in most
cases skip looking at any path through San Francisco or other areas far to
the West; thus, an AI wielding a path finding algorithm like A* can avoid
the combinatorial explosion that would ensue if every possible route had
to be ponderously considered in turn.
The earliest (and easiest to understand) approach to AI was
symbolism (such as formal logic): "If an otherwise healthy adult has a
fever, then they may have influenza". A second, more general, approach
is Bayesian inference: "If the current patient has a fever, adjust the
probability they have influenza in such-and-such way". The third major
approach, extremely popular in routine business AI applications, are
analogizers such as SVM and nearest-neighbor: "After examining the
records of known past patients whose temperature, symptoms, age, and
other factors mostly match the current patient, X% of those patients
turned out to have influenza". A fourth approach is harder to intuitively
understand, but is inspired by how the brain's machinery works:
the artificial neural network approach uses artificial "neurons" that can
learn by comparing itself to the desired output and altering the strengths
of the connections between its internal neurons to "reinforce" connections
that seemed to be useful. These four main approaches can overlap with
each other and with evolutionary systems; for example, neural nets can
learn to make inferences, to generalize, and to make analogies. Some
systems implicitly or explicitly use multiple of these approaches,
alongside many other AI and non-AI algorithms; the best approach is
often different depending on the problem.
Artificial Intelligence (AI), the ability of a digital computer or
computer-controlled robot to perform tasks commonly associated with
intelligent beings. The term is frequently applied to the project of
developing systems endowed with the intellectual processes characteristic
of humans, such as the ability to reason, discover meaning, generalize, or
learn from past experience. Since the development of the digital
computer in the 1940s, it has been demonstrated that computers can be
programmed to carry out very complex tasks—as, for example,
discovering proofs for mathematical theorems or playing chess—with
great proficiency. Still, despite continuing advances in computer
processing speed and memory capacity, there are as yet no programs that
can match human flexibility over wider domains or in tasks requiring
much everyday knowledge. On the other hand, some programs have
attained the performance levels of human experts and professionals in
performing certain specific tasks, so that artificial intelligence in this
limited sense is found in applications as diverse as medical diagnosis,
computer search engines, and voice or handwriting recognition.
2.2 MACHINE LEARNING
Machine learning is a branch of artificial intelligence (AI) and computer
science which focuses on the use of data and algorithms to imitate the
way that humans learn, gradually improving its accuracy. Machine
learning is an important component of the growing field of data science.
Through the use of statistical methods, algorithms are trained to make
classifications or predictions, uncovering key insights within data mining
projects. These insights subsequently drive decision making within
applications and businesses, ideally impacting key growth metrics. As big
data continues to expand and grow, the market demand for data scientists
will increase, requiring them to assist in the identification of the most
relevant business questions and subsequently the data to answer them.
CLASSIFICATION
Leaf disease classification is a vital task in agricultural management, as it
enables farmers to identify and treat plant diseases promptly, thereby
minimizing crop damage and ensuring optimal yield. In recent years,
machine learning (ML) techniques have gained prominence for their
effectiveness in automating this process. The classification task involves
distinguishing between healthy leaves and leaves affected by various
diseases based on features extracted from leaf images.The classification
process typically begins with preprocessing steps such as image
enhancement, segmentation, and feature extraction. Image enhancement
techniques improve the quality of leaf images by adjusting brightness,
contrast, and sharpness, thereby facilitating more accurate disease
identification. Segmentation separates the leaf region from the
background, isolating the area of interest for analysis. Feature extraction
involves extracting relevant information from the segmented leaf images,
such as texture, color, and shape descriptors.
Once the features are extracted, they are used as input to train the ML
models. The dataset used for training comprises images of both healthy
leaves and leaves affected by various diseases, ensuring that the models
learn to differentiate between different classes effectively. During the
training phase, the models adjust their parameters to minimize
classification errors and maximize accuracy.
Convolutional Neural Network (CNN) Models
Convolutional Neural Networks (CNNs) have seen a significant rise in
popularity due to their powerful ability to automatically learn hierarchical
features from raw input data, especially images. Inspired by the human
visual system, CNNs process images by identifying patterns at various
levels of abstraction, from simple edges to complex shapes, making them
highly effective in tasks like image classification, object detection, and
segmentation. This capability is a key reason why Deep Learning (DL), a
subset of machine learning, has become the most widely adopted
architecture for building CNN models.
Components of CNNs
CNN models are composed of several essential components:
convolutional layers, pooling layers, fully connected layers, and
activation functions. Convolutional layers are the heart of CNNs, using
learnable filters to capture features from input images. Pooling layers
reduce the spatial dimensions of the feature maps, helping to lower
computational complexity and enhance the model's robustness. Fully
connected layers, typically found towards the end of the network, are
responsible for making final predictions based on the learned features.
Activation functions introduce non-linearity into the network, allowing it
to model complex relationships between inputs and outputs.
Problem-Solving Capabilities
DL models, particularly CNNs, excel at solving complex problems with
high classification accuracy and low error rates. Their deep architecture
enables them to learn intricate patterns and representations that traditional
machine learning techniques struggle to capture. As a result, CNNs have
become indispensable in a wide range of applications, from computer
vision to autonomous systems, where large-scale data and high
performance are essential.
2.3 LITERATURE SURVEY
2.3.1 Optimized Multi-Layer Convolutional Neural Networks for
Maize Leaf Disease Detection
Gonzalez, H. & Martinez, L. (2023) proposed an optimized multi-layer
convolutional neural network (CNN) model for the detection of maize
leaf diseases. The model utilized a modified version of ResNet
architecture with added layers to enhance feature extraction capabilities.
Their approach achieved an accuracy of 96.5% on a large dataset of
maize leaf images, demonstrating the effectiveness of deep learning
models in agricultural disease detection. The study emphasized the
model's potential to assist farmers in early disease management, leading
to improved crop yields.
2.3.2 Application of Transfer Learning for Citrus Leaf Disease
Classification
Zhang, Y. & Wang, S. (2024) developed a transfer learning-based model
using VGG16 architecture for the classification of citrus leaf diseases. By
fine-tuning the pre-trained VGG16 model on a dataset of citrus leaves,
the authors achieved a classification accuracy of 94.8%. The study
highlighted the advantages of transfer learning in agricultural
applications, especially when dealing with limited labeled data. The
model's ability to generalize across different types of leaf diseases made it
a valuable tool for automated disease diagnosis in citrus orchards.
2.3.3 Ensemble Deep Learning Approach for Rice Leaf Disease
Detection
Liu, Q. & Chen, X. (2023) proposed an ensemble deep learning approach
combining multiple CNN architectures, including DenseNet and
InceptionV3, for detecting rice leaf diseases. The ensemble model
achieved a precision of 97.2%, outperforming individual models in
accuracy and robustness. The research demonstrated that ensemble
learning could significantly improve the reliability of disease detection
systems in agriculture by reducing the variance associated with single-
model predictions.
2.3.4 Deep Learning-Based Automated System for Wheat Leaf Rust
Detection
Patel, R. & Singh, A. (2024) introduced a deep learning-based automated
system for detecting wheat leaf rust using a custom CNN model. Their
approach involved the use of data augmentation techniques to enhance
the diversity of the training set, leading to an accuracy of 95.3%. The
model's high performance in detecting wheat leaf rust early in the crop
cycle underlines its potential to assist in precision agriculture, reducing
the need for widespread fungicide applications.
2.3.5 AI-Driven Plant Leaf Disease Recognition System Using
MobileNetV2
Hassan, M. & Ali, Z. (2023) developed an AI-driven plant leaf disease
recognition system using the MobileNetV2 architecture. The system was
designed for deployment on mobile devices, offering real-time disease
detection capabilities. The model achieved an accuracy of 93.7% in
identifying multiple types of leaf diseases across various plant species.
The study showcased the practicality of deploying deep learning models
on mobile platforms, making advanced diagnostic tools accessible to
farmers in remote areas.
2.3.6 Metaheuristic-Optimized Support Vector Machine for Grape
Leaf Disease Classification
Das, S. & Roy, A. (2024) combined metaheuristic algorithms with
support vector machines (SVM) to classify grape leaf diseases, achieving
an accuracy of 92.4%. The optimization process involved using particle
swarm optimization (PSO) to tune the hyperparameters of the SVM,
resulting in improved classification performance. This hybrid approach
demonstrated the effectiveness of combining traditional machine learning
methods with metaheuristics for complex agricultural tasks.
2.3.7 Deep Learning and Hyperspectral Imaging for Sugarcane Leaf
Disease Detection
Kumar, N. & Verma, P. (2023) explored the use of hyperspectral imaging
coupled with deep learning for the detection of sugarcane leaf diseases.
The CNN model processed hyperspectral data to identify disease-specific
spectral signatures, achieving an accuracy of 98%. This approach
provided a non-invasive method for early disease detection, which could
be integrated into precision agriculture practices to monitor large
sugarcane fields efficiently.
2.3.8 Fusion of CNN and RNN for Sequential Analysis of Soybean
Leaf Disease Progression
Choi, K. & Lee, J. (2024) proposed a fusion model combining
convolutional neural networks (CNN) and recurrent neural networks
(RNN) to analyze the progression of soybean leaf diseases over time. By
leveraging the strengths of CNNs in spatial feature extraction and RNNs
in temporal sequence modeling, the model achieved an accuracy of
95.9%. This method is particularly useful for monitoring the development
of diseases in crops that require timely intervention to prevent widespread
damage.
CHAPTER – 3
SYSTEM DESIGN
EXISTING SYSTEM
Machine Learning (ML) approach for the early prediction of the
probability of disease attack based on Internet of Things (IoT)
directly sensed crop field environmental conditions.
Plant disease life cycles are strongly correlated with environmental
conditions. The crop field environmental conditions are used to
predict the occurrence of plant diseases.
The Multiple Linear Regression (MLR) is applied as the ML model
due to the existence of a linear relationship between disease attack
and environmental conditions.
Internet of Things (IoT) based crop field environmental conditions
help to accurately predict the occurrence of plant diseases using the
ML approach.
This existing model is implemented for the prediction of blister
blight (Exobasidiumvexans) for tea (Camellia sinensis) plant.
EXISTING BLOCK SYSTEM
DISADVANTAGES OF EXISTING SYSTEM
Available Databases and Size Issue.
Issue with Available Feature Extraction Methods.
Difficulties in Classification Module.
Limitations of Available Systems.
PROPOSED SYSTEM
The proposed system for leaf disease classification using machine
learning is designed to provide an efficient, accurate, and user-
friendly solution for diagnosing plant diseases and suggesting
appropriate treatments and fertilizer recommendations.
The system integrates several key components, including data
collection, preprocessing, machine learning model training, disease
diagnosis, and user interface modules.
By leveraging convolutional neural networks (CNNs) and techniques
such as transfer learning, the system is capable of accurately
identifying various plant diseases from leaf images.
Users can upload images through a mobile or web application, where
the images are preprocessed and fed into the trained model to predict
the disease.
The system provides detailed treatment options, including specific
chemical treatments and tailored fertilizer recommendations to
enhance plant health and immunity.
Additionally, it suggests best agricultural practices to prevent future
outbreaks. With a focus on providing timely and accurate diagnoses,
the proposed system aims to assist farmers and agricultural experts in
maintaining healthy crops and optimizing yields, ultimately
contributing to improved agricultural productivity and sustainability.
BLOCK DIAGRAM
Fertilizer
SYSTEM STUDY
The proposed plant disease detection and fertilizer recommendation
system, driven by a Convolutional Neural Network (CNN) algorithm,
undergoes a comprehensive system study to outline its key aspects. The
system's primary objectives include early disease detection, precise
fertilizer recommendations, a user-friendly interface, continuous learning,
and enhanced security. Modules encompass a secure login mechanism, an
informative dashboard, and specialized components for disease detection
and fertilizer advice.The system's data flow navigates through a secure
login, an insightful dashboard, and modules utilizing the CNN algorithm
for disease identification and fertilizer suggestions. Adaptability is
ensured as the CNN algorithm evolves with new data, contributing to
improved accuracy over time. Rigorous testing, especially for disease
detection, recommendation precision, and system responsiveness, forms a
crucial part of system validation. Comprehensive documentation aids
users and administrators in understanding the system features and the
integration of the CNN algorithm. Looking ahead, the system envisions
future enhancements, including advanced machine learning techniques,
dataset expansion, and collaboration with agricultural experts for
continuous improvement. Overall, this system study underscores the
potential of the proposed solution to revolutionize agricultural practices,
offering farmers a powerful tool for informed decision-making and
improved crop yield.
PROPOSED ARCHITECTURE DIAGRAM
Chapter 4:
METHODOLOGY
MODULES DESCRIPTION
4.1Data Collection:
Gather a dataset of images of healthy leaves as well as leaves affected by
various diseases. Ensure that the dataset is diverse and representative of
the types of diseases you want to classify.
4.2 Data Preprocessing:
Preprocess the images to standardize them for analysis. This might
include tasks such as resizing, normalization, and augmentation to
increase the diversity of your dataset and improve the model's robustness.
4.3 Image Upload And Preprocessing Module:
The Leaf Image Upload and Preprocessing Module constitutes a pivotal
component within the plant disease detection system, seamlessly
integrating user interaction and data preparation for accurate disease
classification. The module introduces an intuitive Image Upload Interface
in the graphical user interface (GUI), allowing users to effortlessly submit
plant leaf images directly from their devices or capture them using an
integrated camera. This user-friendly feature is accompanied by progress
indicators and prompts, ensuring a smooth upload experience accessible
to users of varying technical proficiencies.
Upon image submission, a series of Preprocessing techniques are applied
to standardize inputs for the Convolutional Neural Network (CNN)
model. These techniques include resizing images to a consistent
resolution, normalizing pixel values, and potentially implementing image
enhancement methods. The real-time feedback mechanism keeps users
informed about the processing status through visual cues such as progress
bars and status messages, enhancing transparency and user engagement.
Incorporating Quality Assurance Measures, the module conducts checks
for image resolution, orientation, and potential artifacts, ensuring the
uploaded images meet quality standards essential for reliable disease
identification. Users are promptly notified of any issues, guiding them to
upload high-quality images that contribute to the system's overall
accuracy.
The seamless Integration with the CNN Model marks the culmination of
the module's functionality. Preprocessed images are fed into the trained
model, capitalizing on the collaborative effort between the Leaf Image
Upload and Preprocessing Module and the CNN model. This synergy
ensures an optimized process, ultimately enhancing the system's efficacy
in disease identification and reinforcing its commitment to accuracy and
user satisfaction.
4.4. Leaf Disease Classification Model (CNN in ML):
At the core of the system lies the advanced Leaf Disease Classification
Model, driven by the potency of Convolutional Neural Networks (CNN).
The meticulous dataset preparation involves the curation of an extensive
library of plant leaf images, each meticulously labeled with
corresponding diseases. The CNN architecture, comprising convolutional
layers for feature extraction, pooling layers for dimensionality reduction,
and fully connected layers for classification, is honed to perfection
through iterative training sessions. Rigorous validation ensures the
model's robustness, granting it the ability to accurately identify diverse
plant diseases with a high degree of precision.
4.5. Fertilizer Recommendation Module:
In tandem with disease detection, the Fertilizer Recommendation Module
emerges as a critical component, providing actionable insights to farmers.
This module goes beyond conventional recommendations, incorporating
data on identified diseases, soil type, and plant species. The result is a
tailored and precise set of fertilizer recommendations, empowering users
to make informed decisions that directly impact crop yield. By
considering environmental factors and the specific needs of crops, this
module contributes to sustainable farming practices and optimized
agricultural outcomes.
Chapter 5:
EXPERIMENTAL SETUP AND RESULTS
5.1 SYSTEM SPECIFICATION
SOFTWARE REQUIREMENTS
OPERATING SYSTEM : WINDOWS 7/10/11
LANGUAGE USED : PYTHON
FOR MESSAGE : TWILIO SOFTWARE
HARDWARE REQUIREMENTS
System : PC OR LAPTOP
Processor : INTEL I5
RAM : 4 GB Recommended
ROM : 2 GB
DATASETS
In this project we use four different types of datasets.
The datasets consists of both normal and affected leaves.
Types of leaves datasets
5.2 Leaves Data Collection:
BRINJAL LEAVES
CHILLI LEAVES
TOMATO LEAVES
5.3 CNN MODEL LAYERS:
• The CNN model consists of several layers that perform specific
functions to classify the input images into healthy and diseased
categories
• Convolutional Layer 1: This layer will apply 32 filters of size 3x3
to the input image. The output will be passed through a ReLU
activation function to introduce non-linearity.
• Convolutional Layer 2: This layer will apply 64 filters of size 3x3
to the output of the previous layer. The output will be passed
through a ReLU activation function.
• Max Pooling Layer: This layer will perform max pooling over a
2x2 window with a stride of 2 to reduce the spatial dimensions of
the output from the previous layer by half.
• Convolutional Layer 3: This layer will apply 128 filters of size 3x3
to the output of the previous layer. The output will be passed
through a ReLU activation function.
• Max Pooling Layer: This layer will perform max pooling over a
2x2 window with a stride of 2 to further reduce the spatial
dimensions of the output from the previous layer by half.
• Convolutional Layer 4: This layer will apply 256 filters of size 3x3
to the output of the previous layer. The output will be passed
through a ReLU activation function.
• Max Pooling Layer: This layer will perform max pooling over a
2x2 window with a stride of 2 to further reduce the spatial
dimensions of the output from the previous layer by half.
• Flatten Layer: This layer will flatten the output from the previous
layer into a one-dimensional vector.
• Fully Connected Layer 1: This layer will have 512 neurons and
will be fully connected to the output of the previous layer. The
output will be passed through a ReLU activation function.
• Dropout Layer: This layer will randomly drop 50% of the neurons
from the previous layer during training, which can help prevent
overfitting.
• Fully Connected Layer 2: This layer will have a number of neurons
equal to the number of possible disease classes. It will be fully
connected to the output of the previous layer, and will produce the
final output probabilities for each disease class.
CNN MODEL ARCHITECTURE DIAGRAM
CNN ALGORITHM WORKING
A Convolutional Neural Network (CNN) is a type of deep learning
algorithm used for image recognition, object detection, and classification.
The basic architecture of a CNN consists of the following components:
A Convolutional neural network has three layers. And we understand
each layer one by one with the help of an example of the classifier. With
it can classify an image of an X and O. So, with the case, we will
understand all four layers.
Convolutional Neural Networks have the following layers:
o Convolutional
o ReLU Layer
o Pooling
o Fully Connected Layer
There are certain trickier cases where X can represent in these four forms
as well as the right side, so these are nothing but the effects of the
deformed images. Here, there are multiple presentations of X and O's.
This makes it tricky for the computer to recognize. But the goal is that if
the input signal looks like previous images it has seen before,
the "image" reference signal will be convolved with, the input signal.
The resulting output signal is then passed on to the next layer. Consider
the diagram shown below:
A computer understands an image using numbers at each pixel.
In our example, we have considered that a blue pixel will have value 1,
and a white pixel will have -1 value. This is as the way we've
implemented to differentiate the pixels in a primary binary classification.
When we use standard techniques to compare these two images, one is a
proper image of X, and another is a distorted image of X. We found that
the computer is not able to classify the deformed image of X. It is
comparing with the proper representation of X. So when we add the pixel
values of both of these images, we get something, so a computer is not
able to recognize whether it is an X or not.
With the help of CNN, we take small patches of our image, so these
pieces or patches are known as filters. We were finding rough feature
matches in the same position in two pictures. CNN gets better with the
similarity between the whole image matching schemes. We have these
filters, so consider this first filter this is precisely equal to the feature of
the part of the image in the deformed images as well as this is a proper
image.
CNN compares the piece of the image by section.
By finding rough matches, in roughly the same position in two images,
CNN gets a lot better at seeing similarity than whole-image matching
schemes.
We have three features or filters, as shown below.
Multiplying the Corresponding Pixel Values
Adding and Dividing by total number of pixels
Creating a Map to put the value of the filter at the place
To keep track of the feature where we create the map and put an amount
of filter at that place.
Sliding the Filter throughout the Image
Now, using the same functionality and move it to another location and
perform the filtering again.
Convolution Layer Output
We will transfer the features to every other position of the image and will
see how the features match that area. Finally, we will get an output as;
Similarly, we perform the same convolution with every other filter.
ReLU Layer
In this layer, we remove every negative value from the filtered images
and replaces them with zeros.
It is happening to avoid the values from adding up to zero.
Rectified Linear unit(ReLU) transform functions only activates a node
if the input is above a certain quantity. While the data is below zero, the
output is zero, but when the information rises above a threshold. It has a
linear relationship with the dependent variable.
We have considered any simple function with the value as mentioned
above. So the function only operates if the dependent variable obtains that
value. For example, the following values are obtained.
Removing the Negative Values
Output for one feature
Output for all features
Pooling Layer
In the layer, we shrink the image stack into a smaller size. Pooling is done
after passing by the activation layer. We do by implementing the
following 4 steps:
o Pick a window size (often 2 or 3)
o Pick a stride (usually 2)
o Walk your Window across your filtered images
o From each Window, take the maximum value
Let us understand this with an example. Consider performing pooling
with the window size of 2 and stride is 2 as well.
Calculating the maximum value in each Window
Let's start our first filtered image. In our first Window, the maximum or
highest value is 1, so we track that and move the Window two strides.
Moving the Window Across the entire image
Output after passing through pooling layer
Stacking up the layers
So that get the time-frame in one picture we are here with a 4×4 matrix
from a 7×7 matrix after passing the input through 3 layers - Convolution,
ReLU, and Pooling as shown below:
we reduce the image from 4×4 to something lesser?We need to perform 3
operations in the iteration after the first pass. So after the second pass, we
arrived at a 2×2 matrix, as shown below:
The last layer in the network is fully connected, meaning that neurons of
preceding layers are connected to every neuron in subsequent layers.
This mimics high-level reasoning where all possible pathways from the
input to output are considered.
Then, take the shrunk image and put into the single list, so we have got
after passing through two layers of convolution relo and pooling and then
converting it into a single file or a vector.
We take the first Value 1, and then we retake 0.55 we take 0.55 then we
retake 1. Then we take 1 then we take 0.55, and then we take 1 then 0.55
and 0.55 then again retake 0.55 take 0.55, 1, 1, and 0.55. So, this is
nothing but a vector. The fully connected layer is the last layer, where the
classification happens. Here we took our filtered and shrunk images and
put them into one single list as shown below.
Output
When we feed in, 'X' and '0'. Then there will be some element in the
vector that will be high. Consider the image below, as we can see for 'X'
there are different top elements, and similarly, for 'O' we have various
high elements.
There are specific values in my list, which were high, and if we repeat the
entire process which we have discussed for the different individual costs.
Which will be higher, so for an X we have 1st, 4th, 5th, 10th, and the
11th element of vector values are higher. And for O we have 2nd, 3rd,
9th and 12th element vector which are higher. We know now if we have an
input image which has a 1st, 4th, 5th, 10th, and 11th element vector values
high. We can classify it as X similarly if our input image has a list which
has the 2nd 3rd 9th and 12th element vector values are high so that we can
organize it
Then the 1st, 4th, 5th, 10th, and 11th values are high, and we can classify
the image as 'x.' The concept is similar for other alphabets as well - when
certain values are arranged the way they are, they can be mapped to an
actual letter or a number which we require
Comparing the Input Vector with X
After the training is done the entire process for both 'X' and 'O.' Then, we
got this 12 element vector it has 0.9, 0.65 all these values then now how
do we classify it whether it is X or O. We will compare it with the list of
X and O so we have got the file in the previous slide if we notice we have
got two different lists for X and O. We are comparing this new input
image list that we have arrived with the X and O. First let us compare that
with X now as well for X there are certain values which will be higher
and nothing but 1st 4th 5th 10th and 11th value. So, we are going to sum
them, and we have got 5= 1+ 1+ 1+ 1+1 times 1 we got 5, and we are
going to sum the corresponding values of our image vector. So the
1st value is 0.9 then the 4th value is 0.87 5th value is 0.96, and 10th value is
0.89, and 11th value is 0.94 so after doing the sum of these values have
got 4.56 and divide this by 5 we got 0.9.
We are comparing the input vector with 0.
And for X then we are doing the same process for O we have notice
2nd 3rd 9th, and 12th element vector values are high. So when we sum these
values, we get 4 and when we do the sum of the corresponding values of
our input image. We have got 2.07 and when we divide that by 4 we
got 0.51.
Result
Now, we notice that 0.91 is the higher value compared to 0.5 so we have
compared our input image with the values of X we got a higher value
then the value which we have got after comparing the input image with
the values of 4. So the input image is classified as X.
CNN Use Case
Steps:
• Input layer: The input layer receives the input image, which is
typically a matrix of pixels.
• Convolutional layer: The convolutional layer applies a set of filters
to the input image to extract features from it. Each filter detects a
specific feature, such as edges or corners. The output of this layer
is a set of feature maps.
• ReLU layer: The Rectified Linear Unit (ReLU) layer applies a non-
linear activation function to the output of the convolutional layer.
This helps to introduce non-linearity into the model.
• Pooling layer: The pooling layer reduces the spatial dimensionality
of the output of the previous layer by downsampling the feature
maps. This helps to reduce the number of parameters in the model
and improve its computational efficiency.
• Fully connected layer: The fully connected layer takes the output
of the previous layers and flattens it into a 1D vector. This layer is
similar to a traditional neural network layer, and its purpose is to
classify the input image.
• Output layer: The output layer is the final layer of the CNN, and it
produces the classification output based on the input image.
• A convolutional neural network is used to detect and classify
objects in an image.
• Below is a neural network that identifies two types of flowers:
Orchid and Rose.
• In CNN, every image is represented in the form of an array of pixel
values.
• The convolution operation forms the basis of any convolutional
neural network. Let‘s understand the convolution operation using
two matrices, a and b, of 1 dimension.
• a = [5,3,7,5,9,7]
• b = [1,2,3]
• In convolution operation, the arrays are multiplied element-wise,
and the product is summed to create a new array, which
represents a*b.
• The first three elements of the matrix a are multiplied with the
elements of matrix b. The product is summed to get the result.
• The next three elements from the matrix a are multiplied by the
elements in matrix b, and the product is summed up.
• This process continues until the convolution operation is complete.
• Stay ahead of the tech-game with our AI and ML Course in
partnership with Purdue and in collaboration with IBM. Explore
more!
• How Does CNN Recognize Images?
• Consider the following images:
•
• The boxes that are colored represent a pixel value of 1, and 0 if not
colored.
• When you press backslash (\), the below image gets processed.
•
• When you press forward-slash (/), the below image is processed:
•
• Here is another example to depict how CNN recognizes an image:
•
• As you can see from the above diagram, only those values are lit
that have a value of 1.
The working of a CNN can be explained as follows:
• The input image is passed through the input layer, and the
convolutional layer applies a set of filters to the image to extract
features.
• The ReLU layer applies a non-linear activation function to the
output of the convolutional layer, introducing non-linearity into the
model.
• The pooling layer downsamples the feature maps to reduce the
spatial dimensionality of the output.
• The fully connected layer takes the output of the previous layers
and flattens it into a 1D vector.
• The output layer produces the classification output based on the
input image.
• During the training phase, the CNN learns the weights of the filters
in the convolutional layer and the weights of the neurons in the
fully connected layer through backpropagation. Backpropagation is
an optimization algorithm that adjusts the weights of the model
based on the difference between the predicted output and the actual
output.
• Once the CNN is trained, it can be used to classify new input
images by passing them through the trained model. The output of
the model is the predicted class of the input image.
• In summary, a CNN is a deep learning algorithm used for image
recognition and classification. It consists of several layers,
including convolutional, ReLU, pooling, fully connected, and
output layers. The CNN learns the weights of the model through
backpropagation during the training phase, and it can be used to
classify new input images during the testing phase.
A convolution neural network has multiple hidden layers that help in
extracting information from an image. The four important layers in CNN
are:
1. Convolution layer
2. ReLU layer
3. Pooling layer
4. Fully connected layer
Convolution Layer
This is the first step in the process of extracting valuable features from an
image. A convolution layer has several filters that perform the
convolution operation. Every image is considered as a matrix of pixel
values.
Consider the following 5x5 image whose pixel values are either 0 or 1.
There‘s also a filter matrix with a dimension of 3x3. Slide the filter
matrix over the image and compute the dot product to get the convolved
feature matrix.
ReLU layer
ReLU stands for the rectified linear unit. Once the feature maps are
extracted, the next step is to move them to a ReLU layer.
ReLU performs an element-wise operation and sets all the negative pixels
to 0. It introduces non-linearity to the network, and the generated output
is a rectified feature map. Below is the graph of a ReLU function:
The original image is scanned with multiple convolutions and ReLU
layers for locating the features.
Pooling Layer
Pooling is a down-sampling operation that reduces the dimensionality of
the feature map. The rectified feature map now goes through a pooling
layer to generate a pooled feature map.
The pooling layer uses various filters to identify different parts of the
image like edges, corners, body, feathers, eyes, and beak.
Here‘s how the structure of the convolution neural network looks so far:
The next step in the process is called flattening. Flattening is used to
convert all the resultant 2-Dimensional arrays from pooled feature maps
into a single long continuous linear vector.
The flattened matrix is fed as input to the fully connected layer to classify
the image.
Here‘s how exactly CNN recognizes a bird:
The pixels from the image are fed to the convolutional layer that
performs the convolution operation
It results in a convolved map
The convolved map is applied to a ReLU function to generate a
rectified feature map
The image is processed with multiple convolutions and ReLU
layers for locating the features
Different pooling layers with various filters are used to identify
specific parts of the image
The pooled feature map is flattened and fed to a fully connected
layer to get the final output
CHAPTER – 6
SOFTWARE DESCRIPTION
6.1 PYTHON
Python is a wonderful and powerful programming language that's
easy to use (easy to read and write) and with Raspberry Pi lets you
connect your project to the real world.
Python syntax is very clean, with an emphasis on readability and uses
standard English keywords. Start by opening IDLE from the desktop.
IDLE
The easiest introduction to Python is through IDLE, a Python
development environment. Open IDLE from the Desktop or applications
menu:
IDLE gives you a REPL (Read-Evaluate-Print-Loop) which is a
prompt you can enter Python commands in to. As it's a REPL you even
get the output of commands printed to the screen without using print.
>>>1+2
>>> name ="Sarah"
>>>"Hello "+ name
'Hello Sarah'
IDLE also has syntax highlighting built in and some support for
autocompletion. You can look back on the history of the commands
you've entered in the REPL with Alt + P (previous) and Alt + N (next).
BASIC PYTHON USAGE
Hello world in Python:
print("Hello world")
Simple as that!
INDENTATION
Some languages use curly braces { and } to wrap around lines of code
which belong together, and leave it to the writer to indent these lines to
appear visually nested. However, Python does not use curly braces but
instead requires indentation for nesting. For example a for loop in
Python:
foriinrange(10):
print("Hello")
The indentation is necessary here. A second line indented would be a part
of the loop, and a second line not indented would be outside of the loop.
For example:
foriinrange(2):
print("A")
print("B")
would print:
A
B
A
B
whereas the following:
foriinrange(2):
print("A")
print("B")
would print:
A
A
B
VARIABLES
To save a value to a variable, assign it like so:
name ="Bob"
age =15
Note here I did not assign types to these variables, as types are inferred,
and can be changed (it's dynamic).
age =15
age +=1# increment age by 1
print(age)
This time I used comments beside the increment command.
COMMENTS
Comments are ignored in the program but there for you to leave notes,
and are denoted by the hash # symbol. Multi-line comments use triple
quotes like so:
"""
This isa very simple Python program that prints "Hello".
That's all it does.
"""
print("Hello")
LISTS
Python also has lists (called arrays in some languages) which are
collections of data of any type:
numbers =[1,2,3]
Lists are denoted by the use of square brackets [] and each item is
separated by a comma.
ITERATION
Some data types are iterable, which means you can loop over the values
they contain. For example a list:
numbers =[1,2,3]
for number in numbers:
print(number)
This takes each item in the list numbers and prints out the item:
1
2
3
Note I used the word number to denote each item. This is merely the
word I chose for this - it's recommended you choose descriptive words
for variables - using plurals for lists, and singular for each item makes
sense. It makes it easier to understand when reading.
Other data types are iterable, for example the string:
dog_name="BINGO"
for char indog_name:
print(char)
This loops over each character and prints them out:
B
I
N
G
O
RANGE
The integer data type is not iterable and trying to iterate over it will
produce an error. For example:
foriin3:
print(i)
will produce:
TypeError:'int' object isnotiterable
However you can make an iterable object using the range function:
foriinrange(3):
print(i)
range(5) contains the numbers 0, 1, 2, 3 and 4 (five numbers in total).
To get the numbers 1 to 5 use range(1, 6).
LENGTH
You can use functions like len to find the length of a string or a list:
name ="Jamie"
print(len(name))# 5
names =["Bob","Jane","James","Alice"]
print(len(names))# 4
IF STATEMENTS
You can use if statements for control flow:
name ="Joe"
iflen(name)>3:
print("Nice name,")
print(name)
else:
print("That's a short name,")
print(name)
PYTHON FILES IN IDLE
To create a Python file in IDLE, click File > New File and you'll be given
a blank window. This is an empty file, not a Python prompt. You write a
Python file in this window, save it, then run it and you'll see the output in
the other window.
For example, in the new window, type:
n =0
foriinrange(1,101):
n +=i
print("The sum of the numbers 1 to 100 is:")
print(n)
Then save this file (File > Save or Ctrl + S) and run (Run > Run
Moduleor hit F5) and you'll see the output in your original Python
window.
EXECUTING PYTHON FILES FROM THE COMMAND LINE
You can write a Python file in a standard editor like Vim, Nano or
LeafPad, and run it as a Python script from the command line. Just
navigate to the directory the file is saved (use cd and ls for guidance) and
run with python, e.g. python hello.py.
6.2 TENSORFLOW-INTRODUCTION
TensorFlow is a software library or framework, designed by the Google
team to implement machine learning and deep learning concepts in the
easiest manner. It combines the computational algebra of optimization
techniques for easy calculation of many mathematical expressions. The
official website of TensorFlow is mentioned below:
https://www.tensorflow.org/
Let us now consider the following important features of TensorFlow:
It includes a feature of that defines, optimizes and calculates
mathematical expressions easily with the help of multi-dimensional
arrays called tensors.
It includes a programming support of deep neural networks and
machine learning techniques.
It includes a high scalable feature of computation with various data sets.
TensorFlow uses GPU computing, automating management. It also
includes a unique feature of optimization of same memory and the data
used.
Why is TensorFlow So Popular?
TensorFlow is well-documented and includes plenty of machine learning
libraries. It offers a few important functionalities and methods for the
same. TensorFlow is also called a ―Google‖ product. It includes a variety
of machine learning and deep learning algorithms. TensorFlow can train
and run deep neural networks for handwritten digit classification, image
recognition, word embedding and creation of various sequence models.
TensorFlow — Installation
To install TensorFlow, it is important to have ―Python‖ installed in your
system. Python version 3.4+ is considered the best to start with
TensorFlow installation. Consider the following steps to install
TensorFlow in Windows operating system.
pip install tensorflow
TensorFlow — Convolutional Neural Networks
After understanding machine-learning concepts, we can now shift our
focus to deep learning concepts. Deep learning is a division of machine
learning and is considered as a crucial step taken by researchers in recent
decades. The examples of deep learning implementation include
applications like image recognition and speech recognition.
Following are the two important types of deep neural networks:
Convolutional Neural Networks
Recurrent Neural Networks In this chapter, we will focus on the CNN,
Convolutional Neural Networks
6.3 Convolutional Neural Networks
Convolutional Neural networks are designed to process data
through multiple layers of arrays. This type of neural networks is used in
applications like image recognition or face recognition. The primary
difference between CNN and any other ordinary neural network is that
CNN takes input as a two-dimensional array and operates directly on the
images rather than focusing on feature extraction which other neural
networks focus on. The dominant approach of CNN includes solutions for
problems of recognition. Top companies like Google and Facebook have
invested in research and development towards recognition projects to get
activities done with greater speed.
A convolutional neural network uses three basic ideas:
Local respective fields
Convolution
Pooling
Let us understand these ideas in detail.
CNN utilizes spatial correlations that exist within the input data. Each
concurrent layer of a neural network connects some input neurons. This
specific region is called local receptive field. Local receptive field
focusses on the hidden neurons. The hidden neurons process the input
data inside the mentioned field not realizing the changes outside the
specific boundary.
If we observe the above representation, each connection learns a
weight of the hidden neuron with an associated connection with
movement from one layer to another. Here, individual neurons perform a
shift from time to time. This process is called ―convolution‖. The
mapping of connections from the input layer to the hidden feature map is
defined as ―shared weights‖ and bias included is called ―shared bias‖.
CNN or convolutional neural networks use pooling layers, which are the
layers, positioned immediately after CNN declaration. It takes the input
from the user as a feature map that comes out of convolutional networks
and prepares a condensed feature map. Pooling layers helps in creating
layers with neurons of previous layers.
6.4 OPEN CV
OpenCV tutorial provides basic and advanced concepts of OpenCV. Our
OpenCV tutorial is designed for beginners and professionals.
OpenCV is an open-source library for the computer vision. It provides the
facility to the machine to recognize the faces or objects. In this tutorial we
will learn the concept of OpenCV using the Python programming
language.
Our OpenCV tutorial includes all topics of Read and Save Image, Canny
Edge Detection, Template matching, Blob Detection, Contour, Mouse
Event, Gaussian blur and so on.
What is OpenCV?
OpenCV is a Python open-source library, which is used for computer
vision in Artificial intelligence, Machine Learning, face recognition, etc.
In OpenCV, the CV is an abbreviation form of a computer vision, which
is defined as a field of study that helps computers to understand the
content of the digital images such as photographs and videos.
The purpose of computer vision is to understand the content of the
images. It extracts the description from the pictures, which may be an
object, a text description, and three-dimension model, and so on. For
example, cars can be facilitated with computer vision, which will be able
to identify and different objects around the road, such as traffic lights,
pedestrians, traffic signs, and so on, and acts accordingly.
Computer vision allows the computer to perform the same kind of tasks
as humans with the same efficiency. There are a two main task which are
defined below:
o Object Classification - In the object classification, we train a
model on a dataset of particular objects, and the model classifies
new objects as belonging to one or more of your training
categories.
o Object Identification - In the object identification, our model will
identify a particular instance of an object - for example, parsing
two faces in an image and tagging one as Virat Kohli and other one
as Rohit Sharma.
History
OpenCV stands for Open Source Computer Vision Library, which is
widely used for image recognition or identification. It was officially
launched in 1999 by Intel. It was written in C/C++ in the early stage, but
now it is commonly used in Python for the computer vision as well.
The first alpha version of OpenCV was released for the common use at
the IEEE Conference on Computer Vision and Pattern Recognition in
2000, and between 2001 and 2005, five betas were released. The first 1.0
version was released in 2006.
The second version of the OpenCV was released in October 2009 with
the significant changes. The second version contains a major change to
the C++ interface, aiming at easier, more type-safe, pattern, and better
implementations. Currently, the development is done by an independent
Russian team and releases its newer version in every six months.
How OpenCV Works
In this tutorial, we will learn how computers perform image recognition.
How does computer recognize the image?
Human eyes provide lots of information based on what they see.
Machines are facilitated with seeing everything, convert the vision into
numbers and store in the memory. Here the question arises how computer
convert images into numbers. So the answer is that the pixel value is used
to convert images into numbers. A pixel is the smallest unit of a digital
image or graphics that can be displayed and represented on a digital
display device.
The picture intensity at the particular location is represented by the
numbers. In the above image, we have shown the pixel values for a
grayscale image consist of only one value, the intensity of the black color
at that location.
There are two common ways to identify the images:
1. Grayscale
Grayscale images are those images which contain only two colors black
and white. The contrast measurement of intensity is black treated as the
weakest intensity, and white as the strongest intensity. When we use the
grayscale image, the computer assigns each pixel value based on its level
of darkness.
2. RGB
An RGB is a combination of the red, green, blue color which together
makes a new color. The computer retrieves that value from each pixel and
puts the results in an array to be interpreted.
Why OpenCV is used for Computer Vision?
o OpenCV is available for free of cost.
o Since the OpenCV library is written in C/C++, so it is quit fast.
Now it can be used with Python.
o It require less RAM to usage, it maybe of 60-70 MB.
o Computer Vision is portable as OpenCV and can run on any device
that can run on C.
Installation of the OpenCV
Install OpenCV using Anaconda
The first step is to download the latest Anaconda graphic installer for
Windows from it official site. Choose your bit graphical installer. You are
suggested to install 3.7 working with Python 3.
Install OpenCV in the Windows via pip
OpenCV is a Python library so it is necessary to install Python in the
system and install OpenCV using pip command:
1. pip install opencv-python
Open the command prompt and type the following code to check if the
OpenCV is installed or not.
OpenCV Read and Save Image
OpenCV Reading Images
OpenCV allows us to perform multiple operations on the image, but to do
that it is necessary to read an image file as input, and then we can perform
the various operations on it. OpenCV provides following functions which
are used to read and write the images.
OpenCV imread function
The imread() function loads image from the specified file and returns it.
The syntax is:
1. cv2.imread(filename[,flag])
6.5 PYTHON NUMPY
Our Python NumPy Tutorial provides the basic and advanced
concepts of the NumPy. Our NumPy tutorial is designed for beginners
and professionals.
NumPy stands for numeric python which is a python package for the
computation and processing of the multidimensional and single
dimensional array elements.
What is NumPy
NumPy stands for numeric python which is a python package for the
computation and processing of the multidimensional and single
dimensional array elements.
Travis Oliphant created NumPy package in 2005 by injecting the features
of the ancestor module Numeric into another module Numarray. It is an
extension module of Python which is mostly written in C. It provides
various functions which are capable of performing the numeric
computations with a high speed.
NumPy provides various powerful data structures, implementing multi-
dimensional arrays and matrices. These data structures are used for the
optimal computations regarding arrays and matrices. In this tutorial, we
will go through the numeric python library NumPy.
The need of NumPy
With the revolution of data science, data analysis libraries like NumPy,
SciPy, Pandas, etc. have seen a lot of growth. With a much easier syntax
than other programming languages, python is the first choice language for
the data scientist.
NumPy provides a convenient and efficient way to handle the vast
amount of data. NumPy is also very convenient with Matrix
multiplication and data reshaping. NumPy is fast which makes it
reasonable to work with a large set of data.
There are the following advantages of using NumPy for data analysis.
1. NumPy performs array-oriented computing.
2. It efficiently implements the multidimensional arrays.
3. It performs scientific computations.
4. It is capable of performing Fourier Transform and reshaping the
data stored in multidimensional arrays.
5. NumPy provides the in-built functions for linear algebra and
random number generation.
Nowadays, NumPy in combination with SciPy and Mat-plotlib is used as
the replacement to MATLAB as Python is more complete and easier
programming language than MATLAB.
Prerequisite
Before learning Python Numpy, you must have the basic knowledge of
Python concepts.
TRAINING THE MODEL
Because the data required to train a CNN is very large, it is often
desirable to train the model in batches. Loading all the training data into
memory is not always possible because you need enough memory to
handle it and the features too. So we decided to load all the images into a
dataset using h5py library.
Once I had the training data in a kaggle dataset, I trained the model.
ADVANTAGES
1. Accuracy and Precision
High Accuracy: Machine learning models, especially Convolutional
Neural Networks (CNN), can achieve high accuracy in identifying and
classifying leaf diseases, often surpassing human capabilities.
Consistency: Unlike human observers, ML models provide consistent
results, reducing the variability in disease diagnosis.
2. Early Detection
Timely Intervention: Early detection allows for timely intervention,
preventing the spread of disease and minimizing crop damage.
Cost Savings: Early and accurate disease detection can reduce the need
for extensive use of pesticides, leading to cost savings for farmers.
3. Scalability
Large-Scale Application: ML models can be easily scaled to monitor
large fields and numerous plants simultaneously, something that would be
impractical for human workers.
Remote Monitoring: With the integration of drone technology and
satellite imagery, entire fields can be monitored remotely, making it
feasible to manage large agricultural operations.
4. Efficiency
Automated Processes: Automating the disease detection process saves
time and labor, allowing farmers to focus on other important tasks.
Real-Time Analysis: Machine learning models can analyze images and
data in real time, providing immediate feedback and recommendations.
5. Resource Optimization
Targeted Treatments: By accurately identifying diseases, farmers can
apply treatments more precisely, targeting only the affected areas rather
than applying pesticides or fertilizers broadly.
Environmental Benefits: Reduced use of chemicals and targeted
treatments help in preserving beneficial insects and reducing
environmental impact.
APPLICATIONS
1. Precision Agriculture
Targeted Treatments: By accurately identifying the specific diseases
affecting crops, ML models enable farmers to apply treatments precisely
where needed, reducing the use of pesticides and fertilizers.
2. Crop Monitoring and Management
Real-Time Monitoring: Drones and satellites equipped with cameras can
capture images of crops, which are then analyzed by ML models to
monitor plant health in real-time.
3. Disease Research and Development
Disease Patterns and Trends: ML models can analyze large datasets to
identify patterns and trends in disease occurrence, helping researchers
understand disease dynamics.
4. Agricultural Robotics
Automated Disease Detection: Robots equipped with cameras and ML
algorithms can patrol fields, identifying and treating diseased plants
autonomously.
Precision Spraying: Robots can precisely spray affected plants,
minimizing chemical usage and environmental impact.
5. Education and Training
Training Programs: Educational platforms can use ML models to train
farmers and agricultural students on disease identification and
management.
Interactive Learning: ML-powered simulators provide interactive
learning experiences, helping users understand disease impacts and
management techniques.
CHAPTER – 7
7.1 RESULTS AND DISCUSSION
The application of machine learning (ML) in leaf disease classification
has demonstrated significant improvements in the accuracy, efficiency,
and scalability of agricultural practices. By employing Convolutional
Neural Networks (CNN), the model achieved high accuracy in identifying
various leaf diseases, often surpassing traditional methods that rely on
human expertise. This precision is crucial for early detection and timely
intervention, which in turn helps in preventing the spread of diseases and
minimizing crop loss.The deployment of ML models through mobile and
web applications has made advanced diagnostic tools accessible to
farmers worldwide. These platforms allow farmers to upload images of
diseased leaves and receive instant diagnoses and treatment
recommendations, empowering them with knowledge and actionable
insights. The integration of these models with drones and IoT devices
further enhances real-time monitoring and data collection, enabling
comprehensive field management and decision support.
7.2 CONCLUSION
Implementing a machine learning system for leaf disease classification
involves a comprehensive approach, beginning with the collection and
preprocessing of data. A diverse set of images depicting various leaf
diseases is gathered from agricultural research institutions, online
databases like PlantVillage, or directly from the field. These images are
standardized by resizing, normalizing pixel values, and enhancing quality
through techniques like noise reduction. Data augmentation, such as
rotating, flipping, and zooming images, increases the dataset's variability
and size.
The next step involves developing a Convolutional Neural Network
(CNN) model, known for its effectiveness in image classification. The
dataset is split into training, validation, and test sets to train the model,
with the validation set used to tune hyperparameters and prevent
overfitting.
7.3 FUTURE ENHANCEMENT
Future enhancements for the machine learning system in leaf disease
classification could focus on several key areas to further improve
accuracy, usability, and integration with broader agricultural practices.
One potential enhancement is the incorporation of more sophisticated
deep learning architectures, such as transformers and attention
mechanisms, which can capture intricate patterns in leaf images and
improve classification performance. Additionally, expanding the dataset
to include a wider variety of crops and disease types from diverse
geographical regions would enhance the model‘s generalizability and
robustness. Integrating multi-spectral and hyperspectral imaging can
provide additional data layers, such as chemical composition and
moisture content, which are not visible in standard RGB images. This can
lead to more precise disease detection and severity assessment. Moreover,
incorporating real-time environmental data, such as temperature,
humidity, and soil conditions, can enable predictive analytics, helping
farmers anticipate disease outbreaks before they occur.
REFERENCE
[1] S. Tibpromma, Y. Dong, S. Ranjitkar, D. A. Schaefer, S. C.
Karunarathna, K. D. Hyde, R. S. Jayawardena, I. S. Manawasinghe, D. P.
Bebber, I. Promputtha, and J. Xu, ‗‗Climate-fungal pathogen modeling
predict loss of up to one-third of tea growing areas,‘‘ Frontiers Cellular
Infection Microbiol., vol. 11, p. 308, Apr. 2021, doi:
10.3389/fcimb.2021.610567.
[2] V. K. Vishnoi, K. Kumar, and B. Kumar, ‗‗Plant disease detection
using computational intelligence and image processing,‘‘ J. Plant
Diseases Protection, vol. 128, no. 1, pp. 19–53, Aug. 2020, doi:
10.1007/S41348-020- 00368-0.
[3] K. V. Raghavendra, D. S. B. Naik, S. Venkatramaphanikumar, S. D.
Kumar, and S. V. Rama Krishna, ‗‗Weather based prediction of pests in
cotton,‘‘ in Proc. Int. Conf. Comput. Intell. Commun. Netw., Nov. 2014,
pp. 570–574, doi: 10.1109/CICN.2014.129.
[4] C. Chaliha and E. Kalita, ‗‗Blister blight disease of tea: An enigma,‘‘
in Diagnostics of Plant Diseases, Dec. 2020, doi:
10.5772/INTECHOPEN.95362.
[5] S. Sen, M. Rai, D. Das, S. Chandra, and K. Acharya, ‗‗Blister blight a
threatened problem in tea industry: A review,‘‘ J. King Saud Univ. Sci.,
vol. 32, no. 8, pp. 3265–3272, Dec. 2020, doi: 10.1016/
J.JKSUS.2020.09.008.
[6] X. Yang, J. Zhang, D. Guo, X. Xiong, L. Chang, Q. Niu, and D.
Huang, ‗‗Measuring and evaluating anthocyanin in lettuce leaf based on
color information,‘‘ IFAC-PapersOnLine, vol. 49, no. 16, pp. 96–99,
2016, doi: 10.1016/j.ifacol.2016.10.018.
[7] C. Farber, M. Mahnke, L. Sanchez, and D. Kurouski, ‗‗Advanced
spectroscopic techniques for plant disease diagnostics. A review,‘‘ TrAC
Trends Anal. Chem., vol. 118, pp. 43–49, Sep. 2019, doi:
10.1016/J.TRAC.2019.05.022.
[8] H. M. Prathibhani, C. Kumarihami, and K. Jeong, ‗‗Parathibhai,‘‘ J.
Korea Tea Soc., vol. 24, no. 3, pp. 79–87, 2018.
[9] V. Voora, S. Bermúdez, and C. Larrea. (2019). Global Market Report:
Tea|International Institute for Sustainable Development. Accessed: Mar.
16, 2022. [Online]. Available: https://www.iisd.org/publications/ global-
market-report-tea
[10] A. K. Pandey, G. D. Sinniah, A. Babu, and A. Tanti, ‗‗How the
global tea industry copes with fungal diseases—Challenges and
opportunities,‘‘ Plant Disease, vol. 105, no. 7, pp. 1868–1879, Jul. 2021,
doi: 10.1094/PDIS-09- 20-1945-FE.
[11] China: Tea Production 2020 | Statista. Accessed: Mar. 16, 2022.
[Online]. Available: https://www.statista.com/statistics/275639/tea-
production-inchina/
[12] Tea Growing Regions. Accessed: Mar. 16, 2022. [Online].
Available: https://teapeople.co.U.K./tea-growing-regions
[13] S. Tibpromma, Y. Dong, S. Ranjitkar, D. A. Schaefer, S. C.
Karunarathna, K. D. Hyde, R. S. Jayawardena, I. S. Manawasinghe, D. P.
Bebber, I. Promputtha, and J. Xu, ‗‗Climate-fungal pathogen modeling
predicts loss of up to one-third of tea growing areas,‘‘ Frontiers Cellular
Infection Microbiol., vol. 11, p. 1, Apr. 2021, doi: 10.3389/fcimb.
2021.610567.
[14] P. B. Jawade, D. Chaugule, D. Patil, and H. Shinde, ‗‗Disease
prediction of mango crop using machine learning and IoT,‘‘ Tech. Rep.,
2020, pp. 254–260, doi: 10.1007/978-3-030-24322-7_33.
[15] W.-L. Chen, Y.-B. Lin, F.-L. Ng, C.-Y. Liu, and Y.-W. Lin,
‗‗RiceTalk: Rice blast detection using Internet of Things and artificial
intelligence technologies,‘‘ IEEE Internet Things J., vol. 7, no. 2, pp.
1001–1010, Feb. 2020, doi: 10.1109/JIOT.2019.2947624.