Multi-target pest detection method and system based on improved YOLOv5s unstructured environment
By improving the YOLOv5s network model, combining GhostNet, BiFPN and CBAM modules, the efficiency and accuracy problems of small-target pest detection in unstructured environments are solved, and effective application in agricultural scenarios is achieved.
Patent Information
- Application Number
- CN202411227881.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-03
- Publication Date
- 2024-11-15
- Estimated Expiration
- 2044-09-03
AI Technical Summary
In the pest detection, the prior art has problems such as time-consuming and laborious, subjective, error-prone and prediction lag. Especially in the unstructured environment, small-target pest detection is poor and difficult to apply to actual agricultural production.
Using the improved YOLOv5s network model, by removing the large detection head, introducing the GhostNet module and BiFPN module for feature extraction and fusion, replacing the ordinary convolution module in the neck network with DWConv, and adding CBAM module for feature point judgment, building suitable for non-convolutional Multi-target pest detection network in structured environments.
The detection speed and accuracy are improved, and the recognition ability of small-target high-density pests in non-structural environments is improved, making the model more suitable for the application of actual agricultural scenarios.
Smart Images

Figure CN118968312A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, and in particular to a multi-target pest detection method and system based on improved YOLOv5s in an unstructured environment. Background Art
[0002] Wheat, rice, and sugarcane are the main crops in many of my country's main production areas. Their pest problems have always been a problem that needs to be focused on and solved in agricultural production. In the past, pest identification and observation of these crops were mostly carried out manually. In the large-scale pest identification process, due to the wide variety of pests and the large planting area of farmland, on the one hand, manual identification and observation requires the technical staff to train their skills in advance; on the other hand, relying on agricultural technicians to conduct field observations of pests and labor-intensive pest and disease counting to predict the severity of pests is time-consuming, labor-intensive, subjective, prone to errors, and delayed prediction, making it difficult to carry out effectively. The delay in pest control information has led to the large-scale and purposeless application of pesticides. The excessive application of pesticides has also caused people's concerns about the environment. Such situations emphasize the need for innovative and environmentally friendly technology solutions to detect pests in real time and accurately. In recent years, with the introduction of new agricultural IoT devices and the rapid development of machine vision and deep learning in the agricultural field, the time-consuming and labor-intensive problem of manual work has been effectively alleviated. However, a few pest detection methods are ineffective due to the relatively small size of pest targets in images, complex natural environments, and high barriers to entry for using emerging technologies, making them difficult to put into engineering applications in actual agricultural production.
[0003] Modern machine vision technology continues to advance. As an emerging method, deep learning has performed well in many tasks such as pest image recognition, target detection, and instance segmentation, with remarkable results. At the same time, driven by the continuous improvement of the computing power of mobile devices, deep learning technology and hardware devices have been effectively combined. Pest monitoring tasks are expected to further broaden application scenarios and lower the threshold for use, providing more possibilities for pest detection, counting, and engineering applications under machine vision. Therefore, there is an urgent need to provide an effective and feasible pest detection method and application.
[0004] The above problems need to be solved urgently. Summary of the invention
[0005] In view of the existing problems, the present invention designs a multi-target pest detection method and system in an unstructured environment based on improved YOLOv5s. The purpose is to provide an effective and feasible pest detection method and application.
[0006] In order to overcome at least one of the above-mentioned shortcomings of the prior art, on the one hand, an embodiment of the present invention provides a multi-target pest detection method in an unstructured environment based on an improved YOLOv5s, the method comprising: S1: collecting crop images infested by sugarcane aphids, and preprocessing the images as a first target data set; S2: randomly selecting the first target data set and the optimized and annotated AgriPest data set and recombining them to produce a second target data set; S3: dividing the second target data set into a training set, a validation set and a test set; S4: using the YOLOv5s network model as a benchmark model to construct an improved YOLOv5s network model as a multi-target pest detection network model, comprising: removing four YOLOv5s network In the large detection head of the detection head, the backbone network is reconstructed through the GhostNet module for feature extraction, the BiFPN module is introduced into the FPN part for feature fusion, the ordinary convolution module in the neck network is replaced by the DWConv module, and the output features are sent to the detector with the CBAM module added for feature point judgment; S5: the training set is input into the multi-target pest detection network model for model training; S6: the parameters of the multi-target pest detection network model are improved based on the training results to obtain the trained multi-target pest detection network model; S7: the verification set is input into the trained multi-target pest detection network model for model evaluation; S8: the test set is input into the trained multi-target pest detection network model to obtain the multi-target pest detection result.
[0007] Furthermore, in step S4, reconstructing the backbone network for feature extraction through the GhostNet module includes: S41: using a Ghost Bottleneck module with a step size of 1 to replace the C3 module in the original YOLOv5s network model, and using a Ghost Bottleneck module with a step size of 2 to replace the ordinary convolution Conv in the original YOLOv5s network model, forming a feature extraction network with the GhostNet module as the backbone.
[0008] Furthermore, the convolution process in the Ghost Bottleneck module includes: S411: obtaining an intrinsic feature map through conventional convolution to extract basic features of the input data; S412: applying a linear transformation to the feature map of each channel to generate a Ghost feature map, including performing a depth-wise convolution on each channel using a depth-wise separable convolution to generate a Ghost feature map; S413: concatenating the intrinsic feature map and the Ghost feature map to obtain a final output feature map.
[0009] Furthermore, the step S4 of introducing the BiFPN module into the FPN part for feature fusion includes: S42: deleting the feature pyramid network to reduce the impact on the overall network and simplifying the bidirectional network; S43: adding the original input node and output node connection edges of the same feature layer to reduce the computational cost increment.
[0010] Furthermore, in step S4, replacing the ordinary convolution module in the neck network with a DWConv module includes: S44: connecting the two Ghost Bottleneck modules through a depth-separable convolution DWConv with a step size of 2, and replacing all ordinary convolution blocks Conv in the neck convolution BiFPN module with DWConv.
[0011] Furthermore, the output features in step S4 are sent to the detector with the CBAM module added for feature point judgment, including: S45: integrating the CBAM module into the downsampling step of the neck network, and the output of the C3 module is transmitted to the detection head through the CBAM module.
[0012] Furthermore, the CBAM module includes two independent convolution steps to sequentially infer the input feature map, namely the channel attention module and the spatial attention module. The workflow includes: S451: Given an intermediate feature map F∈R C×H×W As input, the input image F is subjected to global maximum pooling and global average pooling by channel in the channel attention module to obtain two one-dimensional vectors; S452: the vectors are operated through a fully connected layer, element-by-element addition operation and Sigmoid activation operation are performed to generate a one-dimensional channel attention mechanism feature map M c ∈R C×1×1 ; S453: as formula M c Perform element-by-element multiplication with the input feature map F to obtain the channel attention adjusted feature map F ′ ; S454: perform global maximum pooling and average pooling according to space; S455: concatenate the two two-dimensional vectors generated by pooling and perform convolution operation; S456: the feature map after dimensionality reduction is activated by Sigmoid operation to generate the spatial attention feature map M S ∈R 1×H×W ; S457: The spatial attention feature map M S Multiply it with the input feature map F' to get the final generated feature In the formula, Represents element-by-element multiplication. During the multiplication operation, M c Indicates the attention extraction operation in the channel dimension, M c (F) represents the weight coefficient obtained by using the channel attention mechanism, M sIndicates the attention extraction operation in the spatial dimension, M S (F ′ ) represents the weight coefficient obtained by using the spatial attention mechanism, F ′ It represents the feature map output after the input feature map F is adjusted by channel attention, and F″ represents the final accurate output.
[0013] Furthermore, the large detection head among the four detection heads of the YOLOv5s network removed in step S4 includes: S46: In the neck network, a new P2 small-scale prediction head is added, including a 160×160×128 upsampling step, and the large target prediction head is removed, including a 20×20×1024 feature layer output.
[0014] Furthermore, the step S7 of inputting the validation set into the trained multi-target pest detection network model for model evaluation includes: inputting the validation set into the trained multi-target pest detection network model, and evaluating the multi-target pest detection network model based on its precision P, recall R and mean average precision mAP; In the formula, TP is the number of correctly predicted positive samples, FN is the number of incorrectly predicted negative samples, and FP is the number of incorrectly predicted positive samples.
[0015] In a second aspect, the present invention also provides a multi-target pest detection system in an unstructured environment based on an improved YOLOv5s, the system comprising: generating a first target data set unit, suitable for collecting crop images infested by sugarcane aphids, and preprocessing the images as the first target data set; generating a second target data set unit, suitable for randomly selecting and recombining the first target data set and the optimized and annotated AgriPest data set to produce a second target data set; a data set division unit, suitable for dividing the second target data set into a training set, a validation set and a test set; a model improvement unit, suitable for constructing an improved YOLOv5s network model as a multi-target pest detection network model based on the YOLOv5s network model as a benchmark model, comprising: removing four YOLOv5s network The large detection head in the detection head reconstructs the backbone network for feature extraction through the GhostNet module, introduces the BiFPN module into the FPN part for feature fusion, replaces the ordinary convolution module in the neck network with the DWConv module, and the output features are sent to the detector with the CBAM module added for feature point judgment; the model training unit is suitable for inputting the training set into the multi-target pest detection network model for model training; the model improvement unit is suitable for improving the parameters of the multi-target pest detection network model based on the training results to obtain the trained multi-target pest detection network model; the model evaluation unit is suitable for inputting the verification set into the multi-target pest detection network model for model evaluation; the result generation unit is suitable for inputting the test set into the multi-target pest detection network model to obtain the multi-target pest detection result.
[0016] On the other hand, the present invention also provides a computer-readable storage medium, wherein one or more instructions are stored in the computer-readable storage medium, and the computer instructions are used to enable the computer to execute the above-mentioned multi-target pest detection method in an unstructured environment based on the improved YOLOv5s.
[0017] On the other hand, the present invention provides an electronic device, comprising: a memory and a processor; the memory stores at least one program instruction; the processor loads and executes the at least one program instruction to implement the above-mentioned multi-target pest detection method in an unstructured environment based on the improved YOLOv5s.
[0018] The beneficial effects of the present invention are:
[0019] 1. Remove the large detection head among the four detection heads in the YOLOv5s network model, and adopt a three-layer detection head to reduce the number of model parameters and improve the detection speed, making the improved model more suitable for small target pest detection tasks in actual agricultural scenarios.
[0020] 2. The GhostNet module is used to replace the original backbone module for feature extraction. At the same time, in order to better combine feature information of different scales, the BiFPN model is introduced into the FPN part for feature fusion to improve the feature extraction accuracy of the GhostNet lightweight network.
[0021] 3. All ordinary convolution modules in the entire neck module are replaced with DWConv (included in the GhostBottleNeck module), and the output features are sent to the detector with CBAM added for feature point judgment to ensure the unification of the overall convolution module.
[0022] 4. The improved YOLOv5s network model has improved its ability to identify small targets and high-density pests in unstructured environments. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.
[0024] Figure 1 This is a flow chart of a multi-target pest detection method in an unstructured environment based on improved YOLOv5s provided in Example 1 of the present invention.
[0025] Figure 2 This is a structural diagram of a multi-target pest detection network model based on improved YOLOv5s provided in Example 1 of the present invention.
[0026] Figure 3 It is a schematic diagram of the application of a Ghost module and a Ghost Bottleneck module provided in Example 1 of the present invention in the YOLOv5s improved networking.
[0027] Figure 4 It is a schematic diagram of the structure of a basic FPN module (PANet) and a feature-fused BiFPN module provided in Example 1 of the present invention.
[0028] Figure 5 This is a schematic diagram of an attention mechanism module (CBAM) provided in Example 1 of the present invention.
[0029] Figure 6 This is a comparison chart of feature levels before and after model improvement provided by Example 1 of the present invention.
[0030] Figure 7 This is a comparison diagram of the detection effects of an aphid dataset before and after the improvement of a benchmark algorithm provided in Example 1 of the present invention.
[0031] Figure 8 It is a schematic diagram of the structure of a multi-target pest detection system in an unstructured environment based on improved YOLOv5s provided in Example 2 of the present invention.
[0032] Fig. 9 This is a partial block diagram of an electronic device provided in Example 4 of the present invention. DETAILED DESCRIPTION
[0033] It should be mentioned before discussing the exemplary embodiments in more detail that some exemplary embodiments are described as processes or methods depicted as flow charts. Although the flow charts describe the operations as sequential processes, many of the operations therein can be implemented in parallel, concurrently or simultaneously. In addition, the order of the operations can be rearranged. The process can be terminated when its operation is completed, but can also have additional steps not included in the accompanying drawings. The process can correspond to a method, function, procedure, subroutine, subprogram, etc.
[0034] It should be understood that, although the terms "first", "second", etc. may be used herein to describe various units, these units should not be limited by these terms. These terms are used only to distinguish one unit from another unit. For example, without departing from the scope of the exemplary embodiments, the first unit may be referred to as the second unit, and similarly the second unit may be referred to as the first unit. The term "and / or" used herein includes any and all combinations of one or more of the listed associated items.
[0035] In order to facilitate subsequent understanding, the professional terms appearing in the following embodiments are explained here:
[0036] DWConv module: depthwise convolution, depthwise separable convolution module.
[0037] BiFPN module: Bi-directional Feature Pyramid Network, weighted bidirectional feature pyramid network.
[0038] FPN: Feature Pyramid Networks, feature pyramid networks for object detection.
[0039] CBAM: Convolutional Block Attention Module, is an attention mechanism that combines channel attention and spatial attention, designed to improve the feature expression ability of convolutional neural networks.
[0040] The present invention will now be described in detail with reference to the accompanying drawings. This figure is a simplified schematic diagram, which only illustrates the basic structure of the present invention in a schematic manner, and therefore only shows the components related to the present invention.
[0041] Example 1
[0042] like Figure 1-2 As shown, a flow chart of a multi-target pest detection method based on an improved YOLOv5s unstructured environment and a structure diagram of an improved YOLOv5s model provided by the present invention are provided.
[0043] As an example, the method includes:
[0044] S1: Collect images of crops infested by sugarcane aphids and preprocess the images as the first target data set.
[0045] S2: Randomly select the first target data set and the optimized and annotated AgriPest data set and recombine them to produce a second target data set.
[0046] Preferably, steps S1 and S2 include: selecting 4 types of pests on 3 crops to construct a new pest dataset of micro-targets, including 860 self-built images of sugarcane aphids (sorghum crops) migrating to sorghum leaves, 1400 wheat spider (wheat crops) images, 1000 wheat aphids (wheat crops) images, and 700 rice planthoppers (rice crops) images in the AgriPest public dataset. The images of the self-built sugarcane aphid dataset were collected from the farm of the Texas A&M University Agricultural Life Research Institute, which covers an area of about 40,000 m2, and about 70-80% of the sorghum plants are infested by sugarcane aphids. In the dataset, the original image is processed by the method of cutting first and then labeling according to the characteristics of the sugarcane aphid dataset image. The original image is divided into 16 sub-images of 4×4 equal parts, and the image resolution is 816×612. The other types of pests in the dataset retain the original image format of the AgriPest public dataset and optimize the target annotation. The size of the pest target will not occupy more than 3% of the entire image.
[0047] S3: Divide the second target data set into a training set, a validation set and a test set.
[0048] Preferably, the images are randomly divided into a training set, a validation set, and a test set in a ratio of 3:1:1.
[0049] S4: An improved YOLOv5s network model is constructed as a multi-target pest detection network model based on the YOLOv5s network model as the benchmark model, including: removing the large detection head among the four detection heads of the YOLOv5s network, reconstructing the backbone network through the GhostNet module for feature extraction, introducing the BiFPN module to the FPN part for feature fusion, replacing the ordinary convolution module in the neck network with the DWConv module, and the output features are sent to the detector with the CBAM module added for feature point judgment.
[0050] Preferably, after the mainstream deep learning model is built, the Tpest-3960 dataset is used for training and test evaluation, and the results are shown in Table 1. The comparison results of the YOLOv5s model with other target detection networks show that it performs well in both model complexity and detection performance parameters. Among them, Faster R-CNN is one of the classic two-stage target detection algorithms (ResNet50 is used as the feature extraction layer in the experiment); RetinaNet, YOLOX, YOLOv7-tiny, YOLOv7 and YOLOv8s are single-stage target detection algorithms.
[0051] Table 1 Performance comparison of different algorithms
[0052]
[0053] In terms of detection accuracy, the detection accuracy of Faster R-CNN, EfficientDet-D0 and RetinaNet is less than 50%, and it is difficult to accurately detect small-sized pest targets. The detection accuracy of YOLOX, YOLOv7-tiny and YOLOv7 is around 70%, but less than 80% of YOLOv5s; in terms of detection speed, the FPS of YOLOv5s is 222.22, which is better than other target detection algorithms; in terms of model size, the model size of Faster R-CNN and RetinaNet is more than 100MB, which greatly increases the deployment cost of the algorithm in hardware devices, while the model size of YOLOv5s is 13.7MB, which is only 64% of YOLOv8s; in terms of model parameter quantity and floating-point operation number, YOLOv5s is second only to YOLOv7-tiny and the difference is not big, but the detection accuracy of YOLOv7-tiny is far less than YOLOv5s. In summary, YOLOv5s has the best comprehensive performance in terms of detection accuracy, detection rate, model complexity, etc., achieving a certain balance, reducing the requirements for storage and computing resources of mobile hardware devices, reducing the difficulty of algorithm deployment, and maintaining good detection accuracy and effect. Therefore, this embodiment uses the YOLOv5s network model as the benchmark model to improve it.
[0054] Preferably, Figure 2As shown in the figure, the existing YOLOv5s model backbone network consists of a Focus module, a Conv module, a C3 module, and a spatial pyramid pooling (SPP) module, which extracts features from the input image and transmits them to the neck network. The neck module uses a combination of a feature pyramid network and a path aggregation network to enhance the detection capability of objects of different scales through the bidirectional integration of low-level spatial features and high-level semantic features. The head network generates a detection box, which displays the location, category, and confidence of the object by applying the anchor box to the multi-scale feature map of the neck network. YOLOv5 changes the size of the model by adjusting the network depth and width control factors. There are four models from small to large: v5s, v5m, v5l, and v5x.
[0055] The improved network based on YOLOv5s mainly includes model lightweighting and performance optimization. The detailed structure is as follows Figure 2 As shown, the specific steps are as follows:
[0056] The step S4 of reconstructing the backbone network for feature extraction by using the GhostNet module includes: S41: using a Ghost Bottleneck module with a step size of 1 to replace the C3 module in the original YOLOv5s network model, and using a Ghost Bottleneck module with a step size of 2 to replace the ordinary convolution Conv in the original YOLOv5s network model, forming a feature extraction network with the GhostNet module as the backbone. In the figure, G-bneck represents the Ghost Bottleneck module.
[0057] Preferably, the convolution process in the Ghost Bottleneck module includes:
[0058] S411: Obtain an intrinsic feature map through conventional convolution to extract the basic features of the input data. Specifically, for ordinary convolution, assuming that the number of channels of the input feature map is n and the convolution step is s, the number of channels after the first part of the convolution is as shown in the formula m 1 =m=n / s, which is m 1 .
[0059] S412: Applying a linear transformation to the feature map of each channel to generate a Ghost feature map, including performing a depthwise convolution on each channel using a depthwise separable convolution to generate a Ghost feature map. Specifically, the grouped convolution, for m 1 Each feature map in the channels (obtained by the first step of convolution) is mapped s times (including 1 identity mapping and (s-1) low-cost linear transformation mappings), as shown in formula m 2 =m 1 ×(s-1)=(n / s)(s-1), the output channel obtained by the second part is m 2 .
[0060] S413: Splice the intrinsic feature map and the Ghost feature map to obtain the final output feature map. Specifically, Identity splicing. 1 The feature layer and the number of channels obtained in step S412 are m 2 The feature layers are added and concatenated to obtain the final output feature layer, as shown in formula m 3 =m 1 +m 2 =m 1 +m 1 ×(s-1)=m×s, the number of channels is m 3 Because m = n / s, the number of output channels after convolution is still n, so that the module can complete a convolution operation with fewer parameters while keeping the number of output channels consistent with the input, and can be plug-and-play to any convolutional neural network model. The use of this module can significantly reduce model parameters while performing feature extraction.
[0061] Preferably, the network structure of the Ghost module and the Ghost Bottleneck module stacked therefrom with step lengths of 1 and 2 respectively is as follows: Figure 3 (a) shows the Ghost Bottleneck. Ghost Bottleneck is mainly composed of two stacked Ghost modules. Ghost module 1 is an expansion layer, which increases the feature dimension by increasing the number of channels. Ghost module 2 is responsible for reducing the channels, which helps to reduce the feature dimension and maintains feature consistency through a shortcut connection with the input. The BN layer and ReLU layer are introduced in the connection between Ghost modules 1 and 2. Only the BN layer is applied in the connection after the output of Ghost module 2, where BN ReLU stands for batch normalized rectified linear unit and Conv stands for convolution.
[0062] Preferably, in step S4, replacing the common convolution module in the neck network with the DWConv module comprises:
[0063] S44: The two Ghost Bottleneck modules are connected by a depth-wise separable convolution DWConv with a stride of 2, and DWConv replaces all ordinary convolution blocks Conv in the neck convolution BiFPN module. Specifically, DWConv is a lightweight convolution operation. The number of feature maps after the convolution is the same as the number of channels of the input layer, which can reduce the calculation of parameters. It is completely different from the conventional convolution in which each convolution kernel operates on each channel of the input image at the same time. Each channel in the DWConv module is only operated by one convolution kernel, which is conducive to extracting pest and disease features with almost the same size. In order to use model parameters more effectively, DWConv has been successfully used in lightweight networks Xception and MobileNets. In the Ghost Bottleneck module, for the case of a stride of 2, such as Figure 3 As shown in (b), the two Ghost modules are connected through a DWConv with a step size of 2.
[0064] Preferably, the step S4 of introducing the BiFPN module into the FPN part for feature fusion includes:
[0065] S42: Delete the feature pyramid network to reduce the impact on the overall network and simplify the bidirectional network. S43: Add the original input node and output node connection edge of the same feature layer to reduce the computational cost increment. Specifically, the BiFPN proposed in recent years can realize effective bidirectional cross-scale connection and weighted feature fusion. Compared with the feature pyramid network of FPN for target detection, its better effect is mainly reflected in the following aspects: Figure 4 The two steps shown are: S42: Delete the feature pyramid network to reduce the impact on the overall network (because a single input contributes little to feature fusion), and simplify the bidirectional network; S43: Add the original input nodes and output nodes of the same feature layer to connect the edges to reduce the incremental computational cost. In the figure, P1-P2 is 1-2 level feature extraction, and P3-P7 is 3-7 level multi-scale features fused from top to bottom. By improving the original FPN+PAN structure to a BiFPN structure, it is intended to fuse more feature layers through simple residual operations without increasing consumption, thereby enhancing feature extraction capabilities.
[0066] Preferably, the output features in step S4 are sent to the detector with the CBAM module added for feature point judgment, including: S45: integrating the CBAM module into the downsampling step of the neck network, and the output of the C3 module is transmitted to the detection head through the CBAM module. Specifically, the CBAM attention mechanism module is a plug-and-play lightweight module that can be seamlessly integrated into the convolutional neural network architecture and assists each feature layer in capturing useful information according to the depth of the layer. This module mainly involves two independent convolution steps to infer the input feature map in sequence, namely the channel attention module and the spatial attention module.
[0067] Preferably, Figure 5 As shown, the CBAM module includes two independent convolution steps to infer the input feature map in sequence, namely the channel attention module and the spatial attention module. The workflow includes:
[0068] S451: Given an intermediate feature map F∈R C×H×W As input, the input image F is globally max-pooled and globally average-pooled by channel in the channel attention module to obtain two one-dimensional vectors;
[0069] S452: The vector passes through a fully connected layer, performs element-by-element addition and Sigmoid activation operations, and generates a one-dimensional channel attention mechanism feature map M c ∈R C×1×1 ;
[0070] S453: As M c Perform element-by-element multiplication with the input feature map F to obtain the channel attention adjusted feature map F ′ ;
[0071] S454: perform global maximum pooling and average pooling by space;
[0072] S455: concatenate the two two-dimensional vectors generated by pooling and perform convolution operation;
[0073] S456: The feature map after dimensionality reduction is activated by Sigmoid to generate the spatial attention feature map M S ∈R 1×H×W ;
[0074] S457: The spatial attention feature map M S And the input feature map F ′ Do multiplication to get the final generated features
[0075] In the formula, Represents element-by-element multiplication. During the multiplication operation, M c Indicates the attention extraction operation in the channel dimension, M c (F) represents the weight coefficient obtained by using the channel attention mechanism, M s Indicates the attention extraction operation in the spatial dimension, M S (F ′ ) represents the weight coefficient obtained by using the spatial attention mechanism, F ′ It represents the feature map output after the input feature map F is adjusted by channel attention, F ′′ Represents the final accurate output.
[0076] Preferably, the step S4 in which the large detection head of the four detection heads of the YOLOv5s network is removed includes: S46: In the neck network, a new P2 small-scale prediction head is added, including a 160×160×128 upsampling step, and the large target prediction head is removed, including a 20×20×1024 feature layer output. Specifically, the feature level comparison before and after the model improvement is as follows: Figure 6 As shown in Figure 2. In the neck network, a new P2 small-scale prediction head (160×160×128 upsampling step) is added, and the large target prediction head (20×20×1024 feature layer output) is removed. Specifically, as Figure 6 (b) is different from Figure 6 In (a), the P3, P4, and P5 feature levels of the original model, the improved method omits the 20×20×1024 downsampling step in the backbone and downsamples the feature map to a feature layer of 40×40×512 size. The output of this feature layer is 1 / 16 of the original image size, which will be fed into the neck network.
[0077] Preferably, step S5: inputting the training set into the multi-target pest detection network model for model training; S6: improving the parameters of the multi-target pest detection network model based on the training results to obtain a trained multi-target pest detection network model, including:
[0078] The main tools in the development environment that the improved model depends on are shown in Table 2. These toolkits and related Python tool libraries can be imported in the corresponding environment through the terminal of the Visual Studio Code platform. Enter pipinstall and the name of the toolkit or Python tool library to automatically install and import.
[0079] In order to speed up the training of the improved model, a method based on transfer learning was used. Transfer learning is the process of using the model of one project as the initial weight in the training of the convolutional neural network, transferring the learned knowledge from the project, finding the similarity of the target, and reusing it to train the model of another project to improve the learning effect of the other project. Transfer learning uses the model pre-trained on a large dataset to migrate to a dataset with a small number of images. Even when there are few image samples in the dataset, the trained model can still obtain good detection performance, and avoid training from scratch, which can save computing resources and shorten training time. In this study, YOLOv5s is used as the benchmark network model. The parameters of the improved model are set to the YOLOv5s.pt weights pre-trained on the COCO (Common Objects in Context) dataset, and then fine-tuned. The main hyperparameters used in the training process are shown in Table 3.
[0080] Table 2 YOLOv5s improved model development environment
[0081]
[0082]
[0083] Table 3 Hyperparameters of network training
[0084]
[0085] Preferably, the step S7 of inputting the validation set into the trained multi-target pest detection network model for model evaluation comprises: inputting the validation set into the trained multi-target pest detection network model, and evaluating the multi-target pest detection network model based on its precision P, recall R and mean average precision mAP;
[0086]
[0087] In the formula, TP is the number of correctly predicted positive samples, FN is the number of incorrectly predicted negative samples, and FP is the number of incorrectly predicted positive samples.
[0088] This embodiment uses mAP as a performance reference indicator. In balancing lightweight and performance, the number of model parameters and the amount of calculation must also be considered, so it is also necessary to introduce floating point calculations (GFLOPs), parameters (Parameters) and detection speed (FPS) as model architecture detail parameters.
[0089] According to the experimental results in Table 4, the improved model outperforms other advanced target detection models in terms of model size, number of parameters, and FLOPs. In terms of model size, it is only 20% of YOLOv5s (baseline model), which is 8%, 24%, 4%, 13%, 3%, 19% and 2% of YOLOX, YOLOv7-tiny, YOLOv7, YOLOv8s, Faster R-CNN, EfficientDet-D0 and RetinaNet respectively. The number of parameters of the YOLOv5s improved model is also the least, accounting for only 1-26% of the other 8 models. In addition, the YOLOv5s improved model has FLOPs comparable to EfficientDet-D0, which is much smaller than the other seven models (2-58%).
[0090] Table 4 Performance comparison of improved methods and different algorithms
[0091]
[0092] The improved model also demonstrated a good balance between detection accuracy and efficiency. On the Tpest-3960 dataset, the mAP reached 80.1%, which was 0.1%, 10.0%, 10.3%, 10.3%, 51.1%, 51.3% and 53.9% higher than YOLOv5s, YOLOv7, YOLOX, YOLOv7-tiny, RetinaNet, EfficientDet-D0 and Faster R-CNN respectively. Although the detection accuracy of YOLOv8s is slightly higher than that of the improved model by 0.9%, the improved model shows a faster detection speed, with FPS 1.6% higher than YOLOv8s. In addition, the model size of the improved model is significantly smaller, only 13% of YOLOv8s, making it more suitable for real-time detection and mobile deployment.
[0093] Preferably, S8: inputting the test set into the trained multi-target pest detection network model to obtain the multi-target pest detection result.
[0094] like Figure 7 As shown in the figure, 50 randomly selected images were analyzed and counted using the Grad-Cam heat map method. Compared with YOLOv5s, the improved model showed better detection performance for densely distributed or scattered pests under complex backgrounds (such as overlapping and occluded leaves). Figure 7As shown in (a), the improved model showed accurate detection capabilities for wheat spiders scattered on different leaves, including those far from the camera. In contrast, YOLOv5s failed to identify these scattered wheat spiders due to overlapping and occluded leaves. Unlike YOLOv5s, which missed more than one target for both sugarcane aphids and wheat aphids (e.g. Figure 7 (b) and 7(c) for sugarcane aphids (SCA) and wheat aphids (WA), the improved model also showed good recognition accuracy when detecting densely distributed and adhered pests, significantly reducing the problem of missed detection due to adhesion. In addition, Figure 7 As shown in (d), the improved model can accurately identify these pests even when some rice planthoppers (RP) are covered and blocked from view.
[0095] The heatmap further shows that the improved model has a higher sensitivity for small object detection compared to the reference baseline method (i.e., YOLOv5s). This improvement is achieved by combining BiFPN’s enhanced multi-channel feature fusion and CBAM’s spatial attention matrix, which enables the network to automatically select important channel and spatial information during the calculation process. As a result, the enhanced network attention ability significantly improves the recognition results and effectively reduces the probability of missed detection and false detection.
[0096] The above embodiment removes the large detection head among the four detection heads in the YOLOv5s network model, reduces the model parameters by adopting a three-layer detection head, and improves the detection speed, so that the improved model is more suitable for small target pest detection tasks in actual agricultural scenarios; the GhostNet module is used to replace the original backbone module for feature extraction, and at the same time, in order to better combine feature information of different scales, the BiFPN model is introduced into the FPN part for feature fusion, thereby improving the feature extraction accuracy of the GhostNet lightweight network; all ordinary convolution modules in the entire neck module are replaced by DWConv (included in the GhostBottleNeck module), and the output features are sent to the detector with CBAM added for feature point judgment to ensure the unification of the overall convolution module; the improved YOLOv5s network model has improved ability to recognize small target high-density pests in unstructured environments.
[0097] Example 2
[0098] See also Figure 8 , This embodiment provides a structural schematic diagram of a multi-target pest detection system in an unstructured environment based on improved YOLOv5s.
[0099] As an example, the system includes:
[0100] The first target data set generating unit 810 is adapted to collect images of crops infested by sugarcane aphids and pre-process the images as the first target data set.
[0101] The second target data set generating unit 820 is adapted to randomly select and recombine the first target data set and the optimized and annotated AgriPest data set to generate a second target data set.
[0102] The data set division unit 830 is adapted to divide the second target data set into a training set, a validation set and a test set.
[0103] The model improvement unit 840 is suitable for constructing an improved YOLOv5s network model as a multi-target pest detection network model based on the YOLOv5s network model as a benchmark model, including: removing the large detection head among the four detection heads of the YOLOv5s network, reconstructing the backbone network through the GhostNet module for feature extraction, introducing the BiFPN module to the FPN part for feature fusion, replacing the ordinary convolution module in the neck network with the DWConv module, and sending the output features to the detector with the CBAM module added for feature point judgment.
[0104] The model training unit 850 is adapted to input the training set into the multi-target pest detection network model for model training.
[0105] The model improvement unit 860 is adapted to improve the parameters of the multi-target pest detection network model based on the training results to obtain a trained multi-target pest detection network model.
[0106] The model evaluation unit 870 is adapted to input the verification set into the multi-target pest detection network model for model evaluation.
[0107] The result generating unit 880 is adapted to input the test set into the multi-target pest detection network model to obtain the multi-target pest detection result.
[0108] It is not difficult to find that this embodiment is a system embodiment corresponding to the first embodiment, and this embodiment can be implemented in conjunction with the first embodiment. The relevant technical details mentioned in the first embodiment are still valid in this embodiment, and in order to reduce repetition, they are not repeated here. Accordingly, the relevant technical details mentioned in this embodiment can also be applied in the first embodiment.
[0109] It is worth mentioning that all units involved in this embodiment are logical units. In practical applications, a logical unit can be a physical unit, a part of a physical unit, or a combination of multiple physical units. In addition, in order to highlight the innovative part of the present invention, this embodiment does not introduce units that are not closely related to solving the technical problem proposed by the present invention, but this does not mean that there are no other units in this embodiment.
[0110] Example 3
[0111] The embodiment of the present invention further proposes a storage medium, on which a multi-target pest detection method based on an improved YOLOv5s unstructured environment is stored, and when the multi-target pest detection program based on an improved YOLOv5s unstructured environment is executed by a processor, the steps of the multi-target pest detection method based on an improved YOLOv5s unstructured environment as described above are implemented. Since the storage medium adopts all the technical solutions of all the above embodiments, it has at least all the beneficial effects brought by the technical solutions of the above embodiments, which will not be repeated here one by one.
[0112] Example 4
[0113] See also Fig. 9 An embodiment of the present invention also provides an electronic device, comprising: a memory and a processor; the memory stores at least one program instruction; the processor loads and executes the at least one program instruction to implement the multi-target pest detection method in an unstructured environment based on the improved YOLOv5s provided in Example 1.
[0114] The memory 602 and the processor 601 are connected in a bus manner, and the bus may include any number of interconnected buses and bridges, and the bus connects various circuits of one or more processors 601 and the memory 602 together. The bus can also connect various other circuits such as peripheral devices, voltage regulators, and power management circuits, which are well known in the art and are therefore not further described herein. The bus interface provides an interface between the bus and the transceiver. The transceiver can be one element or multiple elements, such as multiple receivers and transmitters, providing a unit for communicating with various other devices on a transmission medium. The data processed by the processor 601 is transmitted on a wireless medium via an antenna, and further, the antenna also receives data and transmits the data to the processor 601.
[0115] The processor 601 is responsible for managing the bus and general processing, and can also provide various functions, including timing, peripheral interfaces, voltage regulation, power management and other control functions. The memory 602 can be used to store data used by the processor 601 when performing operations.
[0116] The above is only an embodiment of the present invention. The common sense such as the known specific structure and characteristics in the scheme is not described in detail here. The ordinary technicians in the relevant field know all the common technical knowledge in the technical field of the invention before the application date or priority date, can know all the existing technologies in the field, and have the ability to apply the conventional experimental means before that date. The ordinary technicians in the relevant field can improve and implement this scheme in combination with their own abilities under the enlightenment given by this application. Some typical known structures or known methods should not become obstacles for ordinary technicians in the relevant field to implement this application. It should be pointed out that for those skilled in the art, without departing from the structure of the present invention, several deformations and improvements can be made, which should also be regarded as the scope of protection of the present invention, which will not affect the effect of the implementation of the present invention and the practicality of the patent. The scope of protection required by this application shall be based on the content of its claims, and the specific implementation methods and other records in the specification can be used to interpret the content of the claims.
Claims
1. A multi-target pest detection method in an unstructured environment based on improved YOLOv5s, characterized in that: The method comprises: S1: Collect images of crops infested by sugarcane aphids and preprocess the images as the first target dataset; S2: randomly selecting the first target data set and the optimized and annotated AgriPest data set and recombining them to produce a second target data set; S3: Divide the second target data set into a training set, a validation set and a test set; S4: Using the YOLOv5s network model as the benchmark model, an improved YOLOv5s network model is constructed as a multi-target pest detection network model, including: removing the large detection head among the four detection heads of the YOLOv5s network, reconstructing the backbone network through the GhostNet module for feature extraction, introducing the BiFPN module to the FPN part for feature fusion, replacing the ordinary convolution module in the neck network with the DWConv module, and sending the output features to the detector with the CBAM module added for feature point judgment; S5: inputting the training set into the multi-target pest detection network model for model training; S6: Based on the training results, the parameters of the multi-target pest detection network model are improved to obtain the trained multi-target pest detection network model; S7: inputting the validation set into the trained multi-target pest detection network model for model evaluation; S8: Input the test set into the trained multi-target pest detection network model to obtain a multi-target pest detection result.
2. The multi-target pest detection method based on improved YOLOv5s in an unstructured environment according to claim 1, characterized in that: In step S4, reconstructing the backbone network for feature extraction through the GhostNet module includes: S41: Use the Ghost Bottleneck module with a step size of 1 to replace the C3 module in the original YOLOv5s network model, and use the Ghost Bottleneck module with a step size of 2 to replace the ordinary convolution Conv in the original YOLOv5s network model, forming a feature extraction network with the GhostNet module as the backbone.
3. The multi-target pest detection method based on improved YOLOv5s in an unstructured environment according to claim 2, characterized in that: The convolution process in the Ghost Bottleneck module includes: S411: Obtaining an intrinsic feature map through conventional convolution to extract basic features of the input data; S412: applying a linear transformation to the feature map of each channel to generate a Ghost feature map, including performing a depthwise convolution on each channel by using a depthwise separable convolution to generate a Ghost feature map; S413: Concatenate the intrinsic feature map and the Ghost feature map to obtain a final output feature map.
4. The multi-target pest detection method based on improved YOLOv5s in an unstructured environment according to claim 1, characterized in that: In step S4, introducing the BiFPN module into the FPN part for feature fusion includes: S42: Delete the feature pyramid network to reduce the impact on the overall network and simplify the bidirectional network; S43: Add the original input node and output node connection edge of the same feature layer to reduce the computational cost increment.
5. The multi-target pest detection method based on improved YOLOv5s in an unstructured environment according to claim 1, characterized in that: In step S4, replacing the common convolution module in the neck network with the DWConv module includes: S44: The two Ghost Bottleneck modules are connected by a depth-wise separable convolution DWConv with a stride of 2, and DWConv replaces all ordinary convolution blocks Conv in the bottleneck convolution BiFPN module.
6. The multi-target pest detection method based on improved YOLOv5s in an unstructured environment according to claim 1, characterized in that: The output features in step S4 are sent to the detector with the CBAM module added to perform feature point determination, including: S45: The CBAM module is integrated into the downsampling step of the neck network, and the output of the C3 module is transmitted to the detection head through the CBAM module.
7. The multi-target pest detection method based on improved YOLOv5s in an unstructured environment according to claim 6, characterized in that: The CBAM module includes two independent convolution steps to infer the input feature map in sequence, namely the channel attention module and the spatial attention module. The workflow includes: S451: Given an intermediate feature map F∈R C×H×W As input, the input image F is globally max-pooled and globally average-pooled by channel in the channel attention module to obtain two one-dimensional vectors; S452: The vector passes through a fully connected layer, performs element-by-element addition and Sigmoid activation operations, and generates a one-dimensional channel attention mechanism feature map M c ∈R C×1×1 ; S453: As M c Perform element-by-element multiplication with the input feature map F to obtain the channel attention adjusted feature map F ′ ; S454: perform global maximum pooling and average pooling by space; S455: concatenate the two two-dimensional vectors generated by pooling and perform convolution operation; S456: The feature map after dimensionality reduction is activated by Sigmoid to generate the spatial attention feature map M S ∈R 1×H×W ; S457: The spatial attention feature map M S Multiply it with the input feature map F' to get the final generated feature In the formula, Represents element-by-element multiplication. During the multiplication operation, M c Indicates the attention extraction operation in the channel dimension, M c (F) represents the weight coefficient obtained by using the channel attention mechanism, M s Indicates the attention extraction operation in the spatial dimension, M S (F ′ ) represents the weight coefficient obtained by using the spatial attention mechanism, F ′ It represents the feature map output after the input feature map F is adjusted by channel attention, and F″ represents the final accurate output.
8. The multi-target pest detection method based on improved YOLOv5s in an unstructured environment according to claim 1, characterized in that: The step S4 includes removing the large detection head among the four detection heads of the YOLOv5s network: S46: In the neck network, a new P2 small-scale prediction head was added, including a 160×160×128 upsampling step, and the large object prediction head was removed, including a 20×20×1024 feature layer output.
9. The multi-target pest detection method based on improved YOLOv5s in an unstructured environment according to claim 1, characterized in that: The step S7 of inputting the verification set into the trained multi-target pest detection network model for model evaluation includes: S71: inputting the validation set into the trained multi-target pest detection network model, and evaluating the multi-target pest detection network model based on its precision rate P, recall rate R and mean average precision mAP; In the formula, TP is the number of correctly predicted positive samples, FN is the number of incorrectly predicted negative samples, and FP is the number of incorrectly predicted positive samples.
10. A multi-target pest detection system in an unstructured environment based on improved YOLOv5s, characterized in that: The system comprises: A first target data set generating unit is adapted to collect images of crops infested by sugarcane aphids and pre-process the images as the first target data set; A second target data set generating unit is adapted to randomly select and recombine the first target data set and the optimized and annotated AgriPest data set to generate a second target data set; A data set division unit, adapted to divide the second target data set into a training set, a validation set and a test set; The model improvement unit is suitable for building an improved YOLOv5s network model as a multi-target pest detection network model based on the YOLOv5s network model as a benchmark model, including: removing the large detection head among the four detection heads of the YOLOv5s network, reconstructing the backbone network for feature extraction through the GhostNet module, introducing the BiFPN module to the FPN part for feature fusion, replacing the ordinary convolution module in the neck network with the DWConv module, and the output features are sent to the detector with the CBAM module added for feature point judgment; A model training unit, adapted to input a training set into the multi-target pest detection network model for model training; A model improvement unit, adapted to improve the parameters of the multi-target pest detection network model based on the training results to obtain a trained multi-target pest detection network model; A model evaluation unit, adapted to input a validation set into the multi-target pest detection network model for model evaluation; The result generating unit is suitable for inputting the test set into the multi-target pest detection network model to obtain the multi-target pest detection result.
Citation Information
Patent Citations
Lightweight deployment method based on aero-engine borescope crack detection
CN114998255A
Cloth flaw detection method based on lightweight cascade network
CN115205274A
Lightweight face and face key point detection method based on GhostNetV2
CN116416672A
Driver safety belt detection method based on deep learning
CN117333852A
Cited By
Agricultural product detection method and system based on lightweight deployment model and application
CN119360367A
Method for detecting and identifying tomicus
CN119992155A
