Solenopsis invicta detection method based on improved YOLOv5s
By improving the YOLOv5s model, SCConv convolution, FocalModulation technology and Focaler-loU loss function were introduced, and the existing red fire ant detection methods were solved, and efficient and accurate red fire ant detection was achieved.
Patent Information
- Application Number
- CN202411792214.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-06
- Publication Date
- 2025-04-01
AI Technical Summary
The existing red fire ant detection methods have problems such as low efficiency, low accuracy and insufficient ability to adapt to different environments.
Using the red fire ant detection method based on improved YOLOv5s, an improved object detection model is constructed by introducing SCConv convolution, FocalModulation technology and Focaler-loU loss function to improve the lightweighting of the model, feature characterization efficiency and adaptability.
It realizes efficient detection when processing large amounts of data and complex images, and improves the accuracy of red fire ant detection and the ability to adapt to different environments.
Smart Images

Figure CN119741733A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of target detection, and in particular to a method for detecting red imported fire ants based on improved YOLOv5s. Background Art
[0002] As an extremely destructive invasive species, red fire ants have frequently appeared in many parts of my country in recent years, posing a serious threat to agricultural production, the ecological environment and human health. The invasion of red fire ants not only leads to reduced crop yields and destroys the ecological balance, but its strong aggressiveness and toxicity may also cause allergic reactions in humans and even threaten life. Therefore, achieving efficient and accurate detection of red fire ants is of great significance for timely controlling the spread of red fire ants and protecting agricultural production and the ecological environment.
[0003] At present, the detection methods of red fire ants mainly include traditional questionnaire surveys, visual inspections and bait trapping. Although these methods can detect the presence of red fire ants to a certain extent, they have many shortcomings. For example, the questionnaire survey method relies on residents' reports, which may result in underreporting and false alarms; the visual inspection method requires professionals to observe on-site, which is inefficient and easily affected by environmental factors; the bait trapping method takes a long time to observe the results, and may not be effective for small or hidden red fire ant nests. Therefore, it is particularly important to develop an efficient, accurate and real-time red fire ant detection method. Summary of the invention
[0004] The purpose of the present invention is to provide a red fire ant detection method based on improved YOLOv5s, which has advantages in processing large amounts of data and complex images while achieving the lightweight of the model, and can also improve the model's ability to adapt to different data patterns and the accuracy of red fire ant detection in various environments.
[0005] The technical solution of the present invention is:
[0006] In a first aspect, the present application provides a method for detecting red fire ants based on improved YOLOv5s, which comprises the following steps:
[0007] S1. Obtain a dataset of red fire ant images in real scenes;
[0008] S2, perform data enhancement and expansion on the red fire ant image dataset, and divide the expanded dataset into a training set, a validation set, and a test set;
[0009] S3, introduce SCConv convolution into the YOLOv5s network model, and use FocalModulation technology and Focaler-loU loss function to build an improved YOLOv5s target detection model;
[0010] S4, putting the training set into the improved YOLOv5s target detection model for training to obtain an improved model;
[0011] S5. Deploy the improved model to the terminal device for testing to obtain the test results.
[0012] Furthermore, in step S2, CutMix and Mixup methods are used to perform data enhancement on the red fire ant image dataset.
[0013] Furthermore, step S2 also includes labeling the data-enhanced and expanded red fire ant image dataset through the open source application Labelimg, and converting the dataset into yolo format.
[0014] Further, step S3 includes:
[0015] S31, introduce SCConv convolution into the pre-established YOLOv5s network model to replace the convolution part in the model head and the Dyhead detection head;
[0016] S32, use FocalModulation technology to replace the original SPPF module in the YOLOv5s network model;
[0017] S33. Using the Focaler-loU loss function as the loss function for calculating bounding box regression, an improved YOLOv5s target detection model is constructed based on steps S31 to S32.
[0018] Furthermore, the calculation formula of the Focaler-loU loss function includes:
[0019]
[0020] Where, IoU focaler represents the Focaler-loU loss function, IoU represents the intersection over union ratio, d and u are parameters, and [d,u]∈[0,1].
[0021] Furthermore, step S4 also includes evaluating the improved model, and its expression is:
[0022]
[0023] In the formula, mAP represents the mean average precision, P represents the precision, AP represents the average precision, N represents the total number of categories, R represents the recall rate, TP represents the number of samples predicted by the model to be positive and actually positive, FP represents the number of samples predicted by the model to be positive but actually negative, and FN represents the number of samples predicted by the model to be negative but actually positive.
[0024] In a second aspect, the present application provides an electronic device, including:
[0025] A memory for storing one or more programs;
[0026] processor;
[0027] When the one or more programs are executed by the processor, a method for detecting red fire ants based on improved YOLOv5s as described in any one of the first aspects is implemented.
[0028] In a third aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a red fire ant detection method based on an improved YOLOv5s as described in any one of the first aspects above.
[0029] Compared with the prior art, the present invention has at least the following advantages or beneficial effects:
[0030] (1) The present invention discloses a method for detecting fire ants based on improved YOLOv5s. By introducing SCConv convolution to replace the convolution part in the head and Dyhead of the original model, the number of parameters of the model is reduced, the lightweight model is realized, the computational cost is reduced, and the efficiency of feature representation is effectively improved. This method has more advantages in processing large amounts of data and complex images.
[0031] (2) The present invention replaces the SPPF module in YOLOv5s with the FocalModulation technology, thereby enhancing the YOLOv5s model's ability to capture and express key visual features and improving the detection accuracy of red fire ants;
[0032] (3) The present invention uses Focaler-loU as the loss function for calculating bounding box regression, which helps the YOLOv5s model to better learn to extract features from moderately difficult samples, improves the model's ability to adapt to different data patterns, and thus improves the accuracy of red fire ant detection in various environments. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.
[0034] Figure 1 A schematic diagram of a red imported fire ant detection method based on improved YOLOv5s according to the present invention;
[0035] Figure 2This is a schematic diagram of the improved YOLOv5s model;
[0036] Figure 3 This is the model framework diagram of the improved dyhead detection head;
[0037] Figure 4 Schematic diagram of the curve fitted by YOLOv5s and the improved model during the training process;
[0038] Figure 5 This is a diagram showing the visualization results of the red fire ant detection;
[0039] Figure 6 The figure is a schematic structural block diagram of an electronic device according to an embodiment of the present invention.
[0040] Icon: 101, memory; 102, processor; 103, communication interface. DETAILED DESCRIPTION
[0041] Terminology explanation:
[0042] YOLOv5s: A real-time object detection algorithm based on deep learning in convolutional neural networks.
[0043] SCConv: (Spatial and Channel Reconstruction Convolution) is a convolution module for convolutional neural networks, which aims to reduce spatial and channel redundancy in convolutional neural networks to reduce computational costs and improve performance.
[0044] Dyhead: Attention-based object detection head.
[0045] FocalModulation: Focal modulation technology, a technology used in the field of deep learning to improve target detection and image segmentation;
[0046] SPPF: (Spatial Pyramid Pooling Fast), spatial pyramid pooling fast module;
[0047] Focaler-loU: Improved bounding box regression loss function;
[0048] CutMix: data augmentation technology.
[0049] Mixup: A data augmentation technique commonly used in machine learning and deep learning to generate more training data;
[0050] Beta distribution: Beta distribution, a family of continuous probability distributions defined on the interval [0,1];
[0051] Labelimg: an open-source image annotation tool for creating your own datasets for deep learning training.
[0052] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various different configurations.
[0053] Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the present application for which protection is sought, but merely represents selected embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.
[0054] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0055] It should be noted that, in this article, the term "comprises" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprises..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0056] In conjunction with the accompanying drawings, some embodiments of the present application are described in detail below. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.
[0057] Example 1
[0058] See also Figure 1 , Figure 1 Shown is a step diagram of a red fire ant detection method based on improved YOLOv5s provided in an embodiment of the present application.
[0059] In a first aspect, the present application provides a method for detecting red fire ants based on improved YOLOv5s, which comprises the following steps:
[0060] S1. Obtain a dataset of red fire ant images in real scenes;
[0061] S2, perform data enhancement and expansion on the red fire ant image dataset, and divide the expanded dataset into a training set, a validation set, and a test set;
[0062] S3, introduce SCConv convolution into the YOLOv5s network model, and use FocalModulation technology and Focaler-loU loss function to build an improved YOLOv5s target detection model;
[0063] S4, putting the training set into the improved YOLOv5s target detection model for training to obtain an improved model;
[0064] S5. Deploy the improved model to the terminal device for testing to obtain the test results.
[0065] As a preferred implementation, in step S2, CutMix and Mixup methods are used to perform data enhancement on the red fire ant image dataset.
[0066] Among them, the principle of the CutMix method is to randomly select an area in the image and replace it with the corresponding area of another image; this replacement process is achieved by randomly generating a mask, and the area in the mask will be replaced by the area corresponding to the other image, and then the corresponding label also needs to be adjusted; the principle of the Mixup method is to linearly mix two images and their corresponding labels in a certain proportion, set a parameter λ, randomly sample from the Beta distribution, and then mix the two images in the proportion of λ, and at the same time linearly interpolate their labels in the same proportion.
[0067] It should be noted that the process of step S3 is as follows Figure 2 As shown in the figure, the improved YOLOv5s model is introduced to replace the convolution part in Dyhead and the convolution of the head part in YOLOv5s. At the same time, Dyhead is used as a new detection head to replace the original detection head, and FocalModulation is used to replace the original SPPF module in the YOLOv5s network model.
[0068] As a preferred implementation, step S2 also includes marking the data-enhanced and expanded red fire ant image dataset through the open source application Labelimg, and converting the dataset into yolo format; in this embodiment, after the dataset is converted into yolo format, it is divided into training set, verification set and test set in a ratio of 8:1:1.
[0069] As a preferred implementation, step S3 includes:
[0070] S31, introduce SCConv convolution into the pre-established YOLOv5s network model to replace the convolution part in the model head and the Dyhead detection head;
[0071] Among them, SCConv convolution consists of a spatial reconstruction unit and a channel reconstruction unit;
[0072] The working process of the above spatial reconstruction unit in improving the target detection model of YOLOv5s includes:
[0073] 1) Input features and perform group normalization;
[0074] 2) The result of group normalization is calculated through a nonlinear activation function to obtain the weight of the input feature, and the input feature is weighted;
[0075] 3) The weighted features are divided into two parts, and reconstructed through self-transformation, addition and splicing operations to obtain spatial refined features;
[0076] The working process of the above channel reconstruction unit in improving the target detection model of YOLOv5s includes:
[0077] 1) Split the spatial refined features into two parts and perform different 1x1 convolutions through paths of different scales;
[0078] 2) The two features are further transformed through global convolution and point convolution;
[0079] 3) The transformed features are pooled and SoftMax weighted fused to form the final channel refined features;
[0080] It should be noted that the Dyhead detection head contains a variety of attention modules, including scale-aware attention module, space-aware attention module and task-aware attention module; among them, the scale-aware attention module uses average pooling, 1x1 convolution, ReLU activation function and hard Sigmoid function, the space-aware attention module includes offset learning and 3x3 convolution, and the task-aware attention module is processed by fully connected layers, ReLU activation function, and normalization operations. Replacing the convolution part in the Dyhead detection head is to replace the convolution part with SCConv convolution; the head part of the YOLOv5s network model includes four Conv layers. When replacing the convolution part in the head of the YOLOv5s network model, replace the four Conv layers with SCConv. Figure 3 As shown in the figure, it is a model framework diagram of the improved dyhead detection head. By improving the detection head, the accuracy of target detection, the lightweight of the model and the computational efficiency can be effectively improved.
[0081] S32, use FocalModulation technology to replace the original SPPF module in the YOLOv5s network model;
[0082] Among them, when the FocalModulation technology is used to replace the original SPPF module in the YOLOv5s network model, the SPPF of the last layer of the original backbone part of the YOLOv5s network model is replaced with FocalModulation;
[0083] It should be noted that during the replacement process, FocalModulation uses a stack of deep convolutional layers to encode visual contexts of different ranges. Through the gating mechanism, the contextual information is selectively aggregated into the modulator of each query token, and the aggregated modulator is injected into each query token through affine transformation.
[0084] S33. Using the Focaler-loU loss function as the loss function for calculating bounding box regression, an improved YOLOv5s target detection model is constructed based on steps S31 to S32.
[0085] Among them, the calculation formula of the Focaler-loU loss function includes:
[0086]
[0087] Where, IoU focaler represents the Focaler-loU loss function, IoU represents the intersection over union ratio, d and u are parameters, and [d,u]∈[0,1];
[0088] It should be noted that the Focaler-loU loss function adjusts the loss according to the value of the intersection-over-union ratio. By adjusting the values of d and u, the Focaler-loU loss function can focus on different regression samples: when IoU is less than a lower threshold d, the loss is 0; when IoU is greater than an upper threshold u, the loss is 1; and when IoU is between d and u, the loss is a function that increases linearly according to the IoU value.
[0089] As a preferred implementation, step S4 further includes evaluating the improved model, and the expression is:
[0090]
[0091] In the formula, mAP represents the mean average precision, P represents the precision, AP represents the average precision, N represents the total number of categories, R represents the recall rate, TP represents the number of samples predicted by the model to be positive and actually positive, FP represents the number of samples predicted by the model to be positive but actually negative, and FN represents the number of samples predicted by the model to be negative but actually positive.
[0092] Example 2
[0093] As a preferred implementation, in order to better illustrate the effectiveness of the present invention, YOLOv5s is selected as the baseline network, and an ablation experiment is performed on each improvement point. Figure 4 The comparison results of the fitted curves during the training process before and after the model improvement are shown. The vertical axis mAP@0.5 represents the evaluation index, and the horizontal axis epochs represents the training process. The detection effect of the improved YOLOv5s and the original YOLOv5s on the red fire ant dataset is compared, and the results are shown in Table 1 below:
[0094] Table 1 Comparison of detection results of improved YOLOv5s and original YOLOv5s
[0095]
[0096] Import the trained weight file best.pt into the detect.py detection program and run the program to get the red fire ant detection effect diagram based on the improved YOLOv5s, as shown below: Figure 5 As shown, it can be seen that the actual recognition effect is good.
[0097] Example 3
[0098] See also Figure 6 , Figure 6 A schematic structural block diagram of an electronic device provided in an embodiment of the present application.
[0099] An electronic device includes a memory 101, a processor 102 and a communication interface 103, wherein the memory 101, the processor 102 and the communication interface 103 are electrically connected to each other directly or indirectly to realize data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses or signal lines. The memory 101 can be used to store software programs and modules, and the processor 102 executes various functional applications and data processing by executing the software programs and modules stored in the memory 101. The communication interface 103 can be used to communicate signaling or data with other node devices.
[0100] Among them, the memory 101 can be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable read-only memory (EEPROM), etc.
[0101] The processor 102 may be an integrated circuit chip with signal processing capability. The processor 102 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0102] It is understood that the structure shown in the figure is only for illustration, and a method for detecting red imported fire ants based on improved YOLOv5s may also include more or fewer components than those shown in the figure, or have a different configuration than those shown in the figure. Each component shown in the figure may be implemented by hardware, software, or a combination thereof.
[0103] In the embodiments provided in the present application, it should be understood that the disclosed method can also be implemented in other ways. The embodiments described above are merely schematic, for example, the flowchart or block diagram in the accompanying drawings shows the possible implementation architecture, functions and operations of the method and computer program product according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or the flowchart, and the combination of the boxes in the block diagram and / or the flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0104] In addition, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0105] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0106] In summary, the embodiment of the present application provides a red fire ant detection method based on improved YOLOv5s, which collects red fire ant image data to form an image data set, selects a YOLOv5s network model, introduces SCConv convolution to replace the convolution in the head part of the model and the dyhead detection head, and uses FocalModulation technology to replace the original SPPF. Focaler-loU is used as the loss function for calculating bounding box regression to establish an improved YOLOv5s network model, and the image to be detected is input into the improved YOLOv5s model, and the corresponding red fire ant detection result is output. The present invention improves the YOLOv5s model so that the model has more advantages in processing large amounts of data and complex images, thereby improving the adaptability of the model and the accuracy of red fire ant detection in various environments.
[0107] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
[0108] It will be apparent to those skilled in the art that the present application is not limited to the details of the exemplary embodiments described above, and that the present application can be implemented in other specific forms without departing from the spirit or essential features of the present application. Therefore, the embodiments should be considered exemplary and non-limiting in all respects, and the scope of the present application is defined by the appended claims rather than the above description, and it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims be included in the present application. Any reference numeral in a claim should not be considered as limiting the claim to which it relates.
Claims
1. A red fire ant detection method based on improved YOLOv5s, characterized in that: The following steps are involved: S1. Obtain a dataset of red fire ant images in real scenes; S2, perform data enhancement and expansion on the red fire ant image dataset, and divide the expanded dataset into a training set, a validation set, and a test set; S3, introduce SCConv convolution into the YOLOv5s network model, and use FocalModulation technology and Focaler-loU loss function to build an improved YOLOv5s target detection model; S4, putting the training set into the improved YOLOv5s target detection model for training to obtain an improved model; S5. Deploy the improved model to the terminal device for testing to obtain the test results.
2. A red imported fire ant detection method based on improved YOLOv5s as claimed in claim 1, characterized in that: In step S2, CutMix and Mixup methods are used to perform data enhancement on the red fire ant image dataset.
3. A method for detecting red imported fire ants based on improved YOLOv5s as claimed in claim 2, characterized in that: Step S2 also includes labeling the data-enhanced and expanded red fire ant image dataset through the open source application Labelimg, and converting the dataset into yolo format.
4. A method for detecting red imported fire ants based on improved YOLOv5s as claimed in claim 1, characterized in that: Step S3 includes: S31, introduce SCConv convolution into the pre-established YOLOv5s network model to replace the convolution part in the model head and the Dyhead detection head; S32, use FocalModulation technology to replace the original SPPF module in the YOLOv5s network model; S33. Using the Focaler-loU loss function as the loss function for calculating bounding box regression, an improved YOLOv5s target detection model is constructed based on steps S31 to S32.
5. A method for detecting red imported fire ants based on improved YOLOv5s as claimed in claim 4, characterized in that: The calculation formula of the Focaler-loU loss function is include: Where, IoU focaler represents the Focaler-loU loss function, IoU represents the intersection over union ratio, d and u are parameters, and [d,u]∈[0,1].
6. A method for detecting red imported fire ants based on improved YOLOv5s as claimed in claim 1, characterized in that: Step S4 also includes evaluating the improved model, and its expression is: In the formula, mAP represents the mean average precision, P represents the precision, AP represents the average precision, N represents the total number of categories, R represents the recall rate, TP represents the number of samples predicted by the model to be positive and actually positive, FP represents the number of samples predicted by the model to be positive but actually negative, and FN represents the number of samples predicted by the model to be negative but actually positive.
7. An electronic device, characterized in that: include: A memory for storing one or more programs; processor; When the one or more programs are executed by the processor, a red fire ant detection method based on improved YOLOv5s as described in any one of claims 1 to 6 is implemented.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, a red fire ant detection method based on improved YOLOv5s as described in any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Target detection method and device, equipment and storage medium
CN118587424A
Bridge crack disease identification method and device
CN118781109A
Structural information guided SAR (Synthetic Aperture Radar) target fine granularity identification method and system
CN118941914A