Cross-scale feature fusion detection method and device for cotton field small pests
By constructing the MFD-YOLO model and utilizing cross-scale feature fusion and adaptive weight adjustment, the problems of accuracy and lightweighting in detecting small cotton pests were solved, achieving efficient and accurate monitoring of cotton pests.
Patent Information
- Application Number
- CN202510887579.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-30
- Publication Date
- 2025-10-17
AI Technical Summary
Existing technologies are insufficient for effectively detecting small pests in cotton fields, especially cotton thrips and aphids. Furthermore, existing models struggle to balance accuracy and lightweight design, failing to meet actual production needs.
An MFD-YOLO small pest detection model was constructed. Cross-scale feature fusion was achieved through the CSFM module, key region features were enhanced by combining the CSAM module, multi-scale information capture was optimized using the C3K2_DDR module, and adaptive weight adjustment was performed using the NWD loss function. The model was then deployed on a Raspberry Pi for field detection.
It improves the accuracy and efficiency of small pest detection, enhances the model's ability to identify pests at multiple scales, reduces inference computation costs, adapts to different hardware platforms, and achieves efficient pest monitoring in cotton fields.
Smart Images

Figure CN120807883A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of agricultural pest monitoring, and in particular to a cross-scale feature fusion detection method and device for small pests in cotton fields. BACKGROUND
[0002] The prevention and control of pests and diseases in cotton fields pose a great challenge to farmers growing cotton. Traditionally, farmers use pesticides as a preventive measure. However, this approach has raised concerns due to its potential negative impact on the environment, human health, and ecosystems. If pests can be detected early, more precise measures can be taken to control them, thereby reducing the amount and frequency of pesticide use. During the growth of cotton, the most common pests are cotton thrips and aphids, which not only cause damage to cotton plants but also induce sooty mold, affecting the photosynthesis of leaves. Therefore, it is necessary to monitor aphids and cotton thrips, which helps to detect and control pests early and protect the growth and quality of crops.
[0003] Currently, although deep learning algorithms have been widely used in pest detection, one of the difficulties affecting the accuracy of agricultural pest detection is the effective detection of small pests, which belongs to the subcategory of small object detection. In recent years, general object detection has developed rapidly and has been successfully applied in many fields, but it still faces severe challenges in small target detection. Due to the limitation of low resolution, the features generated by small targets after multiple convolution operations are weaker than those of large targets, resulting in poor detection accuracy of small targets. Existing solutions for small target detection focus on the effective use of context information and the appropriate design of neural architecture.
[0004] Currently, there are still two difficulties in detecting small pests in agriculture:
[0005] (1) These small target detection methods were originally designed to detect common targets, and when used for pest detection, they have difficulty effectively capturing and fully utilizing the fine-grained features such as antennae and feet of small pests in input images;
[0006] (2) Small target detection models require precision while it is difficult to maintain a balance with lightweight, and large models are not easy to deploy on edge devices, which limits their applicability in actual field pest detection tasks. SUMMARY
[0007] The present application provides a cross-scale feature fusion detection method and device for small pests in cotton fields, which solves the problem of poor small target detection effect in existing work and cannot meet the needs of actual production and life, as described in detail below:
[0008] A cross-scale feature fusion detection method for small pests in cotton fields, the method comprising:
[0009] A small pest dataset is constructed by collecting pest images in cotton fields, and the dataset is labeled by class using Labelimg, and divided into training set, test set and validation set as input images;
[0010] An MFD-YOLO small pest detection model composed of a CSFM module, a CSAM module and a C3K2_DDR module is constructed, and the NWD loss function is optimized to adaptively adjust the weight of the detection model;
[0011] The adjusted MFD-YOLO detection model is edge deployed, the weight file trained by MFD-YOLO is converted to ONNX format, and deployed on Raspberry Pi for field detection of small pests in cotton fields.
[0012] The CSFM module is constructed by implementing cross-scale feature fusion through CARAFE up-sampling and 3D convolution to construct a unified multi-scale feature benchmark.
[0013] The C3K2_DDR module is constructed by using the DWR module to extract two-step residual features, optimize multi-scale information capture, and improve it with dilated reparameterization technology.
[0014] Further, the input features of the CSFM module need to follow the mathematical constraint:
[0015]
[0016] In the formula, Φ σ (w,h) represents the feature map obtained by convolution smoothing of the Gaussian filter, and φ(w,h) represents the two-dimensional input feature map with width w and height h, represents convolution operation, and Γ σ (w,h) is a parameter-adjustable Gaussian filter kernel function, which controls the smoothing degree of the feature map by adjusting the standard deviation scaling factor σ.
[0017] The CSAM module adopts a double-branch structure, and the channel attention branch receives features from the upper layer as the first input, and the spatial attention branch integrates the channel attention output and the CSFM feature map as the second input;
[0018] In the channel attention branch, the feature map output by PANet is used as the input source, and the detailed features of the previous layer are inherited;
[0019] A one-dimensional convolution kernel that maintains the channel dimension is used to integrate cross-channel information, and the value of k is proportional to the channel dimension, defined as:
[0020] C=ψ(k)=2 (r×k-b) #
[0021]
[0022] Herein r, b are scaling factors, regulating the correlation degree of the convolution kernel size k and the channel dimension C, wherein the |·|odd operator is defined as taking the nearest odd value, and ψ(k) is a function representing the mapping relationship of the channel number C with respect to the convolution kernel size k, and r and b are scaling parameters controlling the ratio of the convolution kernel size k and the channel dimension C respectively, and ψ(C) is a function opposite to ψ(k).
[0023] The DWR module is:
[0024] In the region residualization stage, a 3*3 standard convolution, a BN layer and a ReLU activation function are used to extract basic features, and in the feature fusion stage, channel splicing and point-by-point convolution are combined to compress and interact information, and residual connection is used to form an optimized feature representation;
[0025] The Dilated Reparam Block in the UniRepLKNet combines a large kernel and a dilated convolution, the Dilated Reparam Block comprises a large kernel convolution layer and a plurality of dilated convolution layers with different dilation rates, the size k and the dilation rate r of each dilated convolution kernel need to meet: (k-1)r+1≤K;the Bottleneck structure in the YOLOv11 feature extraction network is replaced by the DDR to obtain the C3K2_DDR module.
[0026] The optimization of the NWD loss function for self-adaptive weight adjustment of the detection model is:
[0027] The width and height of the target frame of the input object are segmented, and the area of the frame is calculated as a scalar constant in the optimization of the NWD loss function.
[0028] The second aspect is a cross-scale feature fusion detection device for small pests in a cotton field, comprising a processor and a memory, wherein the memory stores program instructions, and the processor invokes the program instructions stored in the memory to enable the device to execute the method of any one of the first aspect.
[0029] The third aspect is a computer readable storage medium storing a computer program, wherein the computer program comprises program instructions, and the program instructions are executed by a processor to enable the processor to execute the method of any one of the first aspect.
[0030] The technical solution provided by the application has the following beneficial effects:
[0031] 1. The application provides a high-efficiency small pest detection framework, which makes pest identification more accurate and efficient, especially in handling small target and high-density pest challenges;
[0032] 2. The application constructs a unified multi-scale feature benchmark through the CSFM module, effectively improves the representation of small pest features, and the CSAM module combines channel and spatial attention mechanisms to strengthen key area features and suppress irrelevant information, further improving detection accuracy; the two modules work together to optimize the detection performance of small pests in cotton fields and ensure the model's recognition ability for multi-scale pests;
[0033] 3. The C3K2_DDR module is designed using the dilation reparameterization technique to optimize multi-scale information capture and improve receptive field adaptability, which enhances small target feature extraction capability, reduces feature redundancy, and reduces inference calculation cost;
[0034] 4. The application uses an adaptive weight NWD loss function to provide an independent scaling factor for each detection object, which can be more accurate when processing different size target boxes. BRIEF DESCRIPTION OF DRAWINGS
[0035] Figure 1 It is a flowchart of a cross-scale feature fusion detection method for small pests in cotton fields;
[0036] Figure 2 It is a schematic diagram of cotton fields and captured pests;
[0037] Figure 3 It is a network structure diagram of a cross-scale feature fusion detection method MFD-YOLO for small pests in cotton fields;
[0038] Figure 4 It is a network structure diagram of the CSFM module;
[0039] Figure 5 It is a CARAFE network structure diagram;
[0040] Figure 6 It is a network structure diagram of the CSAM module;
[0041] Figure 7 It is a schematic diagram of the Dilated Reparam Block with a convolution kernel of 9x9;
[0042] Figure 8 It is a network structure diagram of the DDR module. DETAILED DESCRIPTION
[0043] To make the purpose, technical solutions and advantages of the application clearer, the embodiments of the application are described in further detail below.
[0044] Embodiment 1
[0045] A cross-scale feature fusion detection method for small pests in cotton fields, comprising:
[0046] 101: Collecting pest images in cotton fields to construct a small pest dataset, classifying and labeling the dataset using Labelimg, and dividing it into a training set, a test set, and a validation set as input images;
[0047] Wherein, the step includes: collecting pest images in cotton fields to construct a small pest dataset, classifying and labeling the dataset using Labelimg to obtain an.XML file with labeling information; 3330 images are obtained by segmenting 3264x2448 resolution images according to 640x640 pixel size, and are divided into a training set, a test set, and a validation set according to 8:1:1, and the dataset is named Cotton_small_pest as the input image of the subsequent detection model.
[0048] 102: Constructing an MFD-YOLO small pest detection model composed of a CSFM module, a CSAM module, and a C3K2_DDR module, and optimizing the NWD loss function to adaptively adjust the weight of the MFD-YOLO detection model to obtain an adjusted MFD-YOLO detection model;
[0049] Wherein, the step includes:
[0050] Firstly, the CSFM module is constructed to realize cross-scale feature fusion through CARAFE up-sampling and 3D convolution, construct a unified multi-scale feature benchmark, effectively improve the representation of small pest features, and construct a CSAM module for the CSFM module. This module combines channel and spatial attention mechanisms to strengthen key area features and suppress irrelevant information, further improving detection accuracy.
[0051] Secondly, the C3K2_DDR module is designed, two-step residual feature extraction is performed using the DWR module, multi-scale information capture is optimized, and the dilated reparameterization technique is improved to improve receptive field adaptability. This design enhances the ability to extract small target features, reduces feature redundancy, and reduces inference calculation cost.
[0052] Thirdly, the NWD loss function is optimized, and the MFD-YOLO detection model is adaptively adjusted to obtain an adjusted MFD-YOLO detection model.
[0053] 103: Edge deployment of the MFD-YOLO detection model, converting the weight file trained by the MFD-YOLO into an ONNX format, and deploying it to a Raspberry Pi for field detection of small pests in cotton fields.
[0054] In order to directly use the model to detect pests directly in the field cotton field, the weight file trained by the MFD-YOLO needs to be converted into an ONNX format. The ONNX format is known to those skilled in the art, and the embodiments of the present application do not repeat it.
[0055] In summary, the embodiments of the present application solve the problem of poor small target detection effect in the prior art by steps 101-103, which cannot meet the needs of actual production and life.
[0056] Example 2
[0057] The following specific experimental data, calculation formula, Figures 1-8 The feasibility of the scheme in Example 1 is verified, which is described in detail as follows:
[0058] 201: Collecting crop pest images to construct a data set;
[0059] Among them, the pictures of the data set were collected in the experimental cotton field of Huaxing Farm in Changji Hui Autonomous Prefecture, Xinjiang, China, located at 44°22'N, 87°29'E, and the collection time was from July to September 2024, which coincided with the peak period of pests in the cotton field. The collection interval was 3 days. During this growth cycle, cotton thrips, aphids, ladybugs and other pests were the main pests. Based on the color preference of these pests, they had significant positive phototaxis characteristics to yellow spectrum. Therefore, yellow sticky traps were chosen as data collection devices to simulate the visual preference characteristics of pests, thereby achieving the capture of field pests. When collecting, the yellow sticky traps were arranged at an interval of 1-2 meters. To ensure data quality, an automatic focusing macro lens with a resolution of 3264x2448 was used, and a total of 15660 pest images were obtained, of which cotton thrips accounted for 34.5%, aphids accounted for 53.65%, and ladybugs accounted for 11.85%. The cotton field and captured pests are shown in Figure 2
[0060] In the public MS COCO dataset, the target pixel area is classified into small targets (less than 32x32 pixels), medium targets and large targets. The average pixel size of aphid images is 29x28, and the average pixel size of thrips images is 16x7, both of which are less than 32x32 pixels, so both of these two types of pest targets are classified as small targets. Since the collected pest images are small in volume and dense, it is more beneficial to detect after segmenting the images. In order to ensure the accuracy of target detection and adapt to the input size of most models (640x640), the original image is segmented into 640x640 size. In the segmentation process, in order to avoid the loss of instances caused by incomplete targets, an overlapping area is set, and the size of the overlapping pixels is 50. The total number of segmented images is 3330, which is divided into 2664 training sets, 333 test sets and 333 validation sets according to the ratio of 8:1:1, and finally a dataset named Cotton_small_pest is constructed.
[0061] 202: Constructing the MFD-YOLO model;
[0062] Aiming at the problem of detecting small pests in the field cotton field, since the existing model has a performance bottleneck in small target detection, the embodiment of the present application proposes a new network architecture-MFD-YOLO. The model mainly optimizes the feature fusion strategy, effectively makes up for the loss of correlation system features caused by only using summation or splicing operation in the pyramid feature fusion process of the traditional neck network. First, in order to build a more efficient feature fusion network, in the MFD-YOLO model, a cross-scale feature fusion module (CSFM) and a channel and spatial attention mechanism (CSAM) module are designed. At the same time, through the synergistic effect of CSFM and CSAM, a P2 layer detection head with a resolution of 160x160 is additionally added in the network structure to enhance the perception ability of small targets. Secondly, in order to balance between accuracy and efficiency, the structure of the last three convolutional layers of the backbone network and part of the convolutional layers in the neck network is adjusted, and the Adown structure is used to realize the effective reduction of the model parameter quantity and the calculation quantity on the premise of ensuring the detection accuracy. In addition, the dilated reparameterization technology proposed by UniRepLKNet is used, which can not only reduce the calculation complexity in the inference stage, but also flexibly control the size and dilution rate of the convolution kernel in the parallel branch. Based on this advantage, the DWR module is restructured, and then the DDR module is constructed, and the DDR module is integrated into the C3k2 structure to form the C3k2-DDR module, so as to further improve the feature expression ability and overall detection performance of the model. For the loss function problem, the CIoU Loss loss function used in the original YOLOv11 algorithm has limitations in small target detection tasks: due to the small area of the small target bounding box, slight displacement error may cause the IoU value to fluctuate sharply, thereby making the gradient change unstable and affecting the model convergence, especially in complex background and target dense scenes, coordinate regression is more susceptible to noise interference and reduces the positioning accuracy. Therefore, the NWD designed for small target detection is used and improved, so as to realize higher positioning accuracy and stability in complex scenes, and the overall network structure is as shown in Figure 3 The following is a detailed introduction to the CSFM module, the CSAM module, the C3k2-DDR module and the loss function:
[0063] I. Specific content about constructing CSFM and CSAM modules:
[0064] Among them, the network structures of CARAFE and CSFM are respectively as Figure 4 And Figure 5As shown, the input feature map in the CARAFE module is first passed through a lightweight convolutional network to predict a reorganization convolution kernel for each up-sampling position. These convolution kernels are dynamically generated and related to the content of the current feature. Then, a local region is taken from the original feature map using the previously predicted convolution kernel, and a new up-sampled pixel is generated by reorganizing the features in the region according to the weighting. The CSFM module first performs convolution operation on the multi-scale input features, and uses the CARAFE module with large receptive field, content-aware ability and lightweight advantage to perform feature size unification processing. The image after the CARAFE module is fused by a horizontal concatenation strategy to integrate multi-scale features, and three-dimensional convolution technology is used to extract cross-scale correlation information from the feature sequence to achieve efficient feature expression. In the YOLOv11 backbone network, the high-resolution feature map generated at the P3 level has dual advantages: it not only retains the geometric contour features of large and medium-sized targets, but also accurately captures the fine texture information of small targets.
[0065] Based on this feature, the module aligns the other level features with the P3 layer size through up-sampling operation to build a multi-scale unified benchmark. Then, the adjusted features are upgraded to four-dimensional tensors by performing Unsqueeze operation, concatenated along the depth dimension, and then implemented by 3D convolution operation to effectively mine cross-scale correlation features. The final processing process includes 3D batch normalization, LeakyReLU activation function, three-dimensional maximum pooling and Squeeze dimension reduction operation to complete the deep extraction of multi-scale sequence features.
[0066] The input features of this module need to follow the mathematical constraints of the following formula:
[0067]
[0068]
[0069] In the formula, Φ σ (w,h) represents the feature map obtained by convolution smoothing of the Gaussian filter, and φ(w,h) represents the two-dimensional input feature map with width w and height h, represents convolution operation, and Γ σ (w,h) is a Gaussian filter kernel function with adjustable parameters, and the smoothing degree of the feature map is controlled by adjusting the standard deviation scaling factor σ.
[0070] The CSAM module adopts a double-branch structure: the channel attention branch receives the features from the upper layer as the first input, and the spatial attention branch integrates the channel attention output and the CSFM feature map as the second input. The network structure of the CSAM module is as shown in Figure 6 .
[0071] In the channel attention branch, the feature map output by PANet is used as the input source to inherit the detailed features of the previous layer. Compared with the traditional channel attention scheme of SENet, which uses global mean pooling combined with double fully connected layers and Sigmoid function, the model proposes an improved architecture: first, it discards the dimension compression operation to maintain the integrity of the features, and second, it replaces the global dependency relationship with local neighborhood channel interaction.
[0072] In specific implementation, a one-dimensional convolution kernel (kernel size = k) is used to integrate cross-channel information while maintaining channel dimensions, where k represents the local interaction range. Considering that the conventional channel dimension C often takes the form of an exponential of 2, the value of k is proportional to the channel dimension, specifically defined as:
[0073] C = ψ(k) = 2 (r×k-b) #
[0074]
[0075] Here r and b are proportional factors that regulate the correlation between the convolution kernel size k and the channel dimension C. The |·|odd operator in the formula is defined as taking the nearest odd value. When r = 2 and b = 1, the nonlinear correlation mechanism constructed can make high-dimensional channels exhibit long-range interaction characteristics, while low-dimensional channels exhibit local correlation characteristics. Based on this characteristic, the channel attention module can establish a multi-level feature interaction system across channels.
[0076] The output of the channel attention mechanism is combined with the features output by the CSFM module to serve as the input of the spatial attention network, providing help for extracting key spatial information from each small pest. First, the multi-scale features of average pooling and max pooling are fused in the height and width directions, respectively, and after 3x3 convolution compression and normalization activation, they are divided into height and width branches, and spatial attention weight maps are generated through 1x1 convolution. Finally, the Sigmoid normalized weight is multiplied element by element with the original feature to highlight the key area response while preserving the original information through residual connection.
[0077] II. Specific content of constructing C3K2_DDR module:
[0078] In the Dilation-wise Residual Segmentation (DWRseg) network, the DWR module optimizes the capture of multi-scale context information through residual linkage. Its design divides the traditional single-stage multi-scale feature extraction into two stages: regional residualization and semantic residualization. In the regional residualization stage, 3x3 standard convolution, BN layer and ReLU activation function are used to extract basic features. The introduction of ReLU improves the compactness of feature expression and reduces the computational complexity. In the semantic residualization stage, a grouping strategy is adopted. Through the combination of depth separable convolution and different dilation rates, the matching of feature maps and receptive fields is dynamically optimized, avoiding the redundancy of multi-receptive fields. The two-stage design enhances the capture of multi-scale information while improving the computational efficiency. In the feature fusion stage, channel splicing and point-wise convolution are combined to compress and interact information. Finally, the optimized feature representation is formed through residual connection. UniRepLKNet proposes four criteria for designing large kernel convolutional neural networks. The core is that large kernel convolution has a large receptive field, which can capture a wide range of features, while small kernel convolution is suitable for capturing local features and is usually used with large kernel convolution. Dilated convolution can further expand the receptive field and is suitable for use with large kernel. The Dilated Reparam Block in UniRepLKNet combines large kernel and dilated convolution. The kernel size and dilation rate of each dilated convolution meet certain conditions. The Dilated Reparam Block contains a large kernel convolution layer and multiple dilated convolution layers with different dilation rates. The kernel size k and dilation rate r of each dilated convolution kernel must satisfy: (k-1)r+1≤K. For example, when K=13, k=(5,7,3,3,3), r=(1,2,3,4,5), and the equivalent kernel sizes are (5,13,7,7,9,11) respectively. In the inference stage, all dilated convolutions are converted to non-dilated large kernel convolutions, which are combined into a single large kernel layer to avoid additional computational cost, Figure 7 is an example diagram with a 9x9 convolution kernel. To optimize the dilated convolution in the DWR module, the Dilated Reparam Block is used instead of the Dconv with dilation rates of 3 and 5, named DDR module, as shown in Figure 8 .
[0079] The C3K2_DDR module is obtained by improving the C3K2 module in the feature extraction network of YOLOv11. The YOLOv11n model uses the C3K2 module containing multiple bottleneck structures, but this structure lacks a mechanism for dynamically adjusting the receptive field. When processing multi-scale targets, it is difficult to adaptively match the feature extraction requirements of objects of different sizes, resulting in loss of small target details or insufficient capture of context information on large targets, and there is also too much redundant channel information while extracting more features. The advantages of the DDR module are integrated, the bottleneck structure is replaced by the DDR to construct the C3K2_DDR module to improve the detection capability of the model, as shown in Figure 3 .
[0080] III. Specific content about loss function:
[0081] A normalized Wasserstein distance NWD position regression loss function. For N a and N b is a Gaussian distribution model, according to the boundary box A=(cx a ,cy a ,w a ,h a ) and B=(cx b ,cy b ,w b ,h b ), NWD is defined as the following formula:
[0082]
[0083] Where C is a scalar constant. Its size will affect the sensitivity of the loss function. If C is set too small, the gradient may fluctuate greatly, the training may be unstable, and even gradient explosion may be triggered. If C is set too large, the positioning accuracy of small targets will decrease, and the model will tend to ignore small targets. Therefore, when detecting different targets, a fixed constant C often has limitations. Therefore, the scalar constant C originally used to control the exponential decay rate is changed to a tensor form generated dynamically according to the pixel information of each input image, to achieve more flexible loss adjustment.
[0084] The specific operation is: the width and height of the target box of the input object are segmented from the target box, and the area of the box is taken as C. The segmented width and height belong to a tensor, so C is also a tensor. The original scalar uses the same scaling factor for all detection objects, while the current tensor provides an independent scaling factor for each detection object, which can be more accurate when processing target boxes of different sizes.
[0085] 203: edge deployment;
[0086] This embodiment of the present invention aims to develop an efficient, accurate, and lightweight pest detection model that is adaptable to different hardware platforms, particularly for use in cotton fields. To achieve this goal, the ONNX format is adopted, enabling easy model migration and sharing across various deep learning frameworks. The hardware platform used is a Raspberry Pi 4B, equipped with an ARM Cortex-A72 processor, a 32GB memory card, and an AF-M camera supporting 4K output, providing sufficient computing power for real-time image processing.
[0087] The system's workflow is as follows: First, a camera positioned in a cotton field captures real-time images of yellow sticky traps. Considering the potential for noise and interference, preprocessing is performed, including resizing, denoising, and contrast enhancement, to ensure the data meets model requirements. Next, the MFD-YOLO model is used for pest detection, extracting pest species labels, location coordinates, and density information from the images, providing real-time support for pest management in cotton fields.
[0088] Finally, the detection results are displayed on a Raspberry Pi 4B display, allowing users to view real-time monitoring status. This method, based on a lightweight deep learning model, can run efficiently on devices with limited computing resources and offers strong deployment flexibility to meet the needs of different regions. Furthermore, the ONNX format allows for easy migration of trained models to other hardware platforms, enhancing the system's scalability and applicability.
[0089] Example 3
[0090] In order to verify the detection performance of the proposed model, we select precision (P), average precision (AP), mean average precision (mAP), number of operations per second (GFLOPS), recall (R), and parameters (Params) as metrics. The detailed explanation of these parameters is described by the following formula:
[0091]
[0092] AP = ∫0 1 Precision(Recall)dR#
[0093]
[0094]
[0095] Wherein, Precision (P) evaluates the probability of detecting positive samples, recall (R) evaluates the missed detection rate, and the higher the value, the lower the missed detection rate. Average precision (AP) is the area under the precision-recall (P-R) curve, and average precision (mAP) is the average of all class AP values, which is a key indicator for evaluating model performance. TP, FP and FN represent true positive, false positive and false negative, respectively. Precision (Recall) refers to the precision-recall curve. I represents the defect category, N represents the number of defects, O represents the constant order, K represents the convolution kernel size, C represents the channel number, M represents the input image size, and i represents the iteration number.
[0096] The application performance is evaluated by model parameters, floating point operation speed, model size and other indicators, and the smaller the value, the simpler the network architecture. In addition, the model size and FPS affect the storage requirement and detection requirement of the hardware device, respectively.
[0097] In order to verify the comprehensive performance of the MFD-YOLO model, it is compared with the classic two-stage detection model FasterRCNN and one-stage detection models such as: RETINANET, YOLOv3, YOLOv5n, YOLOv6n, YOLOv7, YOLOv8n, YOLOv9t, YOLOv10n, YOLOv11n, GoldYOLO and DETR on the Cotton_small_pest dataset and the public YST dataset to evaluate its performance. In the training process of these comparison models, the settings of the backbone, loss function, optimizer and other parameters are not adjusted, and the default configuration of the model is adopted.
[0098] The evaluation index table in Table 1 shows that the MFD-YOLO of the embodiment of the application has mAP 50In terms of the aspect, compared with Faster RCNN, RetinaNet, YOLOv3, YOLOv5n, YOLOv6n, YOLOv7, YOLOv8n, YOLOv9t, YOLOv10n, YOLOv11n, Gold YOLO and DETR, it is increased by 44.2%, 32.9%, 0.9%, 2.9%, 5.1%, 6.3%, 3.7%, 3.2%, 5.8%, 3.1%, 2.6%, 11.6% respectively. In terms of precision, it is increased by 58%, 23%, -2%, 7%, 5%, 13%, 5%, 2%, 6%, 6%, 3%, 17% respectively. In terms of GFLOPs, MFD-YOLO is reduced by 1767.83%, 1861.74%, 2354.78%, -64.35%, 2.16%, 798.26%, -20.87%, -33.91%, -28.69%, -45.21%, -20%, 800.87% respectively compared with the above models. In terms of parameter quantity, it is reduced by 1431.36%, 1173.06%, 3725.46%, -34.98%, 56.09%, 1357.56%, -11.07%, 27.31%, -0.37%, -4.80%, 117.67%, 1079.63% respectively compared with these models. In terms of F1 Score, it is increased by 0.49, 0.34, -0.01, 0.03, 0.05, 0.07, 0.04, 0.02, 0.05, 0.04, 0.02, 0.12 respectively, which fully demonstrates its advantages in stability and consistency. It also performs obviously on the public YST dataset.
[0099] The performance improvement is mainly due to the optimization of the structure of MFD-YOLO: by introducing CSFM and CSAM to enhance small target feature extraction and fusion, using DDR module to improve expression ability, combining Adown to realize lightweight, and replacing CIOU with NWD to improve positioning accuracy, while ensuring accuracy, effectively reducing calculation and parameter overhead. In summary, MFD-YOLO has made significant improvements in small pest detection tasks through multiple improvements in structure and loss function.
[0100] Table 1
[0101]
[0102] Example 4
[0103] A cross-scale feature fusion detection device for small pests in cotton fields, the device comprising: a processor and a memory, the memory storing program instructions, the processor invoking the program instructions stored in the memory to make the device execute the following method steps in Example 1:
[0104] A small pest dataset was constructed by collecting pest images in cotton fields, and the dataset was labeled by class using Labelimg and divided into training set, test set and validation set as input images;
[0105] An MFD-YOLO small pest detection model composed of CSFM module, CSAM module and C3K2_DDR module was constructed, and the NWD loss function was optimized to adjust the weights of the detection model adaptively;
[0106] The adjusted MFD-YOLO detection model was edge deployed, the weight file trained by MFD-YOLO was converted to ONNX format, and was deployed on Raspberry Pi for field detection of small pests in cotton fields.
[0107] Among them, the CSFM module is constructed by: cross-scale feature fusion is realized through CARAFE up-sampling and 3D convolution, and a unified multi-scale feature benchmark is constructed.
[0108] Among them, the C3K2_DDR module is constructed by: two-step residual feature extraction is performed using the DWR module, multi-scale information capture is optimized, and the dilated reparameterization technique is improved.
[0109] Further, the input features of the CSFM module need to follow the mathematical constraints:
[0110]
[0111] In the formula, Φ σ (w,h) represents the feature map obtained after the Gaussian filter is convolved and smoothed, and φ(w,h) represents a two-dimensional input feature map with width w and height h, represents convolution operation, and Γ σ (w,h) is a parameter-adjustable Gaussian filter kernel function, which controls the smoothing degree of the feature map by adjusting the standard deviation scaling factor σ.
[0112] Among them, the CSAM module is: a double-branch structure is adopted, the channel attention branch receives features from the upper layer as the first input, and the spatial attention branch integrates the channel attention output and the CSFM feature map as the second input;
[0113] In the channel attention branch, the feature map output by PANet is used as the input source, and the detailed features of the previous layer are inherited;
[0114] A one-dimensional convolution kernel that maintains the channel dimension is used for cross-channel information integration, and the value of k is proportional to the channel dimension, defined as:
[0115] C=ψ(k)=2 (r×k-b) #
[0116]
[0117] Herein r, b are scaling factors, regulating the correlation between the size of the convolution kernel k and the channel dimension C, wherein the |·|odd operator is defined to take the nearest odd value, and ψ(k) is a function representing the mapping relationship of the channel number C with respect to the size of the convolution kernel k, and r and b are scaling parameters controlling the ratio of the size of the convolution kernel k and the channel dimension C, and ψ(C) is a function opposite to ψ(k).
[0118] Wherein, the DWR module is:
[0119] In the region residualization stage, a 3*3 standard convolution, a BN layer and a ReLU activation function are used to extract basic features, and in the feature fusion stage, the information is compressed and interacted through channel splicing and point-by-point convolution, and an optimized feature representation is formed through residual connection;
[0120] The Dilated Reparam Block in the UniRepLKNet combines a large kernel and a dilated convolution, the Dilated Reparam Block comprises a large kernel convolution layer and a plurality of dilated convolution layers with different dilation rates, the size k and the dilation rate r of each dilated convolution kernel need to meet: (k-1)r+1≤K; the Bottleneck structure in the YOLOv11 feature extraction network is replaced by the DDR to obtain the C3K2_DDR module.
[0121] Wherein, the optimization of the NWD loss function for adaptive weight adjustment of the detection model is:
[0122] The width and height of the target frame of the input object are segmented, and the area of the frame is calculated as a scalar constant in the optimization of the NWD loss function.
[0123] It should be pointed out that the device description in the above embodiments corresponds to the method description in the embodiments, and the embodiments of the present application will not be repeated here.
[0124] The execution subject of the processor and the memory described above can be a computer, a single-chip microcomputer, a microcontroller and the like having a computing function, and in specific implementation, the embodiments of the present application do not limit the execution subject, and the selection is made according to the actual application needs.
[0125] The memory and the processor transmit data signals through a bus, and the embodiments of the present application will not be repeated here.
[0126] Based on the same inventive concept, the embodiments of the present application also provide a computer readable storage medium, the storage medium comprises a stored program, and when the program runs, the device where the storage medium is located executes the method steps in the above embodiments.
[0127] The computer readable storage medium includes, but is not limited to, a flash memory, a hard disk, a solid state disk, etc.
[0128] It should be noted that the readable storage medium in the above embodiments is described corresponding to the method description in the embodiments, and the embodiments of the present application will not be described here.
[0129] In the above embodiments, all or part of the embodiments can be realized by software, hardware, firmware or any combination thereof. When realized by software, all or part of the embodiments can be realized in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions according to the embodiments of the present application are generated.
[0130] The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable devices. The computer instructions can be stored in or transmitted by a computer readable storage medium. The computer readable storage medium can be any available medium accessible by the computer or a data storage device such as a server, data center, etc. integrated with one or more available media sets. The available media can be a magnetic medium or a semiconductor medium, etc.
[0131] The model of each device in the embodiments of the present application is not limited unless otherwise specified, and any device that can complete the above functions can be used.
[0132] Those skilled in the art can understand that the above drawings are only schematic diagrams of preferred embodiments, and the above serial numbers of the embodiments of the present application are only for description, not representing the advantages and disadvantages of the embodiments.
[0133] The above description is only the preferred embodiments of the present application, and does not limit the present application. Any modification, equivalent replacement, improvement, etc. within the spirit and principle of the present application should be included in the protection scope of the present application.
Claims
1. A cross-scale feature fusion detection method for small pests in cotton fields, characterized by: The method comprises: Pest images were collected in cotton fields to construct a small pest dataset. The dataset was annotated using Labelimg and divided into training, test, and validation sets as input images. Build the MFD-YOLO small pest detection model consisting of the CSFM module, CSAM module, and C3K2_DDR module, and optimize the NWD loss function to perform adaptive weight adjustment on the detection model. The adjusted MFD-YOLO detection model was deployed on the edge, and the weight file trained by MFD-YOLO was converted into ONNX format and deployed on a Raspberry Pi for field detection of small pests in cotton fields.
2. A cross-scale feature fusion detection method for small pests in cotton fields according to claim 1, characterized in that: The CSFM module is constructed by implementing cross-scale feature fusion through CARAFE upsampling and 3D convolution to build a unified multi-scale feature benchmark.
3. The cross-scale feature fusion detection method for small pests in cotton fields according to claim 1, characterized in that: The C3K2_DDR module is constructed by using the DWR module to perform two-step residual feature extraction, optimizing multi-scale information capture, and improving it with the expansion reparameterization technology.
4. The cross-scale feature fusion detection method for small pests in cotton fields according to claim 2, characterized in that: The input features of the CSFM module must follow mathematical constraints: Where Φ6(w,h) represents the feature map obtained by the Gaussian filter after convolution smoothing, φ(w,h) represents the two-dimensional input feature map with width w and height h. represents the convolution operation, Γ σ (w,h) is a Gaussian filter kernel function with adjustable parameters, and the smoothness of the feature map is controlled by adjusting the standard deviation scaling factor σ.
5. The cross-scale feature fusion detection method for small pests in cotton fields according to claim 1, characterized in that: The CSAM module adopts a dual-branch structure, where the channel attention branch receives features from the upper layer as the first input, and the spatial attention branch integrates the channel attention output and the CSFM feature map as the second input; In the channel attention branch, the feature map output by PANet is used as the input source to inherit the detailed features of the previous layer; A one-dimensional convolution kernel that maintains the channel dimension is used to integrate cross-channel information. The value of k is proportional to the channel dimension and is defined as: C=ψ(k)=2 (r×k-b) # Here, r and b act as scaling factors to regulate the correlation between the kernel size k and the channel dimension C. The |·| odd operator is defined as taking the nearest odd value, ψ(k) is a function that represents the mapping of the number of channels C to the kernel size k, r and b are scaling parameters that control the ratio of the kernel size k to the channel dimension C, and ψ(C) is the inverse function of ψ(k).
6. The cross-scale feature fusion detection method for small pests in cotton fields according to claim 3, characterized in that: The DWR modules are: In the regional residualization stage, 3×3 standard convolution, batch normalization layer and ReLU activation function are used to extract basic features. In the feature fusion stage, channel splicing and point-by-point convolution are combined to compress and interact information, and the optimized feature representation is formed through residual connection. The Dilated Reparam Block in UniRepLKNet combines large kernels and dilated convolutions. The Dilated ReparamBlock consists of a large kernel convolution layer and multiple dilated convolution layers with different dilation rates. The kernel size k and dilation rate r of each dilated convolution must satisfy the following: (k-1)r+1≤K. The Bottleneck structure in the YOLOv11 feature extraction network is replaced with DDR to obtain the C3K2_DDR module.
7. The cross-scale feature fusion detection method for small pests in cotton fields according to claim 1, characterized in that: The optimized NWD loss function is used to adaptively adjust the weight of the detection model: The width and height of the box are segmented from the target box of the input object, and the area of the box is calculated as a scalar constant in the optimized NWD loss function.
8. A cross-scale feature fusion detection device for small pests in cotton fields, characterized by: The device includes: a processor and a memory, wherein program instructions are stored in the memory, and the processor calls the program instructions stored in the memory to enable the device to execute the method according to any one of claims 1 to 7.
9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the processor is caused to perform the method according to any one of claims 1 to 7.
Citation Information
Cited By
Rice and crab target detection device and method for rice field complex scene pictures and training method of target detection network
CN121459392A