An improved method and device for YOLO network model
By annotating and optimizing the growth stage of the YOLO network model, replacing GIoU with SIoU, and introducing the ECA attention mechanism, the problem of low strawberry detection accuracy was solved, and high-precision strawberry growth stage identification was achieved.
Patent Information
- Application Number
- CN202410147610.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-01
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2044-02-01
AI Technical Summary
Existing YOLO network models have low detection accuracy in strawberry detection and are difficult to adapt to the complex environment of small fruits like strawberries, thus affecting detection accuracy.
By acquiring strawberry image data and classifying and labeling its growth stages, the YOLO network model is optimized by replacing GIoU with the bounding box loss function SIoU and introducing the ECA attention mechanism.
It improved the detection accuracy of strawberries at different growth stages to over 90%, increased the recognition accuracy, and reduced the number of model parameters and computational complexity.
Smart Images

Figure CN118154939B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of target recognition and detection, and specifically to an improved method and apparatus for the YOLO network model. Background Technology
[0002] Strawberries are perennial herbaceous plants belonging to the genus *Fragaria* of the Rosaceae family. Their fruits are rich in carotene and vitamin A, which help maintain the health of epithelial tissues and promote growth and development. At the same time, strawberries are rich in dietary fiber, which helps promote digestion in the gastrointestinal tract and prevents acne and colon cancer. Commercial strawberry production is widespread in most parts of China, with the country ranking first in the world in both cultivation area and yield. Due to the dense planting and rapid ripening of strawberries, failure to harvest them promptly can easily lead to rotting, causing economic losses for farmers.
[0003] With the rapid development of agricultural information technology, agricultural automation and intelligentization have become popular trends in agricultural production. Deep learning technology for agricultural product detection is an emerging computer vision method that has been widely applied to maturity recognition, remote intelligent monitoring, yield prediction, and harvesting robots. However, the complex and ever-changing natural environment still has a certain impact on fruit detection. Factors such as leaf occlusion, fruit overlap, plant structure interference, and changes in light intensity are common factors affecting the accuracy of fruit detection. Therefore, improving the performance of fruit detection models is key to solving the aforementioned problems.
[0004] Based on this, this application is hereby submitted to address the issue of how to improve the performance of fruit detection models and enhance the accuracy of detecting and identifying different growth stages of strawberries. Summary of the Invention
[0005] This specification provides an improved method and apparatus for the YOLO network model. The network model is used to detect strawberry image sets at different growth stages, achieving a detection accuracy of over 90%, thus improving the accuracy of identifying different growth stages of strawberries.
[0006] To solve the above-mentioned technical problems, the embodiments in this specification are implemented as follows:
[0007] Firstly, the embodiments of this specification provide an improved method for the YOLO network model, applied to detecting the growth stage of strawberries, characterized by comprising:
[0008] Acquire first strawberry image data; perform image classification and annotation on the first strawberry image data based on preset growth stage classification rules to obtain second strawberry image data with labeled growth stages;
[0009] The second strawberry image data is divided into a dataset based on a preset dataset partitioning rule to obtain a first data partition set; the first data partition set includes a training set and a validation set.
[0010] The first network model is obtained by replacing the bounding box loss function GIoU in the YOLO network model with the bounding box loss function SIoU.
[0011] By introducing the ECA attention mechanism into the first network model, a second network model is obtained;
[0012] Based on the training set and the validation set, the second network model is trained to obtain an optimized YOLO network model for detecting multiple growth stages of strawberries.
[0013] Secondly, the embodiments of this specification provide an improved device for the YOLO network model, applied to detecting the growth stage of strawberries, characterized in that it includes:
[0014] The data acquisition module is used to acquire first strawberry image data; and to perform image classification and annotation on the first strawberry image data based on a preset growth stage classification rule to obtain second strawberry image data with the growth stage annotated.
[0015] The data partitioning module is used to partition the second strawberry image data into a dataset based on a preset dataset partitioning rule to obtain a first data partition set; the first data partition set includes a training set and a validation set.
[0016] A replacement module is used to replace the bounding box loss function GIoU in the YOLO network model with the bounding box loss function SIoU to obtain a first network model.
[0017] An introduction module is used to introduce the ECA attention mechanism into the first network model to obtain a second network model.
[0018] The training module is used to train the second network model based on the training set and the validation set to obtain an optimized YOLO network model for detecting multiple growth stages of strawberries.
[0019] At least one embodiment in this specification achieves the following beneficial effects: First strawberry image data is acquired; image classification and annotation of the first strawberry image data are performed based on preset growth stage classification rules to obtain second strawberry image data with labeled growth stages; the second strawberry image data is then divided into a dataset to obtain a first data partition set including a training set and a validation set; the bounding box loss function GIoU in the YOLO network model is replaced with the bounding box loss function SIoU to obtain a first network model; an ECA attention mechanism is introduced into the first network model to obtain a second network model; the second network model is trained using the training set and the validation set to obtain an optimized YOLO network model for detecting multiple growth stages of strawberries. Using this network model to detect strawberry image sets at different growth stages, the detection accuracy reaches over 90%, improving the accuracy of identifying different growth stages of strawberries. Attached Figure Description
[0020] To more clearly illustrate the technical solutions in the embodiments or prior art of this specification, the drawings used in the description of the embodiments or prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0021] Figure 1 This is a flowchart illustrating an improved method for the YOLO network model provided in the embodiments of this specification.
[0022] Figure 2 This is a schematic diagram of the improved network structure based on the YOLO version 5 network structure in an embodiment of the YOLO network model improvement method provided in this specification.
[0023] Figure 3 This is a schematic diagram illustrating the human-computer interaction interface detection effect in an improved method for the YOLO network model provided in the embodiments of this specification.
[0024] Figure 4 This is a schematic diagram of the structure of an improved device for the YOLO network model provided in the embodiments of this specification. Detailed Implementation
[0025] To make the objectives, technical solutions, and advantages of one or more embodiments of this specification clearer, the technical solutions of one or more embodiments of this specification will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this specification, and not all of them. Based on the embodiments in this specification, all other embodiments obtained by those skilled in the art without creative effort are within the protection scope of one or more embodiments of this specification.
[0026] The technical solutions provided in the various embodiments of this specification are described in detail below with reference to the accompanying drawings.
[0027] In existing technologies, with the continuous iteration of detection models and algorithms, their accurate and efficient detection performance has received widespread attention and application. Based on the method disclosed in this application, the detection model can be further optimized to obtain a detection model with higher accuracy. For example, the YOLO series of detection algorithms also have strong generalization and robustness, and can adapt to target detection tasks under complex conditions such as different scales, poses, and occlusions, which is of great significance for practical applications in the agricultural field. However, the three detection heads of the original YOLO network model are small target detection head P3[(10,13),(16,30),(33,23)], medium target detection head P4[(30,61),(62,45),(59,119)], and large target detection head P5[(116,90),(156,198),(373,326)], and each of the three detection heads has three sets of anchor box sizes, with the anchor box size in pixels; its design is based on the COCO (Common Objects in Context) dataset. The COCO dataset contains over 330,000 labeled images, encompassing more than 80 different object categories. These images primarily depict objects from various everyday scenes, making them less suitable for detecting small fruits like strawberries. Consequently, the YOLO network model achieves low detection accuracy when used for strawberry detection. However, the object detection network model obtained by optimizing the YOLO network model using the method disclosed in this application achieves a detection accuracy exceeding 90%, significantly improving the accuracy of the detection model in detecting and recognizing strawberries at different growth stages.
[0028] To address the shortcomings of existing technologies, this solution provides the following embodiments:
[0029] Figure 1This is a flowchart illustrating an improved method for the YOLO network model provided in the embodiments of this specification. From the perspective of program execution, the executing entity of this described process can be a server or client equipped with the method described in this invention. All uses of terms such as "first," "second," "third," and "fourth" in the embodiments of this invention are merely for distinguishing two entities or parameters with the same name but different meanings; therefore, "first," "second," "third," and "fourth" are used only for convenience and clarity.
[0030] like Figure 1 As shown, the method may include:
[0031] Step 110: Obtain first strawberry image data; perform image classification and annotation on the first strawberry image data based on preset growth stage classification rules to obtain second strawberry image data with labeled growth stages.
[0032] In step 110, there are several ways to acquire the first strawberry image data. It can be done by using a high-powered camera or webcam to periodically capture images of strawberries in their growth stage from different angles; or by using a smartphone to take close-up photos of strawberries in their growth stage. As an example, another way to acquire strawberry images is to use a smartphone to collect 1254 images of strawberries in a greenhouse between 9:00 AM and 5:00 PM under different lighting conditions, shading, and angles. These images are then filtered according to a preset method, removing unqualified images, and finally selecting 1217 strawberry images as the first strawberry image dataset.
[0033] Preferably, acquiring the first strawberry image data may include: acquiring strawberry image data in a strawberry greenhouse based on preset acquisition conditions, wherein the preset acquisition conditions include at least one of different light intensities, different shading conditions, and different angles.
[0034] Furthermore, the first strawberry image dataset needs to be classified and labeled to distinguish the different growth stages of strawberries in the images, thus obtaining second strawberry image data with labeled growth stages; thereby, the dataset can be further divided using the second strawberry image data with labeled growth stages.
[0035] Preferably, the strawberry image data is preprocessed to obtain the first strawberry image data; the preprocessing includes at least one of removing images whose clarity does not meet the preset conditions, removing images with incomplete single strawberry images, and removing images without strawberries.
[0036] It should be noted that an incomplete image of a single strawberry plant means that only a portion of the strawberry plant was captured, such as an image showing only 50% of the area occupied by a particular strawberry plant; an image without strawberries means that the image only shows the strawberry plant itself, without any images of the strawberry fruit.
[0037] Step 120: Divide the second strawberry image data into datasets based on preset dataset partitioning rules to obtain a first data partition set; the first data partition set includes a training set and a validation set.
[0038] In step 120, the second strawberry image data is divided into datasets according to a preset dataset partitioning rule to obtain a first dataset partitioning set; wherein, the first dataset partitioning set may include a training set and a validation set, and may also include a test set; the dataset partitioning of the second strawberry image data based on the preset dataset partitioning rule includes: partitioning the second strawberry image data into datasets based on a preset ratio to obtain the training set, validation set and test set partitioning rule.
[0039] As an example, the first set of data can be divided into training, validation and test sets according to a preset ratio of 8:1:1; the dataset can also be divided according to a preset ratio of 6:3:1; or other data division rules can be set according to user needs. This solution does not impose specific limitations.
[0040] Step 130: Replace the bounding box loss function GIoU in the YOLO network model with the bounding box loss function SIoU to obtain the first network model.
[0041] In step 130, the original default bounding box loss function GIoU in the YOLO network model has multiple local minima, which makes training difficult and sensitive to changes in the size and shape of the target box. It also has high computational complexity and is not good at handling background boxes. Replacing it with the boundary function SIoU can solve the above technical problems.
[0042] Step 140: Introduce the ECA attention mechanism into the first network model to obtain the second network model.
[0043] Step 150: Based on the training set and the validation set, train the second network model to obtain an optimized YOLO network model for detecting multiple growth stages of strawberries.
[0044] In steps 140 to 150, by adding the ECA attention mechanism to the neck structure of the YOLO network model and then feeding it into the head network for prediction, the network will focus more attention on the strawberry target body when detecting strawberries, thereby improving the accuracy of identifying different growth stages of strawberries.
[0045] Furthermore, as an example, the image classification and annotation of the first strawberry image data based on preset growth stage classification rules may include using Labelimg image annotation software to classify and annotate the first strawberry image data, or other image annotation software in the prior art may be used to classify and annotate the image data; the method for annotating fruit images disclosed in this application embodiment may employ the following methods:
[0046] (1) If the first strawberry image includes a fruit image with seeds covering the surface and no pulp showing, then the fruit image with seeds covering the surface and no pulp showing in the first strawberry image is marked as an indicator of the young fruit stage.
[0047] (2) If the first strawberry image includes a fruit image with exposed flesh and green overall, then the label of the first strawberry image with exposed flesh and green overall indicates the expansion period.
[0048] (3) If the first strawberry image includes a fruit image in which the surface of the fruit is red and the red area does not exceed two-thirds of the whole fruit, then the marking of the fruit surface in the first strawberry image in which the red area does not exceed two-thirds of the whole fruit indicates the staining period.
[0049] (4) If the first strawberry image includes a fruit image in which the red color on the surface of the fruit exceeds two-thirds of the whole fruit, then the marking of the fruit image in which the red color on the surface of the fruit exceeds two-thirds of the whole fruit indicates the ripening period.
[0050] Furthermore, in step 130, the bounding box loss function GIoU in the YOLO network model is replaced by the bounding box loss function SIoU to obtain the first network model; wherein the YOLO network model can be the 5th version of the YOLO network model, or other versions of the network model, as well as other object detection network models that include the bounding box loss function GIoU.
[0051] As an example, this application uses the fifth version of the YOLO network model as an illustration.
[0052] Specifically, the original default bounding box loss function GIoU in the YOLO network model v5 has multiple local minima, leading to training difficulties, sensitivity to changes in the size and shape of the target boxes, high computational complexity, and insufficient handling of background boxes. SIoU is chosen as a replacement, as shown in the following formula:
[0053]
[0054]
[0055]
[0056] Where A represents the predicted bounding box, B represents the ground truth bounding box, C represents the minimum bounding box of A and B, Δ represents the distance loss, and ω represents the shape loss.
[0057] By replacing the bounding box loss function GIoU in the YOLO version 5 network model with the bounding box loss function SIoU using the above method, the problems of sensitivity to changes in the size and shape of the target box and high computational complexity are avoided. The training process is simple, and it is easy to handle the background box (anchor box). Furthermore, replacing the bounding box loss function GIoU in the original YOLO version 5 network model with SIoU enhances the network's computational ability for target detection, thereby improving detection accuracy.
[0058] Furthermore, before step 140, that is, before introducing the ECA attention mechanism into the first network model, the method further includes: deleting the large target detection head P5 and related network structures in the first network model to obtain the first network model with the remaining small target detection head P3 and medium target detection head P4; performing cluster analysis on the small target detection head P3 and medium target detection head P4 in the first network model to obtain the small target detection head Q3 and medium target detection head Q4 suitable for strawberry fruit.
[0059] Preferably, the clustering analysis of the small target detection head P3 and the target detection head P4 in the first network model may include:
[0060] The width and height of the target boxes in the small target detection head P3 are normalized using the k-means clustering algorithm to determine a first preset number of center points; based on the two sets of the first preset number of center points, a first preset number of anchor boxes corresponding to the first preset number of center points are determined; the first preset number of anchor boxes are determined as the anchor boxes of the small target detection head Q3.
[0061] The width and height of the target boxes in the target detection head P4 are normalized using the k-means clustering algorithm to determine a first preset number of center points; based on the two sets of the first preset number of center points, a first preset number of anchor boxes corresponding to the first preset number of center points are determined; and the first preset number of anchor boxes are determined as the anchor boxes of the target detection head Q4.
[0062] As an example, the original YOLO version 5 network model has three detection heads: small object detection head P3 [(10,13),(16,30),(33,23)], medium object detection head P4 [(30,61),(62,45),(59,119)], and large object detection head P5 [(116,90),(156,198),(373,326)]. Each detection head has three sets of anchor box sizes, with the unit of anchor box size being pixels. Since the COCO dataset contains over 330,000 labeled images, including over 80 different object categories, these images mainly depict objects in various everyday scenes and are not well-suited for small objects like strawberries. Therefore, the large object detection head P5 was removed, and the strawberry fruit detection boxes in the strawberry dataset were re-clustered using the k-means clustering algorithm to obtain anchor box sizes suitable for strawberry fruits in greenhouse field environments.
[0063] Preferably, the width and height of the target boxes in the training set can first be normalized using the k-means clustering algorithm to determine a first preset number of k center points. These center points correspond to k anchor boxes and are used as the anchor box sizes of the target detection model. These anchor box sizes are more suitable for the detection needs. In this invention, k is set to 3. After k-means clustering, the new anchor boxes of the Q3 detection head are (19,20), (34,35), and (53,55), and the new anchor boxes of the Q4 detection head are (74,79), (99,108), and (129,147); wherein the unit of anchor box size is pixels.
[0064] Specifically, by removing the P5 large target detector and related network structure from the three default detectors in YOLOv5 using the above method, the network can be lightweighted. Then, the true bounding boxes of the strawberry dataset are re-clustered using the k-means clustering algorithm, resulting in six different sizes of check boxes (anchor boxes): (19,20), (34,35), (53,55), (74,79), (99,108), and (129,147). Anchor boxes with sizes (19,20), (34,35), and (53,55) are designated as the anchor boxes for the small target detector Q3, while anchor boxes with sizes (74,79), (99,108), and (129,147) are designated as the anchor boxes for the target detector Q4. This yields anchor box sizes suitable for strawberry fruit in greenhouse field environments, improving the accuracy of detecting strawberry growth stages.
[0065] This invention targets strawberries as small fruit targets by removing the large detection head P5 and related structures from YOLOv5, thus achieving a lightweight network structure. Simultaneously, we used the k-means clustering algorithm to recalculate the candidate box sizes for this greenhouse strawberry image dataset. This method effectively improves the model's detection accuracy and is more suitable for strawberry fruit target detection datasets compared to the original YOLOv5.
[0066] Furthermore, as an example, Figure 2 This is a schematic diagram of the improved network structure based on the YOLOv5 network structure in an embodiment of the YOLO network model improvement method provided in this specification.
[0067] Preferably, introducing the ECA attention mechanism into the first network model can include adding the ECA attention mechanism to the neck structure of the first network model.
[0068] Specific examples Figure 2 As shown, the image is input into the YOLO version 5 network model in a 640 pixel × 640 pixel × 3 channel format. Feature extraction is performed through the backbone network. The sequentially connected modules in the backbone network structure include Conv convolution module -> Conv convolution module -> C3 module -> Conv convolution module -> two C3 modules -> Conv convolution module -> C3 module -> SPPF fast spatial pyramid pooling module.
[0069] Furthermore, feature fusion is performed on the image within the neck network structure. The SPPF fast spatial pyramid pooling module in the backbone network structure is connected to the Conv convolution module in the neck network structure. The sequence is: Conv convolution module -> Unsample module -> Concat connection module -> C3 module -> Conv convolution module -> Concat connection module -> C3 module. One end of the Concat connection module, which is connected to the output of the Unsample module, is also connected to one end of each of the two C3 modules in the backbone network structure. The Conv convolution module, which is connected to the input of the Unsample module, is also connected to the Concat connection module, whose input is connected to the Conv convolution module.
[0070] It should be noted that the Conv convolution module structure includes a Conv2d two-dimensional convolution module, a BatchNorm2d two-dimensional batch normalization module, and a SiLU activation function; the C3 module structure includes three Conv convolution modules, one BottleNeck module, and one Concat connection module; the SPPF module includes two Conv convolution modules, three MaxPool2d two-dimensional max pooling modules, and one Concat connection module; the connection methods between the various modules are in accordance with the existing technology and will not be elaborated here.
[0071] Furthermore, the image is transmitted to the head network structure for prediction via the neck network structure. Specifically, two C3 modules in the neck network structure are connected to two Conv convolutional modules, forming two network paths from C3 module to Conv convolutional module, which are then transmitted to the head network structure for prediction. In this application's method, an ECA attention mechanism module is added after each of the two C3 modules in the neck network structure before being fed into the head network for prediction. With the addition of the attention mechanism, the network structure focuses more attention on the strawberry target body when detecting strawberries. By introducing the ECA attention module into the network, the network's recognition perception and feature extraction capabilities are optimized, highlighting the features of the strawberry fruit target area in the image, thus improving the accuracy and generalization performance of target detection. This application names the improved network model S34E-YOLO.
[0072] By comparing the original YOLO version 5 network model and the improved S34E-YOLO model, the detection accuracy, speed, and model complexity of the two models were evaluated using F1 score, mean average precision (mAP), number of parameters (params), floating point operations (FLOPs), model size, and frames per second (FPS) as metrics. The comparison results are shown in Table 1.
[0073] Table 1. Comparison Table of Original YOLO Version 5 Network Model and Improved Network Model S34E-YOLO
[0074] Model F1 mAP@0.5 Params FLOPs(G) Size (MB) FPS YOLOv5s 86.92% 90.87% 7020913 15.8 13.7 70 S34E-YOLO 87.47% 92.90% 1561820 10.2 3.24 87
[0075] As shown in Table 1, the improved model has improved detection accuracy, and the number of model parameters, computational complexity and model size have been reduced by 77.8%, 36.5% and 76.6% respectively, while the FPS has been increased by 24%. This effectively reduces the computing power requirements of the equipment and makes it easier to deploy at the edge.
[0076] Furthermore, such as Figure 3 As shown, Figure 3 This is a schematic diagram illustrating the human-computer interaction interface detection effect in an improved method for the YOLO network model provided in the embodiments of this specification.
[0077] Based on this, the improved model of this application was accelerated and deployed on Jetson Nano, Raspberry Pi and other platforms, which can effectively detect strawberry image sets at different growth stages and improve the recognition accuracy of strawberry at different growth stages.
[0078] Specifically, in Figure 3 The process can include configuring the corresponding system and environment in the Jetson Nano development version, accelerating and deploying the S34E-YOLO model using TensorRT, designing a human-computer interaction interface, and using the human-computer interaction interface to call the camera to collect strawberry images. The statistical information of the output prediction results can be displayed in the human-computer interaction interface to obtain the type and quantity of strawberries, with a detection accuracy of over 90%. In particular, it has significantly improved the detection effect of strawberry targets in greenhouse fields, enhancing the real-time performance and accuracy of strawberry detection in complex scenarios such as greenhouses.
[0079] Based on this, the improved model was accelerated and optimized using TensorRT and finally deployed on the Jetson Nano development board. A human-computer interaction interface was also designed, which can output the location, type, and quantity of strawberries in the image in real time on the screen. Compared with the original YOLO version 5 network model, the improved network is more lightweight, improving detection accuracy and speed. Therefore, this method can be applied to actual agricultural production operations such as harvesting robots.
[0080] Based on the same idea, embodiments of this specification also provide apparatus corresponding to the above methods. Figure 4 This is a schematic diagram of the structure of an improved device for the YOLO network model provided in the embodiments of this specification.
[0081] like Figure 4 As shown, the device may include:
[0082] The data acquisition module 410 is used to acquire first strawberry image data; and to perform image classification and annotation on the first strawberry image data based on preset growth stage classification rules to obtain second strawberry image data with labeled growth stages.
[0083] The data partitioning module 420 is used to partition the second strawberry image data into a dataset based on a preset dataset partitioning rule to obtain a first data partition set; the first data partition set includes a training set and a validation set;
[0084] Replacement module 430 is used to replace the bounding box loss function GIoU in the YOLO network model with the bounding box loss function SIoU to obtain the first network model;
[0085] Module 440 is introduced to introduce the ECA attention mechanism into the first network model to obtain the second network model;
[0086] The training module 450 is used to train the second network model based on the training set and the validation set to obtain an optimized YOLO network model for detecting multiple growth stages of strawberries.
[0087] exist Figure 4In the device shown, a first strawberry image data is acquired through a data acquisition module, and the image is classified and labeled according to a preset growth stage classification rule to obtain a second strawberry image data labeled with the growth stage. A data partitioning module divides the second strawberry image data into a training set, a validation set, and a test set according to a preset dataset partitioning rule. The training and validation sets are used as training data. A replacement module replaces the bounding box loss function GIoU in the YOLO network model with the bounding box loss function SIoU, matches the optimal target detection scale, and introduces an ECA attention mechanism through an introduction module. A training module uses transfer learning to train the data, resulting in a detection model for multiple strawberry growth stages. The improved target detection model can be used to detect test set data with a detection accuracy of over 90%, improving the accuracy of identifying different growth stages of strawberries.
[0088] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0089] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on its differences from other embodiments. In particular, for... Figure 4 As the apparatus embodiment shown is basically similar to the method embodiment, the description is relatively simple, and relevant parts can be referred to in the description of the method embodiment.
[0090] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0091] This application can be described in the general context of computer-executable instructions, such as program modules, that are executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform a specific task or implement a specific abstract data type. This application can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0092] The above description is merely an embodiment of this application and is not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. An improved method for the YOLO network model, applied to detect the growth stages of strawberries, characterized in that, include: Acquire first strawberry image data; perform image classification and annotation on the first strawberry image data based on preset growth stage classification rules to obtain second strawberry image data with labeled growth stages; The second strawberry image data is divided into a dataset based on a preset dataset partitioning rule to obtain a first data partition set; the first data partition set includes a training set and a validation set. The first network model is obtained by replacing the bounding box loss function GIoU in the YOLO network model with the bounding box loss function SIoU. The large target detection head P5 and related network structures in the first network model are deleted to obtain the third network model with the remaining small target detection head P3 and medium target detection head P4. Cluster analysis of the small target detection head P3 and the medium target detection head P4 in the third network model yields small target detection head Q3 and medium target detection head Q4 suitable for strawberry fruits; The clustering analysis of the small target detection head P3 and the medium target detection head P4 in the third network model includes: The width and height of the target boxes in the small target detection head P3 and the medium target detection head P4 are normalized using the k-means clustering algorithm to obtain a first preset number of anchor boxes; the anchor boxes are used to detect the growth stage of strawberries; Specifically, the k-means clustering algorithm is used to normalize the width and height of the target boxes in the small target detection head P3 to determine the first preset number of center points; based on the two sets of the first preset number of center points, the first preset number of anchor boxes corresponding to the first preset number of center points are determined; the first preset number of anchor boxes are determined as the anchor boxes of the small target detection head Q3. The width and height of the target boxes in the target detection head P4 are normalized using the k-means clustering algorithm to determine a first preset number of center points; based on the two sets of the first preset number of center points, a first preset number of anchor boxes corresponding to the first preset number of center points are determined; the first preset number of anchor boxes are determined as the anchor boxes of the target detection head Q4. An ECA attention mechanism is added to the neck structure of the third network model to obtain a second network model; Based on the training set and the validation set, the second network model is trained to obtain an optimized YOLO network model for detecting multiple growth stages of strawberries.
2. The method as described in claim 1, characterized in that, The acquisition of the first strawberry image data includes: Acquire strawberry image data in a strawberry greenhouse based on preset acquisition conditions, wherein the preset acquisition conditions include at least one of different light intensities, different shading conditions, and different angles; The strawberry image data is preprocessed to obtain the first strawberry image data; the preprocessing includes at least one of the following: removing images whose clarity does not meet the preset conditions, removing images with incomplete single strawberry images, and removing images without strawberries.
3. The method as described in claim 1, characterized in that, The image classification and annotation of the first strawberry image data based on preset growth stage classification rules includes: If the first strawberry image includes an image of a fruit whose surface is covered with seeds and no pulp is exposed, then the image of the fruit whose surface is covered with seeds and no pulp is exposed in the first strawberry image is marked as an indicator of the young fruit stage. If the first strawberry image includes an image of a fruit with exposed flesh and an overall green color, then the label of the first strawberry image with exposed flesh and an overall green color indicates the expansion stage. If the first strawberry image includes a fruit image where the surface of the fruit is red and the red area does not exceed two-thirds of the total fruit area, then the label of the first strawberry image where the surface of the fruit is red and the red area does not exceed two-thirds of the total fruit area represents the staining period. If the first strawberry image includes images of fruits with red covering more than two-thirds of the fruit's surface, then marking the areas in the first strawberry image where red covers more than two-thirds of the fruit's surface indicates the ripening period.
4. The method as described in claim 1, characterized in that, The first data partition set also includes a test set; the partitioning of the second strawberry image data into datasets based on preset dataset partitioning rules includes: The second strawberry image data was divided into a dataset based on a preset ratio to obtain the training set, validation set, and test set.
5. The method as described in claim 1, characterized in that, The first preset number of anchor frames includes six different sizes of anchor frames.
6. An improved device for the YOLO network model, used to detect the growth stages of strawberries, characterized in that, Includes a functional module for performing the method as described in claim 1, the functional module comprising: The data acquisition module is used to acquire first strawberry image data; and to perform image classification and annotation on the first strawberry image data based on a preset growth stage classification rule to obtain second strawberry image data with the growth stage annotated. The data partitioning module is used to partition the second strawberry image data into a dataset based on a preset dataset partitioning rule to obtain a first data partition set; the first data partition set includes a training set and a validation set. A replacement module is used to replace the bounding box loss function GIoU in the YOLO network model with the bounding box loss function SIoU to obtain a first network model. The deletion module is used to delete the large target detection head P5 and related network structures in the first network model to obtain a third network model with the remaining small target detection head P3 and medium target detection head P4. A clustering module is used to perform clustering analysis on the small target detection head P3 and the medium target detection head P4 in the third network model to obtain small target detection heads Q3 and Q4 suitable for strawberry fruits. The clustering analysis includes: normalizing the width and height of the target boxes in the small target detection head P3 and the medium target detection head P4 using the k-means clustering algorithm to obtain a first preset number of anchor boxes; the anchor boxes are used to detect the growth stage of strawberries; wherein, the k-means clustering algorithm is used to normalize the width and height of the target boxes in the small target detection head P3 to obtain a first preset number of anchor boxes; the anchor boxes are used to detect the growth stage of strawberries; wherein, the k-means clustering algorithm is used to normalize the width and height of the target boxes in the small target detection head P3 to obtain a first preset number of anchor boxes. A first preset number of center points are determined; based on the two sets of the first preset number of center points, a first preset number of anchor frames corresponding to the first preset number of center points are determined; the first preset number of anchor frames are determined as the anchor frames of the small target detection head Q3; and the width and height of the target boxes in the medium target detection head P4 are normalized using the k-means clustering algorithm to determine a first preset number of center points; based on the two sets of the first preset number of center points, a first preset number of anchor frames corresponding to the first preset number of center points are determined; the first preset number of anchor frames are determined as the anchor frames of the medium target detection head Q4; An introduction module is used to add an ECA attention mechanism to the neck structure of the third network model to obtain a second network model; The training module is used to train the second network model based on the training set and the validation set to obtain an optimized YOLO network model for detecting multiple growth stages of strawberries.
