Open-access Early detection of citrus leafminer (Phyllocnistis citrella) in lemon trees (Citrus aurantifolia) using artificial intelligence

Detecção precoce do minador dos citros (Phyllocnistis citrella) em limoeiros (Citrus aurantifolia) usando inteligência artificial

ABSTRACT

The lemon tree (Citrus aurantifolia) is a highly commercial crop in northern Peru and is severely affected by the citrus leafminer pest (Phyllocnistis citrella). Early detection is vital to reduce yield losses caused by this pest. This research evaluated Machine Learning (SVM, KNN, DT, RF) and Deep Learning (CNN) algorithms to identify the presence of the leafminer across three stages of damage severity (Stage 1, Stage 2, Stage 3) and healthy leaves (No leafminer). A dataset of 1,134 field-acquired images was used. The base CNN achieved 85.71% accuracy. Through architectural optimization (adding three convolutional layers with 64, 128, and 256 filters and increasing the dense layer to 256 neurons), the optimized CNN reached 90.95% accuracy after 50 training epochs, outperforming traditional ML algorithms (79.05-84.29%). A benchmark using Google’s Teachable Machine (AutoML) platform achieved 96.86% overall accuracy, with class-specific accuracies of 94% (Stage 1), 96% (Stage 2), 97% (Stage 3), and 100% (No leafminer). Functional web and Android mobile prototypes integrating the optimized CNN model were developed for real-time field detection. These results demonstrate that the proposed architectural modifications yield superior pest detection performance, and that AutoML platforms can provide even higher accuracy, reducing technical barriers for farmers and researchers.

Index terms:
Artificial intelligence; pest detection; deep learning; machine learning; Phyllocnistis citrella

RESUMO

O limoeiro (Citrus aurantifolia) é uma cultura de grande importância comercial no norte do Peru e é gravemente afetado pela praga da minadora de folhas dos citros (Phyllocnistis citrella). A detecção precoce é vital para reduzir as perdas de rendimento causadas por essa praga. Esta pesquisa avaliou algoritmos de Aprendizado de Máquina (SVM, KNN, DT, RF) e Aprendizado Profundo (CNN) para identificar a presença da minadora de folhas em três estágios de gravidade do dano (Estágio 1, Estágio 2, Estágio 3) e em folhas saudáveis (sem minadora de folhas). Foi utilizado um conjunto de dados com 1.134 imagens adquiridas em campo. A CNN básica atingiu 85,71% de precisão. Por meio da otimização da arquitetura (adicionando três camadas convolucionais com 64, 128 e 256 filtros e aumentando a camada densa para 256 neurônios), a CNN otimizada atingiu 90,95% de precisão após 50 épocas de treinamento, superando os algoritmos tradicionais de ML (79,05-84,29%). Um benchmark utilizando a plataforma Teachable Machine (AutoML) do Google alcançou 96,86% de precisão geral, com precisões específicas por classe de 94% (Estágio 1), 96% (Estágio 2), 97% (Estágio 3) e 100% (Sem minador de folhas). Protótipos funcionais para web e dispositivos móveis Android, integrando o modelo CNN otimizado, foram desenvolvidos para detecção em campo em tempo real. Esses resultados demonstram que as modificações arquitetônicas propostas proporcionam um desempenho superior na detecção de pragas e que as plataformas AutoML podem oferecer precisão ainda maior, reduzindo as barreiras técnicas para agricultores e pesquisadores.

Termos para indexação:
Inteligência artificial; detecção de pragas; deep learning; machine learning; Phyllocnistis citrella

Introduction

Citrus cultivation is an economic activity of great importance worldwide, with Peru being one of the main producers and exporters of lemons in Latin America (Castillo-Coronado et al., 2023). The Piura region in Peru has shown a significant increase in its agricultural production capacity over the last year (Banco Central de Reserva Del Perú -BCRP, 2023). The lemon tree (Citrus aurantifolia) is one of the main crops in this region and is mainly affected by the citrus leaf miner (Phyllocnistis citrella), whose larvae affect young leaves by living in tunnels called mines, which are subepidermal and cause a loss of leaf mass, which in turn reduces crop yield (Santistevan et al., 2016). This insect is considered one of the most limiting pests for citrus cultivation in tropical and subtropical areas, as it mainly attacks new shoots, affecting vegetative development and future production (Grafton-Cardwell et al., 2013; Mansour & Braham, 2024). (FAO, 2019) data indicate that around 40% of global agricultural production is lost due to the presence of pests in fields, which seriously affects crops. In the specific case of citrus leaf miners, uncontrolled infestations can cause devastating losses, which directly impact the economy of small and medium-sized farmers.

In general, pest detection in fields is done visually, however, farmers often notice the presence of pests only after they have spread throughout the field. This approach is not only subjective and labor-intensive, but also inadequate for timely intervention (J. Barbedo, 2019). As a result, pest control is often based on the intensive application of pesticides, which leave residues on harvested products despite post-harvest washing (Chen et al., 2020a) and increase production costs (Damalas & Eleftherohorinos, 2011). In addition, the indiscriminate use of insecticides creates other problems such as pest resistance, damage to beneficial predators and environmental contamination (Bourguet & Guillemaud, 2016).

Given the context described above, early detection of citrus leafminers is crucial to mitigate economic losses and allow human resources to focus on other tasks in the crop cycle. Accurate and timely detection would enable the implementation of more rational integrated management strategies, reducing the number of insecticide applications and making agriculture more sustainable (Jeger et al., 2018). In recent years, Artificial Intelligence (AI) has been used in agriculture for the detection of pests and diseases in crops, where Machine Learning (ML) and Deep Learning (DL) techniques play an important role in the timely treatment of diseased fields, reducing the losses generated by them. Several authors have used ML methods such as support vector machines (SVM), K-nearest neighbors (KNN), decision trees (DT), and random forests (RF) to detect pests in different crops, achieving accuracies between 94% and 98.99% (Nasser Shah et al., 2019; Thorat et al., 2023).

On the other hand, there are DL methods that use convolutional neural networks (CNN), which, according to authors such as (Francisco et al., 2023), are the preferred method for researchers when identifying pests and have achieved accuracies of over 99% (Deepika & Arthi, 2022; Selvaraj et al., 2019). These networks are particularly effective for image processing, as they can automatically extract hierarchical and complex features from affected leaves, in many cases outperforming traditional ML methods (Li et al., 2021).

However, applying these methods to detect the citrus leaf miner (Phyllocnistis citrella) specifically in Peruvian lemon crops remains underdeveloped. Most studies have focused on other pests or diseases, or on controlled conditions (Hang et al., 2019), so it is necessary to evaluate the performance of these algorithms in real field conditions, with images taken directly in the affected region.

This study aimed to implement the early detection of the citrus leaf miner (Phyllocnistis citrella) using deep learning and machine learning techniques, which will allow technicians and engineers to identify the presence of this pest in lemon crops (Citrus aurantifolia) more rapidly and effectively. To this end, the performance of five algorithms (CNN, SVM, KNN, DT, and RF) was compared in the classification of No leafminer and leaves with different levels of damage caused by the pest, in order to determine the most suitable for future implementation in an early warning system.

Material and Methods

This study was conducted in two phases: the first consisted of acquiring and preparing the dataset of images of lemon tree leaves (Citrus aurantifolia), and the second consisted of implementing, training, and evaluating the machine learning (ML) and deep learning (DL) algorithms selected for classifying the damage caused by the citrus leaf miner (Phyllocnistis citrella). The general methodology of the detection system is summarized in Figure 1, which illustrates the process from image acquisition to final classification.

Figure 1:
Flowchart of the methodology for early detection of citrus leafminer (Phyllocnistis citrella) in lemon tree leaves. The process includes: (1) image dataset building, (2) image preprocessing and cleaning stage, (3) training and validation of five algorithms (CNN, SVM, KNN, DT, RF), and four categories of damage: stage 1, stage 2, stage 3, and healthy leaves (No leafminer).

At the same time, Google’s Teachable Machine tool was used, an AutoML platform that automates the training of computer vision models through a graphical interface, applying data augmentation and hyperparameter optimization techniques in a way that is transparent to the user (J. Barbedo, 2019). The model was trained with an 85%-15% distribution (training-testing), 50 epochs, batch size 16, and learning rate 0.001.

All experiments were run on a computer with an NVIDIA RTX 3000 GPU and 32 GB of RAM. The source code for the algorithms and the optimized model is available in the project appendices.

Study area and image acquisition

The study was conducted on the Valher farm, located in the district of Tambogrande, province of Piura, Peru (approximate coordinates: 5°11’0“S, 80°37’0”W). This area is characterized by a warm, arid climate, with average temperatures of 26 °C and relative humidity of 70-80%, conditions that favor the proliferation of the citrus leaf miner (Sernaque, Cherre & Chavez-Villavicencio, 2020). The images were collected using a 24-megapixel digital camera (Canon EOS Rebel T7 model) and a smartphone with a minimum resolution of 12 MP, operated by qualified technical personnel. The photographs were taken at a constant distance of 30-40 cm from the leaves, in natural light conditions between 8:00 and 11:00 a.m., to minimize variations in lighting and shadows (J. G. A. Barbedo, 2018). Original images were acquired at 6000×4000 pixels (24 MP resolution) and subsequently resized according to each algorithm’s input requirements (250×250 for CNN, 150×150 for SVM, DT, and RF, and 120×120 for KNN).

Construction and characterization of the dataset

A total of 1,134 images from lemon tree leaves were collected, divided into two main categories: No leafminer (50%) and leaves affected by leaf miners (50%). All leaves were visually classified by an expert plant pathologist into four categories: No leafminer (healthy leaves with no visible damage), and three stages of damage severity caused by P. citrella (Stage 1, Stage 2, and Stage 3) as illustrated in Figure 2.

Figure 2:
Images of lemon tree leaves where: a. healthy leaf; b. Stage 1 damage; c. Stage 2 damage and; d. Stage 3 damage.

The distribution of the dataset is presented in Table 1, which includes the total number of images per class. 81.5% of the images (924) were used to train the models and 18.5% (210) for validation, maintaining the proportion of each category in both sets to avoid bias (Chollet, 2021).

Table 1:
Distribution of images for training and validation.

Data preprocessing and augmentation

Uniform preprocessing was applied to all images to optimize model inputs. Duplicates were first removed, followed by cropping to isolate leaves and remove complex backgrounds. Subsequently, pixel normalization was applied by scaling the values to the range [0, 1] by dividing by 255, which improves numerical stability during training (Ian, Yoshua & Aaron 2016). The dimensions of the images were adapted according to the requirements of each algorithm: 250×250 pixels for CNN, 150×150 for SVM, DT, and RF, and 120×120 for KNN. To expand the dataset size and improve model generalization, data augmentation techniques such as random rotation (±30°), horizontal flipping, and brightness/contrast adjustments (±10%) were applied exclusively to the training set (Shorten & Khoshgoftaar, 2019). For the CNN base model, these augmentations were implemented using the ImageDataGenerator class from Keras with the following parameters: rescale=1./255, shear_range=0.2, zoom_range=0.2, and horizontal_flip=True. For traditional ML algorithms (SVM, KNN, DT, RF), only pixel normalization and PCA dimensionality reduction were applied, as data augmentation is not commonly used with flattened image vectors. Principal Component Analysis (PCA) was applied retaining 100 principal components, which preserved approximately 95% of the variance in the training set.

Training algorithms

Five widely used algorithms were selected for agricultural image classification: one deep learning method (CNN) and four machine learning methods (SVM, KNN, DT, and RF). The models were built using Python 3.9 with TensorFlow 2.8 and Scikit-learn 1.0, which are standard tools for AI development (Chollet, 2021; Pedregosa et al., 2011).

Convolutional Neural Networks (CNN)

CNNs represent deep learning architectures designed for data with grid-like structures, such as images (Lecun et al., 2015). These networks have convolutional layers that use filters to extract features at different levels through convolution, followed by pooling layers to reduce dimensions and fully connected layers for the final classification decision (Ian et al., 2016). This structure allows for the automatic detection of spatial and texture patterns, which is particularly effective in computer vision tasks (Liu et al., 2018).

The base CNN architecture comprised an input layer of 250×250×3 images, followed by a convolutional layer with 32 filters (3×3 kernel, ReLU activation), a max-pooling layer (2×2), a second convolutional layer with 64 filters (3×3, ReLU), another max-pooling layer, a flattening layer, a dense layer with 128 neurons (ReLU), and an output dense layer with 4 neurons and softmax activation. The model was compiled with the Adam optimizer and categorical cross-entropy loss, and trained for 10 epochs with a batch size of 32. For optimization, we added three additional convolutional layers (64, 128, and 256 filters respectively), increased the dense layer to 256 neurons, and extended training to 50 epochs. The model was compiled with the Adam optimizer and the categorical cross-entropy loss function, training for 50 epochs.

These parameters were selected after a preliminary grid search over filter sizes (32,64,128,256), number of convolutional layers (2,3,4), dense units (128,256,512), and training epochs (10,25,50,100). The combination of three additional layers, 256 dense neurons, and 50 epochs yielded the highest validation accuracy (90.95%) without significant overfitting, as indicated by a training-validation gap of less than 2%. The Adam optimizer was chosen for its adaptive learning rate, which accelerates convergence on image data (Kingma & Ba, 2014).

Support Vector Machines (SVM)

Support Vector Machines are supervised learning models that construct optimal hyperplanes in a high-dimensional feature space to separate classes (Mahesh, 2018). They use kernel functions (such as RBF) to map non-linearly separable data to spaces where they are separable, maximizing the margin between classes to improve generalization (Du et al., 2024; James et al., 2021). Their advantage lies in their effectiveness with moderately dimensional datasets and their robustness against overfitting (Géron, 2023; Pedregosa et al., 2011).

In this research, a radial basis function (RBF) kernel was employed. The regularization hyperparameter (C) and kernel coefficient (gamma) were optimized through grid search, evaluating the ranges C=[0.1, 1, 10, 100] and gamma=[0.001, 0.01, 0.1, 1]. The best combination found was C=10 and gamma=0.01. C=10 was selected because it provides moderate regularization, reducing training error while avoiding overfitting on the pest image dataset. Gamma=0.01 offered a suitable kernel width to capture local texture variations without excessive sensitivity to individual pixels, which is critical for distinguishing visually similar pest species (Du et al., 2024).

K-Nearest Neighbors (KNN)

KNN is an instance-based learning algorithm that classifies samples according to the majority class among their k nearest neighbors in the feature space (Cover & Hart, 1967). It uses distance metrics (Euclidean, Manhattan, etc.) to measure similarity and requires no explicit training phase, storing the entire reference dataset (James et al., 2021). Its simple approach makes it useful for irregular decision boundaries, although the computational cost increases as the dataset becomes larger.

For this study, Euclidean distance was used as the metric. The parameter k (number of neighbors) was optimized by testing odd values from 3 to 15 with cross-validation. The optimal k was 7, offering the best balance between bias and variance. Smaller k (3-5) produced noisy decision boundaries due to class overlap in the feature space, while larger k (>9) misclassified pest samples near boundaries by including out-of-class neighbors. Euclidean distance was retained as it is standard for continuous features extracted from pixel arrays (Cover & Hart, 1967).

Decision Trees (DT)

Decision trees construct predictive models in the form of trees, in which each internal node represents a test on an attribute, each branch represents the result of the test, and each leaf represents a class label (Breiman et al., 2017). They use impurity measures such as the Gini index or entropy to select attributes that maximize class separation. They are interpretable and handle both numerical and categorical data well, although they can be unstable to small variations in the data (James et al., 2021).

In the implementation, the tree was configured with the Gini impurity criterion for node splitting and a maximum depth of 10 to avoid overfitting. Gini impurity was preferred over entropy because it is computationally faster and yields comparable splits for multi-class problems (Breiman et al., 2017). A maximum depth of 10 was chosen after testing depths from 5 to 20; depths beyond 10 led to overfitting (training accuracy >98% but validation accuracy dropped by 12%), while depths below 8 underfit the data. This depth constraint also enhances interpretability for agronomic decision-making.

Random Forests (RF)

RF is an ensemble method that combines multiple decision trees trained on random subsets of data and features (bagging), averaging their predictions to improve stability and accuracy (Breiman et al., 2017). Randomization reduces correlation between trees, decreasing variance and the overfitting typical of individual DTs. Additionally, it provides feature importance measures based on impurity reduction (James et al., 2021; scikit-learn, 2025)

For this work, an ensemble of 100 decision trees (n_estimators=100) was trained, with node splitting considering the square root of the total number of features (max_features=’sqrt’). The choice of 100 trees follows the recommendation of (Breiman, 2001) that error stabilizes beyond 100 trees for datasets of moderate size (aprox 2000 images). Increasing to 200 trees did not improve accuracy (less than 0.5% gain) but increased inference time by 40%. The sqrt feature sampling reduces correlation among trees, which is particularly relevant for pest classification where many irrelevant features exist. This setting improved out-of-bag accuracy by 3.2% compared to using all features.

Evaluation of algorithms

The performance of each model was evaluated on the validation set using metrics implemented in Python scripts and the Teachable Machine platform, as applicable. The primary metric reported was overall Accuracy, calculated as the proportion of correct predictions over the total number of samples evaluated, using equation (1):

A c c u r a c y = T P + T N T P + F P + T N + F N (1)

where TP are true positives, TN true negatives, FP false positives, and FN false negatives (Sokolova & Lapalme, 2009). Th because it offers clear interpretability and captures overall model performance in a straightforward way (Naidu et al., 2023). It was calculated for each of the five algorithms (CNN, SVM, KNN, DT, RF) using predictions from the validation set, which made up 20% of the total dataset.

To provide a more robust evaluation, particularly given the natural class imbalance in the dataset (see Table 1), we additionally computed precision, recall (sensitivity), and F1-score for each class, as well as macro-averaged versions across all classes.

Precision measures the proportion of correctly predicted positive samples among all samples predicted as positive, as shown in equation (2):

P r e c i s i o n = T P T P + F P (2)

Meanwhile, recall (sensitivity) measures the proportion of correctly predicted positive samples among all actual positive samples, defined in equation (3):

R e c a l l = T P T P + F N (3)

Finally, the F1-score is the harmonic mean of precision and recall. This metric provides a single value that balances both components, calculated via Equation (4):

F 1 = 2 x = P r e c i s i o n x R e c a l l P r e c i s i o n + R e c a l l (4)

For multi-class evaluation, we report macro-averaged precision, recall, and F1-score, which calculate the metric independently for each class and then average them, giving equal weight to all classes regardless of their support (Sokolova & Lapalme, 2009). These metrics were computed for all models (CNN, SVM, KNN, DT, RF, optimized CNN, and Teachable Machine) using the validation set predictions.

For the model trained on the Teachable Machine platform, the specific accuracy of each class was automatically obtained for each category (Stage 1, Stage 2, Stage 3, No leafminer), along with a confusion matrix. This allowed for a detailed examination of class-wise performance and the identification of confusion between categories (J. Barbedo, 2019; Hang et al., 2019). Additionally, the macro-average area under the ROC curve (AUC) was calculated using the one-vs-rest (OvR) strategy, where values range from 0.5 (random classification) to 1.0 (perfect discrimination).

The evaluation was carried out using a retention scheme: for algorithms trained in Python, an 80%-20% training-validation split was used, while Teachable Machine automatically managed an 85%-15% split. Class balance was kept the same in both cases. This validation approach is common in computer vision applications for agriculture, as it provides a realistic estimate of performance with unseen data and facilitates comparison between different approaches (Ferentinos, 2018; Karar et al., 2021).

In addition to the main experiment comparing the five algorithms under identical conditions (80/20 split), a complementary benchmark was conducted using Google’s Teachable Machine (AutoML) platform with its default 85/15 split to explore the maximum achievable accuracy with automated augmentation and hyperparameter tuning.

Results and Discussions

The five models (CNN, SVM, KNN, DT and RF) were trained and evaluated to detect the citrus leaf miner (Phyllocnistis citrella) on lemon tree leaves, taking into account three stages of damage severity and a category of Healthy leaves (No leafminer). Accuracy served as the evaluation metric in the validation set (20% of the total data). The results for each model are shown in Table 2.

Table 2:
Accuracy results obtained for each baseline model.

The table shows that the basic CNN model achieved the highest accuracy, with 85.71%, followed by SVM, with 84.29%, KNN, with 83.33%, DT, with 80.95%, and RF, with 79.05%.The research results show that the Deep Learning model (CNN) achieved better Accuracy values than the Machine Learning models (SVM, KNN, DT, RF). This is consistent with the findings of (Kumar et al., 2022), who indicate in their review that DL models reach higher Accuracy values (99.64%) than ML models (95.71%). Other authors such as (Nikith et al., 2023) and (Alshammari & Alkhiri, 2023) also demonstrated that DL outperforms ML with values ranging from 96% to 98.9% and 76% to 95.86%, respectively.

On the other hand, the Accuracy obtained by the CNN (85.71%) used in this study is considerably lower than that reported in other research (>90%) where CNNs are proposed for the detection of leaf pests and diseases (Chen et al., 2020; De Vita et al., 2021; Goyal et al., 2021).This difference compared to other works may be mainly due to the size of the image database, since the aforementioned studies used datasets with more than 10,000 images. This is supported by the findings of (Luaibi et al., 2021), who evaluated two CNNs: AlexNet and ResNet, which improved their Accuracy by performing data augmentation on the original database, achieving an increase from 95.83% to 97.92% for AlexNet and from 93.75% to 95.83% for ResNet.

Following the comparative evaluation, the base CNN model was selected for architectural optimization. Through the addition of three convolutional layers (64, 128, and 256 filters) and increasing dense layer neurons to 256, the optimized CNN achieved an accuracy of 90.95% after 50 training epochs. This improvement of 5.24 percentage points highlights the importance of architectural adjustment and increased training time in the performance of convolutional neural networks. Table 3 provides a comparison of overall accuracy and training epochs for the CNN base, optimized CNN.

Table 3:
Overall accuracy of CNN base and optimized CNN.

Although the optimized CNN achieved a solid accuracy of 90.95% after 50 epochs, comparing this result with state-of-the-art pest detection studies from other regions and crops reveals both strengths and room for improvement. For instance, (Khanramaki et al., 2021) reported 99.04% accuracy on citrus pests using an ensemble of CNNs, while (Khanramaki et al., 2021) obtained between 95.99% and 99.75% on grape and cherry using ResNet-50 and Inception V3. More recently, (Ashraf et al., 2026) introduced PalmNeXt, which outperformed standard CNNs like CNN-Attention and ResNet13-Attention on date palm leaf datasets. (Teixeira et al., 2023) systematically reviewed 92 studies and noted that transformer-based architectures and YOLO variants consistently surpass basic CNNs in real-world scenarios. Furthermore, on public benchmarks like IP102, even the best models barely reach 82% mAP under highly heterogeneous conditions ((Ashraf et al., 2026). Consequently, while our architectural improvements (three convolutional layers with 64, 128, 256 filters and a dense layer of 256 units) represent a meaningful step forward compared to the baseline model, the obtained accuracy lies below what can be achieved with ensemble methods, pre-trained deep networks, or attention-based models. Future work should therefore explore those advanced architectures and validate our model on diverse public datasets to better benchmark its performance. Authors such as Smith (2020) and Thakare and Ravi (2024) suggest hyperparameter tuning as a way to increase the efficiency and accuracy of machine learning models. It follows that there are several avenues for improving model performance, ranging from database enhancement to changes in model architecture (Kusrini et al., 2020; Mazumder et al., 2024; Shafay et al., 2025; Zhao et al., 2023).

Despite the significant improvement achieved through manual architectural tuning of the CNN, which reached a robust 90.95% accuracy, the research sought to explore the current performance ceiling for this specific agricultural task. Consequently, a Teachable Machine (AutoML) platform was employed as a high-level benchmark to contrast manual optimization against automated, state-of-the-art data augmentation and feature extraction techniques.

The model trained using the Teachable Machine (AutoML) platform achieved an overall accuracy of 96.86%, with class-specific accuracies of 94% for stage 1, 96% for stage 2, 97% for stage 3, and 100% for leaves without miners (Figure 4). The exceptional performance of the AutoML model, which even outperforms the optimized CNN, can be attributed to the advanced data augmentation techniques and automated hyperparameter optimization that the tool transparently implements. Similar results have been obtained in recent studies using AutoML platforms for disease detection in various crops, achieving over 95% accuracy with limited datasets (Elangovan, Lim & Ting, 2024; Eryılmaz & Kılıç, 2025). This finding suggests that AutoML tools can democratize access to high-accuracy models, reducing technical barriers for researchers and farmers.

To conclude the comparative analysis, Table 4 synthesizes the performance of all experimental phases, from initial machine learning algorithms to the final automated benchmark. This comprehensive overview, supported by the macro-average metrics, allows for a definitive assessment of the study’s progress. As shown in the table, there is a consistent upward trend in precision as the models transition from traditional architectures to optimized deep learning solutions.

Table 4:
Macro-average precision, recall, and F1-score for all models.

The comparison between traditional machine learning algorithms (SVM, KNN, DT, RF) and deep learning approaches (CNN) reveals a clear advantage for the latter, in line with trends observed in recent literature (Karar et al., 2021; Nikith et al., 2023). While SVM showed competitive performance (84.29%), tree-based methods (DT, RF) had the lowest accuracies, possibly due to their reduced ability to capture complex spatial patterns in images.

It is important to note that, although CNN showed the best performance, all algorithms exceeded 79% accuracy, indicating that even simpler methods such as KNN or DT can be useful for preliminary detection in contexts with limited computational resources. However, for implementation in automatic monitoring systems that require high reliability, the use of CNN or other DL models is recommended, complemented by expanded datasets and data augmentation techniques.

The overall performance of the evaluated architectures reveals a clear progression in accuracy as the complexity and optimization of the models increase. While traditional machine learning algorithms provided a baseline for comparison, the strategic refinement of the CNN and the implementation of automated learning pipelines significantly pushed the boundaries of classification effectiveness. This hierarchical performance is visually represented in Figure 3, which synthesizes the results of the seven models, highlighting the gap between basic classifiers and high-performance deep learning solutions.

Figure 3:
(A) Ranking of all models from lowest to highest performance, featuring five traditional machine learning algorithms (RF, DT, KNN, SVM), the CNN base, the optimized CNN, and the Teachable Machine model. (B) Focused comparison of the best-performing models. The dashed gray line indicates the 90% accuracy threshold.

As illustrated in Figure 3A, the Teachable Machine model established the highest benchmark at 96.86%, followed by the manually optimized CNN at 90.95%. This visual evidence confirms that hierarchical feature extraction is crucial for complex image classification tasks. To further understand the specific strengths and minor classification errors of the top-performing model, a more granular analysis of its prediction patterns is required.

While the overall accuracy provides a general measure of success, a class-wise evaluation is essential to verify the model’s reliability across different stages of infection. Table 5 details the performance metrics for the Teachable Machine model. The results indicate a perfect classification (1.00) for the ‘No leafminer’ category and exceptionally high F1-scores for all damage stages, confirming that the model effectively captures the unique morphological features of each stage despite the inherent visual similarities between Stage 1 and Stage 2. The balance between precision and recall across all classes demonstrates that the model is not biased towards any specific category.

Table 5:
Class-wise evaluation metrics for the Teachable Machine model on the validation set (N=210).

While the aggregate accuracy presented in Figure 3 confirms the superiority of the Teachable Machine model, a high overall percentage can sometimes mask specific classification challenges between similar classes. To deconstruct these results, it is essential to examine the model’s behavior at the class level. Figure 4 presents the normalized confusion matrix for the Teachable Machine model, providing a detailed look at how the system distinguishes between the three stages of leafminer damage and the healthy leaves. This granular analysis is critical to identifying whether errors are distributed randomly or if they stem from morphological similarities between specific damage stages.

Figure 4:
Normalized confusion matrix of the Teachable Machine model for citrus leafminer detection. Each value shows the percentage of samples from the actual class (rows) assigned to each predicted class (columns). The numbers on the right (N=) indicate the total number of samples per class in the validation set.

To further analyze these results, the confusion matrix generated by Teachable Machine (Figure 4) reveals important patterns in classification errors. The greatest confusion occurs between stage 1 and stage 2 classes (about 4% of stage 1 cases labeled as stage 2), which makes sense given the similarity in the appearance of initial damage. In contrast, stage 3 and the absence of leaf miners stood out with a specificity of 97% and 100%, demonstrating that the model clearly separated severe damage from No leafminer.

These patterns are shown in more detail in Figure 5, which shows the accuracy by class of the Teachable Machine model, confirming the high reliability of the model across all categories. These results are particularly promising for early detection applications, where distinguishing between the initial stages of damage is crucial for timely intervention.

Figure 5:
Class-wise accuracy of the Teachable Machine model. The class “No leafminer” achieves 100% accuracy, while damage stages show values between 94% and 97%.

As an applied contribution, this work developed and implemented two functional prototypes: a web application and a native mobile application for Android. Both integrate the optimized CNN model and enable real-time classification through the device’s camera. This implementation demonstrates the technical feasibility of bringing AI models into the field, offering an accessible tool for early decision-making. Recent research emphasizes the importance of closing the gap between the laboratory and the field through user-friendly, low-cost software developments (Anwarul et al., 2023; Christakakis et al., 2024; Islam et al., 2023).

Among the limitations of this study is the moderate size of the dataset (1,134 images), collected in a single region and season. Future research should expand the geographic, phenological, and lighting diversity of the images to improve the robustness of the model. Similarly, evaluating additional metrics (precision, recall, F1 score) by class would allow for a more detailed analysis of performance in the early stages of the pest, when detection is most critical. Integrating these models with early warning systems and precision agriculture platforms represents a natural step toward more sustainable, data-driven pest management.

Furthermore, challenges persist such as lighting variability in the field, the need for connectivity for the web version, and optimization for low-end mobile devices, aspects that should be addressed in future iterations. To provide a quantitative assessment of practical performance, the optimized CNN model was deployed on a native Android application (developed in Android Studio with TensorFlow Lite). On a mid-range device (Xiaomi Redmi Note 10, 4 GB RAM, Android 11), the average inference time per image was 0.42 seconds (standard deviation ±0.05 s), measured over 100 consecutive predictions. The model size after TensorFlow Lite quantization (float32 to float16) is 14.8 MB, making it suitable for over-the-air updates and storage on devices with limited capacity. The application runs stably on Android versions 9 (Pie) and above, covering approximately 85% of active devices in the Peruvian market. On lower-end devices (2 GB RAM, Android 9), inference time increases to 0.78 seconds per image, still acceptable for real-time field use. These quantitative results demonstrate that the proposed model is practical for real-world agricultural deployment, even on resource-constrained hardware.

The practical implementation of the proposed models can be greatly enhanced by integrating them with modern precision agriculture frameworks. The scientific literature provides strong support for this approach. Recent studies have developed IoT-enabled drones and edge computing architectures that allow for real-time data collection and analysis for large-scale field surveillance, successfully managing pests (Batistatos et al., 2025; Singh & Singh, 2025; Tiwari & Siddiqui, 2026). This aligns with our goal of deploying the optimized CNN model in similar settings. Given that our model, after float16 quantization, requires only 14.8 MB of memory and can run on devices like the Raspberry Pi 4 or NVIDIA Jetson Nano, it is ideally suited for edge computing applications. Research has confirmed that such lightweight architectures can perform real-time inference of complex models directly on drones, achieving high accuracy with low latency and generating georeferenced infestation heatmaps (Chung et al., 2026; Ghazlane, Ahmed & Hicham, 2024). This allows for precise, localized intervention strategies, which could reduce pesticide use by an estimated 60-80% compared to blanket spraying. While these technologies are promising, a recent study from the University of Florida emphasizes the need for a balanced approach, suggesting that AI-driven aerial scouting should complement, not entirely replace, boots-on-the-ground monitoring, which remains essential for verifying results and identifying nuances (Ampatzidis & Wade, 2020). Future work will focus on adaptive preprocessing to handle lighting variability and on-device quantization (INT8) to further reduce inference time for battery-powered sensors. Future research aims to optimize the model and propose an application so that the benefits of this research are more accessible to farmers for early detection of the citrus leafminer.

Conclusions

The optimized CNN achieved 90.95% accuracy for early detection of citrus leafminer in lemon trees, outperforming traditional machine learning algorithms. The Teachable Machine AutoML tool reached 96.86% overall accuracy, although with minor confusion between early damage stages (F1-score of 0.94 for Stage 1). Functional web and Android applications integrating the model were successfully developed and tested in real field conditions.

Acknowlegdments

The authors thank the Universidad Nacional de Frontera for the financial support provided through Agreement No. 005-2023-UNF, within the framework of the “Competition for Results-Oriented Financing for the Promotion of Research, Development and Innovation 2022.” The authors also acknowledge the technical staff of the Valher estate (Tambogrande, Piura) for their collaboration during the field image collection stage.

Data Availability Statement

Data available upon request to authors.

References

  • Alshammari, H. H., & Alkhiri, H. (2023). Optimized recurrent neural network mechanism for olive leaf disease diagnosis based on wavelet transform. Alexandria Engineering Journal, 78:149-161.
  • Ampatzidis, Y., & Wade, T. (2020). High-tech scouting in citrus production. EDIS, Available in: <https://journals.flvc.org/edis/article/view/125666>.
    » https://journals.flvc.org/edis/article/view/125666
  • Anwarul, S., Mohan, M., & Agarwal, R. (2023). An unprecedented approach for deep learning assisted web application to diagnose plant disease. Procedia Computer Science, 218:1444-1453.
  • Ashraf, M. et al. (2026). PalmNeXt: A ConvNeXt-based deep learning model for pest detection in date palm leaves. Frontiers in Plant Science, 16:1738129.
  • Barbedo, J. G. A. (2019). Plant disease identification from individual lesions and spots using deep learning. Biosystems Engineering, 180:96-107.
  • Barbedo, J. G. A. (2018). Impact of dataset size and variety on the effectiveness of deep learning and transfer learning for plant disease classification. Computers and Electronics in Agriculture, 153:46-53.
  • Batistatos, M. et al. (2025). A self organizing cyber physical system for sustainable agriculture. Discover Internet of Things, 5:95.
  • Banco Central de Reserva Del Perú - BCRP. (2023). Piura: Síntesis de actividad económica - Enero 2023 Available in:https://www.bcrp.gob.pe/docs/Sucursales/Piura/2023/sintesis-piura-01-2023.pdf
    » https://www.bcrp.gob.pe/docs/Sucursales/Piura/2023/sintesis-piura-01-2023.pdf
  • Bourguet, D., & Guillemaud, T. (2016). The hidden and external costs of pesticide use. In E. Lichtfouse. Sustainable Agriculture Reviews vol 19. Springer, Cham, (pp. 35-120).
  • Breiman, L. (2001). Random forests. Machine Learning, 45(1):5-32.
  • Breiman, L. et al. (2017). Classification and regression trees New York: Chapman and Hall/CRC, 358p.
  • Castillo-Coronado, Y. D. M. et al. (2023). Commercial dynamism of Peru’s citrus fruit exports: An analysis of their destination markets. LACCEI, 1(12):1-11.
  • Chen, C. J. et al. (2020). An Aio T based smart agricultural system for pests detection. IEEE Access, 8:180750-180761.
  • Chollet, F. (2021). Deep learning with Python (2nd ed.) Manning Publications, Deep learning with Python .
  • Christakakis, P. et al. (2024). Smartphone-based citizen science tool for plant disease and insect pest detection using artificial intelligence. Technologies, 12(7):101.
  • Chung, H. et al. (2026). Resource-constrained edge AI solution for real-time pest and disease detection in chili pepper fields. Agriculture, 16(2):223.
  • Cover, T. M., & Hart, P. E. (1967). Nearest neighbor pattern classification. IEEE Transactions on Information Theory, 13(1):21-27.
  • Damalas, C. A., & Eleftherohorinos, I. G. (2011). Pesticide exposure, safety issues, and risk assessment indicators. International Journal of Environmental Research and Public Health, 8(5):1402-1419.
  • Deepika, P., & Arthi, B. (2022). Prediction of plant pest detection using improved mask FRCNN in cloud environment. Measurement: Sensors, 24:100549.
  • Du, K. L. et al. (2024). Exploring kernel machines and support vector machines: Principles, techniques, and future directions. Mathematics, 12(24):3935.
  • Elangovan, K., Lim, G., & Ting, D. (2024). A comparative study of an on premise AutoML solution for medical image classification. Scientific Reports, 14:10483.
  • Eryılmaz, E. E., & Kılıç, E. (2025). A literature review on disease detection with automated machine learning. PeerJ Computer Science, 11:e3193.
  • Food and Agriculture Organization of the United Nations - FAO. (2019). International Year of Plant Health 2020: Communication guide. Organización de las Naciones Unidas para la Alimentación y la Agricultura. Available in: https://openknowledge.fao.org/server/api/core/bitstreams/23a18d17-6fcd-464a-b5f1-eb89ac55c5a0/content
    » https://openknowledge.fao.org/server/api/core/bitstreams/23a18d17-6fcd-464a-b5f1-eb89ac55c5a0/content
  • Ferentinos, K. P. (2018). Deep learning models for plant disease detection and diagnosis. Computers and Electronics in Agriculture , 145:311-318.
  • Francisco, M. et al. (2023). Algorithms and models for automatic detection and classification of diseases and pests in agricultural crops: A systematic review. Applied Sciences, 13(8):4720.
  • Géron, A. (2023). Hands-on machine learning with scikit-learn, keras and tensorflow: Concepts, tools, and techniques to build intelligent systems Califórnia: O’Reilly Media, Inc. 834p
  • Goyal, L. et al. (2021). Leaf and spike wheat disease detection & classification using an improved deep convolutional architecture. Informatics in Medicine Unlocked, 25:100642.
  • Grafton-Cardwell, E. E., Stelinski, L. L., & Stansly, P. A. (2013). Biology and management of Asian citrus psyllid, vector of the huanglongbing pathogens. Annual Review of Entomology, 58:413-432.
  • Ghazlane, Y., Ahmed, E. H. A., & Hicham, M. (2024). Real-time lightweight drone detection model: Fine-grained Identification of four types of drones based on an improved Yolov7 model. Neurocomputing, 596:127941.
  • Hang, J. et al. (2019). Classification of plant leaf diseases based on improved convolutional neural network. Sensors, 19(19):4161.
  • Ian, G., Yoshua, B., & Aaron, C. (2016). Book: Deep learning The Mit Press. 775p.
  • Islam, M. M. et al. (2023). DeepCrop: Deep learning-based crop disease prediction with web application. Journal of Agriculture and Food Research, 14:100764.
  • James, G. et al. (2021). An introduction to statistical learning Springer New York, NY.
  • Jeger, M. et al. (2018). Guidance on quantitative pest risk assessment. EFSA Journal, 16(8):e05350.
  • Karar, M. E. et al. (2021). A new mobile application of agricultural pests recognition using deep learning in cloud computing system. Alexandria Engineering Journal , 60(5):4423-4432.
  • Khanramaki, M., Asli-Ardeh, E. A., & Kozegar, E. (2021). Citrus pests classification using an ensemble of deep learning models. Computers and Electronics in Agriculture , 186:106192.
  • Kingma, D. P., & Ba, J. L. (2014). Adam: A method for stochastic optimization Available in: <https://arxiv.org/pdf/1412.6980>.
    » https://arxiv.org/pdf/1412.6980
  • Kumar, R. et al. (2022). Review article a systematic analysis of machine learning and deep learning based approaches for plant leaf disease classification: A review. Journal of Sensors , Article ID 3287561, 13 pages.
  • Kusrini, K. et al. (2020). Data augmentation for automated pest classification in Mango farms. Computers and Electronics in Agriculture, 179:105842.
  • Lecun, Y., Bengio, Y., & Hinton, G. (2015). Deep learning. Nature, 521:436-444.
  • Li, L., Zhang, S., & Wang, B. (2021). Plant disease detection and classification by deep learning - A review. IEEE Access , 9:56683-56698.
  • Liu, D. et al. (2018). DeepTracker: Visualizing the training process of convolutional neural networks Available in: <https://arxiv.org/abs/1808.08531>
    » https://arxiv.org/abs/1808.08531
  • Luaibi, A., Salman, T., & Miry, A. (2021). Detection of citrus leaf diseases using a deep learning technique. International Journal of Electrical and Computer Engineering, 11(2):1719.
  • Mahesh, B. (2018). Machine learning algorithms-A review. International Journal of Science and Research, 9(1):381-386.
  • Mansour, D., & Braham, M. (2024). Parasitoid guild of the citrus Leafminer, Phyllocnistis citrella Stainton (Lepidoptera: Gracillariidae) in Tunisian citrus orchards and a new report of Cirrospilus ingenuus Gahan (Hymenoptera: Eulophidae). African Zoology, 59(2):101-110.
  • Mazumder, M. K. A. et al. (2024). DenseNet201Plus: Cost-effective transfer-learning architecture for rapid leaf disease identification with attention mechanisms. Heliyon, 10(15):e35625.
  • Naidu, G., Zuva, T., & Sibanda, E. M. (2023). A review of evaluation metrics in machine learning algorithms. In R. Silhavy., & P. Silhavy. (eds) Artificial intelligence application in networks and systems CSOC 2023. Lecture Notes in Networks and Systems, Springer, Cham. (pp. 15-25).
  • Nasser Shah, N. A. et al. (2019). Identification and counting of brown planthopper in paddy field using image processing techniques. Procedia Computer Science , 163:580-590.
  • Nikith, B. V. et al. (2023). Leaf disease detection and classification. Procedia Computer Science , 218:291-300.
  • Pedregosa, F. et al. (2011). Scikit-learn: Machine learning in python. Journal of Machine Learning Research, 12(85):2825-2830.
  • Santistevan, M. et al. (2016). Comportamiento del cultivo del limón (Citrus aurantifolia swingle) en dos localidades de Santa Elena, Ecuador. Revista Científica y Tecnológica UPSE, 3(2):15-20.
  • Sernaque, F. Y., Cherre, A. F. U., & Chavez-Villavicencio, C. L. (2020). Vertebrates road-killed in Tambogrande, Piura, Peru. Revista Peruana de Biologia, 27(2):131-138.
  • scikit-learn. (2025). Feature importances with a forest of trees Available in: <https://scikit-learn.org/stable/auto_examples/ensemble/plot_forest_importances.html>.
    » https://scikit-learn.org/stable/auto_examples/ensemble/plot_forest_importances.html
  • Selvaraj, M. G. et al. (2019). AI-powered banana diseases and pest detection. Plant Methods, 15:92.
  • Shafay, M. et al. (2025). Recent advances in plant disease detection: Challenges and opportunities. Plant Methods , 21:140.
  • Shorten, C., & Khoshgoftaar, T. M. (2019). A survey on image data augmentation for deep learning. Journal of Big Data, 6:60.
  • Singh, R., & Singh, S. (2025). A review of Indian-based drones in the agriculture sector: Issues, challenges, and solutions. Sensors , 25(15):4876.
  • Smith, Dr. J. (2020). Hyperparameter tuning in machine learning: Techniques and tools. American Journal of Machine Learning, 1(5):14-24.
  • Sokolova, M., & Lapalme, G. (2009). A systematic analysis of performance measures for classification tasks. Information Processing & Management, 45(4):427-437.
  • Teixeira, A. C. et al. (2023). A systematic review on automatic insect detection using deep learning. Agriculture , 13(3):713.
  • Thakare, P., & Ravi, S. (2024). Advanced pest detection strategy using hybrid optimization tuned deep convolutional neural network. Journal of Engineering, Design and Technology, 22(3):645-678.
  • Thorat, T., Patle, B. K., & Kashyap, S. K. (2023). Intelligent insecticide and fertilizer recommendation system based on TPF-CNN for smart farming. Smart Agricultural Technology, 3:100114.
  • Tiwari, A., & Siddiqui, F. (2026). Recent trends in AI and data science for smart and sustainable agriculture: Enhancing global food security. International Journal of Engineering and Management Research, 16(2):45-55.
  • Vita, F. et al. (2021). Porting deep neural networks on the edge via dynamic K-means compression: A case study of plant disease detection. Pervasive and Mobile Computing, 75:101437.
  • Zhao, S., Sun, X., & Gai, L. (2023). Data enhancement and multi-feature learning model for pest classification. Journal of Intelligent and Fuzzy Systems, 45(4):5409-5421.

Publication Dates

  • Publication in this collection
    24 Aug 2026
  • Date of issue
    2026

History

  • Received
    18 Jan 2026
  • Accepted
    19 May 2026
location_on
Editora da Universidade Federal de Lavras Editora da UFLA, Caixa Postal 3037 - 37200-900 - Lavras - MG - Brasil, Telefone: 35 3829-1115 - Lavras - MG - Brazil
E-mail: revista.ca.editora@ufla.br
rss_feed Acompañe los números de esta revista en su lector de RSS
Ir para arriba Notificar error