Improved YOLOv8n-based grape cluster young fruit lightweight detection method
By improving the YOLOV8N model, the lightweight module and the loss function are used to solve the problem of low detection accuracy of grape clusters and high model complexity, achieve efficient, accurate and real -time detection effects, and meet the needs of the agricultural automation management system. Essence
Patent Information
- Application Number
- CN202411398929.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-09
- Publication Date
- 2025-01-21
AI Technical Summary
In the prior art, the detection accuracy of grape cluster young fruits is not high, the model is complex, the calculation amount is high, and the real-time performance is poor, making it difficult to adapt to agricultural scenarios with high requirements for lightweight and real-time performance.
By improving the YOLOV8N model, the C2F-FASTER module is used instead of the original C2F module, using depth to separate convolution, introduces the context anchor attention module, and uses the Wise-Iuu loss function to significantly reduce the computing complexity and number of parameters of the model to increase the number of models, increase the number of parameters of the model, increase the number of parameters, and increase the number of parameters. Detection accuracy and real -time.
It achieves efficient, accurate and real-time detection of grape cluster young fruits, meets the needs of agricultural automation management systems, and improves the accuracy of detection and the lightweight performance of the model.
Smart Images

Figure CN119339367A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer vision and agricultural automation, and in particular to a method for detecting lightweight young fruits of a grape cluster based on improved YOLOv8n. Background Art
[0002] In the process of grape cultivation, testing the young fruits in the grape clusters and screening out low-quality fruits can effectively reduce the nutrient consumption of the grapevines, thereby improving the yield and quality of the grapes. This process is a key link in grape growth management. However, the traditional manual fruit thinning method is difficult to meet the needs of large-scale planting due to its high labor intensity, low efficiency, high cost, and easy to miss the best fruit thinning time. Therefore, automated and intelligent grape young fruit detection and management systems have become an inevitable development trend. Such systems can not only improve the efficiency and accuracy of detection, but also have important significance for the application of intelligent fruit thinning machinery and the improvement of fruit quality. At the same time, they also help to estimate the yield in the early stages of grape growth.
[0003] With the development of artificial intelligence and computer vision technology, convolutional neural networks (CNNs) have been widely used in the field of target detection and have shown good results in grape cluster detection. CNNs can effectively extract features such as posture, color, and illumination of objects and adapt to the complex changes in the grape growing environment. However, most existing studies focus on the detection of grapes in the ripening period. Although the models used have high detection accuracy, they are usually accompanied by increased model complexity and computing resource consumption. This poses a challenge to practical applications, especially agricultural scenarios with high requirements for lightweight and real-time performance.
[0004] For grape detection tasks in natural environments, factors such as occlusion by branches and leaves, overlapping grape fruits, and changes in illumination will affect the detection accuracy, resulting in some targets not being accurately identified. In addition, green ripe grapes are similar in color to leaves, making them more difficult to detect, especially in complex outdoor environments, where they are easily disturbed by illumination and shadows. This results in low recognition accuracy in existing target detection methods when detecting young grape clusters.
[0005] Grape clusters in the young fruit stage are small, irregular in shape, and highly similar in color to the surrounding leaves, which increases the difficulty of detection. In the prior art, although some detection methods have made certain progress by improving the neural network model, while improving the detection accuracy, they often increase the complexity and computational complexity of the model, which is not suitable for scenarios with limited resources. In addition, the existing methods mostly focus on the detection of mature grapes, and there is relatively little research on the detection of young fruits, which affects the improvement of the level of automated management of grape fruit thinning.
[0006] In order to meet this challenge, it is particularly necessary to develop a lightweight target detection method. This method should significantly reduce the computational complexity and number of parameters of the model while ensuring detection accuracy, so as to achieve real-time detection of young fruits in grape clusters. This is of great significance for improving the efficiency of grape growth management and the performance of intelligent fruit thinning systems. Summary of the invention
[0007] In view of the shortcomings of the prior art, the present invention provides a lightweight detection method for young fruit in grape clusters based on improved YOLOv8n, which solves the problems of low accuracy in detection of young fruit in grape clusters, large model complexity, high computational complexity, and poor real-time performance in the prior art.
[0008] To achieve the above objectives, the present invention is implemented by the following technical scheme: a method for detecting lightweight young fruits in grape clusters based on improved YOLOv8n, comprising the following steps:
[0009] Acquire image data containing young fruits of a grape cluster, wherein the image data includes young fruits of a grape cluster under different lighting conditions and shielding degrees;
[0010] Label and process the image data to generate a grape cluster young fruit dataset;
[0011] Improvements are made based on the YOLOv8n model, including:
[0012] The C2f-Faster module is used to replace the original C2f module to reduce the amount of floating-point operations and model parameters;
[0013] Use depth-wise separable convolution instead of standard convolution to further reduce model complexity;
[0014] Introducing a contextual anchor attention module into the neck network of the model to enhance the ability to extract long-distance context information;
[0015] The Wise-IoU loss function is used instead of the CIoU loss function to improve the generalization ability of the model;
[0016] Train and optimize the improved YOLOv8n model, use the grape cluster young fruit dataset to train the model, and improve the robustness of the model through data enhancement;
[0017] Use the trained model to perform real-time detection of young fruits in grape clusters and output the detection results.
[0018] Preferably, the acquisition of the image data includes:
[0019] Select a grapevine and use the device to shoot from a distance of 60 to 80 cm.
[0020] Consider both front light and back light lighting conditions when shooting;
[0021] The collected images include images of various resolutions.
[0022] Preferably, the step of labeling and processing the image data includes: scaling the resolution of the image data between 20% and 90%, manually labeling the grape cluster fruitlets using a labeling tool, and forming a grape cluster fruitlet data set containing different occlusion degrees and lighting conditions.
[0023] Preferably, the step of improving the robustness of the model through data enhancement includes: performing data enhancement processing on the training data set, and the data enhancement method includes random cropping, flipping, rotation and brightness adjustment to simulate different scene changes and enhance the robustness of the model.
[0024] Preferably, the C2f-Faster module consists of a local convolution PConv and two 1×1 convolution layers to form a reverse residual block, and a batch normalization layer and an activation layer are located after the intermediate layer. The PConv performs spatial feature extraction only on some input channels, and the remaining channels remain unchanged, thereby reducing redundant calculations and memory accesses, reducing the computational complexity of the model and improving the inference speed.
[0025] Preferably, the depthwise separable convolution consists of two parts: depthwise convolution DWConv and pointwise convolution PWConv. The depthwise convolution is used to extract spatial features, and the pointwise convolution is used to extract channel features, which reduces the number of parameters and the amount of calculation of the model while maintaining the model performance.
[0026] Preferably, the contextual anchor attention module comprises the following steps:
[0027] Perform average pooling and 1×1 convolution operations on the input feature map to obtain local area features;
[0028] Capture long-range context information in the horizontal direction through 1×K depth convolution;
[0029] Capture long-range contextual information in the vertical direction through K×1 depth convolution;
[0030] A feature map containing contextual information is generated through 1×1 convolution and Sigmoid function, which enhances the model's ability to model long-distance dependencies.
[0031] Preferably, the Wise-IoU loss function introduces a distance attention mechanism, which weakens the penalty for geometric metrics such as distance and aspect ratio when the predicted box and the true box overlap well, reduces the impact of low-quality samples on model training, and improves the generalization ability of the model.
[0032] Preferably, the optimization method used in the model training process is an optimization algorithm based on a dynamic non-monotonic focusing mechanism, which accelerates the convergence of the model and improves detection accuracy.
[0033] The present invention also provides a lightweight detection device for young fruits in a grape cluster based on improved YOLOv8n, comprising:
[0034] A data acquisition unit, used for acquiring images of young fruits in a grape cluster;
[0035] A data processing unit, used for marking and processing the image;
[0036] A detection unit, which performs detection based on an improved YOLOv8n model, wherein the model includes a C2f-Faster module, a depthwise separable convolution, a contextual anchor attention module, and a Wise-IoU loss function;
[0037] The output unit is used to output the detection result of the young fruits in the grape cluster.
[0038] The present invention provides a method for detecting lightweight young fruits of a grape cluster based on improved YOLOv8n.
[0039] It has the following beneficial effects:
[0040] 1. By introducing the contextual anchor attention module (CAA), the present invention enhances the model's ability to capture long-distance contextual information and improves the detection accuracy of young grape clusters in complex backgrounds similar to the surrounding environment. At the same time, the Wise-IoU loss function is used instead of CIoU, which effectively reduces the negative impact of low-quality samples on model training and further improves the detection accuracy.
[0041] 2. The present invention uses C2f-Faster module to replace the original C2f module, and introduces deep separable convolution (DSConv) to replace standard convolution, which greatly reduces the floating point operation amount and number of parameters of the model, and significantly reduces the complexity of the model. This enables the model to run efficiently in an environment with limited computing resources, meeting the needs of embedded systems and real-time applications.
[0042] 3. The improved YOLOv8n model of the present invention adopts a lightweight design, which reduces the consumption of computing resources and greatly improves the model reasoning speed. Combined with the lower floating-point operation amount, the model performs well in real-time performance and can run efficiently in real-time detection tasks, meeting the needs of the automatic management system for grape cluster young fruits.
[0043] 4. The present invention designs a data set that adapts to a variety of lighting conditions and occlusion situations. Combined with the improved model structure, the model can effectively handle the complex natural environment in the wild vineyard, including challenging factors such as light changes, leaf occlusion, and fruit overlap, making the detection of young fruits in grape clusters more accurate and reliable. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 It is a schematic diagram of the method flow of the present invention;
[0045] Figure 2 This is an example of a grape cluster young fruit image dataset of the present invention, wherein: (a) Backlight, (b) Frontlight, (c) Obscured by grapes, (d) Obscured by leaves, (e) Mild occlusion, (f) Heavy occlusion;
[0046] Figure 3 It is a schematic diagram of the structure of the improved YOLOv8n network model of the present invention;
[0047] Figure 4 Schematic diagram of the C2f-Faster module and its components of the present invention, wherein: (a) PConv, (b) FasterNetBlock, (c) C2f-Faster;
[0048] Figure 5 Schematic diagram of the depth-wise separable convolution structure of the present invention;
[0049] Figure 6 It is a schematic diagram of the CAA module structure of the present invention;
[0050] Figure 7 Schematic diagram of heat map comparison of the present invention, where (a) original image, (b) YOLOv8n, (c) improved YOLOv8;
[0051] Figure 8 The detection effect diagrams of the present invention under different complex scenes, including (a) Mild occlusion, (b) Heavy occlusion, (c) Backlight, (d) Frontlight;
[0052] Fig. 9Schematic diagram of detection results of different models of the present invention, including (a) Faster-RCNN, (b) YOLOv5n, (c) YOLOv5s, (d) YOLOv6n, (e) YOLOv7-tiny, (f) YOLOv8n, (g) YOLO v9, (h) ImprovedYOLOv8n (our), (i) YOLOv8n CM;
[0053] Fig.10 It is a schematic diagram of the device structure of the present invention.
[0054] Among them, 10, data acquisition unit; 20, data processing unit; 30, detection unit; 40, output unit. DETAILED DESCRIPTION
[0055] The following will be combined with the drawings in the specification of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0056] Please see attached Figure 1 -Attached Fig. 9 The present invention provides a lightweight detection method for grape cluster young fruits based on improved YOLOv8n, aiming to solve the problems of low accuracy, large model complexity, and poor real-time performance in the prior art. By improving the YOLOv8n model, an efficient and lightweight detection method is proposed, which can accurately detect grape cluster young fruits in complex natural environments.
[0057] The method of the present invention is described in detail below in conjunction with specific implementation steps.
[0058] S1. Obtaining image data containing grape cluster young fruits
[0059] In this step, image data of young grape fruits in clusters under different lighting conditions and shading degrees are obtained to construct a grape fruit cluster dataset with diversity and complexity.
[0060] 1. Collection location and objects: A vineyard in Qufu City, Shandong Province, China was selected. The grape variety was Kyoho and the area was 18 acres.
[0061] 2. Collection time: During the critical period of the young fruit stage of grapes, choose 7:20-10:30 in the morning and 14:30-18:00 in the afternoon from May 22 to May 23, 2022, when the weather is clear.
[0062] 3. Collection equipment: A variety of devices were used for shooting, including Huawei (YAL-AL00, BMH-AN10, JEF-AN00), OPPO (Find X2 Pro, Reno6 Pro 5G), VIVO S7, OnePlus KB2000, Xiaomi M2012K10C and other smartphones. Using a variety of devices can improve the adaptability of the dataset to different cameras and image quality.
[0063] 4. Shooting method: The collectors stood 60-80 cm away from the grapevines and took photos with handheld devices. Taking into account the impact of light on image quality, the photos were taken under direct light and backlight conditions.
[0064] 5. Image features: The resolution of the collected images ranges from 2448×3264 to 4624×3472 pixels, covering different lighting conditions, occlusion levels, and overlaps, making the dataset rich in diversity.
[0065] There are differences in shooting light and different degrees of occlusion and overlap during image acquisition. Some images of young grape clusters are Figure 2 . Figure 2 (a) is an image collected under backlighting. In the image, the young grapes become whitish under the influence of light and lose their original color characteristics. Figure 2 (b) is an image collected under direct light. The young grapes in the shadow in the image become darker and also lose their original color characteristics. Figure 2 In (c), two bunches of grapes overlap significantly. Figure 2 In (d) and (f), many young grapes are severely blocked by leaves. The above-mentioned light differences and different occlusion and overlap situations make the collected grape clusters present different colors, shapes and textures, making the grape cluster feature information more complex, increasing the difficulty of detection and posing greater challenges to the detection network. At the same time, the differences in these natural scenes reflect the complexity and diversity of the dataset, and can also better verify the robustness of the detection algorithm.
[0066] Through the above method, a large amount of image data containing young grape fruits was obtained, providing sufficient sample support for subsequent data processing and model training.
[0067] S2. Label and process the image data to generate a grape cluster young fruit dataset
[0068] In this step, the collected image data is preprocessed, labeled, and divided to generate a grape cluster young fruit dataset for model training and testing.
[0069] 1. Data screening and processing:
[0070] Perform a preliminary screening of the collected images to eliminate blurry, unclear or non-compliant images.
[0071] The images were renamed and their resolution was scaled from 20% to 90% to increase the diversity of the dataset.
[0072] 2. Data annotation:
[0073] Use labeling tools such as LabelImg to manually label the young grape fruits in the image and draw bounding boxes.
[0074] Different degrees of occlusion are taken into account during annotation, and the occlusion degrees are divided into no occlusion, slight occlusion (the occlusion area is less than 50%), and severe occlusion (the occlusion area is greater than 50% or the overlap of multiple bunches of grapes exceeds 30%).
[0075] Record the lighting conditions (front light or back light) and degree of occlusion of the image to facilitate subsequent model analysis.
[0076] 3. Dataset division:
[0077] The processed and annotated dataset is divided into training set, validation set and test set, with proportions of 70%, 10% and 20% respectively.
[0078] Ensure that the images in each dataset are representative in terms of lighting conditions, occlusion levels, and overlaps to avoid data distribution bias.
[0079] In this embodiment, basic information of the grape cluster young fruit dataset GGrape is shown in Table 1.
[0080] Table 1 Basic information of GGrapet dataset
[0081]
[0082] Note: If more than 50% of the grape clusters are blocked, or multiple grape clusters overlap by more than 30%, it is considered severe occlusion, and the rest is light occlusion.
[0083] The generated grape cluster young fruit dataset contains rich scenes and features, which can effectively improve the generalization ability and robustness of the model.
[0084] S3. Improvements based on the YOLOv8n model
[0085] In this step, the YOLOv8n model is improved in many aspects to improve the detection accuracy of the model, reduce the complexity of the model, and achieve the goal of lightweight.
[0086] The YOLO (You Only Look Once) series is the most commonly used technology in target detection algorithms. Among them, YOLOv8 can combine different feature maps of different scales to learn the color, shape and texture features of objects, which helps to achieve high accuracy in near-field object detection tasks. As the smallest of the five network models of YOLOv8, YOLOv8n has a smaller network depth and feature map, so it is smaller in size and faster in detection.
[0087] The structure of YOLOv8 is similar to that of YOLOv5, consisting of three main parts: backbone, neck, and head. However, corresponding changes have also been made, as follows:
[0088] The C2f structure with richer gradient flow is used to replace C3 in YOLOv5. The C2f module combines high-level features with contextual information to improve detection accuracy.
[0089] The head part adopts a decoupled head structure (Decoupled-Head) to separate the classification and detection heads, and also changes from Anchor-Based to Anchor-Free.
[0090] The task-aligned assigner method of matching positive and negative samples is used for loss calculation, and the distribution focal loss (DFL) calculation is introduced.
[0091] A spatial pyramid pooling fast (SPPF) layer accelerates computation by pooling features into a fixed-size map. After improving from SPP to SPPF, the computational complexity of the model has been greatly reduced and the model speed has been improved.
[0092] The accuracy and lightness of the young fruit detection model of grape clusters are the key to improving the efficiency of fruit thinning machinery. In order to improve the accuracy of the young fruit detection model of close-up grape clusters and reduce the complexity of the model, the present invention improves the YOLOv8 model, such as Figure 3 shown.
[0093] 1. Use C2f-Faster module to replace the original C2f module
[0094] The present invention reduces the amount of calculation and the number of parameters of the model by introducing the C2f-Faster module based on the design of partial convolution (PConv) and FasterNet Block.
[0095] As the number of model network layers continues to increase, the number of channels is also increasing. The feature maps of different channels have highly similar information, which will cause feature map redundancy. To address this problem, partial convolution (PConv) only convolves part of the input channel c. p The spatial feature extraction is performed on the other channels, and the other channels remain unchanged. The PConv structure is as follows Figure 4 As shown in (a). Assuming the number of channels is c, the FLOPs of PConv is only:
[0096]
[0097] When the ratio r = c p When / c=1 / 4, the FLOPs of PConv is only 1 / 16 of that of ordinary convolution. In addition, PConv has a smaller memory access, namely:
[0098]
[0099] It is about 1 / 4 of the ordinary convolution. PConv can extract spatial features more efficiently by reducing redundant calculations and memory accesses at the same time.
[0100] FasterNet Block, designed based on PConv, achieves higher running speed while ensuring the accuracy of various device visual tasks. Each FasterNet Block consists of a PConv and two 1×1Conv layers as reverse residual blocks. The batch normalization BN (Batch Normalization) layer and activation layer are placed after the middle layer to maintain feature diversity and achieve lower latency. The FasterNet Block structure is shown in the figure below. Figure 4 (b) shows that the Bottleneck in the C2f module is replaced by FasterNet Block to obtain the C2f-Faster module, which can effectively reduce the number of floating-point operations and parameters, improve the inference speed, and thus reduce the complexity of the model. The C2f-Faster module structure is shown in Figure 4 (c) as shown.
[0101] 2. Use depth-wise separable convolution instead of standard convolution
[0102] DSConv (Depthwise Separable Convolution) is a lightweight convolution operation method that can reduce the number of model parameters and the amount of calculation while maintaining performance. DSConv consists of two parts: depthwise convolution (DWConv) and pointwise convolution (PWConv). Depthwise convolution is used to extract spatial features, while pointwise convolution is used to extract channel features. The structure of DSConv is shown in the figure below. Figure 5 shown.
[0103] In the deep convolution stage, each input channel is convolved with a separate filter to obtain an output feature map with the same number of channels as the input feature map. In the point-by-point convolution stage, a 1×1 convolution operation is performed on the feature map, which is responsible for cross-channel information fusion. The 1×1 convolution is applied to integrate the information of each channel and generate the final output feature map.
[0104] Specifically, if F∈R M×DF×DF is the input feature map, G∈R N×DG×DG is the output feature map, where DF is the spatial width and height of the input feature map, M is the number of input channels, DG is the spatial width and height of the output feature map, N is the number of output channels, the depthwise convolution uses M convolution kernels of size DK×DK, and the point-by-point convolution uses N 1×1 convolution kernels, with a parameter number of P DS , the computational effort is FLOPs DS , the calculation formulas are:
[0105] P DS =DK 2 ×M+M×N
[0106] FLOPs DS =DK 2 ×M×DF 2 +M×N×DF 2
[0107] If the number of parameters processed by standard convolution is P Conv , the computational effort is FLOPs Conv , the calculation formulas are:
[0108] P Conv =DK 2 ×M×N
[0109] FLOPS Conv =DK 2 ×M×N×DF 2
[0110] From the above, we can see that using DSConv to replace standard convolution in the YOLOv8n model can reduce the amount of calculation and improve calculation efficiency.
[0111] 3. Introducing the CAA attention module into the neck network of the model
[0112] Since the young fruits of grape clusters are similar in color to the surrounding environment, the detection difficulty is increased. The accurate detection of young fruits of grape clusters depends not only on their appearance features, but also on contextual information, that is, the surrounding environment of the grape clusters.
[0113] CAA is an attention module used to capture long-range contextual information, aiming to grasp the contextual interdependencies between long-range pixels while enhancing central features. Figure 6 shown.
[0114] For any given input feature map First, average pooling and a 1×1 convolution are used to obtain local area features:
[0115] F pool =Conv 1×1 (p avg (F)
[0116] In the formula, p avg represents an average pooling operation, and then two depthwise convolutions are used as an approximation of the standard large kernel depthwise convolution:
[0117] F w =DWConv 1×k (F pool )
[0118] F h =DWConv k×1 (F w )
[0119] In the formula, DWConv 1×k and DWConv k×1 They represent depthwise convolutions with a width of 1×K and a height of K×1, respectively, which are used to capture long-range contextual information.
[0120] Finally, a 1×1 convolution and Sigmoid function are used to generate a feature map G containing context information with the same dimension as the input feature map.
[0121] G = Sigmoid (Conv 1×1 (F h ))
[0122] In summary, the CAA module can enhance the model's ability to model long-distance dependencies. By adding the CAA attention module to the YOLOv8n model, the performance of near-field object detection can be improved.
[0123] 4. Use Wise-IoU loss function instead of CIoU loss function
[0124] The YOLOv8 model uses CIoU as the bounding box regression loss function (Bounding Box RegressionLoss). CIoU takes into account the losses in three dimensions: overlapping area, center distance, and aspect ratio between the predicted box and the true box. However, since the aspect ratio describes a relative value rather than the true difference value, when the aspect ratio of the predicted box is equal to that of the true box, the CIoU aspect ratio penalty term will become invalid. At the same time, CIoU does not consider the balance between high- and low-quality samples. When the target detection training set contains low-quality examples, the model detection performance will be reduced.
[0125] Wise-IoU is a bounding box regression loss function based on a dynamic focus mechanism. Compared with CIoU, Wise-IoU does not introduce the calculation of the aspect ratio, but builds distance attention based on the distance metric, and obtains the Wise-IoU v1 loss function with a two-layer attention mechanism. When the anchor box and the target box overlap well, the penalty of geometric metrics such as distance and aspect ratio is weakened, without intervening too much in training, so that the model has better generalization ability. The loss function formula is as follows:
[0126] L WIoUv1 =R WIoU L IoU
[0127] Where, L IoU is the bounding box loss IoU, R WIoU is the distance attention, and the calculation formula is as follows:
[0128]
[0129] In the formula, (x,y) and (x gt ,y gt ) are the center coordinates of the predicted box and the real box respectively, and is the width and height of the real box.
[0130] When the predicted box and the true box overlap well, the distance attention term tends to 1, weakening the penalty for distance and aspect ratio. At the same time, it has little impact on low-quality samples, avoiding excessive penalty and improving the generalization ability of the model.
[0131] S4. Train and optimize the improved YOLOv8n model
[0132] In this step, the constructed grape cluster young fruit dataset is used to train the improved YOLOv8n model, and the robustness and detection accuracy of the model are improved through data enhancement and optimization strategies.
[0133] 1. Model training configuration:
[0134] Loss function: The improved Wise-IoU loss function is used for bounding box regression.
[0135] Optimization algorithm: Use an optimization algorithm based on a dynamic non-monotonic focusing mechanism to accelerate model convergence.
[0136] Hyperparameter setting: Set the appropriate learning rate, batch size, and number of training rounds according to the characteristics of the dataset and model.
[0137] 2. Data Augmentation:
[0138] Method: The training dataset is randomly cropped, flipped, rotated, and brightness adjusted to simulate different scene changes.
[0139] Purpose: To increase the diversity of data, improve the adaptability of the model to different environments, and enhance the robustness of the model.
[0140] 3. Model training:
[0141] Process: Use the training set to train the model and monitor the loss function and the detection indicators of the validation set in real time.
[0142] Validation: Use the validation set to evaluate the performance of the model and adjust hyperparameters to prevent overfitting.
[0143] 4. Model optimization:
[0144] Strategy: Based on the training and verification results, further optimize the model structure and parameters to improve detection accuracy and efficiency.
[0145] Save model: Select the best model weights for subsequent testing and application.
[0146] S5. Use the trained model to perform real-time detection of young grape clusters and output the detection results
[0147] In this step, the trained improved YOLOv8n model is used to perform real-time detection of young grape clusters in actual scenes to evaluate the performance of the model.
[0148] 1. Model deployment:
[0149] The trained model is deployed in the target detection system to support real-time image input and result output.
[0150] Ensure the compatibility and stability of the model in the actual operating environment.
[0151] 2. Real-time detection:
[0152] Input: Real-time images of young grape fruits are obtained through camera equipment and input into the model.
[0153] Processing: The model performs a forward pass on the input image and outputs the detection results, including bounding boxes and confidence scores.
[0154] 3. Result output:
[0155] The detection results are visualized on the image, and the locations of the detected young fruits in the grape clusters are marked.
[0156] Record the test results for subsequent analysis and verification.
[0157] 4. Performance evaluation:
[0158] Metrics: Use metrics such as mean average precision (mAP), recall, and detection speed (FPS) to evaluate the performance of the model.
[0159] Effect: Verify the detection accuracy and real-time performance of the model in complex natural environments to ensure that it meets actual application requirements.
[0160] In summary, the present invention significantly reduces the computational complexity and number of parameters of the model by improving the YOLOv8n model, adopts the C2f-Faster module and the depth-separable convolution, and realizes the lightweight of the model; introduces the contextual anchor attention module and the Wise-IoU loss function, enhances the model's ability to extract the features of young fruits in grape clusters and model long-distance dependencies, and improves the detection accuracy under complex backgrounds; combines data enhancement and optimization strategies to improve the robustness of the model and its adaptability to different lighting conditions and occlusion levels; finally realizes the real-time, efficient and accurate detection of young fruits in grape clusters, and meets the requirements of lightweight and high performance of the model in practical applications.
[0161] Test and analysis:
[0162] 1. Experimental configuration:
[0163] The machine configuration used in the experiment is AMD Ryzen 7-5800H CPU, 32GB RAM, 8GB Nvidia GeForceRTX 3070GPU. The PyTorch deep learning framework (Python 3.9, PyTorch1.12.0, Cuda 11.6) was built under the Win10 operating system. The size of the input image is set to 640×640 pixels, the initial learning rate (Lr0) is set to 0.01, the weight decay rate (eight_decay) is set to 0.0005, and the momentum factor (momentum) is set to 0.937. The SGD optimizer is used. After 300 epochs of training, the best weight file obtained is used for model evaluation. The parameter settings are shown in Table 2.
[0164] Table 2 Hyperparameter settings
[0165]
[0166]
[0167] 2. Model Evaluation Metrics
[0168] In order to evaluate the accuracy and lightweight performance of the improved YOLOv8n model, this study uses parameters (Params), floating-point operations per second (FLOPs) and model size (Size) to evaluate the model lightweight and complexity. Params refers to the total number of parameters contained in the trained model, which is used to describe the scale of the model. FLOPs refers to the floating-point calculation amount of the model, which is used to measure the complexity of the model. Size refers to the memory space occupied by the model weights, which is used to describe the size of the model. Precision (P), recall (R), and F1 value are used to evaluate the accuracy of the model. The calculation method is shown in the following formula.
[0169]
[0170] Where TP is the number of grapes correctly identified, FP is the number of grapes misidentified, and FN is the number of grapes not identified.
[0171] 3. Ablation Test
[0172] This paper makes four improvements based on the YOLOv8n model. In the YOLOv8n model, the C2f module is replaced by C2f-Faster, the standard Conv is replaced by DSConv, the CAA attention module is added to the Neck structure, and Wise-IoU is used as the loss function in the Head structure. To verify the effectiveness of various improved modules, each module is integrated separately or multiple modules are combined and improved into the original model through ablation experiments, different improved models are constructed, these models are trained under the same conditions, and the performance of different improved models is evaluated using the same test set. Table 3 shows the ablation test results.
[0173] Table 3 Ablation test results
[0174]
[0175] As shown in Table 3, Experiment 1 is an experiment based on the YOLOv8n benchmark model, and Experiments 2-5 are the above four improvements implemented separately on the benchmark model. Compared with Experiment 1, except for the slightly decreased F1 value of the model obtained in Experiment 2, the F1 values of the models obtained in the other three experiments have all increased. Except for the increase in the Size, Params, and FLOPs values of the model obtained in Experiment 4, the Size, Params, and FLOPs values of the other three experiments have all decreased. Among them, Experiments 3 and 5 achieved good results, but the effect was not obvious. Experiment 6 replaced the C2f module and standard Conv in the original model with the lightweight C2f-Faster module and DSConv on the baseline model. The F1 value, Size, Params and FLOPs values of the obtained model were 90.50%, 3.70MB, 1.73M, and 5.20G, respectively, which were 0.10%, 40.32%, 42.52%, and 35.80% lower than those in Experiment 1. Although the obtained model has obvious advantages in lightweight, it cannot take into account accuracy. In order to balance the model lightweight and accuracy, based on the model obtained in Experiment 6, the CAA attention module was added to the Neck structure (Experiment 7). The F1 value, Size, Params and FLOPs values of the obtained model were 90.99%, 4.10MB, 1.91M, and 5.50G, respectively. The F1 value was improved by 0.44% compared with the baseline model, and the Size, Params and FLOPs values were reduced by 33.87%, 36.54% and 32.10%, respectively. It not only greatly reduced the model complexity, but also slightly improved the model accuracy. On this basis, Wise-IoU was used as the loss function in the Head structure (Experiment 8). The Size, Params and FLOPs values of the obtained model remained unchanged, and the F1 value was further improved to 91.55%, which was 1.06% higher than the baseline model. The model lightweight was achieved while the accuracy was significantly improved.
[0176] From the ablation test results in Table 3, it can be seen that both the C2f-Faster module and DSConv are lightweight. In the original baseline model YOLOv8n, the Size, Params and FLOPs indicators of the model obtained by replacing the C2f module with the C2f-Faster module alone (Test 2) are reduced by 22.58%, 23.59% and 22.22% respectively compared with the baseline model, and the F1 value is reduced by 0.10%. The Size, Params and FLOPs indicators of the model obtained by replacing the standard convolution with DSConv alone are reduced by 17.74%, 18.94% and 14.81% respectively compared with the baseline model. While achieving lightweight, the F1 value of the model is improved by 0.36%. Comparing the two modules, it can be seen that the C2f-Faster module has a higher performance than the DSConv module in terms of lightweight, but a lower performance than the DSConv module in terms of accuracy. Combining these two modules further improves the lightweight level of the model (Test 6). The F1 value, Size, Params, and FLOPs of the obtained model are 90.50%, 3.70MB, 1.73M, and 5.20G, respectively. The Size, Params, and FLOPs values of the model are the smallest among all improved models, which are 40.32%, 42.52%, and 35.80% lower than the baseline model, respectively. The F1 value of the model is only 0.10% lower than that of the baseline model, which is negligible, and has the advantage of high lightweight.
[0177] In order to more intuitively understand the detection effect of the improved YOLOv8n model, the heat map of the improved YOLOv8n model and the baseline YOLOv8n model is compared, as shown in the figure. Figure 7 The intensity of the red hue in the heat map is related to its influence on target positioning, which is given by Figure 7 It can be seen that the improved YOLOv8n model can focus on the location of the grape cluster more accurately than the baseline model, and the boundary between the grape cluster and the background is clearer. This further proves the superiority of the improved model in the detection of young grapes in close-up scenes.
[0178] Furthermore, from the ablation test results in Table 3, it can be seen that when DSConv is replaced alone in the original benchmark model YOLOv8n (Test 3), the CAA attention module is added to the neck structure (Test 4), and WiseIoU is replaced as the loss function (Test 5), the F1 value of the obtained model is 0.36%, 0.28% and 0.25% higher than the benchmark model, respectively, indicating that the three improved modules of DSConv, CAA and WiseIoU can improve the accuracy of the detection model to varying degrees, which is consistent with expectations. In order to further improve the accuracy of the lightweight model (the model obtained in Experiment 6), the CAA attention module (Experiment 7) and the Wise-IoU module (Experiment 8) were successively added to the Neck structure of the model. The resulting model is the improved model proposed in this study, with F1 value, Size, Params and FLOPs values of 91.55%, 4.10MB, 1.91M, and 5.50G, respectively. Compared with the baseline model, the F1 value is increased by 1.06%, and the Size, Params and FLOPs values are reduced by 33.87%, 36.54% and 32.10%, respectively. The proposed improved model significantly reduces the model complexity on the basis of improving the detection accuracy, and is easier to migrate and deploy network models.
[0179] From the comparison between Experiment 1 and Experiment 4, and Experiment 6 and Experiment 7, the use of CAA module has a significant effect on improving the accuracy of the model. The F1 values of Experiment 4 and Experiment 7 are 0.28% and 0.54% higher than those of Experiment 1 and Experiment 6, respectively, which reflects the role of CAA attention module in improving the accuracy of close-up grape clusters, but the Size, Params and FLOPs values of the model have also increased. From the comparison between Experiment 1 and Experiment 5, and Experiment 7 and Experiment 8, the F1 values of Experiment 5 and Experiment 8 are 0.25% and 0.62% higher than those of Experiment 1 and Experiment 7, respectively, indicating that WiseIoU can improve the performance of the detection model without increasing the complexity of the model (the Size, Params and FLOPs values of Experiment 1 and Experiment 5 are the same, and the Size, Params and FLOPs values of Experiment 7 and Experiment 8 are the same). In summary, by adding the CAA attention module to the neck structure of the model and using WiseIoU as the loss function in the Head structure, the accuracy of close-up grape cluster detection in complex scenes can be improved. Figure 8 It is the detection effect of the proposed improved model under different occlusion conditions and different illumination. Figure 8 The young fruits of grape clusters under different occlusion situations and different lighting conditions are accurately detected by the proposed improved model, indicating that the proposed improved model has good accuracy and robustness.
[0180] 4. Performance comparison of different object detection algorithms
[0181] In order to evaluate the performance of the proposed model, the improved YOLOv8n model is compared with other lightweight models, including classic lightweight models such as Faster-RCNN, YOLOv5n, YOLOv5s, YOLOv6n, YOLOv7-tiny, YOLOv8n and YOLOv9. To maintain the fairness of the comparison, all comparison models are trained and tested with the same dataset under the same conditions as the improved YOLOv8n model. The results of the performance test on the test set are shown in Table 4. The test results show that the P, R, F1, Size, Params and FLOPs of the improved YOLOv8n model are 91.70%, 91.40%, 91.55%, 4.10MB, 1.91M and 5.50G respectively. Its P and R values are not the highest among all models, but the F1 value is the highest. The F1 value is improved by 18.74%, 1.12%, 0.89%, 0.89%, 0.55%, 1.06% and 0.62% respectively compared with Faster-RCNN, YOLOv5n, YOLOv5s, YOLOv6n, YOLOv7-tiny, YOLOv8n and YOLOv9 models, which has a significant advantage in accuracy. Its Size value is only higher than that of the YOLOv5n model, and is 96.20%, 71.53%, 58.75%, 66.67%, 33.87%, and 6.82% lower than those of Faster-RCNN, YOLOv5s, YOLOv6n, YOLOv7-tiny, YOLOv8n, and YOLOv9 models, respectively. Its Params value is only higher than that of the YOLOv5n and YOLOv9 models, and is 93.25%, 72.75%, 58.75%, 68.22%, and 36.54% lower than those of Faster-RCNN, YOLOv5s, YOLOv6n, YOLOv7-tiny, and YOLOv8n, respectively. The FLOPs value is only higher than that of the YOLOv5n model, and is 99.39%, 65.19%, 51.50%, 58.33%, 32.10% and 22.54% lower than that of the Faster-RCNN, YOLOv5s, YOLOv6n, YOLOv7-tiny, YOLOv8n and YOLOv9 models, respectively. In summary, the YOLOv5n model has an obvious advantage in lightweight, but the accuracy advantage is not obvious. The improved YOLOv8n model can take into account the requirements of model accuracy and lightweight, and is the model with the best performance among all the compared models.
[0182] In addition, a comparative test was conducted between the improved YOLOv8n model and another YOLOv8n improvement scheme, YOLOv8n CM. The comparison model uses the C2f-Faster module to replace the C2f module, adopts the CA attention mechanism (CoordinateAttention), and uses the EIoU loss function to replace the CIoU loss function. Under the same test conditions, Table 4 shows that the improved YOLOv8n model is superior to the comparison model in terms of indicators such as F1, Params and FLOPs. Specifically, the F1 value of the improved YOLOv8n model is 0.73% higher than that of the comparison model, the Size value is reduced by 10.87%, the Params are reduced by 17.32%, and the FLOPs are reduced by 12.70%. In addition, the detection speed of the improved YOLOv8n model of the present invention is also faster than that of the comparison model, indicating that the technical solution selected by the present invention significantly optimizes the complexity and operation efficiency of the model while maintaining the detection accuracy.
[0183] Table 4 Performance comparison of different detection models
[0184]
[0185]
[0186] The detection results of different models are as follows Fig. 9 As shown, undetected grape berries are marked with yellow ovals, and erroneously detected or duplicated grape berries are marked with yellow arrows. Fig. 9 In the figure, although the color of grape berries is similar to that of leaves, most of them are successfully detected by the comparison model, which shows that the deep learning model has obvious advantages in detecting close-up objects. Fig. 9 It can be seen that Faster-RCNN, YOLOv5s and YOLOv6n models each have one duplicate detection, YOLOv5n, YOLOv5s, YOLOv8n, YOLOv9 and YOLOv8n CM models all miss a grape cluster at the same location, and YOLOv7-tiny and improved YOLOv8n models can accurately detect all grapes, which is consistent with the fact that the two models have higher F1 values in Table 4. Among them, the improved YOLOv8n model has an obvious lightweight advantage over the YOLOv7-tiny model, and can balance the relationship between lightweight and accuracy.
[0187] The grape cluster young fruit lightweight detection device based on improved YOLOv8n described below and the grape cluster young fruit lightweight detection method based on improved YOLOv8n described above can correspond to each other.
[0188] Please see attached Fig.10The present invention also provides a grape cluster young fruit lightweight detection device based on improved YOLOv8n, comprising:
[0189] A data acquisition unit 10 is used to obtain images of young grape clusters;
[0190] A data processing unit 20, used for marking and processing the image;
[0191] A detection unit 30 performs detection based on an improved YOLOv8n model, wherein the model includes a C2f-Faster module, a depth-separable convolution, a contextual anchor attention module, and a Wise-IoU loss function;
[0192] The output unit 40 is used to output the detection result of the young fruits in the grape cluster.
[0193] The device of this embodiment is based on the above method embodiment, and its principles and technical effects are similar, so they will not be repeated here.
[0194] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. A method for detecting lightweight young fruits in grape clusters based on improved YOLOv8n, characterized in that: The following steps are involved: Acquire image data containing young fruits of a grape cluster, wherein the image data includes young fruits of a grape cluster under different lighting conditions and shielding degrees; Label and process the image data to generate a grape cluster young fruit dataset; Improvements are made based on the YOLOv8n model, including: The C2f-Faster module is used to replace the original C2f module; the depth-separable convolution is used to replace the standard convolution; the contextual anchor attention module is introduced in the neck network of the model; the Wise-IoU loss function is used to replace the CIoU loss function; Train and optimize the improved YOLOv8n model, use the grape cluster young fruit dataset to train the model, and improve the robustness of the model through data enhancement; Use the trained model to perform real-time detection of young fruits in grape clusters and output the detection results.
2. A method for detecting light-weight young fruits of grape clusters based on improved YOLOv8n according to claim 1, characterized in that: The acquisition of the image data comprises: Select a grapevine and use the device to shoot from a distance of 60 to 80 cm. Consider both front light and back light lighting conditions when shooting; The collected images include images of various resolutions.
3. A method for detecting light-weight young fruits of grape clusters based on improved YOLOv8n according to claim 1, characterized in that: The steps of labeling and processing the image data include: scaling the resolution of the image data between 20% and 90%, manually labeling the grape cluster fruitlets using a labeling tool, and forming a grape cluster fruitlet data set containing different occlusion degrees and lighting conditions.
4. A method for detecting light-weight young fruits of grape clusters based on improved YOLOv8n according to claim 1, characterized in that: The step of improving the robustness of the model by data enhancement includes: performing data enhancement processing on the training data set, and the data enhancement method includes random cropping, flipping, rotation and brightness adjustment to simulate different scene changes and enhance the robustness of the model.
5. A method for detecting light-weight young fruits of grape clusters based on improved YOLOv8n according to claim 1, characterized in that: The C2f-Faster module consists of a local convolution PConv and two 1×1 convolution layers to form an inverse residual block. The batch normalization layer and the activation layer are located after the intermediate layer. The PConv only performs spatial feature extraction on some input channels, and the remaining channels remain unchanged, reducing redundant calculations and memory accesses, reducing the computational complexity of the model and improving the inference speed.
6. A method for detecting light-weight young fruits of grape clusters based on improved YOLOv8n according to claim 1, characterized in that: The depthwise separable convolution consists of two parts: depthwise convolution DWConv and pointwise convolution PWConv. The depthwise convolution is used to extract spatial features, and the pointwise convolution is used to extract channel features, which reduces the number of parameters and the amount of calculation of the model while maintaining the model performance.
7. A method for detecting light-weight young fruits of grape clusters based on improved YOLOv8n according to claim 1, characterized in that: The contextual anchor attention module includes the following steps: Perform average pooling and 1×1 convolution operations on the input feature map to obtain local area features; Capture long-range context information in the horizontal direction through 1×K depth convolution; Capture long-range contextual information in the vertical direction through K×1 depth convolution; A feature map containing contextual information is generated through 1×1 convolution and Sigmoid function, which enhances the model's ability to model long-distance dependencies.
8. A method for detecting light-weight young fruits of grape clusters based on improved YOLOv8n according to claim 1, characterized in that: The Wise-IoU loss function introduces a distance attention mechanism. When the predicted box and the true box overlap well, it weakens the penalty for geometric metrics such as distance and aspect ratio, reduces the impact of low-quality samples on model training, and improves the generalization ability of the model.
9. A method for detecting light-weight young fruits of grape clusters based on improved YOLOv8n according to claim 1, characterized in that: The optimization method used in the model training process is an optimization algorithm based on a dynamic non-monotonic focusing mechanism, which accelerates the convergence of the model and improves the detection accuracy.
10. A lightweight detection device for young grape fruits in a cluster based on improved YOLOv8n, applied to the method according to any one of claims 1 to 9, characterized in that: include: A data acquisition unit, used for acquiring images of young fruits in a grape cluster; A data processing unit, used for marking and processing the image; A detection unit, which performs detection based on an improved YOLOv8n model, wherein the model includes a C2f-Faster module, a depthwise separable convolution, a contextual anchor attention module, and a Wise-IoU loss function; The output unit is used to output the detection result of the young fruits in the grape cluster.
Citation Information
Cited By
Lightweight PCB defect detection method and device based on improved YOLOv8n and storage medium
CN119559178A
Crop seedling core real-time detection model and eggplant seedling core detection method
CN120339794A
Underwater target detection method, system, equipment and medium
CN120808131A
Potato crop growth monitoring method and system based on remote sensing image
CN120876939A
Improved YOLOv8n-based cloudy orchard multi-class sheltered pear detection method
CN121661511A