Plant pest detection method, device and equipment
By using the YOLOv5 model and the efficient multi-scale attention mechanism module, the accurate identification and growth stage judgment of plant pests is achieved, the problem of inability to effectively detect the pest growth stage in the existing technology is solved, and the effectiveness of prevention and control measures is improved.
Patent Information
- Application Number
- CN202411701722.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-26
- Publication Date
- 2025-03-18
AI Technical Summary
Existing plant pest detection technology cannot effectively detect the growth stage of plant pests, resulting in the inability to provide targeted prevention and control measures.
The plant pest detection model trained by the YOLOv5 model is used. This model includes an efficient multi-scale attention mechanism module, which can identify and locate the target plant pest in the image to be detected and determine its growth stage.
It improves the accuracy of plant pest identification and can identify large and smaller plant pests, including target plant pests at different growth stages, thereby improving the reliability of plant pest control.
Smart Images

Figure CN119649217A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of plant pest detection, and in particular to a method, device and equipment for detecting plant pests. Background Art
[0002] Plant pests not only have a serious impact on plant growth, development and yield, but also pose a threat to the stability of agricultural production.
[0003] Plant pest detection is an important means of protecting plants. By detecting plant pests in crops, targeted prevention and control measures can be taken against pests.
[0004] There are different prevention and control measures for plant pests at different growth stages, but current plant pest detection cannot effectively detect the growth stage of plant pests, and thus cannot effectively provide targeted prevention and control measures. Summary of the invention
[0005] The purpose of this application is to provide a plant pest detection method, device and equipment that can improve the effectiveness of control measures.
[0006] To achieve the above objectives, this application provides the following solutions:
[0007] In a first aspect, the present application provides a method for detecting plant pests, the method comprising:
[0008] Receiving an image to be detected;
[0009] Inputting the image to be detected into a plant pest detection model to obtain the position of each target plant pest in the image to be detected and the growth stage of each target plant pest in the image to be detected, wherein the plant pest detection model is obtained by training a YOLOv5 model, and the YOLOv5 model includes a first efficient multi-scale attention mechanism module;
[0010] Acquire the number of target plant pests in the image to be detected according to the position of each target plant pest in the image to be detected;
[0011] According to the growth stage of each of the target plant pests in the image to be detected, obtaining the number of the target plant pests belonging to the same growth stage in the image to be detected;
[0012] The number of target plant pests in the image to be detected and the number of the target plant pests belonging to the same growth stage are output.
[0013] In a second aspect, the present application provides a plant pest detection device, the plant pest detection device comprising:
[0014] A receiving module, used for receiving an image to be detected;
[0015] A first acquisition module is used to input the image to be detected into a plant pest detection model to obtain the position of each target plant pest in the image to be detected and the growth stage of each target plant pest in the image to be detected, wherein the plant pest detection model is obtained by training a YOLOv5 model, and the YOLOv5 model includes a first efficient multi-scale attention mechanism module;
[0016] A second acquisition module, used for acquiring the number of target plant pests in the image to be detected according to the position of each target plant pest in the image to be detected;
[0017] A third acquisition module is used to acquire the number of the target plant pests belonging to the same growth stage in the image to be detected according to the growth stage of each of the target plant pests in the image to be detected;
[0018] The output module is used to output the number of target plant pests in the image to be detected and the number of the target plant pests belonging to the same growth stage.
[0019] In a third aspect, the present application provides a computer device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of any one of the plant pest detection methods described above.
[0020] In a fourth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of any one of the plant pest detection methods described above.
[0021] In a fifth aspect, the present application provides a computer program product, comprising a computer program, which, when executed by a processor, implements the steps of any one of the plant pest detection methods described above.
[0022] According to the specific embodiments provided in this application, this application discloses the following technical effects:
[0023] The present application provides a plant pest detection method, device and equipment, the plant pest detection method comprising: receiving an image to be detected; inputting the image to be detected into a plant pest detection model to obtain the position of each target plant pest in the image to be detected and the growth stage of each target plant pest in the image to be detected, wherein the plant pest detection model is obtained by training a YOLOv5 model, and the YOLOv5 model includes a first efficient multi-scale attention mechanism module; according to the position of each target plant pest in the image to be detected, the number of target plant pests in the image to be detected is obtained; according to the growth stage of each target plant pest in the image to be detected, the number of target plant pests belonging to the same growth stage in the image to be detected is obtained; and the number of target plant pests in the image to be detected and the number of target plant pests belonging to the same growth stage are output. The present invention adds an efficient multi-scale attention mechanism module to the backbone network of the YOLOv5 model, further enhancing the detection capability of the YOLOv5 model for small targets, so that the YOLOv5 model can not only identify large plant pests, but also identify smaller plant pests well, so that target plant pests at various growth stages can be identified, thereby improving the accuracy of target plant pest identification and further improving the reliability of plant pest control. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0025] Figure 1 The process of a plant pest detection method according to an exemplary embodiment is shown as follows Figure 1 ;
[0026] Figure 2 The process of a plant pest detection method according to an exemplary embodiment is shown as follows Figure 2 ;
[0027] Figure 3 is a schematic diagram of a model training process according to an exemplary embodiment;
[0028] Figure 4 A schematic diagram of functional modules of a plant pest detection device provided in one embodiment of the present application;
[0029] Figure 5 A schematic diagram of the structure of a computer device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0030] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0031] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, the present application is further described in detail below with reference to the accompanying drawings and specific implementation methods.
[0032] Figure 1 is a flow chart of a method for detecting plant pests according to an exemplary embodiment. Figure 1 As shown, the method includes the following steps S101-S105:
[0033] In step S101, an image to be detected is received.
[0034] In step S102, the image to be detected is input into a plant pest detection model to obtain the position of each target plant pest in the image to be detected and the growth stage of each target plant pest in the image to be detected, wherein the plant pest detection model is obtained by training the YOLOv5 model, and the YOLOv5 model includes a first efficient multi-scale attention mechanism module.
[0035] In step S103, the number of target plant pests in the image to be detected is obtained according to the position of each target plant pest in the image to be detected.
[0036] For example, the location of the plant pest can be framed by a rectangular frame.
[0037] The plant pest detection model can detect the position of each target plant pest in the image to be detected. After the position of the target plant pest is detected, the number of the target plant pest in the image to be detected can be counted.
[0038] When the positions of target plant pests are framed in the form of rectangular frames, the number of rectangular frames in the framed image to be detected can be obtained. At this time, the number of rectangular frames in the image to be detected is the number of target plant pests in the image to be detected.
[0039] In step S104, according to the growth stage of each target plant pest in the image to be detected, the number of target plant pests belonging to the same growth stage in the image to be detected is obtained.
[0040] The plant pest detection model can also detect the growth stage of each target plant pest in the image to be detected. After detecting the growth stage of each target plant pest, the number of target plant pests belonging to the same growth stage in the image to be detected can be counted.
[0041] Taking the target plant pest Panonychus citri as an example, the growth stages of Panonychus citri can be roughly divided into four main stages: eggs, larvae, nymphs, and adult mites. The plant pest detection model in the present invention can detect the growth stage of each Panonychus citri in the image to be detected. After detecting the growth stage of each Panonychus citri in the image to be detected, the number of Panonychus citri egg stages, the number of Panonychus citri nymph stages, and the number of Panonychus citri adult stages can be counted.
[0042] In step S105, the number of target plant pests in the image to be detected and the number of target plant pests belonging to the same growth stage are output.
[0043] The present disclosure can output the number of target plant pests in the image to be detected and the number of target plant pests belonging to the same growth stage.
[0044] Traditional solutions usually use manual real-time viewing and counting to count the number of target plant pests in the image to be detected, which has problems such as high labor cost and low recognition efficiency. However, in the present disclosure, the number of target plant pests in the image to be detected can be automatically obtained, which greatly reduces labor costs and improves recognition efficiency.
[0045] Furthermore, the deep learning machine vision-based methods in related technologies can usually only distinguish different types of target plant pests, but cannot classify and count target plant pests of the same type at different growth stages. Classification and counting of target plant pests of the same type at different growth stages is extremely important from the perspective of insecticide development and insecticidal effects.
[0046] The target plant pest is taken as an example of Panonychus citri.
[0047] The citrus red spider mite is an arthropod of the family Tetranychidae in the order Acarina, also known as red spider mites. It causes damage by sucking the juice from the leaves, tender shoots and fruit skin of economic crops.
[0048] The citrus mites can be roughly divided into four main stages: eggs, larvae, nymphs, and adult mites. In the field, the larvae and nymphs and adult mites often cause damage by sucking leaf juice. Some miticides are only effective against larvae and adult mites, not eggs. Some miticides are effective against eggs, but poor against adult mites and larvae. These will cause the mite pest to recur quickly. Therefore, in order to achieve the ideal prevention and control effect, it is necessary to effectively control all growth stages. Therefore, this requires a clear evaluation of the citrus mites at each growth stage in the early drug development or the later technical application. For example, a miticide in the early stages of research and development If a compound or extract is only effective against adult mites but not ideally effective against citrus mites at other growth stages, a comprehensive evaluation combined with cost can determine whether the miticide can enter the subsequent research and development stage, and then choose to continue, abandon or shelve it. Such standards can be used to quickly evaluate existing miticides to improve research and development efficiency; the same is true for technical applications. If a product can kill adult mites, larvae and nymphs, but the egg-killing effect is not ideal, then it needs to be used in combination with a product with an ideal egg-killing effect when applied in the field. Only by fully grasping the activity at different growth stages can an effective insecticide program be identified to achieve a satisfactory insecticide effect.
[0049] Furthermore, since eggs and young mites are smaller than nymphs and adult mites and cannot be observed with the naked eye, the scheme disclosed in the present invention can achieve microscopic-scale identification and can accurately identify these smaller pests.
[0050] The YOLOv5 model is an advanced plant pest detection model with the advantages of high efficiency and accuracy. However, since some target plant pests are small, or some target plant pests are small in size when they are in the egg stage, it is slightly difficult to identify them. The present disclosure adds an Efficient Multi-Scale Attention (EMA) attention mechanism module to the backbone network of the YOLOv5 model, further enhancing the YOLOv5 model's ability to detect small targets, so that the YOLOv5 model can not only identify large plant pests, but also identify smaller plant pests and their eggs. In this way, target plant pests at various growth stages can be identified, thereby improving the accuracy of target plant pest identification and further improving the reliability of plant pest control.
[0051] In one achievable manner, the YOLOv5 model in the present disclosure further includes an attention feature fusion module, which is composed of an iterative attention feature fusion (iAFF) network and a second efficient multi-scale attention mechanism module.
[0052] The present disclosure proposes a unique iEMAFF feature fusion network that combines an iterative attentional feature fusion (iAFF) network with an EMA attention module, which improves the efficiency of target features of different dimensions and retrograde fusion. The iEMAFF feature fusion network is implemented by the attention feature fusion module in the above embodiment.
[0053] Through the above analysis, it can be seen that the existing target detection model has weak detection capabilities for targets with small volume and small pixel area. However, the different growth stages of the same pest faced by the present disclosure make the appearance of different targets to be identified more similar. The EMA attention mechanism module can enhance the ability of small target detection by enhancing the model perception ability and feature extraction effect. The iEMAFF feature fusion module can fuse features between different dimensions (feature map size) to enhance the ability to distinguish features of mites at different stages with similar appearance.
[0054] Before executing the above steps, it is necessary to obtain a plant pest detection model. Figure 2 As shown, the plant pest detection method further includes the following sub-steps S201-S207:
[0055] In step S201, a sample data set is obtained, the sample data set includes: sample images and annotation information of each sample image, the annotation information of each sample image includes: the image position of the target plant pest in each sample image, and the growth stage of each target plant pest in each sample image.
[0056] Specifically, a computer can be used in conjunction with an electronic image acquisition device with a preset magnification to obtain images of target plant pest individuals at multiple different growth stages on plant leaves, wherein one sample image can contain 3-30 different target plant pest individuals.
[0057] For example, the preset magnification may be 30 times.
[0058] The obtained sample images are annotated, and the annotation information is stored in the YOLO format to create a sample data set for training. The annotation information specifically includes: using a rectangular bounding box to mark the image position of the target plant pest individual, and using a text label to identify the growth stage of each target plant pest individual.
[0059] In step S202, a training data set and a verification data set in the sample data set are obtained.
[0060] During model training, the training data set is the main data source for model learning and parameter adjustment. The model learns from the samples in the training data set and continuously adjusts its own parameters to fit the patterns and rules in the data as accurately as possible. The validation data set is used to evaluate the performance of the model during training and adjust the model's hyperparameters. During model training, the validation data set is regularly used to evaluate the performance of the model, such as accuracy, loss value, etc. Based on the performance on the validation set, the model's hyperparameters, such as learning rate, number of layers, number of nodes, etc., can be adjusted to optimize the model's performance.
[0061] In the present disclosure, the sample data set produced in step S201 is segmented into a training data set and a verification data set in a ratio of 8:2.
[0062] In step S203, the YOLOv5 model is trained according to the training data set to obtain a trained YOLOv5 model.
[0063] A plant pest detection model based on YOLOv5 is designed, named EMAFF-YOLOv5, in which the input image received by the plant pest detection model is of a fixed size, but the input image can be of any resolution, and the image will be processed to a size suitable for the YOLOv5 model before entering the YOLOv5 model. For example, the YOLOv5 model of the present disclosure receives an image input with a resolution of 640×640.
[0064] The sample images in the training data set in step S202 will be converted into three-dimensional tensor data and input into the YOLOv5 model, and the dimension names are channel, length, and width respectively.
[0065] In one embodiment, step S203 includes the following sub-steps S2031-S2032:
[0066] In step S2031, the training data set is input into the backbone network of the YOLOv5 model to obtain the feature output of the backbone network, where the backbone network includes a first efficient multi-scale attention mechanism module.
[0067] Specifically, the sample images in the training data set need to be preprocessed; then the preprocessed training data set is input into the backbone network (English: Backbone) of the YOLOv5 model to obtain the feature output of the backbone network.
[0068] Among them, the preprocessing may include converting the sample image into a preset input size corresponding to the YOLOv5 model, for example: converting the sample image into a 640×640 image, and then converting the sample image converted into the preset input size into three-dimensional tensor data, and inputting the converted three-dimensional tensor data into the backbone network of the YOLOv5 model.
[0069] In one embodiment, step S2031 includes the following sub-steps S20311-S20313:
[0070] In step S20311, the training data set is input into the first convolution module to obtain a feature layer of the first resolution.
[0071] The first module of the backbone network is the first convolution (Convolution, referred to as: Conv) module, which performs convolution, batch normalization and activation operations on the input image to obtain the first resolution feature layer.
[0072] The Conv module is a flexible network module. The operation performed inside this module is a convolution operation, and the parameters such as the convolution kernel size, step size, padding and expansion are determined by the parameters provided when calling the module. In this model, the convolution kernel size of the Conv module with unchanged output resolution is 1×1, while the convolution kernel size of the Conv module with reduced output resolution is 3×3.
[0073] The first convolution module may be Focus, which is a special Conv module. Compared with other Conv modules in the backbone network, it uses a 6×6 convolution kernel and a parameter with a step size of 2 to achieve the functions of alternate column sampling and splicing. In terms of specific effect, the Focus module splits the input image (original feature) with a resolution of 640×640×3 (width×height×number of channels) into a feature layer of 320×320×12, thereby reducing the size of the feature map without losing feature details and improving computational efficiency.
[0074] like Figure 3 As shown, the sample images in the training data set are converted into 640×640 images and input into the first convolution module Focus. After processing by the first convolution module Focus, a first feature layer with a resolution of 320×320 is obtained.
[0075] In step S20312, the feature layer of the first resolution is input into the backbone network feature extraction module to obtain a feature layer of a preset resolution; the backbone network feature extraction module includes: multiple feature extraction sub-modules, each backbone network feature extraction sub-module includes: a backbone network convolution (Convolution, Conv) sub-module, a backbone network cubic convolution module and a first efficient multi-scale attention mechanism module.
[0076] The number of feature extraction submodules in this embodiment can be set according to the actual application scenario. The following is an illustration of setting four backbone network feature extraction submodules, where the four backbone network feature extraction submodules are: a first backbone network feature extraction submodule, a second backbone network feature extraction submodule, a third backbone network feature extraction submodule and a fourth backbone network feature extraction submodule.
[0077] In one embodiment, step S20312 includes the following sub-steps A1-A3:
[0078] A1. Input the feature layer of the first resolution into the first backbone network feature extraction submodule to obtain the feature layer of the second resolution.
[0079] Among them, Figure 3 As shown, the first backbone network feature extraction submodule includes: the first backbone network convolution submodule Conv 1 , the first backbone network cubic convolution module C3 1 And the first efficient multi-scale attention mechanism first submodule EMA 1 .
[0080] The feature layer of the first resolution obtained in step S20311 is processed by Conv 1 module, and obtain the second preliminary feature layer with a second resolution of 160×160. This second preliminary feature layer will pass through a C3 1 Module, C3 1 The module performs three convolution operations on the second preliminary feature layer and merges it with the feature layer of the first resolution of the original input to obtain the second intermediate feature layer of the second resolution. The second intermediate feature layer enters EMA 1 A feature layer of the second resolution is obtained.
[0081] Among them, C3 1 The module can achieve the effect of broadening the receptive field and better integrating the contextual information of the image. 1 The convolution kernel size of the module is 1×1, so C3 1 The resolution of the feature layer output by the module does not change and is also the second resolution of 160×160.
[0082] EMA 1 The input feature map is grouped into multiple sub-features in the horizontal and vertical channel space, global information is encoded to recalibrate the channel features in each branch, and the output features of the two branches are further aggregated through cross-dimensional interaction, so that the spatial semantic features are evenly distributed within the channel to achieve the purpose of enhancing the detection efficiency of the model, and EMA 1 The resolution of the feature layer output by the module does not change.
[0083] A2. Input the feature layer of the second resolution into the second backbone network feature extraction submodule to obtain a feature layer of the third resolution.
[0084] Among them, Figure 3 As shown, the second backbone network feature extraction submodule includes: the second backbone network convolution submodule Conv 2 , the second backbone network cubic convolution module C3 2 And the first efficient multi-scale attention mechanism second submodule EMA 2 .
[0085] The feature layer of the second resolution obtained in step A1 is passed through Conv 2 module, and obtain the third preliminary feature layer with a third resolution of 80×80. This third preliminary feature layer will pass through a C3 2 Module, C3 2 The module performs three convolution operations on the third preliminary feature layer and merges it with the second resolution feature layer of the original input to obtain the third intermediate feature layer of the third resolution. The third intermediate feature layer enters EMA 2 A feature layer of the third resolution is obtained.
[0086] Among them, Conv 2 The module can realize smooth operation of features and enhance the perception ability of the model; C3 2 The convolution kernel size of the module is 1×1.
[0087] A3. Input the feature layer of the third resolution into the third backbone network feature extraction submodule to obtain a feature layer of the fourth resolution.
[0088] Among them, Figure 3 As shown, the third backbone network feature extraction submodule includes: the third backbone network convolution submodule Conv 3 , the third backbone network cubic convolution module C3 3 And the third submodule EMA of the first efficient multi-scale attention mechanism 3 .
[0089] The feature layer of the third resolution obtained in step A2 is passed through Conv 3 module, and obtain the fourth preliminary feature layer with a fourth resolution of 40×40. This fourth preliminary feature layer will pass through a C3 3 Module, C3 3 The module performs three convolution operations on the fourth preliminary feature layer and merges it with the feature layer of the third resolution of the original input to obtain the fourth intermediate feature layer of the fourth resolution. The fourth intermediate feature layer enters EMA 3 A feature layer of the fourth resolution is obtained.
[0090] Among them, Conv3 The module can realize smooth operation of features and enhance the perception ability of the model; C3 3 The convolution kernel size of the module is 1×1.
[0091] A4. Input the feature layer of the fourth resolution into the fourth backbone network feature extraction submodule to obtain a feature layer of a preset resolution.
[0092] Among them, Figure 3 As shown, the fourth backbone network feature extraction submodule includes: the fourth backbone network convolution submodule Conv 4 , the fourth backbone network cubic convolution module C3 4 And the fourth submodule EMA of the first efficient multi-scale attention mechanism 4 .
[0093] The feature layer of the fourth resolution obtained in step A3 is processed by Conv 4 module, and obtain the fifth preliminary feature layer with a fifth resolution of 20×20. This fifth preliminary feature layer will be processed by a C3 4 Module, C3 4 The module performs three convolution operations on the fifth preliminary feature layer and fuses it with the feature layer of the fourth resolution of the original input to obtain the fifth intermediate feature layer of the fifth resolution. The fifth intermediate feature layer enters EMA 4 A feature layer of the fifth resolution is obtained.
[0094] The preset resolution in the above embodiment is the fifth resolution.
[0095] Among them, Conv 4 The module can realize smooth operation of features and enhance the perception ability of the model; C3 4 The convolution kernel size of the module is 1×1.
[0096] In step S20313, the feature layer of the preset resolution is input into the backbone network pooling module to obtain the feature output of the backbone network.
[0097] like Figure 3 As shown, the backbone network pooling module in the present disclosure selects the SPPF (Spatial Pyramid Pooling-Fast) module.
[0098] The SPPF module is a fast version of Spatial Pyramid Pooling (SPP), which is used to aggregate features at different scales and enhance the model's ability to detect objects of different sizes. The SPPF module is usually composed of multiple parallel pooling layers with different pooling kernel sizes and step sizes. In this way, the SPPF module can perform pooling operations on the input feature map at different scales to extract multi-scale feature information.
[0099] The output resolution of the SPPF module will not change, and this module is at the end of the Backbone part of the model. Its output is the output of the Backbone, that is, the characteristic output of the backbone network in the above embodiment.
[0100] In step S2032, the feature output of the backbone network is input into the path aggregation network to obtain the feature output of the path aggregation network, which includes an attention feature fusion module.
[0101] The feature output of the backbone network enters the Path Aggregation Network (PANet) part of the YOLOv5 module, that is, Figure 3 The Neck in the model is used to promote the flow of information in the model network, which enhances the representation ability of the backbone network by fusing the bottom-up and top-down paths.
[0102] In one embodiment, step S2032 includes the following sub-steps S20321-S20326:
[0103] Step S20321: Input the feature output of the backbone network into the first path aggregation processing module to obtain a feature layer of the sixth resolution; the first path aggregation processing module includes: a first path aggregation convolution module Conv 5 And the first upsampling module Upsample 1 .
[0104] like Figure 3 As shown in the figure, PANet converts the resolution of Backbone’s output features into 5 Modules and Upsample 1 The module is expanded to 40×40.
[0105] Step S20322: input the feature layer of the sixth resolution and the feature layer of the fourth resolution into the first attention feature fusion module to obtain the first fusion feature.
[0106] like Figure 3As shown, the sixth feature layer with a resolution of 40×40 obtained in step S20321 will be passed through the first attention feature fusion module iEMAFF 1 The features of the fourth resolution feature layer in Backbone, which also has a resolution of 40×40, are fused.
[0107] The iEMAFF module is a combination of the iterative attentional feature fusion (iAFF) network and the EMA attention module. iAFF uses the attention mechanism to improve traditional feature fusion methods such as addition or concatenation, and the EMA attention module is used to replace the MS-CAM attention module in the original iAFF to improve the model fusion capability.
[0108] Step S20323: The first fusion feature is input into the path aggregation three-convolution module C3 5 , and obtain the third convolution feature layer of the sixth resolution.
[0109] Step S20324: input the third convolution feature layer of the sixth resolution into the second path aggregation processing module to obtain a feature layer of the seventh resolution; the second path aggregation processing module includes: a second path aggregation convolution module Conv 6 And the second upsampling module Upsample 2 .
[0110] like Figure 3 As shown, PANet passes the sixth 40×40 resolution cubic convolution feature layer through Conv 6 Modules and Upsample 2 The module is expanded to the seventh resolution of 80×80.
[0111] Step S20325: input the feature layer of the seventh resolution and the feature layer of the third resolution into the second attention feature fusion module to obtain a second fusion feature.
[0112] like Figure 3 As shown, the seventh feature layer with a resolution of 80×80 obtained in step S20324 will be passed through the second attention feature fusion module iEMAFF 2 , in iEMAFF 2 In step S20324, the feature layer with the seventh resolution of 80×80 obtained is fused with the feature layer with the third resolution of 80×80 in Backbone to obtain a second fused feature of 80×80.
[0113] This completes the bottom-up feature flow path in PANet.
[0114] Step S20326: Pass the second fusion feature through the aggregation network feature extraction module to obtain the feature output of the path aggregation network.
[0115] In one embodiment, step S20326 includes the following sub-steps B1-B7:
[0116] B1, the second fusion feature is extracted through the first aggregation network feature extraction submodule C3 6 , obtain the first feature output P3 of the path aggregation network.
[0117] Among them, the first aggregation network feature extraction submodule can be C3 5 module.
[0118] like Figure 3 As shown, the second fusion feature of step S20325 passes through C3 6 The module extracts feature information.
[0119] C3 6 The output content P3 of the module is sent to the head network as the first feature output of the path aggregation network ( Figure 3 Head in the .
[0120] B2. Input the first feature output of the path aggregation network into the first aggregation network convolution module to obtain the first aggregation network convolution output.
[0121] like Figure 3 As shown, the first feature output P3 of the path aggregation network obtained in step B1 is input to the first aggregation network convolution module Conv 7 Module, and obtain the 40×40 first aggregation network convolution output.
[0122] B3. Input the first aggregation network convolution output and the feature layer of the sixth resolution into the third attention feature fusion module to obtain the third fusion feature.
[0123] The first feature output of the path aggregation network output by B1 will itself be used as the starting point of the top-down feature flow path in PANet again, passing through the first aggregation network convolution module Conv 7 After smoothing the features, the first aggregate network convolution output is obtained, and then the first aggregate network convolution output is passed through the third attention feature fusion module iEMAFF 3 Module, in iEMAFF 3 In the module, the first aggregation network convolution output is fused again with the feature layer of the sixth resolution.
[0124] B4. Pass the third fusion feature through the second aggregation network feature extraction submodule to obtain the second feature output P4 of the path aggregation network.
[0125] like Figure 3 As shown, the second aggregation network feature extraction submodule can be C3 7 Module. The third fusion feature of step B3 passes through C3 7 Module to extract feature information, C3 7 The output content P4 of the module is sent to the head network as the second feature output of the path aggregation network.
[0126] B5. Input the second feature output of the path aggregation network into the second aggregation network convolution module to obtain the second aggregation network convolution output.
[0127] like Figure 3 As shown, the second feature output P4 of the path aggregation network obtained in step B4 is input to the second aggregation network convolution module Conv 8 , and obtain the 20×20 second aggregation network convolution output.
[0128] B6. Input the convolution output of the second aggregation network and the feature layer of preset resolution into the fourth attention feature fusion module to obtain the fourth fusion feature.
[0129] like Figure 3 As shown, the second aggregate network convolution output of B5 is passed through the fourth attention feature fusion module iEMAFF 4 Module, in iEMAFF 4 In the module, the second aggregation network convolution output is again fused with the feature layer of the preset resolution, where the preset resolution is the fifth resolution in the above embodiment.
[0130] B7. Pass the fourth fusion feature through the third aggregation network feature extraction submodule to obtain the third feature output P5 of the path aggregation network.
[0131] like Figure 3 As shown, the third aggregation network feature extraction submodule can be C3 8 Module. The fourth fusion feature of step B6 passes through C3 8 Module to extract feature information, C3 8 The output content P5 of the module is sent to the head network as the third feature output of the path aggregation network.
[0132] In step S2033, the feature output of the path aggregation network is input into the head network to obtain the output results corresponding to the sample images in the training data set, and the output results include: the target position and growth stage of the target plant pests in each sample image in the training data set.
[0133] like Figure 3 As shown, the head network (head) includes three detection layers, namely Detect 1、Detect 1 and Detect 3 , and output P3, P4 and P5 to the corresponding detection layers respectively.
[0134] The detection layer runs the target detection algorithm to detect the location of the target plant pests and obtain the growth stage of each target plant pest. 1 、Detect 1 and Detect 3 Then you can get the output results Results.
[0135] In step S2034, the model parameters of the YOLOv5 model are adjusted according to the output result and the annotation information in the corresponding training data set to obtain a trained YOLOv5 model.
[0136] After obtaining the output result, the model parameters of the YOLOv5 model can be adjusted based on the output result and the annotation information in the corresponding training data set to obtain the trained YOLOv5 model. The specific adjustment method is similar to that in the related art and will not be repeated here.
[0137] In step S204, the predicted output results corresponding to the sample images in the verification data set are obtained through the trained YOLOv5 model.
[0138] After training the YOLOv5 model, you also need to use a validation dataset to verify it. Input the validation dataset into the trained YOLOv5 model to obtain the predicted output results corresponding to the sample images in the validation dataset.
[0139] In step S205, the loss function value is calculated based on the prediction output result corresponding to the sample image in the verification data set and the annotation information corresponding to the sample image in the verification data set.
[0140] In step S206, it is detected whether the loss function value meets the preset requirements.
[0141] In step S207, when the loss function value meets the preset requirements, the YOLOv5 model corresponding to the loss function value meeting the preset requirements is used as the plant pest detection model.
[0142] In step S208, when the loss function value does not meet the preset requirements, the parameters of the YOLOv5 model are updated based on the loss function value, and the YOLOv5 model after the updated parameters is used to replace the trained YOLOv5 model, and the above steps of obtaining the preset output results and calculating the loss function value are re-executed until the calculated loss function value meets the preset requirements.
[0143] Taking the citrus mites as an example of plant pests, the model training process in the present disclosure is introduced in detail.
[0144] The citrus mites are arthropods of the family Tetranychidae in the order Acarina, also known as red spider mites and red spider mites. They cause damage by sucking the juice from the leaves, tender shoots and fruit skins of economic crops. In order to evaluate the effectiveness of control measures against the citrus mites, it is necessary to detect and classify the individuals of the citrus mites at different growth stages. Traditional statistical methods are mostly completed in the form of manual real-time viewing and counting, which has problems such as high labor costs and low recognition efficiency. Methods based on deep learning machine vision for pests such as mites usually only focus on the classification of different types of pests. There is no similar solution for the classification and statistical needs of pests of the same type at different growth stages.
[0145] The EMAFF-YOLOv5 growth stage detection model for citrus panonychus mites based on deep learning neural networks disclosed in the present invention introduces an efficient multi-scale (EMA) attention mechanism to enhance the detection capability of small targets, and proposes a unique iEMAFF feature fusion network that combines an iterative attentional feature fusion (iAFF) network with an EMA attention module, thereby improving target features of different dimensions and the efficiency of retrograde fusion.
[0146] refer to Figure 3 , specifically:
[0147] Step 1: Use a computer with an electronic image acquisition device with a magnification of 30 times to obtain sample images of citrus mites at multiple different growth stages on the citrus leaf surface. One sample image will contain 3-30 different individuals.
[0148] Step 2: Annotate the sample images obtained in step 1, store the annotation information in YOLO format, and create a sample data set for training.
[0149] The labeling specifically includes: using a rectangular bounding box to mark the image position of the citrus mites individual, and using a text label to identify the growth stage of the individual.
[0150] Step 3: Split the sample data set produced in step 2 into a training data set and a validation data set in a ratio of 8:2.
[0151] Step 4: Design a plant pest detection model based on YOLOv5, named EMAFF-YOLOv5, which accepts images with a resolution of 640x640 as input. The image in step 3 will be converted into a three-dimensional tensor data input model, and its dimensions are channel, length, and width.
[0152] The plant pest detection model accepts input of a fixed size, and the input image can be of any resolution. The preprocessing part before inputting the model will process the image into a size suitable for the model.
[0153] Step 5: The image data input in step 4 enters the backbone network of the model. The first module of the backbone network is the first convolution module Focus. This module will perform convolution, batch normalization and activation operations on the input image, and obtain the first feature layer with a resolution of 320x320, that is, the P1 layer in the Backbone, named BB-P1 below.
[0154] Step 6: The BB-P1 feature layer obtained in step 5 is passed through Conv 1 module, and obtain the second preliminary feature layer (BB-P2) with a second resolution of 160x160. This feature layer will pass through a C3 1 Module, C3 1 The module performs three convolution operations on the input image and fuses it with the original input to achieve the effect of widening the receptive field and better integrating the contextual information of the image. The resolution of the feature layer output by all C3 modules in Backbone will not change.
[0155] Among them, for the C3 module that does not change the output size, the convolution kernel size of the three convolution operations is 1x1.
[0156] Step 7: After step 6, add EMA 1 Module, the BB-P2 feature layer output in step 6 enters EMA 1 The module obtains the second feature layer (BB-P2`) with a resolution of 160x160. This module groups the input feature map into multiple sub-features in the horizontal and vertical channel space, encodes global information to recalibrate the channel features in each branch, and further aggregates the output features of the two branches through cross-dimensional interaction, so that the spatial semantic features are evenly distributed within the channel to achieve the purpose of enhancing the detection efficiency of the model. Its output is once again passed through a Conv 2 The module is used to achieve smooth operation on features and enhance the perception ability of the model. The resolution of the attention feature layer output by the EMA module does not change.
[0157] Step 8: Repeat step 6 for the feature layer obtained in step 7. 2After the module, the third preliminary feature layer (BB-P3) with a resolution of 80x80 is obtained, and C3 2 The module enriches its information content. Repeat step 7 for this feature layer and use EMA 2 The module enhances the representation capability of features to obtain a third feature layer (BB-P3`) with a resolution of 80x80.
[0158] Step 9: Repeat the same operation on the BB-P3` layer obtained in step 8, and pass the Conv 3 、C3 3 EMA 3 Module, obtain the fourth BB-P4` layer with a resolution of 40x40, and perform the same operation on the BB-P4` layer to obtain the fifth BB-P5` layer with a resolution of 20x20.
[0159] Step 10: The BB-P5` layer obtained in step 9 enters the SPPF module. SPPF is a fast version variant of Spatial Pyramid Pooling (SPP), which is used to aggregate features at different scales and enhance the model's ability to detect objects of different sizes. The output resolution of the SPPF module does not change, and this module is at the end of the Backbone part of the model, and its output is the output of the Backbone.
[0160] Step 11: The output of step 10 enters the Path Aggregation Network (PANet) of YOLOv5 to promote the flow of information in the model network. It enhances the representation ability of the backbone network by fusing the bottom-up and top-down paths. PANet increases the resolution of the feature map output by Backbone through Conv 5 Module and the first upsample 1 ) module is expanded to 40x40, but the features it represents still belong to the BB-P5 layer, named P5'.
[0161] Step 12: The sixth P5' layer with a resolution of 40x40 obtained in step 11 will be processed by iEMAFF 1 The feature fusion module fuses the BB-P4 layer features with the same resolution of 40x40 in Backbone, and then passes C3 5The module obtains the sixth cubic convolution feature layer with a resolution of 40x40. The iEMAFF module is a combination of the iterative attentional feature fusion (iAFF) network and the EMA attention module. iAFF uses the attention mechanism to improve traditional feature fusion methods, such as addition or concatenation, and uses the EMA attention module to replace the MS-CAM attention module in the original iAFF to improve the model fusion capability. The iEMAFF module takes the P5' layer and the BB-P4` layer as input at the same time, realizes the fusion of features of different sizes, and outputs an intermediate feature layer with the same resolution as the input.
[0162] Step 13: The sixth 40x40 resolution cubic convolution feature layer output from step 12 is passed through Conv again. 6 and Upsample 2 The module is extended to the seventh P4' layer with a resolution of 80x80, and the BB-P3` layer is connected through iEMAFF 2 The modules are fused to output the second fused feature layer with a seventh resolution of 80x80, and complete the bottom-up feature flow path in PANet.
[0163] Step 14: The feature layer output from step 13 passes through C3 6 The module extracts feature information, and the output of the module is sent to the detection layer (Detect) as the P3 feature layer for target detection. The output feature itself will again serve as the starting point of the top-down feature flow path in PANet, and after Conv 7 After smoothing the features, pass iEMAFF 3 The module is again fused with the P4' layer.
[0164] Step 15: The feature layer output from step 14 passes through the next C3 7 Module, at this time C3 7 The feature layer resolution of the module output is 40x40, and this output will be sent to Detect as the P4 feature layer. 8 After layer smoothing, pass iEMAFF 4 The module is fused with the P5' layer.
[0165] Step 16: The feature layer output from step 15 is input into the last C3 8 Module, the module sends the feature layer with an output resolution of 20x20 as the P5 feature layer to Detect, and the PANet network ends here.
[0166] Step 17: Detect will run the target detection algorithm on the P3, P4, and P5 feature layers obtained in steps 14, 15, and 16 to detect possible target objects and classify them.
[0167] In this scenario, the target of Panonychus citri is detected and its growth stage is classified. Detect will output the bounding box (bbox) of each target, that is, the rectangular box that frames the target position. Its parameters are the horizontal and vertical coordinates (x, y) and length and width (w, h) of the bbox, as well as the category probability of the framed target. Detect is the last part of the entire EMAFF-YOLOv5 model, and the output of Detect is the output of the entire model.
[0168] Step 18: Put the sample data set produced in step 3 into the model described in steps 4-17 for training. The training set is used to train the model's ability to extract and classify targets, and the validation set is used to evaluate the training effect after each round of training, and to enable the model itself to learn and adjust the parameters within the model.
[0169] Step 19: After the training work in step 18 is completed, the trained plant pest detection EMAFF-YOLOv5 model is obtained. This model can be applied to the detection of citrus mites at their growth stages.
[0170] Based on the same inventive concept, the embodiment of the present application also provides a plant pest detection device for implementing the plant pest detection method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more plant pest detection device embodiments provided below can refer to the limitations of the plant pest detection method above, and will not be repeated here.
[0171] In an exemplary embodiment, Figure 4 As shown, a plant pest detection device is provided, comprising:
[0172] A receiving module 11, used for receiving an image to be detected;
[0173] A first acquisition module 12 is used to input the image to be detected into a plant pest detection model to obtain the position of each target plant pest in the image to be detected and the growth stage of each target plant pest in the image to be detected, wherein the plant pest detection model is obtained by training a YOLOv5 model, and the YOLOv5 model includes a first efficient multi-scale attention mechanism module;
[0174] A second acquisition module 13 is used to acquire the number of target plant pests in the image to be detected according to the position of each target plant pest in the image to be detected;
[0175] A third acquisition module 14 is used to acquire the number of the target plant pests belonging to the same growth stage in the image to be detected according to the growth stage of each target plant pest in the image to be detected;
[0176] The output module 15 is used to output the number of target plant pests in the image to be detected and the number of the target plant pests belonging to the same growth stage.
[0177] As an optional implementation, the YOLOv5 model also includes an attention feature fusion module, which is composed of an iterative attention feature fusion network and a second efficient multi-scale attention mechanism module.
[0178] As an optional implementation, the plant pest detection device further includes:
[0179] A fourth acquisition module is used to acquire a sample data set, wherein the sample data set includes: sample images and annotation information of each sample image, wherein the annotation information of each sample image includes: an image position of a target plant pest in each sample image, and a growth stage to which each target plant pest in each sample image belongs;
[0180] A fifth acquisition module, used to acquire a training data set and a verification data set from the sample data set;
[0181] A training module, used to train the YOLOv5 model according to the training data set to obtain the trained YOLOv5 model;
[0182] A sixth acquisition module, used to obtain the prediction output result corresponding to the sample image in the verification data set through the trained YOLOv5 model;
[0183] A calculation module, used to calculate a loss function value based on the prediction output result corresponding to the sample image in the verification data set and the annotation information corresponding to the sample image in the verification data set;
[0184] A detection module, used to detect whether the loss function value meets the preset requirements;
[0185] A seventh acquisition module is used for, when the loss function value meets the preset requirement, using the YOLOv5 model corresponding to the loss function value meeting the preset requirement as the plant pest detection model;
[0186] The eighth acquisition module is used to update the parameters of the YOLOv5 model based on the loss function value when the loss function value does not meet the preset requirements, and use the YOLOv5 model after the updated parameters to replace the trained YOLOv5 model, and re-execute the above steps of obtaining the preset output result and calculating the loss function value until the calculated loss function value meets the preset requirements.
[0187] As an optional implementation, the training module includes:
[0188] A first acquisition submodule is used to input the training data set into the backbone network of the YOLOv5 model to obtain the feature output of the backbone network, wherein the backbone network includes the first efficient multi-scale attention mechanism module;
[0189] A second acquisition submodule is used to input the feature output of the backbone network into a path aggregation network to obtain the feature output of the path aggregation network, wherein the path aggregation network includes the attention feature fusion module;
[0190] A third acquisition submodule is used to input the feature output of the path aggregation network into the head network to obtain the output results corresponding to the sample images in the training data set, and the output results include: the target position and growth stage of the target plant pests in each of the sample images in the training data set;
[0191] The fourth acquisition submodule is used to adjust the model parameters of the YOLOv5 model according to the output result and the corresponding annotation information in the training data set to obtain the trained YOLOv5 model.
[0192] As an optional implementation manner, the first acquisition submodule is specifically used to:
[0193] Inputting the training data set into a first convolution module to obtain a feature layer of a first resolution;
[0194] Inputting the feature layer of the first resolution into the backbone network feature extraction module to obtain a feature layer of a preset resolution; the backbone network feature extraction module includes: a plurality of feature extraction submodules, each of which includes: a backbone network convolution submodule, a backbone network cubic convolution module and a first efficient multi-scale attention mechanism submodule;
[0195] The feature layer of the preset resolution is input into the backbone network pooling module to obtain the feature output of the backbone network.
[0196] As an optional implementation manner, in the aspect of inputting the feature layer of the first resolution into the backbone network feature extraction module to obtain the feature layer of the preset resolution, the first acquisition submodule is specifically used to:
[0197] Inputting the feature layer of the first resolution into the first backbone network feature extraction submodule to obtain a feature layer of the second resolution;
[0198] Inputting the feature layer of the second resolution into the second backbone network feature extraction submodule to obtain a feature layer of a third resolution;
[0199] Inputting the feature layer of the third resolution into the third backbone network feature extraction submodule to obtain a feature layer of a fourth resolution;
[0200] The feature layer of the fourth resolution is input into the fourth backbone network feature extraction submodule to obtain the feature layer of the preset resolution.
[0201] As an optional implementation manner, in the aspect of inputting the characteristic output of the backbone network into the path aggregation network to obtain the characteristic output of the path aggregation network, the second acquisition submodule is specifically used for:
[0202] Inputting the feature output of the backbone network into a first path aggregation processing module to obtain a feature layer of a sixth resolution; the first path aggregation processing module includes: a first path aggregation convolution module and a first upsampling module;
[0203] Inputting the feature layer of the sixth resolution and the feature layer of the fourth resolution into a first attention feature fusion module to obtain a first fused feature;
[0204] Aggregating the first fusion feature input path into a cubic convolution module to obtain a cubic convolution feature layer of a sixth resolution;
[0205] Inputting the third convolution feature layer of the sixth resolution into the second path aggregation processing module to obtain a feature layer of the seventh resolution; the second path aggregation processing module includes: a second path aggregation convolution module and a second upsampling module;
[0206] Inputting the feature layer of the seventh resolution and the feature layer of the third resolution into a second attention feature fusion module to obtain a second fused feature;
[0207] The second fused feature is passed through an aggregation network feature extraction module to obtain a feature output of the path aggregation network.
[0208] As an optional implementation, in the aspect of obtaining the feature output of the path aggregation network by passing the second fusion feature through the aggregation network feature extraction module, the second acquisition submodule is specifically used for:
[0209] Passing the second fused feature through the first aggregation network feature extraction submodule to obtain the first feature output of the path aggregation network;
[0210] Inputting the first feature output of the path aggregation network into a first aggregation network convolution module to obtain a first aggregation network convolution output;
[0211] Inputting the first aggregation network convolution output and the feature layer of the sixth resolution into a third attention feature fusion module to obtain a third fused feature;
[0212] Passing the third fusion feature through the second aggregation network feature extraction submodule to obtain the second feature output of the path aggregation network;
[0213] Inputting the second feature output of the path aggregation network into a second aggregation network convolution module to obtain a second aggregation network convolution output;
[0214] Inputting the second aggregation network convolution output and the feature layer of the preset resolution into a fourth attention feature fusion module to obtain a fourth fusion feature;
[0215] The fourth fusion feature is passed through the third aggregation network feature extraction submodule to obtain the third feature output of the path aggregation network.
[0216] In an exemplary embodiment, a computer device is provided. The computer device may be a server or a terminal. The internal structure diagram thereof may be as follows: Figure 5 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data required for plant pest detection. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a plant pest detection method is implemented.
[0217] Those skilled in the art will understand that Figure 5The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0218] In an exemplary embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above-mentioned method embodiments when executing the computer program.
[0219] In an exemplary embodiment, a computer-readable storage medium is provided, storing a computer program, and when the computer program is executed by a processor, the steps in the above method embodiments are implemented.
[0220] In an exemplary embodiment, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps in the above method embodiments are implemented.
[0221] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0222] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM may be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0223] The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. The non-relational database may include a distributed database based on blockchain, etc., but is not limited thereto. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but is not limited thereto.
[0224] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0225] This article uses specific examples to illustrate the principles and implementation methods of this application. The description of the above embodiments is only used to help understand the method and core ideas of this application. At the same time, for those skilled in the art, according to the ideas of this application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting this application.
Claims
1. A method for detecting plant pests, characterized in that: The plant pest detection method comprises: Receiving an image to be detected; Inputting the image to be detected into a plant pest detection model to obtain the position of each target plant pest in the image to be detected and the growth stage of each target plant pest in the image to be detected, wherein the plant pest detection model is obtained by training a YOLOv5 model, and the YOLOv5 model includes a first efficient multi-scale attention mechanism module; Acquire the number of target plant pests in the image to be detected according to the position of each target plant pest in the image to be detected; According to the growth stage of each of the target plant pests in the image to be detected, obtaining the number of the target plant pests belonging to the same growth stage in the image to be detected; The number of target plant pests in the image to be detected and the number of the target plant pests belonging to the same growth stage are output.
2. The plant pest detection method according to claim 1, characterized in that: The YOLOv5 model also includes an attention feature fusion module, which consists of an iterative attention feature fusion network and a second efficient multi-scale attention mechanism module.
3. The plant pest detection method according to claim 2, characterized in that: The plant pest detection method also includes: Acquire a sample data set, the sample data set comprising: sample images and annotation information of each sample image, the annotation information of each sample image comprising: an image position of a target plant pest in each sample image, and a growth stage to which each target plant pest in each sample image belongs; Obtaining a training data set and a verification data set from the sample data set; Train the YOLOv5 model according to the training data set to obtain the trained YOLOv5 model; Obtaining the predicted output result corresponding to the sample image in the verification data set through the trained YOLOv5 model; Calculate the loss function value based on the prediction output result corresponding to the sample image in the verification data set and the annotation information corresponding to the sample image in the verification data set; Detecting whether the loss function value meets the preset requirements; When the loss function value meets the preset requirements, the YOLOv5 model corresponding to the loss function value meeting the preset requirements is used as the plant pest detection model; When the loss function value does not meet the preset requirements, the parameters of the YOLOv5 model are updated based on the loss function value, and the YOLOv5 model after the updated parameters is used to replace the trained YOLOv5 model, and the above steps of obtaining the preset output result and calculating the loss function value are re-executed until the calculated loss function value meets the preset requirements.
4. The plant pest detection method according to claim 3, characterized in that: The step of training the YOLOv5 model according to the training data set to obtain the trained YOLOv5 model includes: Inputting the training data set into the backbone network of the YOLOv5 model to obtain feature outputs of the backbone network, wherein the backbone network includes the first efficient multi-scale attention mechanism module; Inputting the feature output of the backbone network into a path aggregation network to obtain the feature output of the path aggregation network, wherein the path aggregation network includes the attention feature fusion module; Inputting the feature output of the path aggregation network into the head network to obtain the output results corresponding to the sample images in the training data set, the output results including: the target position and growth stage of the target plant pests in each of the sample images in the training data set; The model parameters of the YOLOv5 model are adjusted according to the output result and the corresponding annotation information in the training data set to obtain the trained YOLOv5 model.
5. The method for detecting plant pests according to claim 4, characterized in that: The step of inputting the training data set into the backbone network of the YOLOv5 model to obtain feature outputs of the backbone network includes: Inputting the training data set into a first convolution module to obtain a feature layer of a first resolution; Inputting the feature layer of the first resolution into the backbone network feature extraction module to obtain a feature layer of a preset resolution; the backbone network feature extraction module includes: a plurality of feature extraction submodules, each of which includes: a backbone network convolution submodule, a backbone network cubic convolution module and the first efficient multi-scale attention mechanism module; The feature layer of the preset resolution is input into the backbone network pooling module to obtain the feature output of the backbone network.
6. The method for detecting plant pests according to claim 5, characterized in that: The step of inputting the feature layer of the first resolution into a backbone network feature extraction module to obtain a feature layer of a preset resolution includes: Inputting the feature layer of the first resolution into the first backbone network feature extraction submodule to obtain a feature layer of the second resolution; Inputting the feature layer of the second resolution into the second backbone network feature extraction submodule to obtain a feature layer of a third resolution; Inputting the feature layer of the third resolution into the third backbone network feature extraction submodule to obtain a feature layer of a fourth resolution; The feature layer of the fourth resolution is input into the fourth backbone network feature extraction submodule to obtain the feature layer of the preset resolution.
7. The plant pest detection method according to claim 6, characterized in that: The step of inputting the characteristic output of the backbone network into a path aggregation network to obtain the characteristic output of the path aggregation network includes: Inputting the feature output of the backbone network into a first path aggregation processing module to obtain a feature layer of a sixth resolution; the first path aggregation processing module includes: a first path aggregation convolution module and a first upsampling module; Inputting the feature layer of the sixth resolution and the feature layer of the fourth resolution into a first attention feature fusion module to obtain a first fused feature; Aggregating the first fusion feature input path into a cubic convolution module to obtain a cubic convolution feature layer of a sixth resolution; Inputting the third convolution feature layer of the sixth resolution into the second path aggregation processing module to obtain a feature layer of the seventh resolution; the second path aggregation processing module includes: a second path aggregation convolution module and a second upsampling module; Inputting the feature layer of the seventh resolution and the feature layer of the third resolution into a second attention feature fusion module to obtain a second fused feature; The second fused feature is passed through an aggregation network feature extraction module to obtain a feature output of the path aggregation network.
8. The method for detecting plant pests according to claim 7, characterized in that: The step of passing the second fusion feature through an aggregation network feature extraction module to obtain a feature output of the path aggregation network includes: Passing the second fused feature through the first aggregation network feature extraction submodule to obtain the first feature output of the path aggregation network; Inputting the first feature output of the path aggregation network into a first aggregation network convolution module to obtain a first aggregation network convolution output; Inputting the first aggregation network convolution output and the feature layer of the sixth resolution into a third attention feature fusion module to obtain a third fused feature; Passing the third fusion feature through the second aggregation network feature extraction submodule to obtain the second feature output of the path aggregation network; Inputting the second feature output of the path aggregation network into a second aggregation network convolution module to obtain a second aggregation network convolution output; Inputting the second aggregation network convolution output and the feature layer of the preset resolution into a fourth attention feature fusion module to obtain a fourth fusion feature; The fourth fusion feature is passed through the third aggregation network feature extraction submodule to obtain the third feature output of the path aggregation network.
9. A plant pest detection device, characterized in that: The plant pest detection device comprises: A receiving module, used for receiving an image to be detected; A first acquisition module is used to input the image to be detected into a plant pest detection model to obtain the position of each target plant pest in the image to be detected and the growth stage of each target plant pest in the image to be detected, so as to output the number of target plant pests in the image to be detected and the growth stage of each target plant pest, wherein the plant pest detection model is obtained by training a YOLOv5 model, and the YOLOv5 model includes a first efficient multi-scale attention mechanism module; A second acquisition module, used for acquiring the number of target plant pests in the image to be detected according to the position of each target plant pest in the image to be detected; A third acquisition module is used to acquire the number of the target plant pests belonging to the same growth stage in the image to be detected according to the growth stage of each of the target plant pests in the image to be detected; The output module is used to output the number of target plant pests in the image to be detected and the number of the target plant pests belonging to the same growth stage.
10. A computer device comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the plant pest detection method according to any one of claims 1 to 8.