2023-Rice Paddy Disease Classification Using CNNs
2023-Rice Paddy Disease Classification Using CNNs
Charles O’Neill
July 2022
Abstract
Rice is a staple food in the world’s diet, and yet huge percentages of crop yields are lost each year to disease. To combat
this problem, people have been searching for ways to automate disease diagnosis. Here, we extend on previous modelling
work by analysing how disease-classification accuracy is sensitive to both model architecture and common computer vision
techniques. In doing so, we maximise accuracy whilst working in the constraints of smaller model sizes, minimum GPUs
and shorter training times. Whilst previous state-of-the-art models had 93% accuracy only predicting 5 diseases, we
improve this to 98.7% using 10 disease classes.
arXiv:2303.08415v1 [[Link]] 15 Mar 2023
1 Introduction
Rice (Oryza sativa) is one of the most important food crops in the world today. It is considered a staple component in the
diet of over half the world population (Calpe, 2002). However, 70% of crop yields are lost each year to common diseases
(Xu et al., 2017), such as those shown in Figure 1. Because of this, prevention of common rice crop diseases is critical due
to food security concerns (Fina et al., 2013). Whilst most rice disease diagnosis is done manually by local experts (Sethy
and Behera, 2020), this is time-consuming, unreliable and often inaccessible. This engenders a research question: how
can we use mathematical tools and images to accurately and efficiently diagnose rice paddy disease?
As such, many groups have attempted to use mathematical modelling to perform algorithmic rice paddy disease
diagnosis. Support vector machines have previously been used to detect diseased leaves, albeit without classifying them
(Singh and Misra, 2017). Islam et al. (2018) developed on this work to take an RGB sample of the affected portion of the
leaf, and use this as input to a naı̈ve Bayes as a disease classifier. Machine learning technology has even been layered on
top of thermal imaging cameras to identify disease by temperature (Zhu et al., 2018).
However, these methods were limited, as they relied on manual feature extraction (often requiring an expert) as well
as often expensive technology. As a result, several groups have recently attempted to apply deep learning to the problem.
For instance, Deng et al. (2021) achieved 91% classification accuracy on dataset highly similar to ours. Using a VGGNet
with an Inception Module, Chen et al. (2020) achieved an accuracy of 92%. Rahman et al. (2020) improved on this with a
standard convolutional neural network (CNN) architecture, reaching 93.3% accuracy. Others have even designed systems
for real-time disease diagnosis using mobile technology (Temniranrat et al., 2021). Admittedly, some of this success may
be attributed to the number of classes predicted: for instance, Chen et al. (2020) only attempted to predict five diseases.
Obviously, the central goal of any model is performance: how accurately does the model classify the diseases? This
analysis will examine a number of different techniques for maximising accuracy. In addition to this, however, we consider
how to optimise this performance under the constraints of limited model size, memory, and GPU speed. This is a key
consideration in many aspects of model development, particularly deep learning. For instance, farmers attempting to train
their own models on specific crops are unlikely to have access to world-class GPUs and unlimited memory. Thus, the main
contribution of this research is how model performance varies within the constraints outlined above. We hypothesise
that we can develop significantly more accurate models with less compute power and shorter training times.
1
(a) Original image (b) Top-edge kernel (c) Left-edge kernel
1.1 Data
The data were collected by the Paddy Doctor project team at the Department of Computer Science and Engineering,
Manonmaniam Sundaranar University, Tirunelveli, India. It consists of a base dataset of 10,407 labelled paddy leaf
images, with ten classes of disease. We use these images for both training and validation. An additional holdout test set
of 3,469 images are reserved for further evaluating the model. The data are available here.
2 Model
Computer vision has seen big advancements in a relatively short time-period by leveraging the power of deep learning,
particularly convolutional neural networks (CNNs). Such models use backpropagation to update kernels which perform
convolution operations, maintaining sparsity and preserving the spatial integrity of input images (Shorten and Khoshgof-
taar, 2019).
A CNN can be decomposed into four operations: convolution, non-linearity, pooling, and output. As the name suggests,
the key idea of CNNs is the convolution operation. This is motivated by how humans detect images through the visual
cortex; we look for sharp edges and gradients to distinguish objects and recognise depth. Since images are essentially
2D-matrices, we can use what amounts to element-wise matrix multiplication (Hadamard product) over this matrix to
extract features. Depending on the matrix we use for convolution, we can extract vertical edges, horizontal edges and
many other types of visual patterns. Regardless, the aim of the convolution operator (kernel) is to reduce the image size
across all three RBG dimensions by sliding the kernel over the image. Figure 2 shows the effects of different convolutions,
highlighting how different elements in the kernel can detect different features.
The key innovation of CNNs (introduced with Lenet by Bottou et al. (1994)) was to not manually choose the kernels used
for feature extraction, but rather treat the weights of the kernels as parameters that can be optimised via backpropagation
in a neural network. In this way, deep learning finds the best feature detectors that create the richest (and simplest)
representation of the image that can be passed to a fully-connected (FC) layer for output prediction. Along with steps
such as pooling (which takes neighbourhood-based averages of elements in the image matrix to further reduce dimension),
an extremely effective computer vision model can be constructed from scratch in a deep learning framework such as Pytorch
with minimal code. Thus, we select CNN as the architecture for our disease-classifying model.
We begin with an architecture shown in Figure 3. As a general overview of the model design, the initial layers (leftmost)
take in an image of size 224 × 224, and we use a batch-size of 64.1 Convolution operations applied across all three colour
dimensions repeatedly reduce the size of the image, whilst adding a number of channels (intuitively, this can be thought
of as the “thickening” of the blocks shown in the image). Max pooling also contributes to this downsampling.2 Finally,
after several applications of convolution layers, we apply three FC layers, where the inputs are a vector. After applying a
softmax to the final FC layer, we output a vector of size 10, representing the probability of the disease being present in
the image, for each of the 10 diseases.
Once we have instantiated this architecture, we randomly initialise the weights using Kaiming-He initialisation, where
the weights are sampled from a normal distribution following W ∼ N 0, n2l , where n is the size of the input and l is
the number of layers. This ensures that we avoid vanishing or exploding gradients by keeping the mean of weights across
layers as 0, and the standard deviation as 1 (He et al., 2015b). We then perform the training process, implemented using
a for-loop in Pytorch over batches of training images:
1. A training image is forward propagated through the CNN, following the convolution, pooling and activations and
reaches the final FC-layer, where a softmax activation outputs the predicted probabilities for each class.
2. Th the total loss (using cross-entropy loss) is calculated at the output layer.
3. Backpropagation is used to calculate the gradient of the loss with respect to the model parameters.
4. The gradient is multiplied by the learning rate. This is subtracted from the current weights, giving a new set of
parameters that (hopefully) lead to a lower loss and more accurate output predictions.
1 Batch-sizerefers to the number of training examples we use before updating the model weights after backpropagation.
2 Whilstthis report will not go into the details of convolution arithmetic, a fantastic resource for understanding how padding, stride length and
convolutions in general perform downsampling can be found here.
2
Figure 3: Architecture of baseline CNN in Pytorch.
ezi
σ(z)i = PK
j=1 ezj
This gives the formula for the i-th element of the softmax-activated input vector, where K is the number of classes (in
our case 10). We then apply negative log likelihood to the activated outputs to get the cross-entropy loss. Note how
this minimises the distance between the predicted and true probability distributions. This is because cross-entropy loss
penalises predictions for being both wrong (i.e. the largest probability is for the wrong class) and confident (i.e. a very
high probability for one class, and close to zero for the others). Cross-entropy calculates a separate loss for each class label
in a single observation, and takes the sum over labels:
K
X
− p(x) log q(x)
x∈C
Here, K is again the number of classes. p(x) is a binary variable representing whether the particular class label is the
true observation value (as a one-hot encoded vector) and q(x) is the predicted probability that the class is the one in the
image.
3
Figure 4: A skip connection in a residual network.
2.3 Baseline
One of the key parts of this analysis is the sensitivity of performance to model architecture. Hence, several baselines
should be established to provide context for improvements driven by different CNNs. Hence, we generate results for two
different classes of baseline models:
1. Foundational CNN trained with randomly initialised weights
2. Residual network (ResNet34, a common architecture with 34 layers) with randomly initialised weights
3. Pretrained ResNet34 that is fine-tuned on current task
The model itself is a CNN, but we will determine how specific model architecture (i.e. ConvNet vs ResNet vs vanilla
CNN) affects accuracy, as well as techniques such as transfer learning.
2.4 Assumptions
The usefulness of neural networks comes from their capacity for universal function approximation. This negates the need
for assumptions required in models such as linear regression, as our network is tasked with simply fitting a function to
data. However, there are still several key assumptions we make about the data and models we are using. First, we are
assuming that the training and test data come from the same distribution. Without this assumption, any evaluation of
the model would be useless, as neural networks are not invariant to shifts in the data distribution. This assumption is
justified as the test images come from the same regions of India as the training images. (Saying this, the specificity of
the test and training data raises another question about generalisability; see Discussion.) Secondly, we assume that the
amount of data is sufficient for the model to learn generalisable trends about rice paddy disease. Again, this assumption
seems justified, as we have over 10,000 training images. Finally, we assume that we can select an appropriate capacity of
the CNN within the constraints (GPU, memory and training time). A CNN with too few parameters will struggle to learn
the complex relationships inherent in the images, and a CNN with too large a capacity has the tendency to overfit. The
validity of this assumption will become apparent when evaluating the models below.
3 Results
Here, we present the results ordered by complexity of both computer vision techniques and scale of model used. We begin
with simple baselines and demonstrating the benefits of transfer learning. We then explore the effect of certain techniques
on the performance of the model. After iterating quickly with these techniques on smaller models, we select the most
appropriate set of methods and apply them to larger models.
4
Table 1: Baseline model results
5
Figure 7: Example of duplicating a training image using data augmentation.
3.3.4 Mixup
Mixup provides an additional form of augmentation by training the CNN on linear combinations of examples from different
classes (Zhang et al., 2017). It allows non-expert dependent augmentation that can be scaled with the requirements of the
6
dataset. To use Mixup, we select two random images from the training dataset, along with a random weight parameter
λ. By taking a weighted average of the two images, we produce a new training image x̃ (independent variable); similarly,
the same weighted average of the image labels gives the new label ỹ (dependent variable).
x̃ = λxi + (1 − λ)xj
ỹ = λyi + (1 − λ)yj
However, introducing Mixup makes the classification task significantly harder: the model is now required to predict
two classes per image, as well as the weighting applied to each one. Thus, Mixup usually requires significantly more epochs
to get better results. Indeed, we show this after training the ResNet34 for 25 epochs; without Mixup, the model overfits
and achieves an accuracy of 93.8%. However, with Mixup the validation accuracy improves to 97.3%.
The models were chosen from a commonly available list of pretrained image models implemented in Pytorch as part
of the standard repository. Using this technique, it appears that ConvNext, Swin and Vit models (both small and large
versions) all fit in memory.
7
Figure 8: Error rates over the course of training for the ensemble component models.
To address this, Micikevicius et al. (2017) introduced mixed-precision training, which uses FP32 and FP16 interchange-
ably depending on what stage of training we are up to. For instance, forward propagation and backpropagation (gradient
computations) are done in half-precision, but the weights update itself is done in full-precision. This is largely because
small learning rates mean the updates to weights will be small, which can only be represented accurately in full precision.
To achieve this, we store a copy of the weights as we train in full 32-bit precision.
On a NVIDIA GPU, mixed-precision training is easily implementable, so we apply it to the training of the following
large models.
3.5 Ensemble
Using ensembles of fine-tuned computer vision models is common in the literature (Qummar et al., 2019). The idea here
is that different models initialised with different random seeds will make uncorrelated errors when predicting unseen data.
If the predictions are averaged, the expected value of these uncorrelated errors is zero. Whilst errors won’t be completely
uncorrelated in practice, we can still leverage this idea to create an ensemble of models.
The error rate for each of the models in the ensemble is shown in Figure 8. To create an ensemble model, we simply
take the average of predictions across all models. During training, it was noticed that VIT performed slightly better than
other models, so VIT was weighted double in the prediction averages. This yielded an accuracy of 98.90% on the validation
set, and 98.69% on the test set, by far the most accurate model.
4 Discussion
The focus of this mathematical modelling was to conduct a sensitivity analysis of how both model architecture and
computer vision techniques affect accuracy when predicting rice paddy disease. Additionally, to ensure results weren’t
8
driven by computation power alone, we set the constraint of training the predictive models with only one GPU with 16
GB of RAM and short training times (less than five minutes per epoch).
When comparing to vanilla CNNs, model architecture yields the biggest increase in performance. For instance, a
CNN initialised with random weights required 50 epochs to achieve 80% accuracy, whereas a randomly initialised residual
network implementing skip connections in the CNN only required 5 epochs to get to the same point.
However, once this initial improvement was made, further changes to architecture achieved minimal improvement. For
instance, using a ConvNext architecture (which is currently considered the state-of-the-art CNN for computer vision) over
a ResNet34 yielded similar accuracies. The next jump in accuracy was achieved by using transfer learning, where we
instantiate a model with pretrained weights and fine-tune it on the paddy disease task. Doing so improved accuracy by
approximately 10%. This improvement of pretrained models over the baseline networks demonstrates the power of transfer
learning, and this allowed us to select only pretrained models to iterate on.
We then explored how accuracy was sensitive to computer vision techniques that weren’t dependent on architecture. We
found that using appropriate learning rates, data augmentation and test-time augmentation yielded further improvements
in accuracy. Some techniques such as Mixup required many epochs of training to yield improvements, and as such were
disqualified from use due to our self-imposed training time constraints.
A key lens through which we viewed our analysis was a meta-overview of techniques that allowed us to train faster and
with minimal GPUs and memory. Whilst image downsizing was implemented from the beginning, other useful techniques
included gradient accumulation and mixed precision training. Progressive resizing proved effective in reducing training
times, but resulted in considerable degradation in model accuracy, requiring more epochs to correct.
There are several potential limitations with this work. The first is potential generalisation problems. The dataset
came entirely from paddy fields in the Tirunelveli district of Tamilnadu, India. The training data distribution may thus
be significantly different from general crop images. For instance, bacterial blight is a paddy disease that requires humidity
above 70%, and thus may be absent in certain types of fields (Mew, 1987). However, Temniranrat et al. (2021) note that
most rice crops look similar, and climates suitable for rice are specific enough that the same diseases manifest themselves
in most locations. An additional limitation, largely constrained by minimising training time, was that cross-validation
was not used. Here, we evaluated model performance using a validation set and a further hold-out test set (ensuring
hyperparameters could not be optimised to this specific distribution). Whilst this is effective, an even better approach
would be to use k-fold cross validation, where the data is divided into k equal subsets, k − 1 of which are used for
training and the remaining for validation. Repeating this process can yield statistical insights into model accuracy (i.e.
standard deviation as well as mean). However, given the size of the dataset, this would be unlikely to lead to significant
generalisation improvements.
Saying this, the above limitations also engender future research directions. For instance, a further dataset from a
different region with varied climate could be constructed to test the generalisability of the trained model. Additionally,
work could be done on understanding model predictions, particularly how each layer decomposes each image. There are
several tools which may allow this for CNNs specifically, such as class activation maps to visualise which pixels activate
which layers of the network. Finally, work could be done exploring how metrics other than accuracy, such as ROC AUC
(receiver-operating characteristic, area-under-curve) can lead to improved interpretability and better model performance.
5 Conclusion
In this work, we leveraged the power of deep learning to achieve state-of-the-art results for rice paddy disease detection,
improving accuracy from a literature-best of 93% on five classes of disease to 98.7% on a more difficult task of predicting
ten diseases. We did this within the constraints of one GPU, limited RAM and reduced training times, which isolated the
effects on performance of (i) model architecture and (ii) computer vision techniques. Specifically, we conducted a sensitivity
analysis of how these two mathematical modelling considerations contributed to classification accuracy. We found that
model architecture led to small improvements, but it was the techniques that drove the best accuracy. Specifically, finding
an appropriate learning rate allowed the model to converge quicker. Using test-time augmentation and experimenting
with appropriate data augmentation also yielded significant improvements. Further, monitoring GPU memory usage and
implementing gradient accumulation allowed us to ensemble relatively large models, despite limited RAM, and ensured all
training runs were under 12 epochs and 5 minutes per epoch. This highlights how iterative modelling can beat academic
benchmarks, despite reduced modelling capacities. This is particularly important in the current problem: any model that
predicts rice paddy disease will likely have to be light-weight enough to be implemented on a mobile device in order to be
usable by rural farmers, ruling out excessively large architectures.
References
Bottou, L., Cortes, C., Denker, J. S., Drucker, H., Guyon, I., Jackel, L. D., LeCun, Y., Muller, U. A., Sackinger, E., Simard,
P., et al. (1994). Comparison of classifier methods: a case study in handwritten digit recognition. In Proceedings of
the 12th IAPR International Conference on Pattern Recognition, Vol. 3-Conference C: Signal Processing (Cat. No.
94CH3440-5), volume 2, pages 77–82. IEEE.
Calpe, C. (2002). Rice in world trade, part ii. status of the world rice market. Proceedings of the 20 th Session of the
International Rice Commission.
Chen, J., Chen, J., Zhang, D., Sun, Y., and Nanehkaran, Y. A. (2020). Using deep transfer learning for image-based plant
disease identification. Computers and Electronics in Agriculture, 173:105393.
9
Deng, R., Tao, M., Xing, H., Yang, X., Liu, C., Liao, K., and Qi, L. (2021). Automatic diagnosis of rice diseases using
deep learning. Frontiers in Plant Science, page 1691.
Fina, F., Birch, P., Young, R., Obu, J., Faithpraise, B., and Chatwin, C. (2013). Automatic plant pest detection and recog-
nition using k-means clustering algorithm and correspondence filters. International Journal of Advanced Biotechnology
and Research, 4(2):189–199.
He, K., Zhang, X., Ren, S., and Sun, J. (2015a). Deep residual learningfor image recognition. ComputerScience.
He, K., Zhang, X., Ren, S., and Sun, J. (2015b). Delving deep into rectifiers: Surpassing human-level performance on
imagenet classification. In Proceedings of the IEEE international conference on computer vision, pages 1026–1034.
Huh, M., Agrawal, P., and Efros, A. A. (2016). What makes imagenet good for transfer learning? arXiv preprint
arXiv:1608.08614.
Islam, T., Sah, M., Baral, S., and Choudhury, R. R. (2018). A faster technique on rice disease detectionusing image
processing of affected area in agro-field. In 2018 Second International Conference on Inventive Communication and
Computational Technologies (ICICCT), pages 62–66. IEEE.
Mew, T. (1987). Current status and future prospects of research on bacterial blight of rice. Annual review of phytopathology,
25(1):359–382.
Micikevicius, P., Narang, S., Alben, J., Diamos, G., Elsen, E., Garcia, D., Ginsburg, B., Houston, M., Kuchaiev, O.,
Venkatesh, G., et al. (2017). Mixed precision training. arXiv preprint arXiv:1710.03740.
Qummar, S., Khan, F. G., Shah, S., Khan, A., Shamshirband, S., Rehman, Z. U., Khan, I. A., and Jadoon, W. (2019). A
deep learning ensemble approach for diabetic retinopathy detection. Ieee Access, 7:150530–150539.
Rahman, C. R., Arko, P. S., Ali, M. E., Khan, M. A. I., Apon, S. H., Nowrin, F., and Wasif, A. (2020). Identification and
recognition of rice diseases and pests using convolutional neural networks. Biosystems Engineering, 194:112–120.
Sethy, P. K. and Behera, S. K. (2020). Detection of coronavirus disease (covid-19) based on deep features.
Shorten, C. and Khoshgoftaar, T. M. (2019). A survey on image data augmentation for deep learning. Journal of big data,
6(1):1–48.
Singh, V. and Misra, A. K. (2017). Detection of plant leaf diseases using image segmentation and soft computing techniques.
Information processing in Agriculture, 4(1):41–49.
Smith, L. N. (2017). Cyclical learning rates for training neural networks. In 2017 IEEE winter conference on applications
of computer vision (WACV), pages 464–472. IEEE.
Temniranrat, P., Kiratiratanapruk, K., Kitvimonrat, A., Sinthupinyo, W., and Patarapuwadol, S. (2021). A system for
automatic rice disease detection from rice paddy images serviced via a chatbot. Computers and Electronics in Agriculture,
185:106156.
Xu, G., Yuan, M., Ai, C., Liu, L., Zhuang, E., Karapetyan, S., Wang, S., and Dong, X. (2017). uorf-mediated translation
allows engineered plant disease resistance without fitness costs. Nature, 545(7655):491–494.
Zhang, H., Cisse, M., Dauphin, Y. N., and Lopez-Paz, D. (2017). mixup: Beyond empirical risk minimization. arXiv
preprint arXiv:1710.09412.
Zhu, W., Chen, H., Ciechanowska, I., and Spaner, D. (2018). Application of infrared thermal imaging for the rapid
diagnosis of crop disease. IFAC-PapersOnLine, 51(17):424–430.
Zhuang, F., Qi, Z., Duan, K., Xi, D., Zhu, Y., Zhu, H., Xiong, H., and He, Q. (2020). A comprehensive survey on transfer
learning. Proceedings of the IEEE, 109(1):43–76.
10