Next Article in Journal
Timekeeping Method with Dual Iterative Algorithm for GNSS Disciplined OCXO
Previous Article in Journal
A Digital Twin System for the Sitting-to-Standing Motion of the Knee Joint
Previous Article in Special Issue
Mitigating DDoS Attacks in LEO Satellite Networks Through Bottleneck Minimize Routing
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

PestOOD: An AI-Enabled Solution for Advancing Grain Security via Out-of-Distribution Pest Detection

1
School of Intelligent Engineering and Automation, Beijing University of Posts and Telecommunications, Beijing 100876, China
2
School of Artificial Intelligence, Beijing University of Posts and Telecommunications, Beijing 100876, China
*
Author to whom correspondence should be addressed.
Electronics 2025, 14(14), 2868; https://doi.org/10.3390/electronics14142868
Submission received: 25 June 2025 / Revised: 13 July 2025 / Accepted: 16 July 2025 / Published: 18 July 2025

Abstract

Detecting stored-grain pests on the surface of the grain pile plays an important role in integrated pest management (IPM), which is crucial for grain security. Recently, numerous deep learning-based pest detection methods have been proposed. However, a critical limitation of existing methods is their inability to detect out-of-distribution (OOD) categories that are unseen during training. When encountering such objects, these methods often misclassify them as in-distribution (ID) categories. To address this challenge, we propose a one-stage framework named PestOOD for out-of-distribution stored-grain pest detection via flow-based feature reconstruction. Specifically, we propose a novel Flow-Based OOD Feature Generation (FOFG) module that generates OOD features for detector training via feature reconstruction. This helps the detector learn to recognize OOD objects more effectively. Additionally, to prevent network overfitting that may lead to an excessive focus on ID feature extraction, we propose a Noisy DropBlock (NDB) module and integrate it into the backbone network. Finally, to ensure effective network convergence, a Stage-Wise Training Strategy (STS) is proposed. We conducted extensive experiments on our previously established multi-class stored-grain pest dataset. The results show that our proposed PestOOD demonstrates superior performance over state-of-the-art methods, providing an effective AI-enabled solution to ensure grain security.

1. Introduction

The proliferation and infestation of pests during grain storage can lead to the loss of both the quality and quantity of grain [1]. Therefore, integrated pest management (IPM) systems, which aim to detect and control pest infestations, are crucial for grain security [2]. Since pests are often found on the surfaces of grain piles, robust vision-based detection is critical for effective IPM. Recently, numerous deep learning-based pest detection methods have been proposed [3,4], but they still face limitations, particularly in the detection of unknown pest categories. Specifically, existing methods are restricted to detecting in-distribution (ID) categories. This means that detectors can only recognize the categories present in the training set. When faced with out-of-distribution (OOD) categories, detectors are prone to making overconfident predictions for ID categories or missing detections altogether [5]. In IPM, differential treatment strategies are required for distinct pest categories, and newly emerging pest categories often require immediate intervention. Thus, addressing the OOD problem is a critical challenge in pest detection to ensure robust grain security.
To detect OOD categories, a straightforward approach is to incorporate samples of these categories into the training data. However, since such categories are often relatively rare and highly diverse, this incorporation leads to a long-tailed data distribution [6]. Furthermore, expanding the training data with additional OOD categories can divert the detector’s attention away from ID categories, ultimately leading to the degradation of detection accuracy [7]. A more practical approach is to leverage the out-of-distribution object detection (OOD-OD) technique, which is designed to classify and locate ID categories while identifying unseen categories as OOD [8]. Some studies have attempted to identify OOD objects by comparing the differences in intermediate features between ID and OOD objects [9,10]. However, in pest detection tasks, the intra-class similarity of pest features often causes overlap in the feature space [11], making it challenging to distinguish between ID and OOD objects. Other methods address this by estimating the detector’s input uncertainty, where high uncertainty indicates the potential presence of OOD data [12,13]. Unfortunately, the precision of this uncertainty estimation approach is highly sensitive to the network architecture, training data, and parameter settings, which can lead to misjudgments.
Recently, a novel approach has emerged that utilizes generative models to generate OOD features for training detectors, enabling the detection of OOD categories [14,15]. The strength of this approach lies in the creation of diverse synthetic OOD samples. This allows detectors to capture a wider range of unknown distributions and improves their ability to distinguish between ID and OOD objects. However, for pest detection tasks, OOD detection faces two main challenges: (1) The small size of pests poses challenges for robust feature representation, increasing the susceptibility of generative models to mode collapse. (2) Pest detection involves fine-grained classification among pest categories, making it particularly difficult to define clear decision boundaries between ID and OOD features.
Previous studies have demonstrated that flow-based generative models [16] excel in generation and density estimation due to their reversibility [17], a property crucial for OOD feature generation. Thus, inspired by FFS [18], we propose a one-stage framework named PestOOD to address the above challenges in stored-grain pest detection, as shown in Figure 1. Specifically, we first propose a Flow-Based OOD Feature Generation (FOFG) module. This module is optimized using ID feature vectors via maximum likelihood estimation (MLE). This training paradigm enables the FOFG module to estimate the actual distribution of ID features by transforming them into a simple probability distribution within a latent variable space during its forward process. Subsequently, during the inverse process, we reconstruct the latent variables into feature vectors that closely approximate the original ID feature distribution. These reconstructed features exhibit distinctiveness from the ID features and thus serve as generated OOD features. Finally, these OOD features are incorporated into detector training, enabling the detector to identify OOD objects. Furthermore, we propose a Noisy DropBlock (NDB) module and introduce it into the backbone. NDB randomly selects contiguous regions on the original feature maps and replaces them with random Gaussian noise, thereby preventing the backbone network from overfitting and reducing its excessive reliance on ID features. Finally, in conjunction with our framework, we propose a Stage-Wise Training Strategy (STS) to facilitate effective network convergence. The results of extensive experiments demonstrate that PestOOD achieves good performance, outperforming SOTA methods in OOD stored-grain pest detection.
We summarize our contributions as follows:
  • We propose PestOOD, a framework for out-of-distribution stored-grain pest detection via flow-based feature reconstruction to achieve robust grain security.
  • We propose FOFG to generate OOD features for detector training. NDB is introduced into the backbone network to prevent overfitting. Additionally, we propose an STS for effective network convergence.
  • Extensive experiments demonstrate that PestOOD can effectively detect OOD objects, outperforming other SOTA methods in OOD stored-grain pest detection.

2. Related Work

2.1. Research on Pest Detection

With advances in artificial intelligence and computer vision, numerous object detection frameworks have been developed, achieving remarkable performance [19]. Recent research has shown increasing interest in the application of these technologies to pest detection. Some studies have employed image optimization techniques to address the challenges posed by small sizes and low resolution in pest identification. For example, Zhou et al. [20] proposed the combination of a generative model with a classifier to effectively enhance the classification performance of low-resolution insect images, providing a novel approach for automated stored-grain insect identification. Other approaches improve detection accuracy by enhancing detector representation abilities. For example, Li et al. [21] proposed a data augmentation strategy for CNN-based pest detection. They diversified the training data by generating multi-pose samples through image rotation and by cropping images into grids of varying sizes to simulate multi-scale features. Hu et al. [22] proposed the MACNet model based on YOLOv8s, which incorporates CARMF modules and DSConv technology. By optimizing feature sampling and convolution operations, it improves both the accuracy of agricultural pest detection and the model’s lightweight design, making it more suitable for deployment in real-world environments. Amrani et al. [23] proposed a Bayesian-based multi-task learning model. By integrating a joint loss function combining classification and a customized size loss, the model significantly improves detection and estimation accuracy, while the Bayesian approach effectively quantifies prediction uncertainties. Duan et al. [24] proposed a multimodal framework integrating tiny-BERT with R-CNN. Their innovation leverages ensemble learning to optimally fuse text and image modalities, overcoming the limitations of single-modality approaches. Nevertheless, the inability of these methods to detect OOD categories limits their practical application in complex detection scenarios.

2.2. Out-of-Distribution Object Detection

To enhance the adaptability of deep learning methods in practical applications, recent studies have increasingly focused on the OOD-OD task [5,8,25]. Most research distinguishes between ID and OOD objects by applying specific rules in the feature space. For example, Yang et al. [9] proposed a OneRing method, which uses a Cls+1-way classifier to achieve OOD detection. They devised a dual cross-entropy loss training strategy based on source data to enable the effective recognition of unknown classes. Additionally, the method adopts a weighted entropy minimization strategy for target-domain adaptation without requiring access to source data. Wilson et al. proposed a method named SAFE [10], which detects OOD samples by identifying sensitive residual convolutional and batch normalization layers in object detectors. It extracts object-specific SAFE vectors and trains an auxiliary MLP to differentiate between normal ID detections and OOD ones. Wu et al. [13] proposed leveraging PCA decomposition to generate supervisory information for OOD categories and employed dynamic prototypes extracted from residual principal components to help the detector distinguish OOD objects. However, these methods exhibit performance limitations when the detector’s representation ability is insufficient or when features overlap in the feature space. Therefore, recent research has started to focus on employing generative models, such as diffusion models [26], to generate OOD features. For example, Liu et al. [15] proposed using a diffusion model to fit the ID data distribution and generate samples, combined with a K-Nearest Neighbors-based filtering strategy to select low-density OOD samples for training the OOD object detector. Kumar et al. [18] used flow models to synthesize OOD features. In this method, features from ID categories are first mapped into the latent space. Then, random sampling is conducted in the latent space to generate OOD features via the inverse process of the flow model. In our research, we also adopt this OOD feature generation approach and focus on addressing challenges in OOD feature synthesis and decision boundary definition.

3. Methodology

3.1. Preliminaries

Figure 2 shows a schematic of our proposed AI-enabled solution, PestOOD, for detecting stored-grain pests. The camera devices installed in the granaries capture images of the surfaces of the grain piles. These images are transmitted to a computer that runs an object detector, which identifies and classifies the pests present in the captured images.
To enhance the practical adaptability of the detector to ensure grain security, we propose a flow-based feature reconstruction method for out-of-distribution pest detection. We are given a training dataset D T r a i n containing only ID categories C ={ c 1 , c 2 ,..., c n }, where n is the number of ID categories. Our goal is to train a detector that, given input images I containing both ID and OOD pest objects, can localize a set of bounding boxes B  = { b 1 , b 2 ,..., b m } to identify objects in I while correctly classifying ID categories and labeling unseen categories as “ood”. To achieve this, we leverage flow-based feature reconstruction to generate OOD features for detector training, enabling the detector to effectively identify OOD objects. In addition, a Noisy DropBlock module is introduced to prevent overfitting, and a Stage-Wise Training Strategy is proposed to ensure effective network convergence. The mathematical notations used throughout this paper are summarized in Table 1.

3.2. Flow-Based OOD Feature Generation (FOFG)

3.2.1. Objective of the FOFG

Similar to conventional flow-based generative models, our proposed FOFG module consists of two processes: A forward process and an inverse process. The forward process transforms original features into latent variables following a simple distribution, which are used to estimate the complex original distribution in the latent space. Conversely, the inverse process not only enables random sampling from the latent space to generate random features but also reconstructs the original features using the latent variables obtained during the forward pass. These two processes are described as follows:
z = f θ ( x ) = f K f K 1 f 1 ( x )
x = g θ ( z ) = g 1 g 2 g K ( z )
For the pest detection task, the variable x in the aforementioned formula represents a pest feature that follows a complex and highly dimensional distribution. The latent variable z is associated with a simple density p θ ( z ) , such as a Gaussian distribution: p θ ( z ) = N ( z ; 0 , I ) . The function f θ ( x ) is invertible; therefore, given x, the corresponding z is computed as z = f θ ( x ) = g θ 1 ( x ) . The entire FOFG module is composed of a sequence of invertible transformation blocks f 1 , f 2 , . . . , f k . The objective of the FOFG module is to minimize the negative log-likelihood over the given dataset D , which contains only ID categories, as follows:
L ( D ) = 1 N i = 1 N log f θ x ( i )
The OOD pest feature can be generated by reconstructing the latent variable z, which is derived from the forward process, using the inverse process of the FOFG module.

3.2.2. Method of OOD Feature Generation

Figure 3a illustrates the architecture of the FOFG module and the OOD feature generation process. The design of the invertible transformation blocks in the flow model is based on Glow [16], as shown in Figure 3b. Each flow block in the FOFG module comprises an ActNorm layer, an invertible 1 × 1 convolution, and an affine transformation [27]. The FOFG module employs a multi-scale architecture with multiple layers, where each layer is composed of stacked flow blocks.
The generation of OOD features proceeds as follows: During detector training, input images are processed by the backbone network to extract feature maps M R B × C × H × W . Within the one-stage object detection framework, a portion of the feature vectors from the feature maps are labeled as positive samples by the label assignment strategy for classification and localization. These 1D positive samples, which contain only ID features and have a C-dimensional representation, are reshaped into 2D features with shape C × C . These transformed features are then used to train the FOFG module by minimizing the objective function defined in Equation (3). After sufficient iterations, the FOFG module can estimate the ID feature distribution by a simple distribution p θ ( z ) in the latent variable space Z . When applying OOD feature generation, in contrast to random OOD feature generation methods [18], our method leverages the feature reconstruction approach. Specifically, the FOFG forward process first maps 2D ID features to the latent space Z . Subsequently, the resulting latent variables are transformed back into 2D features through the FOFG module’s inverse process. Finally, these 2D features are reshaped into 1D features that conform to the original feature distribution, thus obtaining the OOD pest features. We regulate the randomness of generated features via the temperature parameter T , producing features that are semantically similar to but distributionally distinct from the original pest features. These generated features with similarity below a predefined threshold to the original features are considered OOD features. Finally, these OOD features are fed into the detection head of the detector for training, allowing the detector to identify OOD objects.

3.3. Noisy DropBlock (NDB)

Due to the absence of OOD categories during training, the detector’s backbone network often overemphasizes feature extraction for ID categories, resulting in overfitting to ID categories. Consequently, the detector may either fail to detect OOD objects or incorrectly classify them with high confidence as ID categories. To address the phenomenon of overfitting, traditional deep learning methods tend to introduce regularization techniques such as the dropout layer [28] to mitigate the issue. However, dropout’s effectiveness in convolutional layers is limited [29]. Inspired by DropBlock [30], we propose Noisy DropBlock. Specifically, Noisy DropBlock first randomly selects contiguous regions on the original feature map as mask blocks, as shown in Figure 4b,c. Then, it replaces the feature activations within these mask blocks with random Gaussian noise, as shown in Figure 4d. The size of the block serves as a configurable hyperparameter.
Compared to methods that simply drop contiguous regions in feature maps, our method injects random Gaussian noise into mask blocks. This approach strategically integrates regularization techniques with feature-based data augmentation, thereby compelling the backbone network to learn more generalizable pest representations beyond ID characteristics. In addition, given that shallow features contain more fine-grained information and that deep features are rich in semantic information, to avoid damaging the fine-grained information of pest objects, the NDB module should be applied to deep features. Furthermore, empirical evidence also demonstrates that augmenting deep features enhances detector robustness [31]; therefore, we apply the NDB module to the outputs of Stages 2, 3, and 4 of the backbone, as shown in Figure 4a.

3.4. Stage-Wise Training Strategy (STS)

PestOOD involves optimizing both the FOFG module and the object detector. Given their different optimization objectives, separate training is required to ensure effective convergence. To address this issue, we propose a Stage-Wise Training Strategy (STS) comprising three distinct phases: ID Feature Representation Learning, ID Feature Distribution Estimation, and Detector Fine-Tuning. We summarize the whole strategy in Algorithm 1; the detailed procedure is as follows:
(1) Stage One, ID Feature Representation Learning: In this stage, we train only the object detector to establish the fundamental representational capacity for ID pest features. The standard objective function shown in Equation (4) for the object detector is used, where F c l s ( · ) and F r e g ( · ) are the classification loss and bounding box regression loss, respectively. This stage continues until there is no improvement in detection performance over five consecutive epochs.
L d e t = λ cls · F c l s ( c p , c g t ) + λ reg · F r e g ( b p , b g t )
(2) Stage Two, ID Feature Distribution Estimation: In this stage, we freeze the parameters of the detector backbone network Φ Θ 1 and train the FOFG module f θ using the ID features extracted by Φ Θ 1 . This enables the FOFG module to estimate the original feature distribution in the latent space by minimizing the flow model’s objective function in Equation (3). This stage continues until the loss computed by Equation (3) plateaus below 5% of its initial value.
(3) Stage Three, Detector Fine-Tuning: In this stage, the FOFG module f θ generates OOD features via feature reconstruction. These generated features are then used to fine-tune the detection head h Θ 2 , allowing the detector to detect OOD objects.
Algorithm 1: Stage-Wise Training Strategy (STS) for PestOOD.
Electronics 14 02868 i001
This Stage-Wise Training approach prevents interference between the FOFG module and object detector optimization. In addition, during the Detector Fine-Tuning Stage, the backbone network remains frozen with only the classification head being optimized. This approach preserves robust ID feature representation while equipping the detector with the OOD detection ability, thereby ensuring effective convergence of the overall framework.

4. Experiments

4.1. Datasets and Preprocessing

The training dataset used in this study is our previously established pest dataset, GrainPest [32]. Taking into account pest occurrence frequency and economic impact [1], we select five in-distribution (ID) categories: Cryptolestes ferrugineus (Stephens) “cf”, Rhizopertha dominica (Fabricius) “rd”, Sitophilus zeamais (Linnaeus)/Sitophilus oryzae Motschulsky “sz”, Tribolium castaneum (Herbst) “tc”, and Oryzaephilus surinamensis (Linnaeus) “os”. The terms in double quotations following each scientific name are the corresponding category labels of pests.
For out-of-distribution (OOD) categories, we select three less frequently occurring categories, namely, Trogoderma variabile (Ballion), Alphitobius diaperinus (Panzer), and Lariophagus distinguendus (Förster), all labeled as “ood”. Example images of the ID and OOD pest categories are shown in Figure 5. To standardize image sizes, the original images from the GrainPest dataset are cropped to 512 × 512 pixels. The dataset is then split into training and testing sets in an 8:2 ratio, ensuring that only ID categories are present in the training set.

4.2. Implementation Details and Evaluation Metrics

We adopt UniRepLKNet-T [33] as the backbone. We use the YOLO Head [34] for classification and regression branches in conjunction with the one-stage framework. The FOFG module employs three layers with 16 flow blocks in each layer in our experiments. All experiments are conducted using the PyTorch 1.12.0 framework with two NVIDIA 3090 GPUs. We select SGD [35] as the optimizer. The evaluation metrics comprise the Mean Average Precision for ID categories (mAP(ID)) to assess OOD detection’s impact on ID object detection performance; the False Positive Rate at 95% True Positive Rate (FPR95) [36] to measure the probability of the misdetection of OOD objects under high-recall conditions; and the Area Under the Receiver Operating Characteristic Curve (AUROC) [37] to evaluate the detector’s discrimination ability between ID and OOD categories.

4.3. Comparison Experiments

We compare PestOOD with object detection baselines, including YOLOv10 [38] and RT-DETR [39], and previous SOTA OOD-OD methods: FFS [18] (generating OOD features via random sampling); DFDD [14] (using feature deblurring diffusion); and NAP [40]/CSI [41] (recognizing OOD objects through intermediate feature discrepancies). The detection performance is presented in Table 2. Additionally, we provide confusion matrices, as shown in Figure 6, for four frameworks (YOLOv10, NAP, FFS, and PestOOD), allowing for a visual comparison of their OOD detection abilities.
The results in Table 2 show that the object detection baselines completely fail to detect OOD objects. As a result, evaluation metrics such as the FPR95 and AUROC are not applicable to these baselines. This limitation is visually confirmed in Figure 6a, where YOLOv10 either fails to detect OOD objects or misclassifies them as ID categories. Compared to PestOOD, the methods that directly differentiate ID and OOD objects in the feature space (e.g., NAP and CSI) exhibit a higher FPR95 and lower AUROC. This performance gap highlights the limitation of relying solely on feature-level differences to distinguish OOD from ID objects in object detection tasks involving fine-grained inter-class variation, such as pest detection. This observation is clearly illustrated in the confusion matrix shown in Figure 6b. In addition, FFS generates OOD features by random sampling in the latent space. This approach has a high degree of randomness and yields suboptimal generation quality, which frequently results in false detections. Therefore, it tends to have a high FPR95. In contrast, our method reconstructs features that are similar to but distinct from ID features. This reconstruction process induces a low-density region between the ID feature space and negative samples, with features located in this transitional space designated as OOD features. As a result, our method shows a superior discriminative ability in identifying OOD objects. Figure 6c,d provide a visual comparison of how the two OOD feature generation strategies influence detection performance. Furthermore, flow-based models benefit from a more precise log-likelihood estimation of input data compared to diffusion models [42], enabling more accurate modeling of the pest feature distribution. This enhanced ability facilitates the superior generation of OOD features, which is reflected in PestOOD having superior performance metrics over DFDD.

4.4. Ablation Studies of PestOOD

In the PestOOD framework, FOFG and STS are essential for out-of-distribution detection. Adjusting the temperature T in FOFG affects detection performance by modulating the randomness of feature generation. Furthermore, NDB enhances detection performance through regularization that mitigates overfitting. Therefore, we conduct ablation studies to evaluate the impact of temperature T and the contribution of NDB.

4.4.1. Impact of Temperature T on Detector Performance

Table 3 shows the impact of the temperature parameter T on detection performance. In addition, we provide Figure 7 to intuitively illustrate how T affects the feature distribution and discriminability in the feature space. Our findings demonstrate optimal detection performance at T = 1.1. Higher temperature values introduce greater randomness into the FOFG process, causing the reconstructed features to lose essential pest-specific semantic information. This degradation results in confusion between the generated OOD features and background features, as illustrated in Figure 7b. Conversely, at lower T values, the reconstructed OOD features closely resemble ID features. This leads to confusion in the feature space and undermines the detector’s ability to distinguish between ID and OOD objects, as shown in Figure 7c. Given the significant impact of T on detector performance and the task-dependent nature of its optimal value, empirical tuning of this parameter is critical for optimizing PestOOD’s effectiveness.

4.4.2. Ablative Study of Noisy DropBlock

We compare the impact of different NDB block sizes on detection performance and the implementation location of the NDB module in the backbone. Quantitative results are presented in Table 4. Specifically, a block size of 0 indicates that NDB is disabled. In our experiments, NDB modules are incorporated in Stages 2, 3, and 4 by default. The results show that, when the block size is 0, the detector exhibits a high FPR95, indicating a tendency to misclassify OOD objects as ID. In contrast, excessively large block sizes, such as 0.6, substantially reduce the AUROC. This shows that overly aggressive dropout regions hinder discriminative spatial feature learning, thereby compromising the detection accuracy of pest categories. Among all results, a block size of 0.4 achieves optimal overall performance by striking the best balance between ID and OOD detection abilities. Additionally, applying NDB across all four backbone layers results in underperformance on all evaluation metrics, demonstrating that damaging shallow features degrades the representation ability, thus affecting detection performance.

4.5. Visualization and Analysis

Figure 8 shows the detection results of the object detection baselines YOLOv10 and RT-DETR, as well as those of our proposed PestOOD. The results indicate that the baseline methods tend to overlook OOD objects or misclassify them as ID objects. This failure arises from their fundamental inability to represent OOD features, leading to a complete failure in detecting OOD objects. In contrast, PestOOD successfully identifies OOD categories. Notably, our framework accurately localizes both ID and OOD objects, demonstrating its effectiveness in comprehensive pest detection. This distinction is particularly important in real-world pest monitoring scenarios.
Figure 9 provides a comparative visualization of the detection results of the PestOOD and SOTA OOD-OD frameworks. Since NAP distinguishes ID and OOD objects solely based on feature discrepancies, its detection results exhibit significantly higher false detection rates. FFS shows both increased false positives and missed detections, which aligns with our previous analysis. The OOD features generated through random sampling are of suboptimal quality, and training detectors on such features compromises their accuracy in pest detection. In contrast, our proposed PestOOD significantly outperforms other frameworks in OOD object detection while maintaining a strong balance in detection accuracy in both ID and OOD instances. Thus, PestOOD demonstrates enhanced adaptability and robustness. Given the complexity of practical detection scenarios, a robust OOD detection ability is critical to ensure reliable pest detection. Therefore, PestOOD provides an effective AI-enabled solution to ensure grain security.

5. Conclusions

In this paper, we propose PestOOD, a novel framework for OOD stored-grain pest detection. Our primary contribution is the introduction of an FOFG module, which generates OOD features for the detector’s training, thus enabling the robust identification of OOD objects. Additionally, to prevent the backbone network from overfitting and to reduce its excessive reliance on ID features, we propose an NDB module and incorporate it into the backbone network. Finally, we further propose STS to facilitate effective network convergence. Experimental results show that PestOOD can effectively distinguish between ID and OOD pest objects and outperforms other SOTA methods. In future work, we will track emerging technologies in deep learning and computer vision with the aim of developing more adaptable pest detection frameworks. We hope that this work will contribute to the security of food and grain storage and improve the practicality of AI-enabled security in real-world applications.

Author Contributions

Conceptualization, J.T.; Methodology, J.T. and C.M.; Software, C.M.; Validation, C.M. and J.L.; Formal Analysis, H.Z.; Investigation, J.T. and C.M.; Resources, J.L.; Data Curation, H.Z.; Writing—Original Draft Preparation, J.T.; Writing—Review and Editing, H.Z.; Visualization, J.T. and C.M.; Supervision, H.Z.; Project Administration, H.Z.; Funding Acquisition, H.Z. All authors have read and agreed to the published version of the manuscript.

Funding

This research was funded by the Proof-of-Concept Program for University Research Achievements in Changping District, Beijing Municipal Science and Technology Commission. Project title: Sensor and Intelligent Analysis System for Grain Pest Occurrence Monitoring. Grant number: SHGNYZ202302.

Institutional Review Board Statement

Not applicable.

Informed Consent Statement

Not applicable.

Data Availability Statement

Data will be made available on request.

Conflicts of Interest

The authors declare no conflicts of interest.

References

  1. Deshwal, R.; Vaibhav, V.; Kumar, N.; Kumar, A.; Singh, R. Stored grain insect pests and their management: An overview. J. Entomol. Zool. Stud. 2020, 8, 969–974. [Google Scholar]
  2. Rustia, D.J.A.; Chiu, L.Y.; Lu, C.Y.; Wu, Y.F.; Chen, S.K.; Chung, J.Y.; Hsu, J.C.; Lin, T.T. Towards intelligent and integrated pest management through an AIoT-based monitoring system. Pest Manag. Sci. 2022, 78, 4288–4302. [Google Scholar] [CrossRef] [PubMed]
  3. Chithambarathanu, M.; Jeyakumar, M. Survey on crop pest detection using deep learning and machine learning approaches. Multimed. Tools Appl. 2023, 82, 42277–42310. [Google Scholar] [CrossRef] [PubMed]
  4. Guo, B.; Wang, J.; Guo, M.; Chen, M.; Chen, Y.; Miao, Y. Overview of pest detection and recognition algorithms. Electronics 2024, 13, 3008. [Google Scholar] [CrossRef]
  5. Yang, J.; Zhou, K.; Li, Y.; Liu, Z. Generalized out-of-distribution detection: A survey. Int. J. Comput. Vis. 2024, 132, 5635–5662. [Google Scholar] [CrossRef]
  6. Yu, W.; Yang, T.; Chen, C. Towards resolving the challenge of long-tail distribution in UAV images for object detection. In Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision (WACV), Virtual, 5–9 January 2021; IEEE: Piscataway, NJ, USA, 2021; pp. 3258–3267. [Google Scholar]
  7. Kennerley, M.; Wang, J.G.; Veeravalli, B.; Tan, R.T. Cat: Exploiting inter-class dynamics for domain adaptive object detection. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), Nashville, TN, USA, 11–15 June 2025; IEEE: Seattle, WA, USA, 2024; pp. 16541–16550. [Google Scholar]
  8. Cui, P.; Wang, J. Out-of-distribution (OOD) detection based on deep learning: A review. Electronics 2022, 11, 3500. [Google Scholar] [CrossRef]
  9. Yang, S.; Wang, Y.; Wang, K.; Jui, S.; van de Weijer, J. OneRing: A simple method for source-free open-partial domain adaptation. arXiv 2022, arXiv:2206.03600. [Google Scholar]
  10. Wilson, S.; Fischer, T.; Dayoub, F.; Miller, D.; Sünderhauf, N. Safe: Sensitivity-aware features for out-of-distribution object detection. In Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV), Paris, France, 2–3 October 2023; IEEE: Paris, France, 2023; pp. 23565–23576. [Google Scholar]
  11. Wu, X.; Zhan, C.; Lai, Y.K.; Cheng, M.M.; Yang, J. Ip102: A large-scale benchmark dataset for insect pest recognition. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), Long Beach, CA, USA, 15–20 June 2019; IEEE: Long Beach, CA, USA, 2019; pp. 8787–8796. [Google Scholar]
  12. Liu, W.; Wang, X.; Owens, J.; Li, Y. Energy-based out-of-distribution detection. In Proceedings of the Advances in Neural Information Processing Systems (NeurIPS), Virtual, 6–12 December 2020; pp. 21464–21475. [Google Scholar]
  13. Wu, A.; Deng, C.; Liu, W. Unsupervised out-of-distribution object detection via PCA-driven dynamic prototype enhancement. IEEE Trans. Image Process. 2024, 33, 2431–2446. [Google Scholar] [CrossRef] [PubMed]
  14. Wu, A.; Chen, D.; Deng, C. Deep feature deblurring diffusion for detecting out-of-distribution objects. In Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV), Paris, France, 1–6 October 2023; IEEE: Paris, France, 2023; pp. 13381–13391. [Google Scholar]
  15. Liu, J.; Yu, X.; Zheng, A.; Sun, K.L.; Qi, X. Diffusion-based Data Generation for Out-of-Distribution Object Detection. In Proceedings of the International Conference on Learning Representations (ICLR), Vienna, Austria, 7–11 May 2024. [Google Scholar]
  16. Kingma, D.P.; Dhariwal, P. Glow: Generative flow with invertible 1x1 convolutions. In Proceedings of the Advances in Neural Information Processing Systems (NeurIPS), Montréal, QC, Canada, 3–8 December 2018; pp. 10236–10245. [Google Scholar]
  17. Liu, D.; Jain, M.; Dossou, B.F.; Shen, Q.; Lahlou, S.; Goyal, A.; Malkin, N.; Emezue, C.C.; Zhang, D.; Hassen, N.; et al. Gflowout: Dropout with generative flow networks. In Proceedings of the International Conference on Machine Learning (ICML), PMLR, Honolulu, HI, USA, 23–29 July 2023; pp. 21715–21729. [Google Scholar]
  18. Kumar, N.; Šegvić, S.; Eslami, A.; Gumhold, S. Normalizing flow based feature synthesis for outlier-aware object detection. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), Vancouver, BC, Canada, 17–24 June 2023; IEEE: Vancouver, BC, Canada, 2023; pp. 5156–5165. [Google Scholar]
  19. Zou, Z.; Chen, K.; Shi, Z.; Guo, Y.; Ye, J. Object detection in 20 years: A survey. Proc. IEEE 2023, 111, 257–276. [Google Scholar] [CrossRef]
  20. Zhou, H.; Miao, H.; Li, J.; Jian, F.; Jayas, D.S. A low-resolution image restoration classifier network to identify stored-grain insects from images of sticky boards. Comput. Electron. Agric. 2019, 162, 593–601. [Google Scholar] [CrossRef]
  21. Li, R.; Wang, R.; Zhang, J.; Xie, C.; Liu, L.; Wang, F.; Chen, H.; Chen, T.; Hu, H.; Jia, X.; et al. An effective data augmentation strategy for CNN-based pest localization and recognition in the field. IEEE Access 2019, 7, 160274–160283. [Google Scholar] [CrossRef]
  22. Hu, Y.; Wang, Q.; Wang, C.; Qian, Y.; Xue, Y.; Wang, H. MACNet: A more accurate and convenient pest detection network. Electronics 2024, 13, 1068. [Google Scholar] [CrossRef]
  23. Amrani, A.; Diepeveen, D.; Murray, D.; Jones, M.G.; Sohel, F. Multi-task learning model for agricultural pest detection from crop-plant imagery: A Bayesian approach. Comput. Electron. Agric. 2024, 218, 108719. [Google Scholar] [CrossRef]
  24. Duan, J.; Ding, H.; Kim, S. A multimodal approach for advanced pest detection and classification. arXiv 2023, arXiv:2312.10948. [Google Scholar] [CrossRef]
  25. Hsu, Y.C.; Shen, Y.; Jin, H.; Kira, Z. Generalized odin: Detecting out-of-distribution image without learning from out-of-distribution data. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), Seattle, WA, USA, 13–19 June 2020; IEEE: Piscataway, NJ, USA, 2020; pp. 10951–10960. [Google Scholar]
  26. Ho, J.; Jain, A.; Abbeel, P. Denoising diffusion probabilistic models. In Proceedings of the Advances in Neural Information Processing Systems (NeurIPS), Virtual, 6–12 December 2020; pp. 6840–6851. [Google Scholar]
  27. Dinh, L.; Krueger, D.; Bengio, Y. Nice: Non-linear independent components estimation. arXiv 2014, arXiv:1410.8516. [Google Scholar]
  28. Srivastava, N.; Hinton, G.; Krizhevsky, A.; Sutskever, I.; Salakhutdinov, R. Dropout: A simple way to prevent neural networks from overfitting. J. Mach. Learn. Res. 2014, 15, 1929–1958. [Google Scholar]
  29. Gal, Y.; Ghahramani, Z. Dropout as a bayesian approximation: Representing model uncertainty in deep learning. In Proceedings of the International Conference on Machine Learning (ICML), PMLR, New York, NY, USA, 19–24 June 2016; pp. 1050–1059. [Google Scholar]
  30. Ghiasi, G.; Lin, T.Y.; Le, Q.V. Dropblock: A regularization method for convolutional networks. In Proceedings of the Advances in Neural Information Processing Systems (NeurIPS), Montréal, QC, Canada, 3–8 December 2018. [Google Scholar]
  31. Wang, Y.; Qi, L.; Shi, Y.; Gao, Y. Feature-based style randomization for domain generalization. IEEE Trans. Circuits Syst. Video Technol. 2022, 32, 5495–5509. [Google Scholar] [CrossRef]
  32. Li, D.; Tian, J.; Li, J.; Sun, M.; Zhou, H.; Zheng, Y. Establishment of a Dataset for Detecting Pests on the Surface of Grain Bulks. Appl. Eng. Agric. 2024, 40, 363–376. [Google Scholar] [CrossRef]
  33. Ding, X.; Zhang, Y.; Ge, Y.; Zhao, S.; Song, L.; Yue, X.; Shan, Y. Unireplknet: A universal perception large-kernel convnet for audio video point cloud time-series and image recognition. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), Seattle, WA, USA, 16–22 June 2024; IEEE: Seattle, WA, USA, 2024; pp. 5513–5524. [Google Scholar]
  34. Varghese, R.; Sambath, M. Yolov8: A novel object detection algorithm with enhanced performance and robustness. In Proceedings of the Advances in Data Engineering and Intelligent Computing Systems (ADICS), Chennai, India, 18–19 April 2024; IEEE: Chennai, India, 2024; pp. 1–6. [Google Scholar]
  35. Amari, S.i. Backpropagation and stochastic gradient descent method. Neurocomputing 1993, 5, 185–196. [Google Scholar] [CrossRef]
  36. Aguilar, E.; Raducanu, B.; Radeva, P.; Van de Weijer, J. Continual evidential deep learning for out-of-distribution detection. In Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV), Paris, France, 1–6 October 2023; IEEE: Paris, France, 2023; pp. 3444–3454. [Google Scholar]
  37. Wang, H.; Liu, W.; Bocchieri, A.; Li, Y. Can multi-label classification networks know what they don’t know? In Proceedings of the Advances in Neural Information Processing Systems (NeurIPS), Virtual, 6–14 December 2021; pp. 29074–29087. [Google Scholar]
  38. Wang, A.; Chen, H.; Liu, L.; Chen, K.; Lin, Z.; Han, J.; Ding, G. Yolov10: Real-time end-to-end object detection. In Proceedings of the Advances in Neural Information Processing Systems (NeurIPS), Vancouver, BC, Canada, 9–15 December 2024; pp. 107984–108011. [Google Scholar]
  39. Zhao, Y.; Lv, W.; Xu, S.; Wei, J.; Wang, G.; Dang, Q.; Liu, Y.; Chen, J. Detrs beat yolos on real-time object detection. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), Seattle, WA, USA, 16–22 June 2024; IEEE: Seattle, WA, USA, 2024; pp. 16965–16974. [Google Scholar]
  40. Olber, B.; Radlak, K.; Chachuła, K.; Łyskawa, J.; Frątczak, P. Detecting Out-of-Distribution Objects Using Neuron Activation Patterns. In European Conference on Artificial Intelligence (ECAI); IOS Press: Kraków, Poland, 2023; pp. 1803–1810. [Google Scholar]
  41. Tack, J.; Mo, S.; Jeong, J.; Shin, J. Csi: Novelty detection via contrastive learning on distributionally shifted instances. Adv. Neural Inf. Process. Syst. 2020, 33, 11839–11852. [Google Scholar]
  42. Papamakarios, G.; Nalisnick, E.; Rezende, D.J.; Mohamed, S.; Lakshminarayanan, B. Normalizing flows for probabilistic modeling and inference. J. Mach. Learn. Res. 2021, 22, 1–64. [Google Scholar]
Figure 1. Overall PestOOD framework. The FOFG module is first trained on ID features. After this, OOD features are generated by feature reconstruction. Finally, these generated OOD features are fed into the classification head of the PestOOD detector for training.
Figure 1. Overall PestOOD framework. The FOFG module is first trained on ID features. After this, OOD features are generated by feature reconstruction. Finally, these generated OOD features are fed into the classification head of the PestOOD detector for training.
Electronics 14 02868 g001
Figure 2. A schematic of PestOOD for detecting stored-grain pests.
Figure 2. A schematic of PestOOD for detecting stored-grain pests.
Electronics 14 02868 g002
Figure 3. Flow-Based OOD Feature Generation (FOFG) module. (a) The process for OOD feature generation. (b) Structure of flow block.
Figure 3. Flow-Based OOD Feature Generation (FOFG) module. (a) The process for OOD feature generation. (b) Structure of flow block.
Electronics 14 02868 g003
Figure 4. Operational mechanism of Noisy DropBlock (NDB). (a) Implementation location of NDB in the backbone. (b) Original feature map. (c) Mask block selection. (d) Addition of Gaussian noise. NDB randomly selects contiguous regions as mask blocks and replaces their activations with Gaussian noise to achieve dropout and data augmentation. It is applied in the shallow layers of the backbone to avoid disrupting semantic information.
Figure 4. Operational mechanism of Noisy DropBlock (NDB). (a) Implementation location of NDB in the backbone. (b) Original feature map. (c) Mask block selection. (d) Addition of Gaussian noise. NDB randomly selects contiguous regions as mask blocks and replaces their activations with Gaussian noise to achieve dropout and data augmentation. It is applied in the shallow layers of the backbone to avoid disrupting semantic information.
Electronics 14 02868 g004
Figure 5. Example images of ID and OOD pest categories. (a) Cryptolestes ferrugineus (Stephens). (b) Oryzaephilus surinamensis (Linnaeus). (c) Rhizopertha dominica (Fabricius). (d) Sitophilus zeamais (Linnaeus)/Sitophilus oryzae Motschulsky. (e) Tribolium castaneum (Herbst). (f) Trogoderma variabile (Ballion). (g) Alphitobius diaperinus (Panzer). (h) Lariophagus distinguendus (Förster).
Figure 5. Example images of ID and OOD pest categories. (a) Cryptolestes ferrugineus (Stephens). (b) Oryzaephilus surinamensis (Linnaeus). (c) Rhizopertha dominica (Fabricius). (d) Sitophilus zeamais (Linnaeus)/Sitophilus oryzae Motschulsky. (e) Tribolium castaneum (Herbst). (f) Trogoderma variabile (Ballion). (g) Alphitobius diaperinus (Panzer). (h) Lariophagus distinguendus (Förster).
Electronics 14 02868 g005
Figure 6. Confusion matrix. (a) YOLOv10. (b) NAP. (c) FFS. (d) PestOOD.
Figure 6. Confusion matrix. (a) YOLOv10. (b) NAP. (c) FFS. (d) PestOOD.
Electronics 14 02868 g006
Figure 7. Effects of T on feature distribution and discrimination. (a) Feature distribution and decision boundaries at optimal T = 1.1. (b) Feature distribution and boundaries at high T . (c) Feature distribution and boundaries at low T .
Figure 7. Effects of T on feature distribution and discrimination. (a) Feature distribution and decision boundaries at optimal T = 1.1. (b) Feature distribution and boundaries at high T . (c) Feature distribution and boundaries at low T .
Electronics 14 02868 g007
Figure 8. Comparison of detection results between PestOOD and object detection baselines.
Figure 8. Comparison of detection results between PestOOD and object detection baselines.
Electronics 14 02868 g008
Figure 9. Comparison between detection results of PestOOD and SOTA methods.
Figure 9. Comparison between detection results of PestOOD and SOTA methods.
Electronics 14 02868 g009
Table 1. Summary of mathematical notations.
Table 1. Summary of mathematical notations.
NotationsDescriptionsNotationsDescriptions
xOriginal features Φ Θ 1 Backbone of detector
zLatent variable h Θ 2 Detection head of detector
p θ ( z ) Distribution of latent variable L ( D ) Objective function of FOFG
f K ( x ) Flow block L d e t Objective function of detector
D T r a i n Training data Z Latent variable space
T Temperature f θ ( x ) FOFG module
B Bounding boxes C ID categories
M Feature maps
Table 2. Comparative results of PestOOD with baseline method and SOTAs.
Table 2. Comparative results of PestOOD with baseline method and SOTAs.
MethodEvaluation Metrics
FPR95 ↓AUROC ↑mAP(ID) ↑
YOLOv10--0.812
RT-DETR--0.768
FFS0.9790.1620.653
DFDD0.7570.2770.676
NAP0.5790.4210.667
CSI0.5070.5070.650
Ours0.4250.5950.727
Table 3. Impact of temperature T on detector performance.
Table 3. Impact of temperature T on detector performance.
T ValueEvaluation Metrics
FPR95 ↓AUROC ↑mAP(ID) ↑
0.90.8780.2980.302
1.10.4220.5950.727
1.30.7630.4800.711
Table 4. Impact of block size and implementation location of NDB on detector performance.
Table 4. Impact of block size and implementation location of NDB on detector performance.
Block SizeEvaluation Metrics
FPR95 ↓AUROC ↑mAP(ID) ↑
00.8530.1960.291
0.20.4480.5260.740
0.40.4220.5950.727
0.4 10.4120.5270.713
0.60.4130.5520.753
1 applying NDB across all four backbone layers.
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Tian, J.; Ma, C.; Li, J.; Zhou, H. PestOOD: An AI-Enabled Solution for Advancing Grain Security via Out-of-Distribution Pest Detection. Electronics 2025, 14, 2868. https://doi.org/10.3390/electronics14142868

AMA Style

Tian J, Ma C, Li J, Zhou H. PestOOD: An AI-Enabled Solution for Advancing Grain Security via Out-of-Distribution Pest Detection. Electronics. 2025; 14(14):2868. https://doi.org/10.3390/electronics14142868

Chicago/Turabian Style

Tian, Jida, Chuanyang Ma, Jiangtao Li, and Huiling Zhou. 2025. "PestOOD: An AI-Enabled Solution for Advancing Grain Security via Out-of-Distribution Pest Detection" Electronics 14, no. 14: 2868. https://doi.org/10.3390/electronics14142868

APA Style

Tian, J., Ma, C., Li, J., & Zhou, H. (2025). PestOOD: An AI-Enabled Solution for Advancing Grain Security via Out-of-Distribution Pest Detection. Electronics, 14(14), 2868. https://doi.org/10.3390/electronics14142868

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop