Garden plant pest detection method based on multi-scale attention residual U-Net

CN122929273APending Publication Date: 2026-10-16ZHENGZHOU GUANTONG FORESTRY TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611065695.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-17
Publication Date
2026-10-16

AI Technical Summary

Technical Problem

然而,标准U-Net及其变体在面对上述背景-前景高度混淆的挑战时,其性能依然受限

Benefits of technology

[0007]与现有技术相比,本申请提供的一种基于多尺度注意力残差U-Net的园林植物害虫检测方法,其通过金字塔式残差编码网络捕获丰富的多尺度特征,为精准识别奠定基础,引入一种对比增强式特征解码机制:该机制在解码的各层级中,不再被动融合特征,而是主动地对局部背景进行在线统计建模,并基于此模型计算各像素特征的统计离群度。通过这种方式,它能够选择性地仅增强那些统计上显著偏离背景的离群特征(即真实害虫),同时有效抑制外观相似但符合背景自身变化规律的伪目标(如叶脉)。这种从学习绝对外观到辨别相对统计差异的范式转变,从根本上解决了背景-前景混淆问题,能够显著降低虚警率,提升算法在真实多变园林环境中的检测鲁棒性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122929273A_ABST
    Figure CN122929273A_ABST
Patent Text Reader

Abstract

The application relates to the technical field of image processing, and specifically discloses a garden plant pest detection method based on a multi-scale attention residual U-Net. The method captures rich multi-scale features through a pyramid residual coding network, lays a foundation for accurate identification, introduces a contrast-enhanced feature decoding mechanism, actively performs online statistical modeling on local backgrounds in each decoding level, and calculates the statistical outlying degree of each pixel feature based on the model. In this way, it can selectively enhance only the outlying features (i.e. real pests) that are statistically significantly deviated from the background, while effectively suppressing pseudo-targets (such as leaf veins) that are similar in appearance but conform to the change law of the background itself. This paradigm shift from learning absolute appearance to identifying relative statistical difference fundamentally solves the background-foreground confusion problem, can significantly reduce the false alarm rate, and improves the detection robustness of the algorithm in a real and variable garden environment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of image processing technology, and more specifically, to a method for detecting pests in garden plants based on multi-scale attention residual U-Net. Background Technology

[0002] The frequent occurrence of pests and diseases in garden plants is a key factor restricting their quality, causing huge economic losses every year. Traditional pest control methods mainly rely on manual inspections and periodic, large-scale pesticide spraying. These methods are not only costly in terms of manpower and resources and inefficient, making it difficult to respond quickly to early and localized pests, but the overuse of pesticides also poses a serious threat to ecological and environmental safety. Therefore, developing a technology that can quickly, accurately, and automatically detect pests in garden plants is of vital practical significance and application value for achieving precision pesticide application, protecting garden ecology, and promoting sustainable development.

[0003] With the rise of deep learning, especially convolutional neural networks, image-based pest identification technology has made significant progress. Early research mainly used image classification networks to identify cropped pest images, or used general object detection models (such as YOLO and Faster R-CNN) to locate pests in images using bounding boxes. However, these methods have encountered bottlenecks in the complex scenes of garden plants. On the one hand, the background of garden environments is extremely complex and varied. Pests are often small in size and varied in shape, and they are often highly similar to the crop background (such as leaf veins, soil, shadows, water droplet reflections, etc.) in terms of color, texture, and other local features due to their camouflage or location (such as the back of leaves, stem crevices). This background-foreground confusion problem makes existing models prone to generating a large number of false alarms (misclassifying the background as pests) or missed detections, seriously affecting the reliability of detection. On the other hand, pixel-level accurate segmentation is crucial for assessing the infestation area of ​​pests, determining their developmental stage, and achieving more precise spot spraying, but traditional classification and detection models cannot meet this requirement. Encoder-decoder segmentation networks, exemplified by U-Net, offer a fundamental framework for addressing this problem due to their superior skip connection structure, enabling semantic segmentation while preserving high-resolution details. However, the performance of standard U-Net and its variants remains limited when facing the aforementioned challenge of highly obfuscated background-foreground interactions. The root cause lies in the fact that while existing networks excel at learning the absolute appearance features of targets, they generally lack a mechanism to actively learn and utilize the relative relationships between targets and their immediate background, thus failing to effectively distinguish visually similar but fundamentally different patterns.

[0004] Therefore, an optimized pest detection scheme for garden plants is desired. Summary of the Invention

[0005] To address the aforementioned technical problems, this application is proposed. Embodiments of this application provide a method for detecting pests in garden plants based on multi-scale attention residual U-Net.

[0006] According to one aspect of this application, a method for detecting pests in garden plants based on multi-scale attention residual U-Net is provided, comprising: Obtain original images of garden plants; The original images of garden plants are preprocessed to obtain preprocessed images of garden plants. Pyramid-style residual feature encoding is performed on the preprocessed garden plant images to obtain crop visual bottleneck feature maps and a set of hierarchical crop visual coding feature maps. Comparative enhancement feature decoding is performed on the crop visual bottleneck feature map and a set of hierarchical crop visual coding feature maps to obtain the final decoded feature map; Pointwise convolutional encoding and nonlinear activation are applied to the final decoded feature map to obtain the segmentation mask.

[0007] Compared with existing technologies, this application provides a garden plant pest detection method based on multi-scale attention residual U-Net. It captures rich multi-scale features through a pyramid-shaped residual coding network, laying the foundation for accurate identification. It introduces a contrast-enhanced feature decoding mechanism: in each decoding level, this mechanism no longer passively fuses features but actively performs online statistical modeling of the local background and calculates the statistical outlier of each pixel feature based on this model. In this way, it can selectively enhance only those statistically significant outlier features that deviate significantly from the background (i.e., real pests), while effectively suppressing false targets (such as leaf veins) that are similar in appearance but conform to the background's own variation patterns. This paradigm shift from learning absolute appearance to distinguishing relative statistical differences fundamentally solves the background-foreground confusion problem, significantly reduces the false alarm rate, and improves the algorithm's robustness in real and varied garden environments. Attached Figure Description

[0008] The above and other objects, features, and advantages of this application will become more apparent from the more detailed description of the embodiments of this application in conjunction with the accompanying drawings. The drawings are provided to further illustrate the embodiments of this application and form part of the specification. They are used together with the embodiments of this application to explain this application and do not constitute a limitation thereof. In the drawings, the same reference numerals generally represent the same components or steps.

[0009] Figure 1 This is a flowchart of a garden plant pest detection method based on multi-scale attention residual U-Net according to an embodiment of this application; Figure 2This is a schematic diagram of the data flow of the garden plant pest detection method based on multi-scale attention residual U-Net according to an embodiment of this application; Figure 3 This is a flowchart illustrating the preprocessing of original garden plant images to obtain preprocessed garden plant images, based on the multi-scale attention residual U-Net-based garden plant pest detection method according to embodiments of this application. Figure 4 This is a flowchart illustrating the process of performing comparative enhanced feature decoding on a crop visual bottleneck feature map and a set of hierarchical crop visual encoded feature maps to obtain the final decoded feature map, according to an embodiment of the garden plant pest detection method based on multi-scale attention residual U-Net in this application. Figure 5 This is a flowchart illustrating the background-foreground contrast enhancement of a fused feature map to obtain a contrast-enhanced feature map, according to an embodiment of the artificial intelligence-based power system fault analysis and diagnosis method of this application. Detailed Implementation

[0010] Hereinafter, exemplary embodiments according to this application will be described in detail with reference to the accompanying drawings. Obviously, the described embodiments are merely some embodiments of this application, and not all embodiments of this application. It should be understood that this application is not limited to the exemplary embodiments described herein.

[0011] As indicated in this application and claims, unless the context clearly indicates otherwise, the words "a," "an," "an," and / or "the" are not specifically singular and may include plural forms. Generally speaking, the terms "comprising" and "including" only indicate the inclusion of explicitly identified steps and elements, which do not constitute an exclusive list, and the method or apparatus may also include other steps or elements.

[0012] While this application makes various references to certain modules of the systems according to embodiments of this application, any number of different modules can be used and run on user terminals and / or servers. The modules described are merely illustrative, and different aspects of the systems and methods may use different modules.

[0013] Flowcharts are used in this application to illustrate the operations performed by the system according to embodiments of this application. It should be understood that the preceding or following operations are not necessarily performed in exact order. Instead, various steps can be processed in reverse order or simultaneously as needed. Furthermore, other operations can be added to these processes, or one or more steps can be removed from them.

[0014] Hereinafter, exemplary embodiments according to this application will be described in detail with reference to the accompanying drawings. Obviously, the described embodiments are merely some embodiments of this application, and not all embodiments of this application. It should be understood that this application is not limited to the exemplary embodiments described herein.

[0015] To address the technical challenge of background-foreground confusion caused by the high visual similarity between the target and a complex background in garden plant pest detection, this application proposes a garden plant pest detection method based on multi-scale attention residual U-Net. In implementation, after the network decoder initially fuses deep semantic information with shallow detail information, this method does not directly perform subsequent processing. Instead, it first dynamically predicts the foreground region probability of the current feature map through an auxiliary module. Based on this, it performs online statistical modeling on regions identified as background, accurately calculating the mean prototype and covariance matrix describing the background feature distribution. Subsequently, it calculates the Mahalanobis distance of each pixel feature relative to the background statistical distribution. This distance measures the outlier degree of the feature deviating from common background variation patterns. Through this key metric, an adaptive enhanced attention map capable of accurately distinguishing between real targets and camouflaged backgrounds is generated. Ultimately, this attention map was used to guide the enhancement of features identified as statistical outliers (i.e., pests) while suppressing normal variations within the background (such as leaf veins), thereby outputting a high signal-to-noise ratio feature map with significantly sharpened foreground and effectively suppressed background, fundamentally improving the model's detection accuracy and robustness in complex scenes.

[0016] Figure 1 This is a flowchart of a garden plant pest detection method based on multi-scale attention residual U-Net according to an embodiment of this application. Figure 2 The data flow diagram of the garden plant pest detection method based on multi-scale attention residual U-Net according to the embodiments of this application is shown below. Figure 1 and Figure 2 As shown, the garden plant pest detection method based on multi-scale attention residual U-Net according to an embodiment of this application includes: S100, acquiring original images of garden plants; S200, preprocessing the original images of garden plants to obtain preprocessed images of garden plants; S300, performing pyramid-style residual feature encoding on the preprocessed images of garden plants to obtain a crop visual bottleneck feature map and a set of hierarchical crop visual encoding feature maps; S400, performing contrast-enhanced feature decoding on the crop visual bottleneck feature map and the set of hierarchical crop visual encoding feature maps to obtain a final decoded feature map; S500, performing point convolutional encoding and nonlinear activation on the final decoded feature map to obtain a segmentation mask.

[0017] Specifically, in step S100, original images of garden plants are acquired. It should be understood that subsequent automated analysis and intelligent decision-making are based on a digital representation of the objective state of the physical world. Therefore, acquiring original images of garden plants captures and records a real garden scene containing all visual elements, including the target to be detected, the crop itself, and its surrounding environment. This provides the necessary, unprocessed raw data source for subsequent image preprocessing, feature encoding, contrast enhancement decoding, and other algorithmic steps, enabling the entire pest detection method based on multi-scale attention residual U-Net to be started and executed.

[0018] More specifically, in a concrete example of this application, the implementation of the step of acquiring original images of garden plants encompasses the entire process from on-site acquisition to data transmission. First, image acquisition equipment is deployed within the target garden area. This equipment can be a high-resolution digital camera mounted on a fixed pole for fixed-point, continuous monitoring of key areas; or an imaging unit integrated into a mobile platform such as a garden drone or ground inspection robot for conducting cruise-style photography over a wide area. Next, the imaging equipment is configured with precise settings for its image resolution, focal length, exposure compensation, and white balance mode to ensure that the acquired images maintain high clarity and color fidelity even in the constantly changing natural lighting conditions of the forest. After the equipment configuration is complete, image acquisition is performed according to a preset monitoring plan or real-time control commands, capturing a snapshot of the target area's instantaneous state and encoding it into a digital image file. Finally, the acquired digital image file is transmitted from the front-end acquisition device to a local edge computing node or a remote cloud server via a wireless communication module, such as a 5G network, or via a wired connection. This server is equipped with the pest detection algorithm described in this invention, thus completing the input of the original image.

[0019] Specifically, in step S200, the original images of garden plants are preprocessed to obtain preprocessed images. It should be understood that original images of garden plants directly acquired from front-end devices suffer from problems such as varying sizes, changing shooting angles, and complex lighting conditions. Furthermore, their data formats and numerical ranges are not directly applicable to the computational requirements of deep neural networks. Additionally, limited labeled data cannot cover all real-world scene variations, easily leading to insufficient model generalization ability. Therefore, in the technical solution of this application, the original images of garden plants are further preprocessed to obtain preprocessed images. This eliminates the differences between the original data, expands the diversity of training samples through data augmentation, and converts all image data into a unified, standardized tensor format. This significantly improves the training stability and convergence speed of the subsequent neural network model, enhances the model's generalization ability and robustness to changes in lighting, scale, and viewing angle, thereby providing a high-quality, standardized data foundation for achieving high-precision pest detection.

[0020] Figure 3 This is a flowchart illustrating the preprocessing of original garden plant images to obtain preprocessed garden plant images, according to the garden plant pest detection method based on multi-scale attention residual U-Net as described in this application embodiment. Figure 3 As shown, step S200 includes: S210, performing geometric morphology normalization and enhancement on the original image of garden plants to obtain a geometrically enhanced image; S220, performing photometric perturbation on the geometrically enhanced image to obtain a photometric enhanced image; S230, performing data type conversion and numerical standardization on the photometric enhanced image to obtain a preprocessed image of garden plants.

[0021] Accordingly, in step S210, the original images of garden plants are geometrically normalized and enhanced to obtain geometrically enhanced images. It should be understood that due to the diversity of front-end acquisition devices and the uncontrollability of the shooting process, the acquired original images of garden plants vary in spatial resolution, and the pose, scale, and position of the target pests and their attached plants in the images are highly random. Therefore, in the technical solution of this application, the original images of garden plants are further geometrically normalized and enhanced to obtain geometrically enhanced images. This standardizes the dimensions of all input images to the fixed size required by the neural network and generates a large number of training samples online with different rotation angles, flip states, and other geometrical changes. This ensures the consistency of data flow processing within the network and greatly improves the model's adaptability and invariance to various pose, scale, and positional changes that the target may exhibit in real-world scenarios, thereby enhancing the generalization performance and robustness of the final pest detection.

[0022] More specifically, in a concrete example of this application, when performing the geometric normalization and enhancement step, the input original image of the garden plants is first subjected to size normalization processing. This processing uses a bicubic interpolation algorithm to accurately resample the original images of varying sizes to a preset, fixed input size, such as 512×512 pixels. After size normalization, the image is then subjected to geometric enhancement operations to expand data diversity. Specifically, the image is randomly horizontally flipped with a 50% probability to simulate the situation where the target appears on the left or right sides of the crop. Subsequently, an angle value is randomly selected from a preset angle range, such as -10 degrees to +10 degrees, and the image is rotated using this angle to simulate different shooting perspectives. After the rotation transformation, random cropping can also be performed, that is, the image is first slightly enlarged, and then the area of ​​the original target size is randomly cropped from it. After this series of normalization and enhancement operations, the resulting image is the output of this step, the geometrically enhanced image.

[0023] Accordingly, in step S220, the geometrically enhanced image is perturbed by photometric properties to obtain a photometrically enhanced image. It should be understood that the open environment in which garden plants are located leads to significant uncertainty and dynamic changes in lighting conditions (such as sunlight intensity and color temperature) and imaging effects (such as contrast and saturation), and the limited dataset collected cannot fully cover all possible lighting scenarios. Therefore, in the technical solution of this application, the geometrically enhanced image is further perturbed by photometric properties to obtain a photometrically enhanced image, thereby synthesizing a large number of image samples with different brightness, contrast, saturation, and hue characteristics online, thus simulating the complex and varied lighting environment in the real world at the data level. This forces the neural network model to learn more fundamental pest characteristics that are insensitive to changes in photometric intensity, reducing its dependence on specific lighting conditions, thereby significantly enhancing its detection stability and generalization ability in all weather conditions and multiple scenarios.

[0024] Specifically, in this embodiment, perturbing the photometric properties of a geometrically enhanced image to obtain a photometrically enhanced image includes: generating a brightness adjustment factor, a contrast adjustment factor, a saturation adjustment factor, and a hue adjustment factor through perturbation sequence randomization; and adjusting the brightness, contrast, saturation, and hue of the geometrically enhanced image based on these factors to obtain the photometrically enhanced image. More specifically, the process of perturbing the photometric properties of the geometrically enhanced image first determines a random application order for the current input image, including four transformations: brightness, contrast, saturation, and hue, through perturbation sequence randomization. Then, the brightness adjustment factor, contrast adjustment factor, saturation adjustment factor, and hue adjustment factor are generated through perturbation sequence randomization. Specifically, brightness, contrast, and saturation adjustment factors are independently and randomly selected from a preset multiplicative range, such as [0.7, 1.3]. Simultaneously, a hue adjustment factor is randomly selected from a preset additive range, such as [-0.1, 0.1]. Finally, based on these generated adjustment factors, brightness, contrast, saturation, and hue adjustments are sequentially performed on the input geometrically enhanced image according to the random order determined in the first step. For example, if the random order is determined to be "saturation-brightness-hue-contrast," the image's saturation is adjusted first, and then brightness transformation is applied to the adjusted result, and so on, until all photometric transformations are completed. The resulting photometrically enhanced image is the output of this step.

[0025] Accordingly, in step S230, the photometrically enhanced image undergoes data type conversion and numerical standardization to obtain a preprocessed image of the garden plants. It should be understood that since the image after photometric perturbation still uses integer data representation, its numerical range is large and unevenly distributed. Furthermore, its dimensional structure does not conform to the input specifications of deep neural networks, which directly affects the stability of numerical computation and the convergence efficiency of model training. Therefore, in the technical solution of this application, the photometrically enhanced image is further converted to a data type and standardized to obtain a preprocessed image of the garden plants. This converts the pixel representation of the image from integer to floating-point, and through standardization operations, adjusts its numerical distribution to an ideal distribution with a mean of zero and a standard deviation of one, ultimately reconstructing a four-dimensional tensor that conforms to the network input protocol. This ensures that gradients propagate effectively in the network, avoids training instability caused by differences in numerical scales, and thus significantly improves the efficiency of model training and the final performance.

[0026] More specifically, in a concrete example of this application, the implementation process of data type conversion and numerical standardization for a photoluminescence-enhanced image is as follows: First, the data type of the image's pixel values ​​is uniformly converted from 8-bit unsigned integers to 32-bit floating-point numbers. Next, Z-score standardization is performed, that is, for the red, green, and blue channels, the pixel mean and standard deviation of the corresponding channels, pre-calculated on the entire training dataset, are used to subtract the mean and then divide by the standard deviation for each pixel value of the current image. After this, the dimensions of the standardized data tensor are rearranged, changing its storage order from "height, width, number of channels" to "number of channels, height, width". Finally, a batch dimension of size 1 is added to the front of the data tensor, thus forming a four-dimensional tensor that conforms to the input specifications of the subsequent neural network. This tensor is the preprocessed garden plant image that is the final output of this step.

[0027] Specifically, in step S300, the preprocessed garden plant image is subjected to pyramid-style residual feature encoding to obtain a crop visual bottleneck feature map and a set of hierarchical crop visual encoding feature maps. It should be understood that, due to the significant multi-scale characteristics of garden plant pest targets, and the fact that their local features are often highly similar to the complex crop background, a single-level feature representation cannot simultaneously capture the high-frequency details required for accurate localization and the global context required for semantic understanding. Furthermore, constructing a network capable of learning deep abstract features faces training difficulties due to gradient vanishing. Therefore, in the technical solution of this application, the preprocessed garden plant image is further subjected to pyramid-style residual feature encoding to obtain a crop visual bottleneck feature map and a set of hierarchical crop visual encoding feature maps. This constructs a feature pyramid through a layer-by-layer downsampling encoder structure, which outputs feature maps with different receptive fields and semantic depths at different levels. Simultaneously, a residual connection mechanism is used to ensure effective training of the deep network. In this way, while retaining the fine spatial perception capability for tiny pest targets, it can obtain a powerful global semantic understanding capability for complex scenes, and provide a rich and high-quality feature foundation containing information from the bottom edge and texture to the high-level category information for the subsequent decoder to accurately reconstruct the segmentation mask.

[0028] More specifically, in this embodiment, pyramid-style residual feature encoding is performed on the preprocessed garden plant image to obtain a crop visual bottleneck feature map and a set of hierarchical crop visual encoding feature maps. This includes: performing shallow feature mapping on the preprocessed garden plant image to obtain an initial crop visual feature map; and performing iterative hierarchical feature abstraction and residual downsampling on the initial crop visual feature map to obtain a crop visual bottleneck feature map and a set of hierarchical crop visual encoding feature maps. That is, in a specific example of this application, shallow feature mapping is first performed on the preprocessed garden plant image. This operation feeds the input preprocessed image tensor into an initial convolutional layer with a large kernel size, such as 7×7, and a specific stride, such as 2, followed by batch normalization and ReLU nonlinear activation. This step quickly maps the input image from pixel space to a high-dimensional feature space and performs initial size downsampling, thereby generating an initial crop visual feature map. Subsequently, iterative hierarchical feature abstraction and residual downsampling are performed on the initial crop visual feature map. This process is divided into multiple encoding stages, such as four stages. At each stage, the input feature map is first processed through a set of cascaded residual modules for deep feature extraction. Each residual module contains two parallel paths: one is a transformation path consisting of convolution, batch normalization, and activation functions; the other is a shortcut connection that directly connects the input to the output. After processing by the residual module group, the resulting feature map is saved as a crop visual encoding feature map for that layer, for use by the subsequent decoder. Next, this feature map is downsampled through a 2×2 max-pooling layer, halving its spatial resolution while doubling its number of channels. The downsampled result serves as the input for the next encoding stage. After all encoding stages have iterated, the final feature map is the crop visual bottleneck feature map.

[0029] Specifically, in step S400, a comparative enhancement feature decoding is performed on the crop visual bottleneck feature map and a set of hierarchical crop visual coding feature maps to obtain the final decoded feature map. It should be understood that the hierarchical feature maps extracted in the encoder, especially the shallow features containing rich spatial details, inevitably mix in a large amount of morphologically similar but essentially background interference information, such as leaf vein textures, while preserving the fine outline of the pest target. If these unfiltered features are simply fused with deep semantic features directly in the decoding stage, it is very easy for the model to confuse in the final pixel discrimination, misidentifying background noise as foreground targets. Therefore, in the technical solution of this application, a comparative enhancement feature decoding is further performed on the crop visual bottleneck feature map and a set of hierarchical crop visual coding feature maps to obtain the final decoded feature map. This implements an active and dynamic feature selection and enhancement strategy in the process of restoring the image spatial resolution layer by layer. The core of this strategy is to explicitly model and utilize the statistical differences between the foreground and background. This approach fundamentally solves the problem of target-background confusion, generating a high signal-to-noise ratio feature representation where the foreground target is highly highlighted and the complex background is effectively suppressed, laying a solid foundation for achieving accurate pixel-level segmentation.

[0030] Figure 4 This document describes a flowchart illustrating a method for performing enhanced feature decoding on a normalized context event stream to obtain a dynamic influence vector, based on an embodiment of this application. The method involves comparing a crop visual bottleneck feature map with a set of hierarchical crop visual encoded feature maps to obtain the final decoded feature map. Figure 4 As shown, step S400 includes: S410, receiving the lower-layer decoded feature map output from a deeper decoder; S420, extracting the corresponding level feature map from the crop visual bottleneck feature map and a set of hierarchical crop visual coding feature maps as encoder skip feature maps; S430, performing attention-gated skip connections on the encoder skip feature map based on the lower-layer decoded feature map to obtain a gated coding feature map; S440, performing preliminary fusion on the gated coding feature map and the lower-layer decoded feature map to obtain a fused feature map; S450, performing background-foreground contrast enhancement on the fused feature map to obtain a contrast-enhanced feature map.

[0031] Accordingly, in steps S410 and S420, the lower-layer decoded feature map output from the deeper-layer decoder is received, and the corresponding-level feature map is extracted from the crop visual bottleneck feature map and a set of hierarchical crop visual coding feature maps as the encoder skip feature map. It should be understood that in the decoding path of the U-Net architecture, in order to recover the spatial resolution of the feature maps layer by layer and ultimately generate a segmentation mask with the same size as the original image, each decoding stage must combine features from deeper layers containing rich semantic information with features from the corresponding level of the encoder that preserve fine spatial details. Without these two key inputs, the decoder cannot simultaneously handle high-level semantic understanding and low-level detail reconstruction, resulting in segmentation results that are either blurry at the boundaries or semantically incorrect. Therefore, in the technical solution of this application, the lower-layer decoded feature map output from the deeper-layer decoder is received, and the corresponding-level feature map is extracted from the crop visual bottleneck feature map and a set of hierarchical crop visual coding feature maps as the encoder skip feature map. This prepares all the necessary information for feature fusion and optimization in the current decoding stage, namely, high-level semantic guidance information and high-resolution spatial detail information at the same scale. This ensures that the decoding process can effectively integrate multi-scale features at each level, providing the necessary data foundation for the final generation of a fine and accurate pest segmentation mask.

[0032] More specifically, in a concrete example of this application, the process is performed iteratively from bottom to top at each stage of the decoder (except the lowest level). First, a feature map output from its immediate neighboring, deeper decoder module is received. This feature map is upsampled through a 2×2 transposed convolutional layer, doubling its spatial resolution while halving its number of channels, resulting in a lower-level decoded feature map that matches the target size of the current decoding stage. Simultaneously, from a set of hierarchical crop visual encoded feature maps pre-stored in the encoding stage, the feature map with the exact same spatial resolution as the current lower-level decoded feature map is directly extracted by index and designated as the encoder skip feature map for this stage. At this point, a feature map from the decoding path and a feature map from the encoding path required for the current decoding stage are ready for use by subsequent attention gating and fusion modules.

[0033] Accordingly, in step S430, attention-gated skip connections are performed on the encoder skip feature map based on the lower-layer decoded feature map to obtain a gated encoded feature map. It should be understood that since the skip feature map directly from the encoder, while containing high-resolution details crucial for accurate localization, inevitably carries a large amount of redundant information and noise from complex backgrounds unrelated to the target. Directly fusing it with features containing high-level semantic information in the decoder would create a semantic gap and interfere with the model's accurate reconstruction of the target region. Therefore, in the technical solution of this application, attention-gated skip connections are further performed on the encoder skip feature map based on the lower-layer decoded feature map to obtain a gated encoded feature map. This utilizes the global contextual information contained in the deep feature map as guidance to perform spatially selective filtering of the shallow feature map, thereby actively suppressing the feature response of the background region while enhancing the feature representation of the target region. In this way, effective artifact removal can be completed before high-resolution detail information is passed to the decoding path, generating a gated coding feature map with a higher signal-to-noise ratio and stronger target relevance, providing a higher quality input for subsequent feature fusion and final accurate segmentation.

[0034] More specifically, in a concrete example of this application, the implementation of this process comprises two core steps. First, the lower-layer decoded feature map is compared with the corresponding encoder skip features. Figure 1 A spatial attention module is used to generate a spatial attention weight map. Within this module, the two input feature maps are linearly transformed through independent 1×1 convolutional layers. The transformed results are then element-wise summed and activated by a ReLU function. This activated feature map is then compressed through another 1×1 convolutional layer and finally passed through a sigmoid function, generating a single-channel spatial attention weight map with unchanged spatial dimensions and values ​​ranging from 0 to 1. Next, a positional dot product is calculated between the original encoder skip feature map and this spatial attention weight map. This operation multiplies each weight value in the attention weight map by its corresponding feature vector in the spatial encoder skip feature map, selectively scaling the features. After this operation, feature responses in regions unrelated to the target are effectively suppressed by multiplying by weights close to 0, while features in target-related regions are preserved by multiplying by weights close to 1. The final result is the output of this step: the gated encoded feature map.

[0035] Accordingly, in step S440, the gated encoded feature map and the lower-level decoded feature map are initially fused to obtain a fused feature map. It should be understood that the lower-level decoded feature map, containing only high-level semantic information, is relatively coarse in spatial detail, while the encoder skip feature map, after attention-gated filtering, retains accurate local edge and texture information, but lacks sufficient semantic context for explicit pixel classification. Therefore, in the technical solution of this application, the gated encoded feature map and the lower-level decoded feature map are further initially fused to obtain a fused feature map, thereby effectively integrating the filtered high-resolution spatial details provided by the encoder with the context-rich deep semantic information transmitted by the decoder. This generates a comprehensive feature representation that combines accurate spatial localization capabilities with high-level semantic discrimination capabilities, providing a more complete and high-quality input foundation for subsequent contrast enhancement processing and final segmentation mask generation.

[0036] Specifically, in a concrete example of this application, the preliminary fusion process of the gated encoded feature map and the lower-level decoded feature map is as follows: First, the two are concatenated along their channel dimensions. This operation juxtaposes the high-frequency spatial detail features from the encoding path with the deep semantic features from the decoding path in the same feature tensor, such that the number of channels in the concatenated feature map is the sum of the number of channels in the two input feature maps. Subsequently, the concatenated high-dimensional feature map is fed into a fusion module containing two sequential convolutional blocks. Each convolutional block consists of a 3×3 convolutional layer, a batch normalization layer, and a ReLU nonlinear activation function. After processing by this fusion module, the resulting feature map is the final output of this step, whose channel dimension is effectively integrated and reduced, preparing for the subsequent contrast enhancement step.

[0037] Accordingly, in step S450, the fused feature map undergoes background-foreground contrast enhancement to obtain a contrast-enhanced feature map. It should be understood that although the feature map after initial fusion combines semantic and spatial information, it still faces a core challenge: certain complex background structures, such as crop leaf veins and reflective water droplets, may have feature representations that are numerically highly similar to real pest targets, leading to significant confusion between the two. Conventional fusion alone cannot fundamentally separate them. In other words, in the above embodiment, when processing the task of detecting pests in garden plants, a critical bottleneck arises due to a large number of false alarms caused by background-foreground confusion. The fundamental technical reason lies in the design limitations of the contrast enhancement mechanism used to distinguish between foreground and background. Specifically, this mechanism makes an oversimplified homogeneity assumption about the complex and varied garden scene background. It abstracts all different forms of background information in a local area into a single, global background prototype vector by calculating a weighted average. However, the actual background of garden plants exhibits significant heterogeneity. For example, a single crop leaf may simultaneously contain smooth leaf tissue, sharply textured veins, reflective water droplets, and irregularly shaped shadows. A single average prototype vector cannot adequately capture the diversity and variance within the background itself, resulting in insufficient representation of the background. Furthermore, the linear enhancement method employed by this mechanism lacks consideration of the statistical relationship between the feature distributions of the foreground and background. It determines the enhancement intensity solely based on the numerical difference between the feature vector and a single background prototype, ignoring a crucial special relationship: the covariance of the background feature distribution. In real-world scenarios, the feature vector of a pixel belonging to the background (such as a leaf vein) may deviate numerically from the background mean, but its deviation direction often aligns with the direction of common background variation patterns, i.e., it changes along the principal axis with high covariance. Conversely, the feature deviation direction of a pixel belonging to the foreground, such as a pest, is likely to be a low-probability direction in the background distribution. The original mechanism cannot effectively distinguish between these two distinct deviations, and therefore easily misclassifies backgrounds with special textures, such as leaf veins, as foregrounds and performs incorrect enhancements. This directly leads to insufficient robustness of the model's detection results and a high false alarm rate.

[0038] To address the shortcomings revealed by the aforementioned technical reasons, this improved solution proposes an adaptive contrast enhancement technique based on background statistical distribution. This technique no longer abstracts the background as an isolated average point, but dynamically models it as a multidimensional statistical distribution containing mean and covariance, and performs adaptive nonlinear contrast enhancement based on this distribution. In this technical solution, the fused feature map is further enhanced with background-foreground contrast to obtain a contrast-enhanced feature map. This avoids treating the background as a single average point, instead dynamically and adaptively constructing a multidimensional statistical distribution model of background features containing mean and covariance for each local region. Based on this model, the statistical outlier degree of each feature point is calculated, thus achieving a nonlinear, statistically differential adaptive feature enhancement. This effectively distinguishes between two distinct types of deviations: deviations belonging to common background variation patterns (such as leaf veins) and anomalous deviations truly belonging to the foreground target (such as pests). By actively enhancing the latter and suppressing the former, this step fundamentally eliminates background-foreground confusion, significantly improves the robustness of the final detection results, and drastically reduces the false alarm rate.

[0039] Figure 5 This is a flowchart illustrating the background-foreground contrast enhancement of a fused feature map to obtain a contrast-enhanced feature map, according to an embodiment of the garden plant pest detection method based on multi-scale attention residual U-Net, as described in this application. Figure 5 As shown, step S450 includes: S451, inputting the fused feature map into the foreground prediction module to obtain a foreground mask; S452, performing background feature statistical distribution modeling based on the fused feature map and the foreground mask to obtain a background mean prototype and a background inverse covariance matrix; S453, performing dynamic weighting of the foreground outlier on the fused feature map and the foreground mask based on the background mean prototype and the background inverse covariance matrix to obtain an adaptive enhanced attention map; S454, performing adaptive feature enhancement and reorganization on the adaptive enhanced attention map, the background mean prototype, and the fused feature map to obtain a contrast enhanced feature map.

[0040] Specifically, in step S451, the fused feature map is input into the foreground prediction module to obtain a foreground mask. It should be understood that the feature map after preliminary fusion still faces the critical bottleneck of numerous false alarms due to background-foreground confusion, especially for backgrounds with special textures commonly found in garden plant scenes, such as sharp leaf veins or reflective water droplets. Their feature representations may numerically deviate from the background mean, but without differentiation, they are easily erroneously amplified, leading to insufficient robustness and a high false alarm rate. Therefore, in the technical solution of this application, the fused feature map is input into the foreground prediction module to obtain a foreground mask. This allows for a preliminary and rapid foreground-background attribution probability judgment for each pixel in the fused feature map. Its core purpose is not to obtain the final segmentation result, but rather to provide a clear and distinguishable regional division basis for subsequent background statistical distribution modeling. In this way, the pixels in the feature map can be initially divided into a high-probability background set and a high-probability foreground set, laying the foundation for subsequent dynamic and adaptive statistical modeling (including mean and covariance) only for the background region. This enables the subsequent contrast enhancement mechanism to effectively distinguish between two types of deviations that are completely different in nature: deviations that belong to common change patterns of the background itself, and low-probability deviations that truly belong to the foreground target.

[0041] More specifically, in a concrete example of this application, the foreground prediction module implementing this step consists of a lightweight convolutional sub-network. This module receives the fused feature map as input and first refines the features by passing it through a 3×3 convolutional layer, followed by a batch normalization layer and a ReLU non-linear activation function. Then, the processed feature map is input into a 1×1 convolutional layer, whose output channel number is set to 1, mapping the high-dimensional feature vector to a single scalar logical value. Finally, a Sigmoid activation function is applied to this logical value to generate a single-channel foreground mask with the same spatial resolution as the fused feature map, where the value of each pixel is in the range of 0 to 1, representing the probability estimate that the pixel at the corresponding spatial location belongs to the foreground object.

[0042] Specifically, in step S452, background feature statistical distribution modeling is performed based on the fused feature map and foreground mask to obtain the background mean prototype and background inverse covariance matrix. It should be understood that, although the fused feature map obtained in the previous steps has initially integrated semantic and spatial information, it is essentially still an expression of absolute features and fails to explicitly address the inherent background heterogeneity problem of garden plant scenes. A simple, global background prototype vector cannot fully capture the diversity and variance within the background itself; for example, a single crop leaf may simultaneously contain smooth leaf tissue, sharp veins, reflective water droplets, and irregularly shaped shadows. If the enhancement intensity is determined solely based on the numerical difference between the feature vector and a single background mean, a crucial special relationship will inevitably be ignored: the covariance of the background feature distribution. Therefore, in the technical solution of this application, background feature statistical distribution modeling is further performed based on fused feature maps and foreground masks to obtain the background mean prototype and background inverse covariance matrix. This avoids abstracting the background as an isolated average point, but instead utilizes the region division provided by the foreground mask to dynamically construct a complete multidimensional statistical distribution model that describes the central position, dispersion, and variation pattern of the feature pixels identified as background. This provides the necessary statistical basis for subsequently distinguishing between two distinctly different deviations: one is background pixels that deviate from the mean but whose deviation direction is consistent with the common variation pattern of the background itself (such as leaf veins); the other is foreground pest pixels whose deviation direction belongs to a low-probability direction in the background distribution.

[0043] More specifically, in a concrete example of this application, the modeling process first calculates a background mean prototype based on a foreground mask. This is accomplished by weighting the feature vectors of all pixels in the fused feature map, where the background weight of each pixel is determined by the complement of its corresponding value in the foreground mask, i.e., (1 - foreground probability). Through this weighted averaging, the features of high-probability background pixels contribute more to the mean calculation, thus obtaining a background mean prototype vector that accurately represents the center position of the background features. This is expressed by the following formula: ; in, Represents the prototype of the background mean. Let be the probability value of the foreground mask at pixel (i,j). This is the feature vector of the fused feature map at pixel (i,j).

[0044] Next, based on the calculated mean, the weighted covariance matrix of the background features is further calculated. The calculation method is as follows: For each pixel's feature vector, subtract the background mean prototype to obtain a centered vector. Then, calculate the outer product of this centered vector and its transpose. Multiply this outer product by the background weight (1 - foreground probability) corresponding to that pixel. Summing the weighted outer product matrices obtained from all pixels and dividing by the total sum of background weights yields the background covariance matrix. This covariance matrix not only measures the variation range of each feature channel but, more importantly, captures the linear correlation between different feature channels. For example, it can mathematically describe the pattern where leaf veins typically exhibit strong synchronous changes in the texture and brightness channels. Finally, to ensure the invertibility of the matrix, a small regularization term is added to the diagonal of the covariance matrix, and the resulting matrix is ​​inverted to obtain one of the final outputs of this step: the background inverse covariance matrix. It is expressed by the following formula: ; in, The background inverse covariance matrix, Represents the transpose of a vector. This is a diagonal regularization term added to ensure matrix invertibility. This results in a statistical model that comprehensively describes the central location, dispersion, and variation patterns of background features, providing essential statistical basis for subsequent accurate and discriminative contrast enhancement.

[0045] Specifically, in step S453, based on the background mean prototype and the background inverse covariance matrix, the fused feature map and foreground mask are dynamically weighted according to foreground outlier to obtain an adaptive enhanced attention map. It should be understood that since a statistical distribution model of the background alone is insufficient to directly enhance features, an advanced metric is needed to replace simple Euclidean distance to assess the probability that each pixel feature belongs to the true foreground, i.e., a statistical outlier. If the direction of deviation is not distinguished, a feature, although numerically deviating from the background mean, is still essentially part of the background if its deviation direction matches a common change pattern described by the background covariance matrix (e.g., leaf veins); conversely, if its deviation direction is a rare change pattern in the background (e.g., pests), then it is highly likely to be a true foreground feature. Therefore, in the technical solution of this application, the foreground outlier is dynamically weighted based on the background mean prototype and the background inverse covariance matrix to obtain an adaptive enhanced attention map. This introduces a statistical distance that takes into account the data distribution pattern, namely Mahalanobis distance, to calculate the true outlier of each pixel feature relative to the modeled background distribution, and combines the outlier with the previously obtained foreground prior probability.

[0046] More specifically, in a concrete example of this application, the process of performing this step begins by calculating the foreground outlier. For each pixel feature vector in the fused feature map... Calculate the squared Mahalanobis distance relative to the modeled background statistical distribution. It can be expressed by the following formula: ; in, The background inverse covariance matrix, This serves as the prototype for the background mean. In particular, it's worth noting that Mahalanobis distance is essentially a statistical distance calculation that takes into account the data distribution pattern. When the features of a pixel (such as a leaf vein) deviate from the background mean, but the direction of deviation aligns with the common variation pattern described by the background covariance matrix, its Mahalanobis distance will be calculated to be small; conversely, when the features of a pixel (such as a pest) deviate from a rare variation pattern in the background, its Mahalanobis distance will be very large.

[0047] Subsequently, the graph composed of the squared Mahalanobis distances of all pixels is non-linearly mapped using a Sigmoid function to obtain a preliminary outlier weight map. Finally, this outlier weight map is element-wise multiplied with the foreground mask generated in the previous step, which serves as the foreground prior probability, to generate the final adaptive enhanced attention map. This is expressed by the following formula: ; in, To adaptively enhance the weight value of the attention map at pixel (i,j), This is the Sigmoid function. By generating an adaptive weight map that accurately reflects the true outlier status of each pixel, this weight map provides highly selective guidance for subsequent enhancement operations, assigning high enhancement weights only to pixels that are statistically highly unlikely to belong to the background (i.e., the real pest targets), thereby achieving precise highlighting of the foreground and fundamental suppression of false targets in complex backgrounds.

[0048] Specifically, in step S454, adaptive feature enhancement and recombination are performed on the adaptive enhanced attention map, the background mean prototype, and the fused feature map to obtain a contrast-enhanced feature map. It should be understood that since the previous steps only generated an adaptive enhanced attention map that guides the direction and intensity of feature enhancement, without actually changing the feature representation of the fused feature map itself, the problem of foreground and background confusion in the feature map still exists if the final enhancement and recombination operation is not performed. Therefore, in the technical solution of this application, adaptive feature enhancement and recombination are further performed on the adaptive enhanced attention map, the background mean prototype, and the fused feature map to obtain a contrast-enhanced feature map, thereby accurately applying the carefully calculated adaptive enhancement weights from the previous steps to the feature map, completing the final feature enhancement. This is a process of achieving precise guidance of enhancement intensity, the purpose of which is to differentiate the features based on the statistical attributes of each pixel.

[0049] More specifically, in a concrete example of this application, firstly, the modeled background mean prototype vector is broadcast to the same spatial dimension as the fused feature map. Then, the difference between the fused feature map and the broadcasted background prototype map is calculated, resulting in an enhancement direction vector map representing the enhancement direction of each pixel feature. Subsequently, the enhancement direction vector map is weighted element-wise using the adaptive enhancement attention map obtained in the previous step. This weighting operation is achieved by multiplying the scalar weight value at each position in the attention map with the entire enhancement direction vector corresponding to its spatial position. Finally, the weighted enhancement vector map is added element-wise to the original fused feature map, resulting in the final contrast enhancement feature map after adaptive enhancement and reorganization. Adaptive feature enhancement and reorganization are performed on the adaptive enhancement attention map, background mean prototype, and fused feature map using the following formula: ; in, It is a contrast-enhanced feature map. It is an adaptive enhanced attention map. Represents element-wise multiplication. As the background mean prototype, For broadcast algorithms, To enhance the direction vector map, To fuse feature maps, for pest regions determined as true foreground by Mahalanobis distance, the corresponding attention weight A is close to 1, enhancing the signal. The feature is significantly sharpened when fully utilized; however, for regions such as leaf veins that are determined by Mahalanobis distance to be variations within the background, the weight A is close to 0, and the enhanced signal is effectively suppressed. The ultimate goal and effect of this step is to output a high signal-to-noise ratio feature map where foreground features are greatly highlighted and complex background features are effectively suppressed, paving the way for subsequent feature learning by the decoder and the final pixel classification task.

[0050] The aforementioned optimization mechanism solves the background-foreground confusion problem caused by the high similarity in local features between target pests and the background (such as crop veins, soil, and shadows) in complex visual scenes like gardens. The technical effects achieved through this approach are significant. It transforms the simple matching problem based on absolute feature differences in traditional models into an online statistical hypothesis test performed at each pixel location. This mechanism enables the neural network model to learn and distinguish relative statistical impossibilities, rather than relying solely on absolute appearance similarity. Ultimately, this significantly reduces the false alarm rate of the entire pest detection system, especially for pests with camouflage characteristics that blend into the background, thus significantly improving the detection accuracy and comprehensively enhancing the robustness and reliability of the detection algorithm in realistic and varied garden environments.

[0051] Specifically, in step S500, the final decoded feature map is subjected to pointwise convolutional encoding and nonlinear activation to obtain a segmentation mask. It should be understood that since the final decoded feature map obtained after contrast-enhanced decoding is still a high-dimensional multi-channel feature representation, it contains a rich feature vector at each pixel location, rather than a direct class assignment probability usable for binary decision-making. To complete the mapping from the complex feature space to the final pixel-level classification result, this high-dimensional representation must be converted into a clear and interpretable single-channel probability map. Therefore, in the technical solution of this application, the final decoded feature map is further subjected to pointwise convolutional encoding and nonlinear activation to obtain a segmentation mask, thereby performing a final pixel-by-pixel classification decision. A 1×1 pointwise convolution is used to linearly combine and reduce the dimensionality of the feature vector of each pixel, followed by a probabilistic mapping using a nonlinear activation function. In this way, all the discriminative information about pests learned by the network from deep features can be integrated and compressed into a single scalar value, which directly quantifies the confidence that each pixel belongs to the pest category, thereby generating the final pixel-level pest detection result that is exactly the same size as the original image.

[0052] More specifically, in a concrete example of this application, the process is implemented as follows. First, the final decoded feature map is received as input. This feature map has the same spatial resolution as the original input image but contains multiple feature channels, such as 64 channels. Next, this multi-channel feature map is input into a point convolutional layer, specifically a convolutional layer with a kernel size of 1×1. The key configuration of this convolutional layer is that its output channel number is set to 1. This operation is equivalent to applying a fully connected layer to the 64-dimensional feature vector at each pixel location, linearly transforming it into a single-dimensional scalar output, which is referred to as a logistic value in machine learning context. Subsequently, this single-channel logistic value map is input into a sigmoid non-linear activation function. This function independently performs a sigmoid transformation on each logistic value in the map, mapping its numerical range from the unbounded real number domain to a closed interval between 0 and 1. After this nonlinear activation, the resulting single-channel map is the final segmentation mask output in this step. The value of each pixel, for example, 0.85, directly represents that the probability of that location belonging to a garden plant pest is 85%.

[0053] In summary, the garden plant pest detection method based on multi-scale attention residual U-Net according to the embodiments of this application is elucidated. It captures rich multi-scale features through a pyramid-shaped residual coding network, laying the foundation for accurate identification. A contrast-enhanced feature decoding mechanism is introduced: in each decoding level, this mechanism no longer passively fuses features but actively performs online statistical modeling of the local background and calculates the statistical outlier of each pixel feature based on this model. In this way, it can selectively enhance only those statistically significant outlier features that deviate significantly from the background (i.e., real pests), while effectively suppressing false targets (such as leaf veins) that are similar in appearance but conform to the background's own variation patterns. This paradigm shift from learning absolute appearance to distinguishing relative statistical differences fundamentally solves the background-foreground confusion problem, significantly reduces the false alarm rate, and improves the algorithm's robustness in real and varied garden environments.

[0054] The various embodiments of this disclosure have been described above. These descriptions are exemplary and not exhaustive, nor are they limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen to best explain the principles, practical application, or improvement of the technology in the market, or to enable others skilled in the art to understand the embodiments disclosed herein.

Claims

1. A method for detecting pests in garden plants based on multi-scale attention residual U-Net, characterized in that, include: Obtain original images of garden plants; The original images of garden plants are preprocessed to obtain preprocessed images of garden plants. Pyramid-style residual feature encoding is performed on the preprocessed garden plant images to obtain crop visual bottleneck feature maps and a set of hierarchical crop visual coding feature maps. Comparative enhancement feature decoding is performed on the crop visual bottleneck feature map and a set of hierarchical crop visual coding feature maps to obtain the final decoded feature map; Pointwise convolutional encoding and nonlinear activation are applied to the final decoded feature map to obtain the segmentation mask.

2. The method for detecting garden plant pests based on multi-scale attention residual U-Net according to claim 1, characterized in that, Preprocessing the original images of garden plants to obtain preprocessed images of garden plants includes: Geometric morphology normalization and enhancement are performed on the original images of garden plants to obtain geometrically enhanced images; Photometric properties perturbation is applied to geometrically enhanced images to obtain photometrically enhanced images; Data type conversion and numerical standardization were performed on the photometric enhanced image to obtain the preprocessed garden plant image.

3. The method for detecting garden plant pests based on multi-scale attention residual U-Net according to claim 2, characterized in that, To obtain a photometrically enhanced image, the photometric properties of the geometrically enhanced image are perturbed, including: Brightness adjustment factor, contrast adjustment factor, saturation adjustment factor, and hue adjustment factor are generated by randomizing the perturbation sequence. The brightness, contrast, saturation, and hue of the geometrically enhanced image are adjusted using brightness adjustment factors, contrast adjustment factors, saturation adjustment factors, and hue adjustment factors, respectively, to obtain a luminance-enhanced image.

4. The method for detecting garden plant pests based on multi-scale attention residual U-Net according to claim 1, characterized in that, Pyramid-style residual feature encoding is performed on the preprocessed garden plant images to obtain crop visual bottleneck feature maps and a set of hierarchical crop visual coding feature maps, including: Shallow feature mapping is performed on the preprocessed garden plant images to obtain the initial visual feature maps of the crops. Iterative hierarchical feature abstraction and residual downsampling are performed on the initial crop visual feature map to obtain the crop visual bottleneck feature map and a set of hierarchical crop visual coding feature maps.

5. The method for detecting garden plant pests based on multi-scale attention residual U-Net according to claim 1, characterized in that, Contrastive augmented feature decoding is performed on the crop visual bottleneck feature map and a set of hierarchical crop visual encoded feature maps to obtain the final decoded feature map, including: Receive the lower-level decoded feature map output from the deeper-level decoder; Extract the corresponding level feature map from the crop visual bottleneck feature map and a set of hierarchical crop visual coding feature maps as encoder skip feature maps; Based on the lower-layer decoded feature map, attention-gated jump connections are performed on the encoder jump feature map to obtain the gated encoded feature map. The gated coding feature map and the lower-layer decoded feature map are initially fused to obtain a fused feature map; Background-foreground contrast enhancement is performed on the fused feature map to obtain a contrast-enhanced feature map.

6. The method for detecting garden plant pests based on multi-scale attention residual U-Net according to claim 5, characterized in that, Based on the lower-layer decoded feature map, attention-gated skip connections are performed on the encoder skip feature map to obtain a gated encoded feature map, including: The lower-layer decoded feature map is input into the spatial attention module to obtain the spatial attention weight map; The gated coding feature map is obtained by multiplying the encoder jump feature map by its positional points and the spatial attention weight map.

7. The method for detecting garden plant pests based on multi-scale attention residual U-Net according to claim 5, characterized in that, Background-foreground contrast enhancement is performed on the fused feature map to obtain a contrast-enhanced feature map, including: The fused feature map is input into the foreground prediction module to obtain the foreground mask; Background feature statistical distribution modeling is performed based on fused feature map and foreground mask to obtain background mean prototype and background inverse covariance matrix; Based on the background mean prototype and the background inverse covariance matrix, the fused feature map and the foreground mask are dynamically weighted by the foreground outlier degree to obtain an adaptive enhanced attention map. Adaptive feature enhancement and reorganization are performed on the adaptive enhanced attention map, background mean prototype, and fused feature map to obtain a contrast-enhanced feature map.

8. The method for detecting garden plant pests based on multi-scale attention residual U-Net according to claim 7, characterized in that, Adaptive feature enhancement and reorganization are performed on the adaptive enhanced attention map, the background mean prototype, and the fused feature map to obtain a contrast-enhanced feature map. This includes: performing adaptive feature enhancement and reorganization on the adaptive enhanced attention map, the background mean prototype, and the fused feature map using the following formula: ; in, It is a contrast-enhanced feature map. It is an adaptive enhanced attention map. The symbol represents element-wise multiplication. As the background mean prototype, For broadcast algorithms, To fuse feature maps.