A strawberry maturity detection method and system based on improved YOLOv8

By introducing the CBAM module and spatial pyramid pooling module into the YOLOv8 model, combined with the channel and spatial attention mechanism, the problem of insufficient accuracy of strawberry ripeness detection in complex scenes and illumination changes in the existing technology is solved, and the detection accuracy is improved. It has high performance and robustness, achieving accurate strawberry ripeness detection and positioning picking in open scenarios.

CN117315473BActive Publication Date: 2024-09-10ANHUI AGRICULTURAL UNIVERSITY

Patent Information

Application Number
CN202311273707.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-28
Publication Date
2024-09-10
Estimated Expiration
2043-09-28

AI Technical Summary

Technical Problem

Existing strawberry ripeness detection methods have limited effects when dealing with complex scenes and changing lighting conditions. The traditional YOLO v8 lacks an attention mechanism, resulting in insufficient attention to different scales and important features, affecting detection accuracy and robustness.

Method used

The CBAM module and the spatial pyramid pooling module are introduced into the YOLOv8 model, combining the channel attention and spatial attention mechanisms to enhance the model's perception of strawberry ripeness characteristics, and improve the model's robustness and generalization ability through data enhancement technology. .

Benefits of technology

It improves the accuracy and robustness of strawberry ripeness detection, enhances the model's ability to detect strawberries of different sizes and proportions, reduces the false detection rate, and enables accurate detection and positioning for picking in open scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117315473B
    Figure CN117315473B
Patent Text Reader

Abstract

The present invention relates to a strawberry maturity detection method and system based on improved YOLOv8, comprising: collecting strawberry images to be detected; performing maturity recognition on the strawberry images to be detected based on an improved YOLOv8 model to obtain strawberry maturity detection results; wherein the improved YOLOv8 model is trained through a training set, and the training set data is a set of strawberry images with maturity annotated. The present invention can improve the accuracy of strawberry recognition by a target detection model and the accuracy of positioning and picking in an open scene.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical fields of computer vision, deep learning and strawberry maturity detection, and in particular to a strawberry maturity detection method and system based on improved YOLOv8. Background Art

[0002] At present, common strawberry maturity detection methods include image processing-based and deep learning-based methods. Image processing-based methods mainly rely on manually designed feature extraction algorithms and classifiers, but they are limited in effect when dealing with complex scenes and changing lighting conditions, and their performance needs to be improved. Deep learning-based methods widely use convolutional neural networks (CNNs), among which the YOLO series is a common target detection algorithm, but there are still some challenges and shortcomings when dealing with small-sized and highly variable strawberry maturity detection tasks.

[0003] Traditional YOLO v8 does not introduce an attention mechanism, and its attention to different scales and important features may not be sufficient. In strawberry maturity detection, specific maturity features are crucial for classification and localization, and require special attention to improve accuracy and robustness.

[0004] Prior art 1 provides a tomato maturity detection method based on lightweight improved YOLO: the backbone part of the original YOLOv5 adopts CSPDarknet53. Based on the consideration of model lightweighting, the present invention uses the inverse residual bncek structure of MobileNetV3 to replace the backbone part of YOLOv5. The inverse residual bncek structure of MobileNetV3 mainly includes channel separable convolution + SE channel attention mechanism + residual connection. The specific processing flow is: first, the input features are passed through a convolution combination layer and a depth separable convolution combination layer, and then the obtained feature map is passed through an SE attention structure, and then the output of the SE attention structure is channel-weighted by the features of the depth separable convolution output through the concat operation, and finally the input features are added to the weighted features through the add jump connection, and then processed by a convolution combination layer and output; wherein, the convolution combination layer includes a 1×1 convolution layer, a BatchNorm regularization layer and an activation function; the depth separable convolution combination layer includes a 3×3 depth separable convolution layer, a BatchNorm regularization layer and an activation function; the SE attention structure includes an average pooling layer and two 1×1 convolution layers; wherein, according to the different convolution kernel sizes and step sizes, whether the SE attention mechanism is used or not, and the different activation functions (ReLU6 and hard-swish), the specific parameters of the bneck structures of different layers are adjusted and combined to finally obtain the improved overall network.

[0005] Although the network structure of YOLO v5 has been improved in the prior art 1 to make the model lighter, the real-time detection speed and accuracy are still not optimal under the same hardware conditions, and there are limitations in adaptability to complex scenes and target tracking.

[0006] Prior art 2 provides a strawberry maturity detection method and device using YOLO V3: a strawberry maturity detection method and device based on YOLO V3, by collecting strawberry images and preprocessing the strawberry images to obtain preprocessed images; the maturity is detected according to the strawberry maturity recognition model of YOLO V3, and the maturity detection result is output. The training process of the strawberry maturity recognition model of YOLO V3 includes: artificial data collection, which is the basis of the training model. Through the shooting of the fixed-point camera, actual strawberry pictures in the actual agricultural production scene are collected; data set annotation, the process of cable data set annotation, the annotation tool used is labelimg; data processing, after obtaining the data and the corresponding annotation information, the data must be processed, including data enhancement, random rotation, random cropping, color jitter, Gaussian noise, horizontal flip, and vertical flip operations on the collected pictures; anchor setting, using the k-means algorithm to process the obtained annotation information, and then obtain the anchor suitable for the cable data set; network structure design, using the YOLOV3 network model; training process, using the given YOLO V3 code and the obtained data set for training, so as to efficiently and accurately detect the maturity of strawberries. Prior art 2 did not improve the algorithm but only applied the YOLO V3 algorithm, and the detection result was inaccurate. Summary of the invention

[0007] In order to solve the above technical problems, the present invention proposes a strawberry maturity detection method and system based on improved YOLOv8, which can accurately identify and detect the maturity information of strawberries in images.

[0008] To achieve the above object, the present invention provides a strawberry maturity detection method based on improved YOLOv8, comprising:

[0009] Collect the strawberry image to be detected;

[0010] Based on the improved YOLOv8 model, the strawberry image to be detected is subjected to maturity recognition to obtain a strawberry maturity detection result;

[0011] The improved YOLOv8 model is trained using a training set, wherein the training set data is a set of strawberry images with maturity annotated.

[0012] Optionally, before labeling the training set data, the method further includes: collecting original strawberry image data, and preprocessing the original strawberry image data includes:

[0013] The original strawberry image is subjected to denoising processing, and the denoised strawberry image is subjected to unified processing to obtain strawberry image data.

[0014] Optionally, the maturity annotation of the strawberry image set includes:

[0015] Maturity and immaturity.

[0016] Optionally, the improved YOLOv8 model is:

[0017] Add the CBAM module to each convolutional block of the YOLOv8 model, and connect the spatial pyramid pooling module to the output of the extraction layer in the YOLOv8 model;

[0018] Based on the CBAM module and the spatial pyramid pooling module, an improved YOLOv8 model is obtained.

[0019] Optionally, the CBAM module includes: a channel attention submodule and a spatial attention submodule;

[0020] The output end of the channel attention submodule is connected to the input end of the spatial attention submodule.

[0021] Optionally, the channel attention submodule includes:

[0022] Performing global average pooling on the feature map to reduce the dimension of the feature map into a weight vector;

[0023] Input the weight vector into two fully connected layers to obtain channel attention weights;

[0024] The attention weight is processed by using an activation function, and the processed channel attention weight is applied to each channel in the feature map to obtain a weighted feature map;

[0025] The spatial attention submodule includes:

[0026] Compress the feature map through a convolutional layer, perform global average pooling on the compressed feature map, and input the feature map after average pooling into two fully connected layers to obtain spatial attention weights;

[0027] The spatial attention weights are processed using an activation function, and the processed spatial attention weights are applied to the compressed feature map to obtain a weighted feature map.

[0028] Optionally, the data enhancement process includes: rotating, translating, scaling, cropping, flipping, and adjusting contrast and brightness of the original strawberry image data image.

[0029] Optionally, the spatial pyramid pooling module includes:

[0030] Inputting the features of the extraction layer into a preset number of branches, performing pooling processing on the features in the branches through the spatial pyramid pooling module to obtain scale features;

[0031] The scale features are combined to obtain multi-scale features.

[0032] The present invention also discloses a strawberry maturity detection system based on improved YOLOv8, comprising:

[0033] An acquisition unit, used for acquiring the strawberry image to be detected;

[0034] The detection unit is used to identify the maturity of the strawberry image to be detected based on the improved YOLOv8 model to obtain a strawberry maturity detection result; wherein the improved YOLOv8 model is trained through a training set, and the training set data is a set of strawberry images with maturity marked.

[0035] Compared with the prior art, the present invention has the following advantages and technical effects:

[0036] (1) The present invention proposes a strawberry maturity detection method and application based on improved YOLOv8, which can accurately identify and detect the maturity information of strawberries in an image, perform maturity detection and locate the picking of strawberry fruits in farmland or greenhouse, and improve the accuracy of target detection model in identifying strawberries and the accuracy of locating and picking in open scenes, while reducing the false detection rate of the model.

[0037] (2) The use of the CBAM module in the present invention can enhance the model's perception of strawberry maturity features. The CBAM module combines channel attention and spatial attention mechanisms, and can automatically learn important features in different channels and spatial positions. By introducing the CBAM module, the yolov8 model can more accurately identify features related to strawberry maturity and improve detection accuracy.

[0038] (3) The data enhancement module in the present invention can increase the diversity of data by performing various random transformations and expansions on the training data. By randomly changing the size, rotation angle, brightness, etc. of the image during the training process, the model can have better robustness and generalization ability. The data enhancement module can help the yolov8 model better adapt to different strawberry maturity detection scenarios and improve the robustness and accuracy of the model.

[0039] (4) The spatial pyramid pooling module can be used in the present invention to extract feature information of different scales, and these multi-scale features are used to locate and classify targets during the detection process. By introducing the spatial pyramid pooling module, the yolov8 model can better handle strawberry maturity targets of different sizes and proportions, and improve the accuracy and effect of target detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] The drawings constituting a part of the present application are used to provide a further understanding of the present application. The illustrative embodiments and descriptions of the present application are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0041] Figure 1 A schematic diagram of a strawberry maturity detection method based on improved YOLOv8 according to an embodiment of the present invention;

[0042] Figure 2 A test schematic diagram of a strawberry maturity detection method based on improved YOLOv8 of the present invention;

[0043] Figure 3 Schematic diagram of the structure of the CBAM attention mechanism of an embodiment of the present invention;

[0044] Figure 4 Schematic diagram of the structure of the improved YOLOv8 model according to an embodiment of the present invention. DETAILED DESCRIPTION

[0045] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0046] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0047] The present invention provides a strawberry maturity detection method based on improved YOLOv8, the specific steps are as follows: Figure 1 As shown, including:

[0048] S1. Collect strawberry image data and create a data set: Collect strawberry images, preprocess the images, and use the Structural Similarity Index (SSIM) algorithm with a similarity threshold of 0.95 (maximum value is 1) to filter out similar images to eliminate data redundancy and enhance the generalization of the model. Specifically, the imread() function of the OpenCV library is used to read the images, and then the collected images are converted into grayscale images, and then the SSIM algorithm is used. where μ P , μ Q Respectively represent the mean of images P and Q, σ P , σ Q Represent the standard deviation of images P and Q, σ PQ , is the covariance of the two strawberry images, C1 and C2 are constants to avoid the denominator being 0, calculate the similarity of the two images, and evaluate the image similarity by comparing the structural similarity of the grayscale images. Finally, remove the images with a similarity greater than the threshold of 0.95.

[0049] The filtered images were annotated using labelimg annotation software to obtain a data set containing two types of labels: ripe strawberries and unripe strawberries.

[0050] S2. Divide the data set: Divide the data set into training set, validation set, and test set in a ratio of 6:2:2. Before dividing the data, all data must be converted into txt format.

[0051] S3, YOLOv8 model improvements include: adding CBAM (Convolutional Block Attention Module) attention mechanism, adding online data enhancement module and adding spatial pyramid pooling module. The structural diagram is shown below Figure 4 As shown;

[0052] Add CBAM attention mechanism, such as Figure 3 As shown in the figure: The CBAM attention mechanism combines channel attention and spatial attention, which can simultaneously focus on the channel correlation and important spatial positions of the feature map. The CBAM module improves the model's perception of important features by simultaneously considering the relationship between channels and the relationship between spaces. It can be applied to various layers of YOLOv8, such as after the convolution layer or residual block. The CBAM module consists of two steps: first, the channel attention weights are learned through global average pooling and fully connected layers; then, the spatial attention module is applied to the feature map to emphasize important spatial positions by learning position attention weights. By adding the CBAM module to each convolution block in the YOLOv8 model, the model's ability to detect the ripeness of strawberries can be enhanced.

[0053] Channel attention mechanism calculation formula:

[0054]

[0055] Among them, M c (F) is the channel attention mechanism, f is a sigmoid function, W0∈R C / r×C ,W1∈R C×r / C Note that the MLP weights W0 and W1 are shared, the activation function is followed by W0, and F is the input W×H×C strawberry feature map. is the W×H×C strawberry feature map after global average pooling in the channel dimension, It is the W×H×C strawberry feature map after maximum pooling in the channel dimension.

[0056] Spatial attention mechanism calculation formula:

[0057]

[0058] Among them, M s (F) is the spatial attention mechanism, f represents the sigmoid function, μ 7×7 represents a convolution operation with a filter size of 7×7, is the W×H×C strawberry feature map after global average pooling in the spatial dimension. It is the W×H×C strawberry feature map after the maximum pooling of the spatial dimension.

[0059]

[0060] Among them, e -x is the negative power of the natural exponential function, f is the activation function, and the output value is limited to 0 to 1, so the output of each neuron is normalized.

[0061] The process of the channel attention mechanism is as follows: input the strawberry feature map of W×H×C, first perform global average pooling on each channel of the feature map to become 1×1×C, and then use a two-layer fully connected neural network for nonlinear transformation to obtain a weight of 1×1×C. The first layer of the fully connected neural network is used for dimensionality reduction, and the second layer is used to restore it to its initial state to obtain the weight of the channel attention W c , and finally use this weight to perform a weighted operation on each channel of the input feature map. The channel attention network uses FCex to assign different weights to each channel.

[0062] The spatial attention mechanism process is as follows: input a W×H×C strawberry feature map, first perform a channel global average pooling and a channel maximum pooling, so as to obtain two W×H×1 channel descriptions; then splice the two channel descriptions. After a 7×7 convolution kernel μ7×7 , and after the Sigmoid activation function, the weight coefficient W of W×H×1 is obtained s On this basis, a new feature map is obtained by spatially multiplying the original feature map and the weight coefficient. The experiment found that the effect of sequentially connecting the spatial attention module and the channel attention module is better than that of parallel connection.

[0063] The CBAM technology can enhance the correlation of each channel, and the deeper the CBAM module, the greater the correlation between the feature weight and the category. In this way, the quality of the shared underlying representation can be effectively improved in the shallow CBAM-based modules, and the advantages of CBAM re-adjusting feature weights at all depths can be accumulated continuously, thereby improving the accuracy of strawberry maturity detection.

[0064] In the CBAM attention mechanism, the channel attention submodule and the spatial attention submodule use different submodules to process the channel and spatial correlation of feature maps respectively.

[0065] The channel attention submodule contains global average pooling, two fully connected layers, and a sigmoid activation function to calculate the channel attention weights. The spatial attention submodule contains 1x1 convolution, a sigmoid activation function, and spatial recalibration to calculate the spatial attention weights. The two submodules process the feature map relationship of the channel and spatial dimensions respectively.

[0066] In the YOLOv8 model, the two fully connected layers in the channel attention submodule of the CBAM module are not specific layers corresponding to YOLOv8. The two fully connected layers of the CBAM module are designed for the CBAM module itself, not for specific layers. The two fully connected layers in the channel attention submodule of the CBAM module are used to reduce the dimension of the feature map after global average pooling and obtain the channel attention weights. The two fully connected layers may have different numbers of neurons, and the specific design and parameters depend on the requirements of the model and the characteristics of the training data.

[0067] Therefore, the CBAM attention module can be added after each convolutional block of YOLOv8, but the two fully connected layers of the channel attention submodule do not directly correspond to the specific layers of YOLOv8. They are used as part of the CBAM module to learn the channel attention weights. Similarly, the two fully connected layers in the spatial attention submodule are also independent layers of the YOLOv8 model.

[0068] The CBAM attention mechanism can be operated through the following steps:

[0069] 1. Define CBAM module: Define a CBAM module, which will be applied to each convolutional block of the YOLOv8 model. The CBAM module consists of two sub-modules: channel attention sub-module and spatial attention sub-module.

[0070] 2. Channel attention submodule: The channel attention module is used to learn the channel correlation weights of the feature map. The operation of the channel attention submodule includes the following steps:

[0071] Perform global average pooling on the feature map to reduce its dimension into a weight vector;

[0072] The weight vector is fed into two fully connected layers to learn the channel attention weights;

[0073] The attention weights are processed using the Sigmoid activation function to ensure that the weights are positive;

[0074] These channel attention weights are applied to each channel in the feature map to generate a weighted feature map.

[0075] 3. Spatial attention submodule: The spatial attention module is used to learn the spatial position weights of the feature map. The operation of the spatial attention submodule includes the following steps:

[0076] The feature map is compressed through a convolutional layer to extract spatial information;

[0077] The compressed feature map is globally averaged and pooled, and then passed into two fully connected layers to learn the spatial attention weights; the two fully connected layers are the fully connected layers in the channel attention submodule. The above function is to process the feature vector after global average pooling to obtain the spatial attention weights. The two fully connected layers may have different numbers of neurons, and the specific design and parameters depend on the requirements of the model and the characteristics of the training data; through these two fully connected layers, the spatial attention submodule will generate spatial attention weights, which will be multiplied with the original feature map to perform feature fusion and extraction in the form of weighted feature representation.

[0078] Process the spatial attention weights and use the Sigmoid activation function to ensure that the weights are positive;

[0079] These spatial attention weights are applied to the compressed feature maps to generate weighted feature maps.

[0080] The convolutional layers in the spatial attention submodule are used to compress the feature map to extract spatial information, and the compressed feature map is multiplied with the original feature map in the last step to apply the spatial attention weights.

[0081] Specifically: The convolutional layer in the spatial attention submodule is used to reduce the number of channels in the feature map, thereby extracting a more compact feature representation. This compressed feature map will be element-wise multiplied with the original feature map to obtain a weighted feature representation.

[0082] Therefore, in the spatial attention submodule, the convolutional layer is applied at the last step, that is, in the step of fusing the compressed feature map with the original feature map. In this way, through the element-wise multiplication operation, the spatial attention weights will be applied to the spatial dimensions of the feature map, making the model pay more attention to the region of interest.

[0083] 4. Add CBAM module to YOLOv8 model: Apply the defined CBAM module to each convolution block of the YOLOv8 model, adding the CBAM module after each convolution layer.

[0084] The design of online data enhancement module includes: Online data enhancement refers to the real-time data enhancement operation for each training sample during the model training process. Data enhancement can change the appearance, size, rotation, translation, scaling and other attributes of the training samples, thereby increasing the diversity of the training samples. By increasing the number and diversity of training samples, the model can better learn the characteristics and patterns of the data, improving the performance and generalization ability of the model.

[0085] Data augmentation operations include:

[0086] Random rotation: Randomly rotate the image at a certain angle to simulate maturity detection at different angles.

[0087] Random translation: Randomly translate the image by a certain distance to simulate maturity detection in different positions.

[0088] Random Scaling: Randomly scale the image size to simulate maturity detection at different distances.

[0089] Random Crop: Randomly crop a portion of the image to simulate maturity detection in different areas.

[0090] Contrast and Brightness Adjustment: Randomly adjust the contrast and brightness of the image to simulate ripeness detection under different lighting conditions.

[0091] Random Flip: Randomly flip the image horizontally or vertically to simulate mirror images and asymmetric shapes for maturity detection.

[0092] Data augmentation during training In each training batch, the online data augmentation module is used to perform a series of random augmentation operations on the input images. This allows different augmentation samples to be used in each training, increasing the diversity of the data and improving the accuracy of the model in detecting the ripeness of strawberries in various situations.

[0093] A spatial pyramid pooling module is added after the extraction layer to extract multi-scale features.

[0094] Spatial pyramid pooling is a method for extracting multi-scale features. It divides the input image into multiple regions of different sizes and performs a pooling operation on each region to obtain features with different scales and context information.

[0095] The spatial pyramid pooling module divides the input feature map into sub-regions of different scales and performs a pooling operation on each sub-region to extract multi-scale features. This helps the model detect objects of different sizes. Similarly, the spatial pyramid pooling module can be applied to each layer of YOLOv8 in a similar way.

[0096] 1. Modify the network structure: Modify the network structure of YOLOv8 In the network structure of YOLOv8, find the extraction layer, which is responsible for feature extraction. Generally speaking, the extraction layer is located in the early stage of the entire network. According to the network structure of YOLOv8, the size of the extraction layer features is usually large and contains rich semantic information.

[0097] 2. Add a spatial pyramid pooling module: After the extraction layer, add a spatial pyramid pooling module. This module can perform pooling operations on the extracted features based on different scales to generate features of multiple scales. Specifically, the features of the extraction layer can be input into multiple branches, and each branch uses convolution kernels or pooling kernels of different sizes to perform pooling operations to generate features of corresponding scales. These features are then combined according to certain rules to obtain multi-scale feature representations.

[0098] 3. Adjust the structure of subsequent layers: After adding the spatial pyramid pooling module, the structure of subsequent layers needs to be adjusted accordingly to adapt to the new feature size. This may involve adjusting the convolution kernel size, step size and other parameters of the next layer to ensure matching between features.

[0099] S4. Train and evaluate the improved YOLOv8 model: Build an improved YOLOv8 network and use the data set to train the improved YOLOv8 model to obtain a strawberry maturity detection model. Then, use the cross-validation method to evaluate the model performance using the validation set after each training cycle, and adjust the model parameters according to the evaluation results to achieve the best model performance.

[0100] During the training process, IOU_Loss is the ratio of the intersection between the predicted box and the true box to the union between the predicted box and the true box. This loss has certain problems: if the predicted box has no intersection with the true box, IoU = 0, and the distance between the two boxes cannot be reflected. In other words, IOU_Loss cannot optimize the situation where the two boxes do not intersect. In response to the above problems, GIOU_Loss was introduced, and the intersection scale was increased, that is, the minimum enclosing rectangle and the difference between the enclosing rectangle and the union were introduced. However, this method cannot completely solve this problem, and there are still other problems. If the predicted box and the true box intersect, GIOU becomes IOU, and the relative position relationship between the two boxes cannot be distinguished. In response to the problems of IOU_Loss and GIOU_Loss, DIOU_Loss was generated. DIOU_Loss takes into account the overlapping area and center point distance between the predicted box and the true box. When the true box wraps the predicted box, the distance between the two boxes can be directly measured, so that the convergence speed of DIOU_Loss is faster. CIOU_Loss adds an influencing factor based on DIOU_Loss, taking into account the aspect ratio between the predicted box and the real box, that is, CIOU_Loss takes into account the overlapping area, center point distance and aspect ratio of the real box, which significantly improves the AP value. Therefore, this paper uses the loss function of CIOU_Loss to improve the convergence speed of the model. The specific calculation method is shown in the following formula:

[0101]

[0102] Among them, CIOU Loss represents the complete intersection-over-union loss, CIOU represents the complete intersection-over-union ratio, ρ represents the Euclidean distance between two rectangular boxes, c is used to prevent the value of the loss function from being too large and to improve the convergence speed, b represents the center point of the prediction box, and b gt Represents the center point of the real box, v is used to measure the consistency of the aspect ratio and is defined as follows:

[0103]

[0104] Among them, w gt Indicates the width of the real box, h gt represents the height of the real box, w represents the width of the predicted box, h represents the height of the predicted box, π is the circumference, and α represents the weight coefficient, which is defined as follows:

[0105]

[0106] Among them, IOU means intersection over union.

[0107] From the intersection-over-union ratio, we can get the distance between the predicted box and the real box, which indirectly reflects the effect of the algorithm detection. However, as a loss function, it has the following disadvantages: if there is no intersection between the two boxes, the IoU of the loss function is 0, which cannot fully reflect the degree of overlap between the two; at the same time, when IoU = 0, IoU_Loss = 1-IoU = 1, there is no gradient backpropagation, which will cause the algorithm to be unable to continue learning and training, so CIo U_Loss is used in the bounding box regression loss function of YOLOv8. The EIOU penalty item is based on the CIOU penalty item, which decomposes the influencing factors of the aspect ratio so that it can calculate the length and width of the target box and the anchor box separately. The overlap loss and center distance loss of this loss function are still calculated in the same way as in CIOU, but the width and height loss will minimize the difference in width and height between the target box and the anchor box, thereby accelerating convergence. The EIOU penalty item formula is shown below:

[0108]

[0109] Among them, L EIOU represents the extended intersection-over-union loss, L IOU represents the intersection-over-union loss, L dis Represents the distance loss, L asp represents the aspect ratio loss, C w 2 represents the width variance, C h 2 Represents the height variance.

[0110] S5. Real-time detection of strawberry maturity: The model is deployed on the hardware, real-time strawberry video stream is collected, and the improved YOLOv8 algorithm is used to detect the strawberry maturity in real time and return the result to the front end. The detection result is as follows: Figure 2 shown.

[0111] Example 2

[0112] The present invention also provides a strawberry maturity detection system based on improved YOLOv8, comprising:

[0113] An acquisition unit, used for acquiring the strawberry image to be detected;

[0114] The detection unit is used to identify the maturity of the strawberry image to be detected based on the improved YOLOv8 model to obtain the strawberry maturity detection result; wherein the improved YOLOv8 model is trained through a training set, and the training set data is a set of strawberry images with maturity marked.

[0115] The above are only preferred specific implementations of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A strawberry maturity detection method based on improved YOLOv8, It is characterized in that include: Collect the strawberry image to be detected; Based on the improved YOLOv8 model, the strawberry image to be detected is subjected to maturity recognition to obtain a strawberry maturity detection result; Wherein, the improved YOLOv8 model is trained through a training set, and the training set data is a set of strawberry images with maturity marked; The improved YOLOv8 model includes: a CBAM module and a spatial pyramid pooling module; The CBAM module includes: a first CBAM module and a second CBAM module; the first CBAM module and the second CBAM module are added to the first CBS layer and the second CBS layer of the Neck network respectively; the spatial pyramid pooling module includes: a first spatial pyramid pooling module, a second spatial pyramid pooling module, and a third spatial pyramid pooling module; the first spatial pyramid pooling module, the second spatial pyramid pooling module, and the third spatial pyramid pooling module are located in the Head network; the C2f module located between the first CBS layer and the second CBS layer of the Neck network is connected to the first spatial pyramid pooling module; the C2f module located after the second CBS layer of the Neck network is connected to the second spatial pyramid pooling module; the remaining C2f modules in the Neck network are connected to the third spatial pyramid pooling module; The CBAM module includes: a channel attention submodule and a spatial attention submodule; The output end of the channel attention submodule is connected to the input end of the spatial attention submodule; The channel attention submodule includes: Performing global average pooling on the feature map to reduce the dimension of the feature map into a weight vector; Input the weight vector into two fully connected layers to obtain channel attention weights; The attention weight is processed by using an activation function, and the processed channel attention weight is applied to each channel in the feature map to obtain a weighted feature map; The spatial attention submodule includes: Compress the feature map through a convolutional layer, perform global average pooling on the compressed feature map, and input the feature map after average pooling into two fully connected layers to obtain spatial attention weights; Processing the spatial attention weights using an activation function, applying the processed spatial attention weights to the compressed feature map, and obtaining a weighted feature map; The spatial pyramid pooling module includes: Inputting the features of the Neck layer into a preset number of branches, performing pooling processing on the features in the branches through the spatial pyramid pooling module to obtain scale features; The scale features are combined to obtain multi-scale features.

2. A strawberry maturity detection method based on improved YOLOv8 according to claim 1, It is characterized in that Before labeling the training set data, the method further includes: collecting original strawberry image data, and preprocessing the original strawberry image data includes: The original strawberry image is subjected to denoising processing, and the denoised strawberry image is subjected to unified processing to obtain strawberry image data.

3. A strawberry maturity detection method based on improved YOLOv8 according to claim 1, It is characterized in that The maturity annotation of the strawberry image set includes: Maturity and immaturity.

4. A strawberry maturity detection system based on improved YOLOv8, It is characterized in that include: An acquisition unit, used for acquiring the strawberry image to be detected; A detection unit is used to identify the maturity of the strawberry image to be detected based on an improved YOLOv8 model to obtain a strawberry maturity detection result; wherein the improved YOLOv8 model is trained through a training set, and the training set data is a set of strawberry images with maturity marked; The improved YOLOv8 model includes: a CBAM module and a spatial pyramid pooling module; The CBAM module includes: a first CBAM module and a second CBAM module; the first CBAM module and the second CBAM module are added to the first CBS layer and the second CBS layer of the Neck network respectively; the spatial pyramid pooling module includes: a first spatial pyramid pooling module, a second spatial pyramid pooling module, and a third spatial pyramid pooling module; the first spatial pyramid pooling module, the second spatial pyramid pooling module, and the third spatial pyramid pooling module are located in the Head network; the C2f module located between the first CBS layer and the second CBS layer of the Neck network is connected to the first spatial pyramid pooling module; the C2f module located after the second CBS layer of the Neck network is connected to the second spatial pyramid pooling module; the remaining C2f modules in the Neck network are connected to the third spatial pyramid pooling module; The CBAM module includes: a channel attention submodule and a spatial attention submodule; The output end of the channel attention submodule is connected to the input end of the spatial attention submodule; The channel attention submodule includes: Performing global average pooling on the feature map to reduce the dimension of the feature map into a weight vector; Input the weight vector into two fully connected layers to obtain channel attention weights; The attention weight is processed by using an activation function, and the processed channel attention weight is applied to each channel in the feature map to obtain a weighted feature map; The spatial attention submodule includes: Compress the feature map through a convolutional layer, perform global average pooling on the compressed feature map, and input the feature map after average pooling into two fully connected layers to obtain spatial attention weights; Processing the spatial attention weights using an activation function, applying the processed spatial attention weights to the compressed feature map, and obtaining a weighted feature map; The spatial pyramid pooling module includes: Inputting the features of the Neck layer into a preset number of branches, performing pooling processing on the features in the branches through the spatial pyramid pooling module to obtain scale features; The scale features are combined to obtain multi-scale features.

Citation Information

Patent Citations

  • Strawberry maturity detection method and device based on YOLO V3

    CN114724140A

  • Strawberry disease and pest detection method and system based on AM-YOLOX

    CN115631462A

  • Infrared image target identification method and system for power transmission and transformation equipment

    CN116681885A

  • Lightweight target detection method and system based on YOLOv8 improvement

    CN116740538A

Cited By

  • Strawberry maturity detection method and system based on improved YOLO11

    CN120411623A