Tobacco pest automatic detection method based on improved YOLOv5s
By improving the YOLOv5s model and introducing CBAM and BiFPN modules, the problem of feature extraction and fusion for small target detection in tobacco fields was solved, achieving high-precision and lightweight automatic detection of tobacco pests, which is suitable for pest monitoring in tobacco fields and drone inspections.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-11
- Publication Date
- 2026-03-13
AI Technical Summary
Existing YOLO models struggle with small target detection in tobacco field environments, suffer from insufficient feature extraction capabilities, and are prone to false positives and false negatives due to complex background textures. They also lack multi-scale feature fusion, have an attention mechanism, and their increased complexity makes them unsuitable for terminal devices.
By improving the YOLOv5s model, a convolutional block attention module (CBAM) is introduced to enhance the insect body attention capability. A bidirectional feature pyramid network (BiFPN) is used for feature fusion. A data collection, annotation and enhancement process suitable for tobacco pests is constructed, and the training process is optimized to improve model performance.
It achieves high-precision detection of small targets in complex tobacco field backgrounds. The model is lightweight and highly robust, suitable for tobacco field pest monitoring devices and UAV inspection systems. It improves mAP@0.5 to 0.947 and F1 to 0.91, and has strong adaptability.
Smart Images

Figure CN121661452A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the fields of smart agriculture, target detection and computer vision technology, specifically involving an automatic detection method for tobacco pests based on an improved YOLOv5s, which is particularly suitable for the automatic identification and real-time monitoring of small targets such as scarab beetles and beet armyworms in complex tobacco field environments. Background Technology
[0002] Tobacco pests are a significant factor affecting tobacco leaf yield and quality, especially scarab beetles and beet armyworms, whose feeding behavior can damage tobacco leaves, reduce yield, or even kill the entire plant. Traditional manual field patrols are inefficient, time-consuming, and reliant on professional experience, making it difficult to meet the demands of modern tobacco production for "real-time, accurate, and automated" pest monitoring.
[0003] In recent years, deep learning has made significant progress in the field of object detection, and the YOLO series has been widely used for agricultural pest detection due to its speed and lightweight structure. However, directly applying the YOLO model to tobacco field images still faces the following challenges: small target scale: scarabs and beet armyworms account for a very small proportion in natural scenes, resulting in insufficient feature extraction capabilities; complex background texture: leaf texture, soil reflection, and changes in lighting in the tobacco field environment can easily cause false detections and false negatives; insufficient multi-scale feature fusion: the FPN+PAN structure of YOLOv5s has limited fusion capabilities in small target scenes; lack of attention mechanism: the model's ability to distinguish between background and insects needs to be improved; most of the improvement methods in existing literature focus on increasing model complexity, such as introducing excessively deep networks and stacking a large number of attention structures, which increases the number of parameters and is not suitable for terminal devices. Summary of the Invention
[0004] To address the aforementioned issues, targeted improvements to the network structure and optimization of the training process can enhance the detection performance of small-scale pests in tobacco fields while maintaining model lightweightness and inference efficiency. This invention makes targeted adjustments to the feature extraction and fusion modules of the YOLOv5s model and constructs a corresponding collection, annotation, and enhancement process suitable for tobacco pests to ensure the reproducibility and engineering usability of the method. It provides an automatic detection method for tobacco pests based on an improved YOLOv5s model, solving technical challenges such as complex backgrounds in tobacco fields, difficulty in detecting small targets, severe feature loss, and limited dataset size.
[0005] This invention is achieved through the following technical solution: an automatic detection method for tobacco pests based on an improved YOLOv5s model, characterized in that: the automatic detection of tobacco pests is based on a structural improvement of the YOLOv5s model to form a YOLOv5s-CBN model, thereby realizing the detection of tobacco pests; the specific steps for designing and implementing the YOLOv5s-CBN model are as follows:
[0006] S1. Field Image Acquisition and Classification: High-resolution image data of target pests, including scarabs and beet armyworms, are collected using tobacco field pest monitoring devices, fixed cameras, or drones equipped with imaging modules. At the same time, background tobacco leaf images without pests are also collected. The acquisition device includes an insect-attracting light source, an imaging sensor, a light compensation module, a dustproof and waterproof shell, and a wireless data transmission module to ensure that stable quality samples can be obtained under different lighting conditions, different heights, and different angles.
[0007] The image resolution was selected to be greater than 4000×3000 pixels to ensure that the outline of the pests remained distinguishable under high scaling conditions; the collected data was initially screened by hand and classified and labeled according to category to ensure the accuracy of image labels, thereby providing reliable data input for deep learning models;
[0008] S2. Data Preprocessing, Integration and Enhancement: The acquired images are uniformly resized and cropped to the model input size of 640×640 pixels. At the same time, normalization and pixel value standardization preprocessing operations are performed to improve the stability of model training.
[0009] Multiple data augmentation strategies were implemented, including random cropping, horizontal flipping, scaling, rotational perturbation, color jittering, brightness variation, contrast adjustment, and gamma mapping, to simulate the changes in illumination, angle, and scale in the tobacco field environment, improve the model's generalization ability, and form an augmented training dataset.
[0010] The enhanced training dataset is divided into a training set and a validation set in an 8:2 ratio; if it is necessary to evaluate the deployment effect of the model, an additional test set that is not used for training is also created.
[0011] S3. Construct an improved YOLOv5s model with CBAM: Insert a Convolutional Block Attention Module (CBAM) into the Backbone part of the YOLOv5s model to enhance the model's ability to focus on key regions of the worm.
[0012] CBAM consists of two parts: Channel Attention (CAM) and Spatial Attention (SAM). CAM performs global average pooling and global max pooling on the intermediate feature map information, and then generates an attention weight vector with the same number of channels through a multilayer perceptron (MLP). After sigmoid activation, the channel attention weights are obtained. The specific calculation formula is as follows:
[0013] ,
[0014] in, It is the channel attention weight. It is an intermediate feature map. yes function, It is average pooling. It is max pooling, MLP is multilayer perceptron, and F represents the input feature map;
[0015] Subsequently, SAM performs max pooling and average pooling on the CAM-weighted feature map to highlight important information feature regions. Spatial attention weights are then obtained through 7×7 convolution and sigmoid activation, further emphasizing important regions in the location dimension. The specific calculation formula is as follows:
[0016] ,
[0017] in, It is spatial attention weight. It is the sigmoid function. It is average pooling. It is max pooling. Represents a 7×7 convolution. The output feature map represents the representation of the feature map.
[0018] S4. Introducing the BiFPN structure in the feature fusion stage: The YOLOv5s model mainly uses Feature Pyramid Network (FPN) and Path Aggregation Network (PAN) to fuse features at different scales. FPN usually merges multi-scale features by simple addition or concatenation, failing to distinguish the relative importance of features at each layer in the detection task. Although PAN achieves bidirectional flow, it treats all input features equally, cannot adaptively weight features at different scales, and has a relatively fixed structure. To compensate for these shortcomings, the Bidirectional Feature Pyramid Network (BiFPN) is introduced. The specific way the Bidirectional Feature Pyramid Network (BiFPN) is integrated into the YOLOv5s model is as follows:
[0019] 1) Structural replacement:
[0020] The FPN+PAN structure in the Neck part of the YOLOv5s model is replaced with BiFPN. BiFPN introduces learnable weight parameters while maintaining the bidirectional information flow of top-down (FPN) and bottom-up (PAN), enabling the network to dynamically weight features at different levels according to task importance.
[0021] 2) Enhanced cross-layer connectivity:
[0022] BiFPN adds cross-layer connections (shortcut connections) between input and output features at the same level, avoiding information loss during multi-layer transmission, which is especially beneficial for the preservation and enhancement of small target features;
[0023] 3) Weighted fusion mechanism:
[0024] During feature fusion, BiFPN normalizes different input features and then performs a weighted summation using learnable weights, as shown in the following formula:
[0025] ,
[0026] in, This indicates the characteristics of weighted fusion. This represents the weight of the i-th feature. Represents the i-th input feature;
[0027] 4) Integration into the location:
[0028] BiFPN is embedded between the Backbone and Head, receiving multi-scale feature maps from the Backbone and outputting enhanced feature maps for the detection head (Head) to perform category and location prediction;
[0029] S5. Model Training and Loss Optimization: The SGD optimizer was used for model training with an initial learning rate of 0.01, a momentum term of 0.937, a batch size of 16, and 100 training epochs. The loss function included classification loss, confidence loss, and bounding box regression loss, with full intersection-union loss (CIoU Loss) used for bounding box regression. During training, the anchor box size was dynamically adjusted and a cosine annealing learning rate strategy was implemented to enhance convergence stability, resulting in the YOLOv5s-CBN model.
[0030] S6. Model Validation, Performance Analysis, and Repeated Training: Perform performance analysis on the validation set using the trained YOLOv5s-CBN model, calculating Precision, Recall, F1, and mAP@0.5; simultaneously record the PR curve, F1–Confidence curve, and loss convergence curve.
[0031] ,
[0032] ,
[0033] ,
[0034] ,
[0035] To verify the stability and robustness of the model, the YOLOv5s-CBN model was repeatedly trained, and the fluctuation of performance indicators under different training rounds and different initialization conditions was statistically analyzed.
[0036] S7. Non-maximum suppression (NMS) processing during the inference stage: Non-maximum suppression (NMS) is performed on candidate detection boxes with a confidence level higher than 0.25. When the IoU between two candidate boxes is greater than 0.5, the box with the higher confidence level is retained, and redundant boxes are filtered out to ensure the uniqueness and stability of the output results.
[0037] S8. Test Set Evaluation and Model Deployment: The trained YOLOv5s-CBN model was applied to the test set to classify and identify the Scarabaeidae and Beetroot moths and detect their locations. The experimental results showed that the model achieved an mAP@0.5 score of 0.947 and an F1 score of 0.91, demonstrating high robustness even under complex background conditions.
[0038] As a preferred embodiment of the automatic detection method for tobacco pests based on the improved YOLOv5s described in this invention: In the CBAM module, channel attention adopts a weight generation mechanism that combines global average pooling and max pooling with a multilayer perceptron; spatial attention adopts a spatial attention graph generation mechanism that uses max pooling and average pooling followed by 7×7 convolution.
[0039] As a preferred embodiment of the automatic detection method for tobacco pests based on the improved YOLOv5s described in this invention: the BiFPN uses learnable weights in the feature fusion process to normalize and fuse features at different scales.
[0040] As a preferred embodiment of the automatic detection method for tobacco pests based on the improved YOLOv5s described in this invention: the model training uses an input image size of 640×640, a confidence threshold of 0.25, and an IoU threshold of 0.5.
[0041] As a preferred embodiment of the automatic detection method for tobacco pests based on the improved YOLOv5s described in this invention: the precision of the model for the Scarabaeidae category is 0.90, the recall is 0.930, and the mAP@0.5 is 0.920; the precision of the Beet armyworm category is 0.90, the recall is 0.95, and the mAP@0.5 is 0.94.
[0042] As a preferred embodiment of the automatic detection method for tobacco pests based on the improved YOLOv5s described in this invention: the detection results are filtered by non-maximum suppression (NMS) to remove redundant frames, with the NMS threshold set to 0.5.
[0043] Beneficial technical effects of the present invention:
[0044] The model of this invention has a small number of parameters and low computational requirements, and can be deployed in tobacco field pest monitoring devices, portable detection terminals, or UAV inspection systems to achieve real-time automated pest identification. By improving the YOLOv5s model through feature enhancement, multi-scale fusion, and reasonable training strategies, the established YOLOv5s-CBN model achieves an mAP@0.5 of 0.947 and an F1 score of 0.91. Compared with the original YOLOv5s model, it significantly improves the performance of small target identification, and has high accuracy, high robustness, and good engineering value.
[0045] This invention introduces a Convolutional Block Attention (CBAM) module into the backbone network of the YOLOv5s model and a Bidirectional Feature Pyramid (BiFPN) into the feature fusion network to achieve efficient extraction and deep fusion of multi-scale pest features, significantly improving the detection accuracy of small targets. Furthermore, this invention proposes a systematic method including data acquisition, preprocessing, data augmentation, annotation standards, training procedures, and evaluation systems. This method is compatible with different data acquisition devices and production area conditions, and has good reproducibility and promotional value. Attached Figure Description
[0046] Figure 1 A device for capturing and photographing pests;
[0047] Figure 2 Images of insect traps;
[0048] Figure 3 Enhanced data visualization;
[0049] Figure 4 This is a diagram of the overall framework of YOLOv5s-CBN;
[0050] Figure 5 For CABM attention module;
[0051] Figure 6 For different feature fusion network structures;
[0052] Figure 7 The training results for the YOLOv5s-CBN model;
[0053] Figure 8 The results of pest identification;
[0054] Figure 9 Training performance metrics for different models. Detailed Implementation
[0055] To make the technical solution of this invention clearer, the following detailed description of the tobacco pest detection method based on the improved YOLOv5s, in conjunction with the accompanying drawings and embodiments, is provided. This embodiment focuses on two pests, the scarab beetle and the beet armyworm, and constitutes a complete technical path through steps such as data collection, dataset construction, model improvement, training, and evaluation. Those skilled in the art can make equivalent substitutions to the embodiments without departing from the spirit of this invention, and all such substitutions fall within the scope of protection of this invention.
[0056] 1. Data acquisition device and raw image acquisition
[0057] like Figure 1 As shown, this study used an intelligent insect monitoring device for pest image acquisition. The system includes a solar power module, an insect-attracting light source module, an imaging module, an automatic cleaning module, and a data transmission module. The device uses a specific wavelength light source to attract pests and automatically completes the photographing and sample collection process. The light source height was set approximately 60 cm above the top of the tobacco plants to ensure a clear outline of pests when they enter the imaging area.
[0058] The entire data collection period was from May 1st to September 30th, 2025. During this period, pest images were continuously collected from Xianzong Village, Lushi County, Sanmenxia City (34.2192°N, 110.9448°E). Some of the original pest images collected are shown below. Figure 2 As shown, the resolution is 5472×3648 pixels, and the images are characterized by large variations in lighting, complex backgrounds, and small-scale pest targets.
[0059] 2. Dataset Construction and Labeling
[0060] S1. Data Preprocessing
[0061] To ensure the uniformity and computability of model training, all original images were scaled to 640×640 pixels. Subsequently, random cropping, random scaling, illumination enhancement, and gamma transformation were performed to enhance the model's adaptability to complex conditions such as uneven illumination and scale variations.
[0062] The original images of scarab beetles (451 images) and beet armyworms (405 images) were enhanced and expanded to 1804 and 1620 images respectively; for example... Figure 3 As shown, the enhanced samples exhibit significant changes in brightness, position, and rotation angle, which can effectively alleviate the problem of insufficient dataset size.
[0063] S2. Data Labeling
[0064] The LabelImg tool was used to annotate each image individually, outputting a YOLO format txt file containing the category number and the normalized bounding box coordinates (x, y, w, h). Finally, the dataset was divided into training and validation sets in an 8:2 ratio to ensure that the model training and validation were statistically significant.
[0065] 3. Improve the YOLOv5s-CBN model structure
[0066] This invention addresses the problems of severe feature loss and insufficient feature fusion in the YOLOv5s model for small object detection by improving it from two aspects: the backbone network and the feature fusion network (Neck).
[0067] (I) Design of CBAM Module in Backbone Network
[0068] CBAM module structure as follows Figure 5 As shown, it consists of two parts: channel attention and spatial attention.
[0069] 1. Channel attention mechanism
[0070] Channel attention is achieved by performing global average pooling and max pooling on the input feature map, resulting in two feature vectors. These vectors are then processed by a multilayer perceptron (MLP) with shared weights to generate channel attention weights, as shown in the following formula:
[0071] ,
[0072] in:
[0073] Channel attention map;
[0074] It is the sigmoid function;
[0075] This is the input feature map.
[0076] 2. Spatial attention mechanism
[0077] The channel-weighted feature maps are subjected to average pooling and max pooling operations, concatenated, and then subjected to 7×7 convolution to generate spatial attention weights.
[0078] The formula is as follows:
[0079] ,
[0080] in:
[0081] F' is the weighted feature map;
[0082] This is a spatial attention map.
[0083] By overlaying CBAM, the target area of pests can be highlighted in both the channel and spatial dimensions, enhancing the model's sensitivity to small-sized insects.
[0084] (II) Feature Fusion of BiFPN in Neck Structure
[0085] The original YOLOv5s PANet uses simple weighting of features at different levels, which fails to reflect the importance of each feature. Therefore, this invention employs a BiFPN structure (…). Figure 6 The weighted fusion formula is as follows:
[0086] ,
[0087] in:
[0088] This indicates the characteristics of weighted fusion.
[0089] This represents the weight of the i-th feature.
[0090] Represents the i-th input feature
[0091] BiFPN achieves efficient fusion through bidirectional paths and learnable weights, enhancing the expressive power of small targets in high-level feature maps.
[0092] (III) Overall Improved Structure of YOLOv5s-CBN
[0093] The improved overall network is as follows Figure 4 As shown, the Backbone is responsible for extracting the low-level and mid-level texture features, the Neck fuses multi-scale semantic features, and the Head outputs the bounding box coordinates, confidence scores, and class probabilities. This structure improves the accuracy of small object detection while being lightweight.
[0094] (iv) Model training methods and parameter settings
[0095]
[0096] During training, CIoU Loss is used to optimize the bounding box regression branch, and the model convergence stability is ensured by comparing the training loss curve.
[0097] (v) Model performance evaluation
[0098] 1. Indicator System
[0099] The following indicators are used to evaluate the performance of this invention:
[0100] Precision (P): The proportion of samples that the model predicted as pests but were actually pests.
[0101] Recall (R): The proportion of actual pest samples that are correctly identified by the model;
[0102] F1: Harmonic mean of P and R;
[0103] mAP@0.5: Average accuracy when the IoU threshold is 0.5.
[0104] 2. Performance Results
[0105] like Figure 7 As shown, the F1-Confidence curve of the YOLOv5s-CBN model reaches the optimal F1 (0.91) at 0.43, indicating that the model achieves a good balance between P and R; the PR curve shows that the model achieves mAP@0.5 of 0.947 on both types of pests.
[0106] Detection results are as follows Figure 8 As shown, the model can accurately identify the location and type of pests in complex backgrounds.
[0107] (vi) Model Comparison Experiment
[0108] To verify the advantages of the method of this invention, YOLOv5s-CBN is compared with the original YOLOv5s model, such as... Figure 9 As shown in Table 1, the improved model significantly outperforms the original model in terms of convergence speed, loss stability, and final accuracy.
[0109] Table 1 Comparative Experiment Results
[0110]
[0111] For the Scarabaeidae family: Precision increased from 0.872 to 0.881; Recall increased from 0.896 to 0.930; and mAP increased to 0.920.
[0112] Beet armyworm: Precision increased from 0.868 to 0.902; Recall increased from 0.928 to 0.952; mAP increased to 0.941.
[0113] (vii) Application Examples and Generalization
[0114] The method of this invention is applicable to: tobacco field pest monitoring systems; real-time pest identification and early warning devices; intelligent plant protection systems and drone inspection platforms;
[0115] The model has advantages such as being lightweight, easy to deploy, and highly adaptable, and can be extended to various crop pest monitoring tasks.
[0116] (viii) Conclusion
[0117] The above embodiments are merely preferred embodiments of the present invention. Any equivalent substitutions or modifications made within the spirit and principles of the present invention should be covered within the scope of protection of the present invention.
Claims
1. An automatic detection method for tobacco pests based on an improved YOLOv5s, characterized in that: This automatic detection method for tobacco pests is based on the YOLOv5s model, which has been structurally improved to form the YOLOv5s-CBN model, enabling the detection of tobacco pests. The specific steps for designing and implementing the YOLOv5s-CBN model are as follows: S1. Field Image Acquisition and Classification: High-resolution image data of target pests, including scarabs and beet armyworms, are collected using tobacco field pest monitoring devices, fixed cameras, or drones equipped with imaging modules. At the same time, background tobacco leaf images without pests are also collected. The acquisition device includes an insect-attracting light source, an imaging sensor, a light compensation module, a dustproof and waterproof shell, and a wireless data transmission module to ensure that stable quality samples can be obtained under different lighting conditions, different heights, and different angles. The image resolution was selected to be greater than 4000×3000 pixels to ensure that the outline of the pests remained distinguishable under high scaling conditions; the collected data was initially screened by hand and classified and labeled according to category to ensure the accuracy of image labels, thereby providing reliable data input for deep learning models; S2. Data Preprocessing, Integration and Enhancement: The acquired images are uniformly resized and cropped to the model input size of 640×640 pixels. At the same time, normalization and pixel value standardization preprocessing operations are performed to improve the stability of model training. Multiple data augmentation strategies were implemented, including random cropping, horizontal flipping, scaling, rotational perturbation, color jittering, brightness variation, contrast adjustment, and gamma mapping, to simulate the changes in illumination, angle, and scale in the tobacco field environment, improve the model's generalization ability, and form an augmented training dataset. The enhanced training dataset is divided into a training set and a validation set in an 8:2 ratio; if it is necessary to evaluate the deployment effect of the model, an additional test set that is not used for training is also created. S3. Construct an improved YOLOv5s model with CBAM: Insert the convolutional block attention module CBAM into the backbone of the YOLOv5s model to enhance the model's ability to focus on key regions of the worm. CBAM consists of two parts: Channel Attention (CAM) and Spatial Attention (SAM). CAM performs global average pooling and global max pooling on the intermediate feature map information, then generates an attention weight vector with the same number of channels through a multilayer perceptron (MLP). After sigmoid activation, the channel attention weights are obtained. The specific calculation formula is as follows: , in, It is the channel attention weight. It is an intermediate feature map. yes function, It is average pooling. It is max pooling, MLP is multilayer perceptron, and F represents the input feature map; Subsequently, SAM performs max pooling and average pooling on the CAM-weighted feature map to highlight important information feature regions. Spatial attention weights are then obtained through 7×7 convolution and sigmoid activation, further emphasizing important regions in the location dimension. The specific calculation formula is as follows: , in, It is spatial attention weight. It is the sigmoid function. It is average pooling. It is max pooling. Represents a 7×7 convolution. The output feature map represents the representation of the feature map. S4. Introducing the BiFPN structure in the feature fusion stage: The YOLOv5s model mainly uses the Feature Pyramid Network (FPN) and the Path Fusion Network (PAN) to fuse features at different scales. FPN typically merges multi-scale features through simple addition or concatenation, failing to distinguish the relative importance of features at each layer in the detection task. While PAN achieves bidirectional flow, it treats all input features equally, cannot adaptively weight features at different scales, and has a relatively fixed structure. To compensate for these shortcomings, the Bidirectional Feature Pyramid Network (BiFPN) is introduced. The specific integration of the BiFPN into the YOLOv5s model is as follows: 1) Structural replacement: The FPN+PAN structure in the Neck part of the YOLOv5s model is replaced with BiFPN. BiFPN introduces learnable weight parameters while maintaining the bidirectional information flow of top-down FPN and bottom-up PAN, enabling the network to dynamically weight features at different levels according to task importance. 2) Enhanced cross-layer connectivity: BiFPN adds cross-layer shortcut connections between input and output features at the same level, which avoids information loss during multi-layer transmission and is especially beneficial for the preservation and enhancement of small target features. 3) Weighted fusion mechanism: During feature fusion, BiFPN normalizes different input features and then performs a weighted summation using learnable weights, as shown in the following formula: , in, This indicates the characteristics of weighted fusion. This represents the weight of the i-th feature. Represents the i-th input feature; 4) Integration into the location: BiFPN is embedded between the Backbone and Head, receiving multi-scale feature maps from the Backbone and outputting enhanced feature maps for the Head to perform category and location prediction. S5. Model Training and Loss Optimization: The SGD optimizer was used for model training with an initial learning rate of 0.01, a momentum term of 0.937, a batch size of 16, and 100 training epochs. The loss function included classification loss, confidence loss, and bounding box regression loss, with the bounding box regression using the complete intersection-union (CIoU) loss. During training, the anchor box size was dynamically adjusted, and a cosine annealing learning rate strategy was implemented to enhance convergence stability, resulting in the YOLOv5s-CBN model. S6. Model Validation, Performance Analysis, and Repeated Training: Perform performance analysis on the validation set using the trained YOLOv5s-CBN model, calculating Precision, Recall, F1, and mAP@0.5; simultaneously record the PR curve, F1–Confidence curve, and loss convergence curve. , , , , To verify the stability and robustness of the model, the YOLOv5s-CBN model was repeatedly trained, and the fluctuation of performance indicators under different training rounds and different initialization conditions was statistically analyzed. S7. Non-maximum suppression (NMS) processing during the inference stage: Non-maximum suppression (NMS) is performed on candidate detection boxes with a confidence level higher than 0.
25. When the IoU between two candidate boxes is greater than 0.5, the box with the higher confidence level is retained, and redundant boxes are filtered out to ensure the uniqueness and stability of the output results. S8. Test Set Evaluation and Model Deployment: The trained YOLOv5s-CBN model was applied to the test set to classify and identify the Scarabaeidae and Beetroot moths and detect their locations. The experimental results showed that the model achieved an mAP@0.5 score of 0.947 and an F1 score of 0.91, demonstrating high robustness even under complex background conditions.
2. The automatic detection method for tobacco pests based on improved YOLOv5s according to claim 1, characterized in that: In the CBAM module, channel attention uses a weight generation mechanism that combines global average pooling and max pooling with a multilayer perceptron; spatial attention uses a mechanism that generates a spatial attention graph by max pooling and average pooling followed by 7×7 convolution.
3. The automatic detection method for tobacco pests based on improved YOLOv5s according to claim 1, characterized in that: The BiFPN employs learnable weights during feature fusion, normalizing features at different scales before fusing them.
4. The automatic detection method for tobacco pests based on improved YOLOv5s according to claim 1, characterized in that: The model training uses an input image size of 640×640, a confidence threshold of 0.25, and an IoU threshold of 0.
5.
5. The automatic detection method for tobacco pests based on improved YOLOv5s according to claim 1, characterized in that, The model achieved a precision of 0.90, a recall of 0.930, and a mAP@0.5 of 0.920 for the Scarabaeidae family; and a precision of 0.90, a recall of 0.95, and a mAP@0.5 of 0.94 for the Beet armyworm.
6. The automatic detection method for tobacco pests based on improved YOLOv5s according to claim 1, characterized in that: The detection results are filtered by non-maximum suppression (NMS) to remove redundant frames, with the NMS threshold set to 0.5.