Image-based pest detection method and device and computer equipment
By extracting global and local feature information in pest detection and dynamically adjusting feature fusion, the problems of limited computing resources and high background complexity in agricultural pest detection are solved, and efficient and accurate pest recognition is achieved.
Patent Information
- Application Number
- CN202510392231.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-31
- Publication Date
- 2025-08-05
AI Technical Summary
In agricultural pest detection, the existing technology faces the problems of limited computing resources, high background complexity, large changes in target characteristics, low contrast and difficult to accurately define target boundaries, which leads to increased detection difficulty, especially for insects with small size and light colors, which are easy to be confused with the background, which can easily lead to misjudgment.
By extracting the global and local feature information of the pest image to be detected, dynamic adjustment feature fusion method is adopted to achieve feature information fusion at different levels and ranges, and multi-scale feature extraction and fusion is used to improve feature utilization efficiency and detection accuracy.
It improves the accuracy and efficiency of pest detection, can better identify pests in complex backgrounds, reduce the rate of misjudgment, and improves the detection ability of small pests.
Smart Images

Figure CN120431350A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image detection technology, and in particular to an image-based pest detection method, device, computer equipment and storage medium. Background Art
[0002] Image recognition methods, particularly those based on convolutional neural networks (CNNs), have become crucial in this field due to their efficiency, scalability, and end-to-end learning framework. Among them, object detection networks (such as the YOLO (You Only Look Once) series) have become a crucial tool for pest detection.
[0003] However, in practical agricultural applications, pest detection still faces multiple challenges, including limited computational resources, high background complexity, and large variations in target features. Furthermore, the complex environments in which pests operate, such as dense vegetation in fields and multi-layered greenhouse structures, result in low contrast between pests and the background, increasing the difficulty of detection. Pests are numerous in variety, and many insects exhibit significant morphological changes during flight, making it difficult to precisely define target boundaries. Some tiny, light-colored insects can easily be confused with the background, leading to misdetection. Summary of the Invention
[0004] Based on this, the purpose of the present invention is to provide an image-based pest detection method, device, computer equipment, and storage medium. By extracting global feature information and local feature information at different levels of the pest image to be detected, and adopting a dynamically adjusted feature fusion method, it is possible to more comprehensively achieve the fusion of feature information at different levels and within different ranges, effectively improving feature utilization efficiency and detection accuracy for pest detection, realizing pest detection in the pest image to be detected, and improving the accuracy and efficiency of pest detection. The specific solution is as follows:
[0005] In a first aspect, an embodiment of the present application provides an image-based pest detection method, comprising the following steps:
[0006] S1: Obtain an image of a pest to be detected and a pest detection model; wherein the pest detection model includes a backbone network, a neck network, and a detection network; the neck network includes a global feature extraction module, a local feature extraction module, and a feature fusion module; the local feature extraction module includes a shallow global feature extraction module and a deep global feature extraction module;
[0007] S2: Inputting the pest image to be detected into the backbone network to perform multi-scale feature extraction to obtain backbone feature maps of several scales; inputting the backbone feature maps of several scales into the global feature extraction module to perform global feature extraction and multi-scale segmentation operations to obtain global feature maps of several scales;
[0008] S3: dividing the backbone feature maps of several scales into several backbone feature maps of shallow scales and several backbone feature maps of deep scales; inputting the backbone feature maps of several shallow scales into the shallow global feature extraction module for local feature extraction to obtain several local feature extraction maps of shallow scales; inputting the local feature extraction maps of several shallow scales and the global feature maps of corresponding scales into the feature fusion module for feature fusion to obtain several feature fusion maps of shallow scales;
[0009] S4: Inputting the backbone feature map of the first deep scale and the corresponding feature fusion map of the shallow scale of the previous scale into the deep local feature extraction module for local feature extraction to obtain the first deep scale local feature map; inputting the local feature map of the first deep scale and the global feature map of the corresponding scale into the feature fusion module for feature fusion to obtain the first deep scale feature fusion map; inputting the feature fusion map of the first deep scale and the corresponding backbone feature map of the next deep scale into the deep local feature extraction module, repeating step S4 until the last deep scale feature fusion map is obtained, and obtaining several deep scale feature fusion maps;
[0010] S5: Inputting the feature fusion maps of several shallow scales and the feature fusion maps of several deep scales into the detection network to perform pest detection, and obtaining the pest detection result of the pest image to be detected.
[0011] In a second aspect, an embodiment of the present application provides an image-based pest detection device, comprising:
[0012] A data acquisition module is used to obtain an image of a pest to be detected and a pest detection model; wherein the pest detection model includes a backbone network, a neck network, and a detection network; the neck network includes a global feature extraction module, a local feature extraction module, and a feature fusion module; the local feature extraction module includes a shallow global feature extraction module and a deep global feature extraction module;
[0013] A multi-scale global feature extraction module is used to input the pest image to be detected into the backbone network for multi-scale feature extraction to obtain backbone feature maps of several scales; and input the backbone feature maps of several scales into the global feature extraction module for global feature extraction and multi-scale segmentation operations to obtain global feature maps of several scales;
[0014] A shallow scale feature processing module is used to divide the backbone feature maps of several scales into several shallow scale backbone feature maps and several deep scale backbone feature maps; input the several shallow scale backbone feature maps into the shallow global feature extraction module for local feature extraction to obtain several shallow scale local feature extraction maps; input the several shallow scale local feature extraction maps and the global feature maps of the corresponding scales into the feature fusion module for feature fusion to obtain several shallow scale feature fusion maps;
[0015] A deep-scale feature processing module is used to input the backbone feature map of the first deep scale and the corresponding shallow-scale feature fusion map of the previous scale into the deep local feature extraction module for local feature extraction to obtain the first deep-scale local feature map; input the first deep-scale local feature map and the global feature map of the corresponding scale into the feature fusion module for feature fusion to obtain the first deep-scale feature fusion map; input the first deep-scale feature fusion map and the corresponding next deep-scale backbone feature map into the deep local feature extraction module, repeatedly execute the deep-scale feature processing module until the last deep-scale feature fusion map is obtained, and obtain several deep-scale feature fusion maps;
[0016] The pest detection module is used to input the feature fusion maps of several shallow scales and the feature fusion maps of several deep scales into the detection network to perform pest detection and obtain the pest detection result of the pest image to be detected.
[0017] In a third aspect, an embodiment of the present application provides a computer device comprising: a processor, a memory, and a computer program stored on the memory and executable on the processor; when the computer program is executed by the processor, the steps of the image-based pest detection method as described in the first aspect are implemented.
[0018] In a fourth aspect, an embodiment of the present application provides a storage medium storing a computer program, which, when executed by a processor, implements the steps of the image-based pest detection method as described in the first aspect.
[0019] In an embodiment of the present application, an image-based pest detection method, apparatus, computer equipment, and storage medium are provided. By extracting global feature information and local feature information at different levels of the pest image to be detected and adopting a dynamically adjusted feature fusion method, feature information fusion at different levels and within different ranges can be more comprehensively realized, effectively improving feature utilization efficiency and detection accuracy for pest detection, thereby realizing pest detection of the pest image to be detected and improving the accuracy and efficiency of pest detection.
[0020] For better understanding and implementation, the present invention is described in detail below with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 A schematic diagram of a process flow of an image-based pest detection method provided in one embodiment of the present application;
[0022] Figure 2 A schematic diagram of the process of step S2 in the image-based pest detection method provided in one embodiment of the present application;
[0023] Figure 3 A schematic diagram of the process of step S3 in the image-based pest detection method provided in one embodiment of the present application;
[0024] Figure 4 A schematic diagram of the process of step S3 in the image-based pest detection method provided in another embodiment of the present application;
[0025] Figure 5 A schematic diagram of the process of step S4 in the image-based pest detection method provided in one embodiment of the present application;
[0026] Figure 6 A schematic diagram of the process of step S5 in the image-based pest detection method provided in one embodiment of the present application;
[0027] Figure 7 A schematic diagram of the process of step S6 in an image-based pest detection method provided in another embodiment of the present application;
[0028] Figure 8 A schematic structural diagram of an image-based pest detection device provided in one embodiment of the present application;
[0029] Figure 9 A schematic diagram of the structure of a computer device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0030] Exemplary embodiments will be described in detail herein, with examples illustrated in the accompanying drawings. In the following description, when referring to the drawings, identical numerals in different figures represent identical or similar elements, unless otherwise indicated. The embodiments described in the following exemplary embodiments are not intended to represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
[0031] The terms used in this application are for the purpose of describing specific embodiments only and are not intended to limit this application. As used in this application and the appended claims, the singular forms "a," "an," "the," and "the" are intended to include the plural forms, unless the context clearly indicates otherwise. It should also be understood that the term "and / or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items.
[0032] It should be understood that although the terms first, second, third, etc. may be used in this application to describe various information, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from each other. For example, without departing from the scope of this application, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the words "if" / "if" as used herein may be interpreted as "at the time of" or "when" or "in response to a determination."
[0033] See also Figure 1 , Figure 1 A flowchart of an image-based pest detection method provided in one embodiment of the present application is provided, wherein the method comprises the following steps:
[0034] S1: Obtain an image of a pest to be detected and a preset pest detection model.
[0035] The image-based pest detection method is implemented by a detection device for the image-based pest detection method (hereinafter referred to as the detection device). In an optional embodiment, the detection device may be a computer device, a server, or a server cluster composed of multiple computer devices.
[0036] In this embodiment, the detection device can obtain images of the pests to be detected using a preset neural network-based ECC architecture for IoT applications. This neural network-based ECC architecture includes data acquisition, real-time detectors, cloud deployment, and data storage and analysis. Specifically, this neural network-based ECC architecture for IoT applications includes a cloud server with rich computing power, a relatively limited edge computing device, the Jetson Xavier NX, and a multi-device image acquisition platform. This intelligent detection system based on different IoT devices enables data acquisition at the terminal, lightweight model detection at the edge, and intelligent applications in the cloud.
[0037] This component is responsible for data acquisition and processing based on multiple IoT sensors. Robots, traps, surveillance cameras, and mobile devices are directly connected to the Jetson Xavier NX. Images collected periodically by different edge devices undergo data preprocessing (such as deduplication) before being sent to edge computing devices.
[0038] For real-time detectors, due to the limited computing, storage, and communication capabilities of edge computing devices, a preset pest detection model is deployed on the edge computing device, which can be used for data collection and real-time detection. At the same time, only detection images containing key information for pest identification will be uploaded to the cloud server, thereby limiting the workload of network communication and reducing the energy consumption of data transmission.
[0039] For cloud deployment, cloud servers with computing power are used to train pest detection models, as model training requires more computing power than inference. This layer provides a programming platform and runtime environment for different applications, facilitating model training and upgrades. The retrained model weights can be transferred to edge computing devices, enabling more accurate and efficient detection.
[0040] Data storage and analysis primarily store images, results, and in-depth data analysis. This component is connected to a cloud database, enabling the secure deployment of intelligent applications. Once an edge device detects the presence of a pest, the detection results are uploaded to the cloud server. This allows for a quick overview of the pest situation in the area and allows for more in-depth analysis. Processing within the cloud server provides cloud users with critical and detailed pest and disease information, enabling efficient and accurate disease prevention or control. Furthermore, data can be fully extracted from the cloud server, reducing data acquisition costs for similar tasks. Pest images can be used to further expand the dataset.
[0041] The detection device obtains a preset pest detection model, wherein the pest detection model includes a backbone network, a neck network and a detection network; the neck network includes a global feature extraction module, a local feature extraction module and a feature fusion module; the local feature extraction module includes a shallow global feature extraction module and a deep global feature extraction module.
[0042] S2: Inputting the pest image to be detected into the backbone network for multi-scale feature extraction to obtain backbone feature maps of several scales; inputting the backbone feature maps of several scales into the global feature extraction module for global feature extraction and multi-scale segmentation operations to obtain global feature maps of several scales.
[0043] In this embodiment, the detection device inputs the image of the pest to be detected into the backbone network to perform multi-scale feature extraction to obtain backbone feature maps of several scales.
[0044] Specifically, the backbone network is composed of several stacked cross-stage local networks (CSPNETs). The detection device inputs the pest image to be detected into the backbone network for multi-scale feature extraction to obtain backbone feature maps of several scales.
[0045] The detection device inputs the backbone feature maps of several scales into the global feature extraction module to perform global feature extraction and multi-scale segmentation operations to obtain global feature maps of several scales.
[0046] The global feature extraction module includes a shallow global feature extraction module and a deep global feature extraction module; the deep global feature extraction module includes several stacked deep global feature extraction submodules, and the deep global feature extraction submodule includes a multi-head attention mechanism network, a feedforward network and a residual connection layer; please refer to Figure 2 , Figure 2 The flowchart of S2 in the image-based pest detection method provided in one embodiment of the present application includes steps S21 to S24, which are specifically as follows:
[0047] S21: According to the scale of the backbone feature map and the corresponding dynamic adjustment algorithm, the backbone feature maps of several scales are dynamically adjusted to obtain the backbone feature maps of several scales after dynamic adjustment; the backbone feature maps of several scales after dynamic adjustment are spliced and convolved to obtain a first convolution feature map.
[0048] In this embodiment, the detection device dynamically adjusts the backbone feature maps of several scales according to the scale of the backbone feature map and the corresponding dynamic adjustment algorithm to obtain the backbone feature maps of several scales after dynamic adjustment, wherein the dynamic adjustment algorithm is:
[0049]
[0050] Where x′ i is the backbone feature map of the i-th scale after dynamic adjustment, F Interpolate (·) is the interpolation function, F AdaptiveAvgPool (·) is the average pooling function, x i is the backbone feature map of the i-th scale, H i is the height of the backbone feature map at the i-th scale, W i is the width of the backbone feature map at the i-th scale.
[0051] Select appropriate operations based on the size of the feature map to better handle multi-scale features. Interpolation is performed on small-sized feature maps to increase the number of spatial dimensions of the feature map, effectively improving its resolution while preserving fine features to maintain consistency in size with high-resolution feature maps. Average pooling is performed on large-sized feature maps to reduce noise, improve robustness, and reduce the number of spatial dimensions of the feature map while preserving the main features of the image.
[0052] The detection device splices and convolves the backbone feature maps of the dynamically adjusted multiple scales to obtain a first convolution feature map to ensure sufficient information aggregation.
[0053] S22: Input the first convolution feature map into the shallow global feature extraction module to perform multi-layer reparameterized convolution processing and convolution operations in sequence to obtain a shallow global feature map.
[0054] In this embodiment, the detection device inputs the first convolution feature map into the shallow global feature extraction module and performs multi-layer reparameterized convolution processing and convolution operations in sequence to obtain a shallow global feature map.
[0055] S23: Use the first convolution feature map as the input feature map of the first deep global feature fusion submodule in the deep global feature extraction module, perform attention feature extraction according to the multi-head attention mechanism network in the deep global feature extraction submodule, and obtain a first attention feature map; splice the first attention feature map and the convolution feature map to obtain a first spliced feature map; input the first spliced feature map into the feedforward network for feature processing to obtain a hidden feature map; splice the first spliced feature map and the hidden feature map to obtain a second spliced feature map; use the second spliced feature map as the input feature map of the next deep global feature extraction submodule, repeat the feature processing, and obtain the second spliced feature map output by the last deep global feature extraction submodule as the deep global feature map.
[0056] S24: Perform a multi-scale segmentation operation according to the shallow global feature map and the deep global feature map to obtain segmentation feature maps of several scales as the global feature map.
[0057] In this embodiment, the detection device performs a multi-scale segmentation operation based on the shallow global feature map and the deep global feature map to obtain segmentation feature maps of several scales as the global feature map.
[0058] S3: Divide the backbone feature maps of several scales into backbone feature maps of several shallow scales and backbone feature maps of several deep scales; input the backbone feature maps of several shallow scales into the shallow global feature extraction module for local feature extraction to obtain several local feature extraction maps of shallow scales; input the local feature extraction maps of several shallow scales and the global feature maps of corresponding scales into the feature fusion module for feature fusion to obtain several feature fusion maps of shallow scales.
[0059] In this embodiment, the detection device divides the backbone feature maps at the multiple scales into multiple shallow-scale backbone feature maps and multiple deep-scale backbone feature maps. The detection device inputs the multiple shallow-scale backbone feature maps into the shallow global feature extraction module for local feature extraction, thereby obtaining multiple shallow-scale local feature extraction maps.
[0060] See also Figure 3 , Figure 3 The flowchart of S3 in the image-based pest detection method provided in one embodiment of the present application includes steps S31 to S32, which are specifically as follows:
[0061] S31: constructing a combination of several shallow-scale backbone feature maps according to the several shallow-scale backbone feature maps.
[0062] In this embodiment, the detection device constructs a combination of backbone feature maps of several shallow scales based on the backbone feature maps of several shallow scales, wherein the backbone feature map combination includes the backbone feature map of the current scale and the backbone feature maps of several adjacent scales. Specifically, the backbone feature maps of the adjacent scales are the backbone feature maps of the two scales before and after the current scale. If the current scale is the first scale, the backbone feature map of the scale before the first scale is the backbone feature map of the last scale output by the backbone network.
[0063] S32: According to the scales of the backbone feature maps in the combination of several shallow-scale backbone feature maps, the backbone feature maps in the combination of the backbone feature maps are sampled to obtain several shallow-scale backbone feature map combinations after the sampling process; the backbone feature maps in the combination of the several shallow-scale backbone feature maps after the sampling process are respectively spliced and convolved to obtain several shallow-scale local feature maps.
[0064] In this embodiment, the detection device samples the backbone feature maps in the combination of several shallow-scale backbone feature maps according to the scales of the backbone feature maps in the combination of several shallow-scale backbone feature maps to obtain the sampling-processed combinations of several shallow-scale backbone feature maps.
[0065] Specifically, for the scales of the backbone feature maps in the backbone feature map combination, the backbone feature map of the smallest scale, that is, the backbone feature map of the next scale, is upsampled to obtain the backbone feature map after upsampling, as described below:
[0066] z i+1 =F AddptiveAvGPool (F Conv (x i+1 ))
[0067] Where z i+1 is the backbone feature map after upsampling at the i+1th scale, F Conv (·) is the convolution function.
[0068] The backbone feature map of the largest scale, that is, the backbone feature map of the previous scale, is subjected to average pooling downsampling processing to obtain the backbone feature map after downsampling processing, as described below:
[0069] z i-1 =F1(x i-1 )
[0070] Where z i+1 is the backbone feature map after upsampling at the i+1th scale, and F1(·) is the average pooling downsampling function.
[0071] For the backbone feature map of the current scale, convolution processing is performed on the backbone feature map of the current scale to obtain the backbone feature map after convolution processing, and the backbone feature map after upsampling processing, the backbone feature map after downsampling processing and the backbone feature map after convolution processing are combined to obtain a combination of backbone feature maps of several shallow scales after sampling processing to ensure that the backbone feature maps of different scales are adjusted to the target size.
[0072] The detection device inputs several shallow-scale local feature extraction maps and corresponding-scale global feature maps into the feature fusion module for feature fusion, and obtains several shallow-scale feature fusion maps to enhance branch detection capability.
[0073] See also Figure 4 , Figure 4 The flowchart of S3 in the image-based pest detection method provided in another embodiment of the present application includes steps S33 to S35, which are specifically as follows:
[0074] S33: performing convolution processing on the local feature extraction maps of several shallow scales and the global feature maps of corresponding scales to obtain second convolution feature maps corresponding to the local feature maps of several shallow scales and third convolution feature maps corresponding to the global feature maps of several shallow scales.
[0075] In this embodiment, the detection device performs convolution processing on the local feature extraction maps of several shallow scales and the global feature maps of corresponding scales to obtain second convolution feature maps corresponding to the local feature maps of several shallow scales and third convolution feature maps corresponding to the global feature maps of several shallow scales.
[0076] S34: The second convolution feature maps corresponding to the local feature maps of several shallow scales are sequentially processed by the activation function and the interpolation function to obtain the first intermediate feature maps of several shallow scales; the second convolution feature maps corresponding to the local feature maps of several scales are processed by the interpolation function to obtain the second intermediate feature maps of several shallow scales.
[0077] In this embodiment, the detection device sequentially processes the second convolution feature maps corresponding to the local feature maps of several shallow scales through the activation function and the interpolation function to obtain the first intermediate feature maps of several shallow scales, as described below:
[0078] Y′ i =Resize(Sigmoid(F Conv (Y i )))
[0079] Where Y′ i is the first intermediate feature map of the i-th scale, F Conv (Y i ) is the second convolution feature map corresponding to the local feature map of the i-th scale, Sigmoid(·) is the activation function, and Resize(·) represents F Interpolate (·) and F AdaptiveAvgPool (·) represents the interpolation operation and pooling operation, respectively, and the resizing is determined by the preset scale threshold.
[0080] The detection device processes the second convolution feature maps corresponding to the local feature maps of several scales through an interpolation function to obtain second intermediate feature maps of several shallow scales, as described below:
[0081] Y″ i =Resize(F Conv (Y i ))
[0082] Where, Y″ i is the second intermediate feature map of the i-th scale.
[0083] By simplifying operations such as pooling and interpolation, the number of information flow paths at all levels is increased, effectively determining the size of feature maps and accurately determining appropriate operations for them. This is particularly useful when feature map scales vary little and information concentration is required. Pooling can help improve the model's perceptual field and feature expression. Through concatenation and convolutional fusion, no additional convolutional layers are added, keeping the computational load relatively stable and achieving performance improvements without significantly increasing latency.
[0084] S35: multiplying the third convolutional feature map of the same shallow scale with the first intermediate feature map to obtain several third intermediate feature maps of shallow scales; splicing the second intermediate feature map of the same shallow scale with the third intermediate feature map to obtain several third spliced feature maps of shallow scales; performing residual connection on the third spliced feature maps of several shallow scales to obtain several residual connection feature maps of shallow scales as the feature fusion map.
[0085] In this embodiment, the detection device multiplies the third convolutional feature map of the same shallow scale with the first intermediate feature map to obtain several third intermediate feature maps of shallow scales; splices the second intermediate feature map of the same shallow scale with the third intermediate feature map to obtain several third spliced feature maps of shallow scales; and performs residual connection on the third spliced feature maps of several shallow scales to obtain several residual connection feature maps of shallow scales as the feature fusion map, as described below:
[0086] Z′ i =F C2f (F Conv (Z i )*Y′ i +Y″ i )
[0087] Where Z′ i is the residual connection feature map of the i-th scale, F C2f (·) is the residual connection function.
[0088] S4: Input the backbone feature map of the first deep scale and the feature fusion map of the corresponding shallow scale of the previous scale into the deep local feature extraction module for local feature extraction to obtain the first deep scale local feature map; input the local feature map of the first deep scale and the global feature map of the corresponding scale into the feature fusion module for feature fusion to obtain the first deep scale feature fusion map; input the feature fusion map of the first deep scale and the backbone feature map of the corresponding next deep scale into the deep local feature extraction module, repeat step S4 until the last deep scale feature fusion map is obtained, and obtain several deep scale feature fusion maps.
[0089] In this embodiment, the detection device inputs the backbone feature map of the first deep scale and the feature fusion map of the corresponding shallow scale of the previous scale into the deep local feature extraction module for local feature extraction to obtain the local feature map of the first deep scale.
[0090] See also Figure 5 , Figure 5 The flowchart of S4 in the image-based pest detection method provided in one embodiment of the present application includes steps S41 to S42, which are specifically as follows:
[0091] S41: upsampling the backbone feature map of the current deep scale by using a bilinear interpolation method to obtain the backbone feature map of the current deep scale after upsampling.
[0092] In this embodiment, the detection device uses a bilinear interpolation method to perform upsampling processing on the backbone feature map of the current deep scale to obtain the backbone feature map of the current deep scale after the upsampling processing.
[0093] S42: Perform convolution processing on the feature fusion map of the shallow scale of the corresponding previous scale to obtain the fourth convolution feature map of the corresponding previous scale, splice the backbone feature map of the current depth scale after upsampling processing with the fourth convolution feature map of the corresponding previous scale to obtain a third spliced feature map of the current depth scale, perform convolution processing on the third spliced feature map of the current depth scale to obtain a fifth convolution feature map of the current depth scale as the local feature map.
[0094] In this embodiment, the detection device performs convolution processing on the feature fusion map of the shallow scale of the corresponding previous scale to obtain the fourth convolution feature map of the corresponding previous scale, splices the backbone feature map of the current depth scale after upsampling processing with the fourth convolution feature map of the corresponding previous scale to obtain the third spliced feature map of the current depth scale, and performs convolution processing on the third spliced feature map of the current depth scale to obtain the fifth convolution feature map of the current depth scale as the local feature map.
[0095] The detection device inputs the local feature map of the first deep scale and the global feature map of the corresponding scale into the feature fusion module for feature fusion, thereby obtaining the first deep-scale feature fusion map. The first deep-scale feature fusion map and the corresponding backbone feature map of the next deep scale are then input into the deep local feature extraction module, and step S4 is repeated until the last deep-scale feature fusion map is obtained, thereby obtaining several deep-scale feature fusion maps. This effectively fuses feature information at various scales to reduce complexity and computational load. By combining high-dimensional and low-dimensional feature information, it is possible to more comprehensively achieve the fusion of feature information at different levels and within different ranges, effectively improving feature utilization efficiency and detection accuracy, enhancing the model's performance in detecting small objects, and further improving the accuracy of pest detection.
[0096] S5: Inputting the feature fusion maps of several shallow scales and the feature fusion maps of several deep scales into the detection network to perform pest detection, and obtaining the pest detection result of the pest image to be detected.
[0097] In this embodiment, the detection device inputs the feature fusion maps of several shallow scales and the feature fusion maps of several deep scales into the detection network to perform pest detection, and obtains the pest detection result of the pest image to be detected, wherein the pest labeling result includes label data of several target pest detection frames; the labeling data includes plane data and classification data, the plane parameters are used to indicate the size of the predicted pest detection frame, the classification data is used to indicate the category of the predicted pest detection frame, and the classification data includes prediction probability data of several preset categories.
[0098] The feature fusion maps of several scales are input into the attention mechanism network for attention extraction to obtain attention feature maps of several scales.
[0099] The detection network includes an attention mechanism network and a detection module; the attention mechanism network includes a multi-head attention module and a multi-scale attention module; please refer to Figure 6 , Figure 6The flowchart of S5 in the image-based pest detection method provided in one embodiment of the present application includes steps S51 to S55, which are specifically as follows:
[0100] S51: Input the feature fusion map of several scales into the multi-head attention module, perform channel feature space mapping on the feature fusion map, and obtain channel feature space mapping maps of several scales and initial matrix data of several scales.
[0101] In this embodiment, the detection device inputs the feature fusion map of several scales into the multi-head attention module, performs channel feature space mapping on the feature fusion map, and obtains channel feature space mapping maps of several scales and initial matrix data of several scales, wherein the initial matrix data includes a query matrix, a key matrix, and a value matrix.
[0102] S52: According to the preset number of multi-head attentions, a deep separation convolution method is used to divide the query matrix, key matrix and value matrix in the initial matrix vector data to obtain several matrix sub-vectors corresponding to the multi-head attention corresponding to the query matrix, key matrix and value matrix.
[0103] In this embodiment, the detection device uses a deep separation convolution method to divide the query matrix, key matrix and value matrix in the initial matrix vector data according to a preset number of multi-head attentions, and obtains several matrix sub-vectors corresponding to the query matrix, key matrix and value matrix.
[0104] S53: Perform normalization processing on the matrix sub-vectors corresponding to the query matrix, key matrix and value matrix corresponding to several multi-head attentions to obtain the normalized query matrix, key matrix and value matrix corresponding to several multi-head attentions, respectively multiply the matrix sub-vectors corresponding to the normalized query matrix, key matrix and value matrix corresponding to several multi-head attentions to obtain target matrix data of several scales; perform attention feature extraction on the target matrix data of several scales and the feature fusion map of the corresponding scales to obtain first attention feature maps of several scales.
[0105] In this embodiment, the detection device performs normalization processing on the matrix sub-vectors corresponding to the query matrix, key matrix and several multi-head attention corresponding to the value matrix to obtain the normalized query matrix, key matrix and several multi-head attention corresponding to the value matrix, and multiplies the matrix sub-vectors corresponding to the normalized query matrix, key matrix and several multi-head attention corresponding to the value matrix to obtain target matrix data of several scales; performs attention feature extraction based on the target matrix data of several scales and the feature fusion map of the corresponding scale to obtain first attention feature maps of several scales, so as to better capture the multi-granularity spatial and channel relationships in the feature map and improve the model's adaptability to complex scenes.
[0106] S54: Input the feature fusion maps of several scales into the multi-scale attention module to extract attention features, obtain second attention feature maps of several scales, and splice the first attention feature map and the second attention feature map of the same scale to obtain attention feature maps of several scales.
[0107] In this embodiment, the detection device inputs the feature fusion maps of several scales into the multi-scale attention module (Exponential Moving Average, EMA) to extract attention features, obtain second attention feature maps of several scales, and splices the first attention feature map and the second attention feature map of the same scale to obtain attention feature maps of several scales. The introduction of the multi-scale attention module focuses on extracting rich feature information and local feature enhancement at different scales, and the introduction of the multi-head attention module enhances some features. It not only focuses on the features of the local area, but also can capture the relationship between any two positions in the feature map, thereby improving long-range dependencies.
[0108] S55: Inputting the attention feature maps of several scales into the detection module to perform pest detection, and obtaining the pest detection result of the pest image to be detected.
[0109] In this embodiment, the detection device inputs the attention feature maps of several scales into the detection module to perform pest detection, and obtains the pest detection result of the pest image to be detected.
[0110] Specifically, the detection network can include several detectors, each with several anchor boxes. These are typically clustered using K-means clustering on the target boxes in the training set. The computational process is integrated into the model, adaptively training different anchor boxes during training. These anchor boxes are then used to generate pest detection boxes during prediction. Regression is performed on each pest detection box to determine its position and size.
[0111] The attention feature maps of several scales of the detection device are gridded and predicted in turn, and a convolution operation is used to obtain a convolution feature map of a specified number of channels. Based on the convolution feature map, the image of the pest to be detected is grid-divided to obtain the grid coordinate information of the image of the pest to be detected.
[0112] The detection device inputs the grid coordinate information of the pest image to be detected into the detector, calculates the center and width and height of the prediction area according to the detection frame parameters and the preset regression coefficient, and obtains the pest detection result of the pest image to be detected.
[0113] In an optional embodiment, the method further includes step S6: training the pest detection model. Figure 7 , Figure 7 The flowchart of S6 in the image-based pest detection method provided in another embodiment of the present application includes steps S61 to S66, which are specifically as follows:
[0114] S61: Obtain several sample pest images and pest labeling results.
[0115] In this embodiment, the detection device obtains several sample pest images and pest labeling results, wherein the pest labeling results include label data of several target pest detection frames; the labeling data includes plane data and classification data, the plane parameters are used to indicate the size of the pest detection frame, the classification data is used to indicate the category of the pest detection frame, and the classification data includes probability data of several preset categories, that is, includes true probability data of preset categories of several target pest detection frames.
[0116] S62: Inputting a plurality of the sample pest images into the pest detection model to obtain pest detection results of the plurality of the sample pest images.
[0117] In this embodiment, the detection device inputs a plurality of sample pest images into the pest detection model to obtain pest detection results for the plurality of sample pest images, wherein the pest detection results include a plurality of predicted pest detection frames and label data of the predicted pest detection frames;
[0118] S63: Based on the pest labeling result and the pest detection result of the same sample pest image, determine the target pest detection frame corresponding to the multiple predicted pest detection frames of the multiple sample pest images, and obtain the width difference, height difference, and intersection-over-union ratio between the multiple predicted pest detection frames of the multiple sample pest images and the corresponding target pest detection frames.
[0119] In this embodiment, the detection device confirms the target pest detection frame corresponding to several predicted pest detection frames of several sample pest images based on the pest labeling result and pest detection result of the same sample pest image, and obtains the width difference, height difference and intersection-over-union ratio between several predicted pest detection frames of several sample pest images and the corresponding target pest detection frames.
[0120] S64: Based on the same sample pest image and the preset width importance coefficient and height importance, the width difference is multiplied by the width importance coefficient, and the height difference is multiplied by the height importance coefficient. The obtained width difference product results and height difference product results are accumulated to obtain penalty terms between several predicted pest detection frames of several sample pest images and the corresponding target pest detection frames.
[0121] In this embodiment, the detection device multiplies the width difference by the width importance coefficient and the height importance based on the same sample pest image and the preset width importance coefficient and height importance, and accumulates the obtained width difference product results and height difference product results to obtain penalty terms between several predicted pest detection frames of several sample pest images and the corresponding target pest detection frames.
[0122] S65: Obtain a first loss value according to penalty terms, intersection-over-union ratios (IoUs) and a preset first loss algorithm between a plurality of predicted pest detection frames of a plurality of sample pest images and corresponding target pest detection frames.
[0123] To address the problem that traditional IoU only calculates the overlap rate based on the intersection and connection between the predicted frame and the actual frame, ignoring the geometric differences and position offsets between frames, and may lead to insufficient detection accuracy when processing irregular morphology or multi-scale pest targets, in this embodiment, the detection device introduces an exponential decay coefficient q=exp(-P) and an expansion parameter Λ based on the penalty term, intersection-over-union ratio, and a preset first loss algorithm between several predicted pest detection frames of several sample pest images and the corresponding target pest detection frames, thereby improving the accuracy of small objects and enhancing the detection capability of small objects and irregularly shaped targets, and obtaining a first loss value. The first loss algorithm is:
[0124]
[0125] PIoU=3×(exp(-P)-Λ)×exp(-(exp(-P)-Λ) 2 )×L
[0126] L=(1-IoU)-exp(-P 2 )+1
[0127] Where PFIoU is the loss value, PIoU is the first intermediate parameter, d is the preset lower limit parameter, u is the preset upper limit parameter, P is the penalty term, Λ is the preset expansion parameter, L is the second intermediate parameter, and IoU is the intersection-over-union ratio.
[0128] S66: Obtain a second loss value based on the classification data of several predicted pest detection frames of several sample pest images, the classification data of several target pest detection frames, and a preset second loss algorithm, and train the pest detection model based on the first loss value and the second loss value.
[0129] The second loss function is:
[0130]
[0131] Where, Loss BcE is the second loss value, d is the number of preset categories, y i is the true probability data of the i-th preset category in the classification data of the target pest detection frame, p i It is the predicted probability data of the i-th preset category in the classification data of the predicted pest detection frame.
[0132] In this embodiment, the detection device obtains a second loss value based on the classification data of several predicted pest detection frames for several sample pest images, the classification data of several target pest detection frames, and a preset second loss algorithm. The first and second loss values are then accumulated to obtain a total loss value, and the pest detection model is trained based on the total loss value. This provides a smoother loss gradient, avoiding the vanishing gradient problem that can occur with traditional IoUs when the intersection point is very small, thereby accelerating model convergence, better handling shape and scale differences in pest images, and improving pest detection accuracy.
[0133] Please refer to Figure 8 , Figure 8 This is a schematic diagram of the structure of an image-based pest detection device provided in one embodiment of the present application. The device can implement all or part of the image-based pest detection device through software, hardware, or a combination of both. The device 8 includes:
[0134] The data acquisition module 81 is used to obtain an image of a pest to be detected and a pest detection model; wherein the pest detection model includes a backbone network, a neck network, and a detection network; the neck network includes a global feature extraction module, a local feature extraction module, and a feature fusion module; the local feature extraction module includes a shallow global feature extraction module and a deep global feature extraction module;
[0135] The multi-scale global feature extraction module 82 is used to input the pest image to be detected into the backbone network to perform multi-scale feature extraction to obtain backbone feature maps of several scales; input the backbone feature maps of several scales into the global feature extraction module to perform global feature extraction and multi-scale segmentation operations to obtain global feature maps of several scales;
[0136] The shallow-scale feature processing module 83 is used to divide the backbone feature maps of several scales into several backbone feature maps of shallow scales and several backbone feature maps of deep scales; input the backbone feature maps of several shallow scales into the shallow global feature extraction module for local feature extraction to obtain several local feature extraction maps of shallow scales; input the local feature extraction maps of several shallow scales and the global feature maps of corresponding scales into the feature fusion module for feature fusion to obtain several feature fusion maps of shallow scales;
[0137] The deep-scale feature processing module 84 is configured to input the first deep-scale backbone feature map and the corresponding shallow-scale feature fusion map of the previous scale into the deep local feature extraction module for local feature extraction to obtain the first deep-scale local feature map; input the first deep-scale local feature map and the global feature map of the corresponding scale into the feature fusion module for feature fusion to obtain the first deep-scale feature fusion map; input the first deep-scale feature fusion map and the corresponding next deep-scale backbone feature map into the deep local feature extraction module, and repeatedly execute the deep-scale feature processing module until the last deep-scale feature fusion map is obtained, thereby obtaining several deep-scale feature fusion maps;
[0138] The pest detection module 85 is used to input the feature fusion maps of several shallow scales and the feature fusion maps of several deep scales into the detection network to perform pest detection and obtain the pest detection result of the pest image to be detected.
[0139] In an embodiment of the present application, a data acquisition module is used to obtain an image of pests to be detected and a pest detection model; wherein the pest detection model includes a backbone network, a neck network and a detection network; the neck network includes a global feature extraction module, a local feature extraction module and a feature fusion module; the local feature extraction module includes a shallow global feature extraction module and a deep global feature extraction module; through a multi-scale global feature extraction module, the image of pests to be detected is input into the backbone network for multi-scale feature extraction to obtain backbone feature maps of several scales; the backbone feature maps of several scales are input into the global feature extraction module for global feature extraction and multi-scale segmentation operations to obtain global feature maps of several scales; through a shallow scale feature processing module, the backbone feature maps of several scales are divided into backbone feature maps of several shallow scales and backbone feature maps of several deep scales; the backbone feature maps of several shallow scales are input into the shallow global feature extraction module for local feature extraction to obtain local feature extraction maps of several shallow scales; The local feature extraction map of the scale and the global feature map of the corresponding scale are input into the feature fusion module for feature fusion to obtain several shallow-scale feature fusion maps; the first deep-scale backbone feature map and the corresponding shallow-scale feature fusion map of the previous scale are input into the deep local feature extraction module through the deep-scale feature processing module for local feature extraction to obtain the first deep-scale local feature map; the first deep-scale local feature map and the global feature map of the corresponding scale are input into the feature fusion module for feature fusion to obtain the first deep-scale feature fusion map; the first deep-scale feature fusion map and the corresponding next deep-scale backbone feature map are input into the deep local feature extraction module, and the deep-scale feature processing module is repeatedly executed until the last deep-scale feature fusion map is obtained, thereby obtaining several deep-scale feature fusion maps; the several shallow-scale feature fusion maps and the several deep-scale feature fusion maps are input into the detection network through the pest detection module for pest detection to obtain the pest detection result of the pest image to be detected. By extracting global feature information and local feature information at different levels of the pest image to be detected and adopting a dynamically adjusted feature fusion method, it is possible to more comprehensively realize the fusion of feature information at different levels and within different ranges, effectively improving feature utilization efficiency and detection accuracy for pest detection, realizing pest detection in the pest image to be detected, and improving the accuracy and efficiency of pest detection.
[0140] Please refer to Figure 9 , Figure 9This is a schematic diagram of the structure of a computer device provided in one embodiment of the present application. The computer device 9 includes: a processor 91, a memory 92, and a computer program 93 stored in the memory 92 and executable on the processor 91; the computer device may store multiple instructions, which are suitable for being loaded and executed by the processor 91. Figures 1 to 7 The method steps of the embodiment shown in the figure can be seen in the specific execution process. Figures 1 to 7 The detailed description of the illustrated embodiment will not be repeated here.
[0141] The processor 91 may include one or more processing cores. The processor 91 utilizes various interfaces and circuits to connect to various components within the server. By running or executing instructions, programs, code sets, or instruction sets stored in the memory 92 and accessing data within the memory 92, the processor 91 performs various functions of the image-based pest detection device 8 and processes data. Optionally, the processor 91 may be implemented in the form of at least one of a digital signal processing (DSP), a field-programmable gate array (FPGA), or a programmable logic array (PLA). The processor 91 may integrate one or a combination of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. The CPU primarily processes the operating system, user interface, and application programs; the GPU is responsible for rendering and drawing the content displayed on the touchscreen display; and the modem handles wireless communications. It is understood that the modem may not be integrated into the processor 91 and may be implemented as a separate chip.
[0142] Among them, the memory 92 may include a random access memory 92 (Random Access Memory, RAM), and may also include a read-only memory 92 (Read-Only Memory). Optionally, the memory 92 includes a non-transitory computer-readable storage medium. The memory 92 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 92 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as touch instructions, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above-mentioned various method embodiments, etc. The memory 92 may also optionally be at least one storage device located away from the aforementioned processor 91.
[0143] The present application also provides a storage medium that can store multiple instructions, which are suitable for the processor to load and execute the above-mentioned instructions. Figures 1 to 7 The method steps of the embodiment shown in the figure can be seen in the specific execution process. Figures 1 to 7 The detailed description of the illustrated embodiment will not be repeated here.
[0144] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0145] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant description of other embodiments.
[0146] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraint algorithm of the technical solution. Professionals and technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present invention.
[0147] In the embodiments provided by the present invention, it should be understood that the disclosed devices / terminal equipment and methods can be implemented in other ways. For example, the device / terminal equipment embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0148] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0149] In addition, the functional units in the various embodiments of the present invention may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0150] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the process in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, it can implement the steps of the above-mentioned various method embodiments. The computer program includes computer program code, which can be in source code form, object code form, executable file or some intermediate form.
[0151] The present invention is not limited to the above-mentioned embodiments. If various changes or modifications of the present invention do not depart from the spirit and scope of the present invention, and if these changes and modifications fall within the scope of the claims of the present invention and equivalent technologies, the present invention is also intended to include these changes and modifications.
Claims
1. An image-based pest detection method, characterized in that: The following steps are involved: S1: Obtain an image of a pest to be detected and a pest detection model; wherein the pest detection model includes a backbone network, a neck network, and a detection network; the neck network includes a global feature extraction module, a local feature extraction module, and a feature fusion module; the local feature extraction module includes a shallow global feature extraction module and a deep global feature extraction module; S2: Inputting the pest image to be detected into the backbone network to perform multi-scale feature extraction to obtain backbone feature maps of several scales; inputting the backbone feature maps of several scales into the global feature extraction module to perform global feature extraction and multi-scale segmentation operations to obtain global feature maps of several scales; S3: dividing the backbone feature maps of several scales into several backbone feature maps of shallow scales and several backbone feature maps of deep scales; inputting the backbone feature maps of several shallow scales into the shallow global feature extraction module for local feature extraction to obtain several local feature extraction maps of shallow scales; inputting the local feature extraction maps of several shallow scales and the global feature maps of corresponding scales into the feature fusion module for feature fusion to obtain several feature fusion maps of shallow scales; S4: Inputting the backbone feature map of the first deep scale and the corresponding shallow scale feature fusion map of the previous scale into the deep local feature extraction module for local feature extraction to obtain the first deep scale local feature map; inputting the local feature map of the first deep scale and the global feature map of the corresponding scale into the feature fusion module for feature fusion to obtain the first deep scale feature fusion map; Inputting the feature fusion map of the first deep scale and the corresponding backbone feature map of the next deep scale into the deep local feature extraction module, and repeating step S4 until the feature fusion map of the last deep scale is obtained, thereby obtaining feature fusion maps of several deep scales; S5: Inputting the feature fusion maps of several shallow scales and the feature fusion maps of several deep scales into the detection network to perform pest detection, and obtaining the pest detection result of the pest image to be detected.
2. The image-based pest detection method according to claim 1, wherein: The global feature extraction module includes a shallow global feature extraction module and a deep global feature extraction module; the deep global feature extraction module includes several stacked deep global feature extraction submodules, and the deep global feature extraction submodule includes a multi-head attention mechanism network, a feedforward network and a residual connection layer; The step of inputting the backbone feature maps of several scales into the global feature extraction module to perform global feature extraction and multi-scale segmentation operations to obtain global feature maps of several scales includes the following steps: According to the scale of the backbone feature map and the corresponding dynamic adjustment algorithm, the backbone feature maps of several scales are dynamically adjusted to obtain the backbone feature maps of several scales after dynamic adjustment; the backbone feature maps of several scales after dynamic adjustment are spliced and convolved to obtain a first convolution feature map; Inputting the first convolution feature map into the shallow global feature extraction module to perform multi-layer reparameterized convolution processing and convolution operations in sequence to obtain a shallow global feature map; Using the first convolutional feature map as the input feature map of the first deep global feature fusion submodule in the deep global feature extraction module, performing attention feature extraction according to the multi-head attention mechanism network in the deep global feature extraction submodule to obtain a first attention feature map; The first attention feature map and the convolution feature map are spliced to obtain a first spliced feature map; the first spliced feature map is input into the feedforward network for feature processing to obtain a hidden feature map; the first spliced feature map and the hidden feature map are spliced to obtain a second spliced feature map; the second spliced feature map is used as the input feature map of the next deep global feature extraction submodule, and the feature processing is repeated to obtain a second spliced feature map output by the last deep global feature extraction submodule as the deep global feature map; A multi-scale segmentation operation is performed according to the shallow global feature map and the deep global feature map to obtain segmentation feature maps of several scales as the global feature map.
3. The image-based pest detection method according to claim 2, characterized in that: The step of inputting the backbone feature maps of several shallow scales into the shallow global feature extraction module for local feature extraction to obtain several shallow scale local feature extraction maps comprises the following steps: Constructing a plurality of shallow-scale backbone feature map combinations based on the backbone feature maps of the plurality of shallow-scales, wherein the backbone feature map combinations include a backbone feature map of the current scale and backbone feature maps of the plurality of adjacent scales; According to the scales of the backbone feature maps in the combination of several shallow-scale backbone feature maps, the backbone feature maps in the combination of the backbone feature maps are sampled to obtain several shallow-scale backbone feature map combinations after the sampling process; the backbone feature maps in the combination of the several shallow-scale backbone feature maps after the sampling process are respectively spliced and convolved to obtain several shallow-scale local feature maps.
4. The image-based pest detection method according to claim 3, characterized in that: The method of inputting several shallow-scale local feature extraction maps and corresponding-scale global feature maps into the feature fusion module for feature fusion to obtain several shallow-scale feature fusion maps includes the following steps: Performing convolution processing on the local feature extraction maps of several shallow scales and the global feature maps of corresponding scales to obtain second convolution feature maps corresponding to the local feature maps of several shallow scales and third convolution feature maps corresponding to the global feature maps of several shallow scales; The second convolution feature maps corresponding to the local feature maps of several shallow scales are sequentially processed by an activation function and an interpolation function to obtain first intermediate feature maps of several shallow scales; the second convolution feature maps corresponding to the local feature maps of several scales are processed by an interpolation function to obtain second intermediate feature maps of several shallow scales; The third convolutional feature map of the same shallow scale is multiplied by the first intermediate feature map to obtain several third intermediate feature maps of shallow scales; the second intermediate feature map of the same shallow scale is spliced with the third intermediate feature map to obtain several third spliced feature maps of shallow scales; the third spliced feature maps of several shallow scales are residually connected to obtain several residual connection feature maps of shallow scales as the feature fusion map.
5. The image-based pest detection method according to claim 4, characterized in that: The first deep-scale backbone feature map and the corresponding shallow-scale feature fusion map of the previous scale are input into the deep-level local feature extraction module to extract local features, thereby obtaining the first deep-scale local feature map, including the following steps: Performing upsampling processing on the backbone feature map of the current deep scale by using a bilinear interpolation method to obtain the backbone feature map of the current deep scale after upsampling processing; Convolution processing is performed on the feature fusion map of the shallow scale of the corresponding previous scale to obtain the fourth convolution feature map of the corresponding previous scale, the backbone feature map of the current depth scale after upsampling processing is spliced with the corresponding fourth convolution feature map of the previous scale to obtain a third spliced feature map of the current depth scale, and convolution processing is performed on the third spliced feature map of the current depth scale to obtain a fifth convolution feature map of the current depth scale as the local feature map.
6. The image-based pest detection method according to claim 5, characterized in that: The detection network includes an attention mechanism network and a detection module; the attention mechanism network includes a multi-head attention module and a multi-scale attention module; The step of inputting the feature fusion maps of several shallow scales and the feature fusion maps of several deep scales into the detection network to perform pest detection and obtaining the pest detection result of the pest image to be detected comprises the following steps: The step of inputting the feature fusion graphs of several scales into the attention mechanism network for attention extraction to obtain attention feature graphs of several scales includes the following steps: Inputting the feature fusion graphs at several scales into the multi-head attention module, performing channel feature space mapping on the feature fusion graphs, and obtaining channel feature space mapping graphs at several scales and initial matrix data at several scales, wherein the initial matrix data includes a query matrix, a key matrix, and a value matrix; According to the preset number of multi-head attentions, the query matrix, the key matrix and the value matrix in the initial matrix vector data are divided by a deep separable convolution method to obtain a number of matrix sub-vectors corresponding to the query matrix, the key matrix and the value matrix; Normalizing the matrix subvectors corresponding to the query matrix, the key matrix, and the value matrix to obtain the normalized matrix subvectors corresponding to the multi-head attention matrix, the key matrix, and the value matrix, respectively multiplying the normalized matrix subvectors corresponding to the multi-head attention matrix, the key matrix, and the value matrix to obtain target matrix data of several scales; extracting attention features based on the target matrix data of several scales and the feature fusion graphs of the corresponding scales to obtain first attention feature graphs of several scales; Inputting the feature fusion maps of several scales into the multi-scale attention module to extract attention features, obtaining second attention feature maps of several scales, and splicing the first attention feature map and the second attention feature map of the same scale to obtain attention feature maps of several scales; The attention feature maps of several scales are input into the detection module to perform pest detection, and the pest detection result of the pest image to be detected is obtained.
7. The image-based pest detection method according to claim 3, characterized in that: The method further includes the steps of: training the pest detection model; The training of the pest detection model comprises the steps of: Obtaining a plurality of sample pest images and pest labeling results, wherein the pest labeling results include label data for a plurality of target pest detection frames; the labeling data includes plane data and classification data, wherein the plane parameters are used to indicate the size of the pest detection frame, the classification data is used to indicate the category of the pest detection frame, and the classification data includes probability data for a plurality of preset categories; Inputting a plurality of the sample pest images into the pest detection model to obtain pest detection results for the plurality of the sample pest images, wherein the pest detection results include a plurality of predicted pest detection frames and label data of the predicted pest detection frames; Determining target pest detection frames corresponding to a plurality of predicted pest detection frames of a plurality of the sample pest images based on the pest labeling result and the pest detection result of the same sample pest image, and obtaining width differences, height differences, and intersection-over-union ratios between the plurality of predicted pest detection frames of the sample pest images and the corresponding target pest detection frames; Based on the same sample pest image and the preset width importance coefficient and height importance, multiplying the width difference by the width importance coefficient, multiplying the height difference by the height importance coefficient, and accumulating the obtained width difference product results and height difference product results to obtain penalty terms between several predicted pest detection frames and corresponding target pest detection frames of several sample pest images; A first loss value is obtained based on penalty terms, intersection-over-union ratios, and a preset first loss algorithm between a plurality of predicted pest detection frames of a plurality of sample pest images and corresponding target pest detection frames, wherein the first loss algorithm is: PIoU=3×(exp(-P)-Λ)×exp(-(exp(-P)-Λ) 2 )×L L=(1-IoU)-exp(-P 2 )+1 Where PFIoU is the loss value, PIoU is the first intermediate parameter, d is the preset lower limit parameter, u is the preset upper limit parameter, P is the penalty term, Λ is the preset expansion parameter, L is the second intermediate parameter, and IoU is the intersection-over-union ratio; A second loss value is obtained based on the classification data of the plurality of predicted pest detection frames of the plurality of sample pest images, the classification data of the plurality of target pest detection frames, and a preset second loss algorithm. The pest detection model is trained based on the first loss value and the second loss value, wherein the second loss function is: Where, Loss BcE is the second loss value, d is the number of preset categories, y i is the true probability data of the i-th preset category in the classification data of the target pest detection frame, p i It is the predicted probability data of the i-th preset category in the classification data of the predicted pest detection frame.
8. An image-based pest detection device, characterized in that: include: A data acquisition module is used to obtain an image of a pest to be detected and a pest detection model; wherein the pest detection model includes a backbone network, a neck network, and a detection network; the neck network includes a global feature extraction module, a local feature extraction module, and a feature fusion module; the local feature extraction module includes a shallow global feature extraction module and a deep global feature extraction module; A multi-scale global feature extraction module is used to input the pest image to be detected into the backbone network for multi-scale feature extraction to obtain backbone feature maps of several scales; and input the backbone feature maps of several scales into the global feature extraction module for global feature extraction and multi-scale segmentation operations to obtain global feature maps of several scales; A shallow scale feature processing module is used to divide the backbone feature maps of several scales into several shallow scale backbone feature maps and several deep scale backbone feature maps; input the several shallow scale backbone feature maps into the shallow global feature extraction module for local feature extraction to obtain several shallow scale local feature extraction maps; input the several shallow scale local feature extraction maps and the global feature maps of the corresponding scales into the feature fusion module for feature fusion to obtain several shallow scale feature fusion maps; A deep-scale feature processing module is used to input the backbone feature map of the first deep scale and the corresponding shallow-scale feature fusion map of the previous scale into the deep local feature extraction module for local feature extraction to obtain the first deep-scale local feature map; input the first deep-scale local feature map and the global feature map of the corresponding scale into the feature fusion module for feature fusion to obtain the first deep-scale feature fusion map; input the first deep-scale feature fusion map and the corresponding next deep-scale backbone feature map into the deep local feature extraction module, repeatedly execute the deep-scale feature processing module until the last deep-scale feature fusion map is obtained, and obtain several deep-scale feature fusion maps; The pest detection module is used to input the feature fusion maps of several shallow scales and the feature fusion maps of several deep scales into the detection network to perform pest detection and obtain the pest detection result of the pest image to be detected.
9. A computer device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and executable on the processor; when the computer program is executed by the processor, the steps of the image-based pest detection method according to any one of claims 1 to 7 are implemented.
10. A storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the image-based pest detection method according to any one of claims 1 to 7 are implemented.