Cherry classification detection lightweight method based on improved YOLOv8n
By making lightweight improvements to the YOLOv8n model and introducing FasterNet Block and CBAM modules, the problem of slow detection speed and low accuracy of visual recognition system in cherry picking is solved, and efficient cherry detection is achieved, supporting automatic picking and yield prediction.
Patent Information
- Application Number
- CN202411115492.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-14
- Publication Date
- 2024-11-15
AI Technical Summary
The existing visual recognition system has slow detection speed, low detection accuracy and is not light enough in cherry picking, making it difficult to apply to automated picking.
By making lightweight improvements to the YOLOv8n model, the FasterNet Block module and the CBAM attention mechanism module based on partial convolution are introduced to form a new C2f-Faster module, and the marked cherry data set is randomly divided into training at a ratio of 8:2. Set and validation set, perform online data augmentation and training, optimize the model to improve detection accuracy and speed.
It realizes the advantages of high detection accuracy, small memory occupancy and fast detection speed, and can effectively support automatic cherry picking and yield prediction.
Smart Images

Figure CN118968503A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of classification and detection of cherry fruits in the agricultural maturity period, and specifically is a lightweight method for classification and detection of cherry fruits based on improved YOLOv8n. Background Art
[0002] Nowadays, cherries are usually picked manually, but due to the short ripening period of cherries and the large reduction in the rural labor force, there is a shortage of labor and the picking process is very labor-intensive.
[0003] The automated picking robot improves the picking efficiency, reduces the damage to the cherry fruit, and can also reduce labor costs. The visual recognition system is an important component of the fruit tree picking robot system, playing a vital role in fruit tree target identification and positioning, automatic picking, and fruit and vegetable yield estimation.
[0004] However, up to now, the visual recognition system has problems such as slow detection speed, low detection accuracy and insufficient lightness, making it difficult to apply to automated picking. Summary of the invention
[0005] In order to solve the technical problems of low efficiency and low accuracy of the above-mentioned visual system, the purpose of the present invention is to provide a lightweight method for cherry classification detection based on improved YOLOv8n. First, an image data set is obtained, and the obtained image data is annotated by software, and the original Yolov8n model is lightweight improved. By adding a CBAM attention mechanism module in the backbone network area, the annotated cherry data set is randomly divided into a training set and a verification set. The improved Yolov8n lightweight model loads the data set for online data enhancement and is trained and verified. It has the lightweight advantages of high detection accuracy, small memory usage and fast detection speed. The improved model has the advantages of lightweight, fast recognition speed and high recognition accuracy, and can provide technical support for automatic cherry picking, cherry classification and yield prediction.
[0006] The technical solution adopted by the present invention to achieve the above technical purpose is as follows: step one: obtain cherry image data sets of different time periods; step two: annotate the image data collected in step one through software, and annotate ripe cherries as ripe, and unripe cherries as unripe; step three: lightweight improvement is made to the original Yolov8n model, and a FasterNet Block module based on partial convolution is introduced to form a new C2f-Faster module, and a CBAM attention mechanism module is added to the backbone network area, and the CBAM module consists of channel attention and spatial attention; step four: randomly divide the cherry data set annotated in step two into a training set and a validation set, and use the improved Yolov8n lightweight model in step three to load the data set for online data enhancement and training and validation to obtain the optimal detection result.
[0007] Further optimization, the image types of the cherry image data set obtained in step one mainly include image features under different situations: ripe cherries, unripe cherries, cherry fruits blocked by branches and leaves, overlapping occlusion between fruits, backlit shooting, frontlit shooting, close-up shooting, and long-distance shooting.
[0008] For further optimization, in step 2, the marked file is saved in txt format.
[0009] For further optimization, in the step three, firstly, the FasterNet Block module based on partial convolution is introduced to replace the Bottleneck module in the C2f module of YOLOv8n to form a new C2f-Faster module; secondly, the CBAM attention mechanism module is added between the SPPF module and the C2f-Faster module in the backbone network area to capture the correlation between features; the CBAM module consists of channel attention and spatial attention, and F1 is used as the input of the spatial attention module.
[0010] Further optimization, the Bottleneck module structure in step three is composed of two 3×3 regular convolutions in series, and batch normalization and SiLU activation function operations are performed after each convolution, and finally the convolution result is added to the input feature map.
[0011] Further optimization, the FasterNet Block module structure based on partial convolution in step 3, by introducing partial convolution operation, first a partial convolution layer with a convolution kernel size of 3×3, then two point convolution layers with a convolution kernel size of 1×1, and the normalization layer and the activation layer are placed after the middle point convolution layer; PConv only convolves part of the channels of the input feature map, and the remaining channels are not processed. When the proportion of channels involved in the convolution is 1 / 4, the calculation amount of partial convolution is only 1 / 16 of that of ordinary convolution, and the memory access amount is only 1 / 4 of that of ordinary convolution. The C2f-Faster module is used to greatly reduce the amount of model parameters and calculation, and ensure high detection accuracy, laying the foundation for lightweight design.
[0012] Further optimization, the attention mechanism module first performs global maximum pooling and global average pooling operations on each channel of the input feature map F to obtain two 1-channel feature maps, and then inputs the channel feature map after global maximum pooling and average pooling into a shared network layer; then, the feature map output by the shared network layer is added and activated by the sigmoid function to generate the final channel feature map Mc. Finally, Mc is multiplied by the input feature map F to generate the input feature F1 required by the spatial feature map module.
[0013] For further optimization, in step 4, the labeled cherry data set is randomly divided into a training set and a validation set in a ratio of 8:2.
[0014] Compared with the prior art, the present invention has the following beneficial effects: 1) This paper improves the original Yolov8n model by making it lightweight, and introduces the FasterNetBlock module based on partial convolution to form a new C2f-Faster module, which can more effectively extract spatial features by reducing redundant calculations and memory accesses at the same time. While greatly reducing the number of model parameters and the amount of calculation, it can also ensure high detection accuracy, laying the foundation for lightweight design; 2) The present invention adds a CBAM attention mechanism module in the backbone network area to enhance the ability to extract target features before multi-scale feature maps are fused, thereby further enhancing the detection accuracy of the target; 3) The present invention randomly divides the labeled cherry dataset into a training set and a validation set in a ratio of 8:2, uses the improved Yolov8n lightweight model to load the dataset for online data enhancement, training and validation, and obtains the optimal detection result. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 This is the improved YOLOV8n network structure diagram of the present invention; Figure 2 It is the structural diagram of the Bottleneck module of the present invention; Figure 3 It is the module structure diagram of FasterNet Block of the present invention; Figure 4 It is a partial convolution structure diagram of the present invention; Figure 5 It is the structural diagram of the CBAM module of the present invention. DETAILED DESCRIPTION
[0016] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments that can be easily changed or replaced by ordinary technicians in this field without creative work are within the scope of protection of the present invention. The structures, proportions, sizes, etc. illustrated in the drawings of the specification are only used to match the contents disclosed in the specification for people familiar with this technology to understand and read, and are not used to limit the limiting conditions for the implementation of the present invention, so they have no technical substantive significance. Any modification of the structure, change of the proportional relationship or adjustment of the size should still fall within the scope of the technical content disclosed by the present invention without affecting the effects and purposes that can be achieved by the present invention.
[0017] At the same time, it should be noted that, unless otherwise specified, "multiple" means two or more; the directions or positional relationships indicated by the terms "upper", "lower", "left", "right", "front end", "rear end", etc. are based on the directions or positional relationships shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific direction, be constructed and operated in a specific direction, and therefore cannot be understood as a limitation on the present invention. Changes or adjustments in their relative relationships shall also be regarded as the scope of the implementation of the present invention without substantially changing the technical content.
[0018] A lightweight method for cherry classification detection based on improved YOLOv8n, such as Figure 1As shown in the figure, step 1: obtain a dataset of cherry images at different time periods; step 2: annotate the image data collected in step 1 through software, with ripe cherries labeled as ripe and unripe cherries labeled as unripe; step 3: lightweight improve the original Yolov8n model and introduce FasterNet based on partial convolution The Block module forms a new C2f-Faster module, which can more effectively extract spatial features by reducing redundant calculations and memory accesses at the same time. It can greatly reduce the number of model parameters and calculations while ensuring high detection accuracy, laying the foundation for lightweight design, and adding a CBAM attention mechanism module in the backbone network area. The CBAM module consists of channel attention and spatial attention, which can enhance the ability to extract target features before multi-scale feature maps are fused, and further enhance the detection accuracy of the target; Step 4: Randomly divide the cherry data set marked in step 2 into training sets and validation sets, and randomly divide them into training sets and validation sets in a ratio of 8:2. Use the improved Yolov8n lightweight model in step 3 to load the data set for online data enhancement and training and verification to obtain the optimal detection result, which has the lightweight advantages of high detection accuracy, small memory usage, and fast detection speed.
[0019] like Figure 2 and Figure 3 As shown, in the step 3, firstly, the FasterNet Block module based on partial convolution is introduced to replace the Bottleneck module in the C2f module of YOLOv8n to form a new C2f-Faster module, which can significantly reduce the number of model parameters and the amount of calculation while ensuring high detection accuracy; secondly, the CBAM attention mechanism module is added between the SPPF module and the C2f-Faster module in the backbone network area to capture the correlation between features, thereby improving the performance of the image recognition task, and enhancing the ability to extract target features before the fusion of multi-scale feature maps, and further enhancing the detection accuracy of the target. The CBAM module consists of channel attention and spatial attention.
[0020] like Figure 4 As shown in the figure, the Bottleneck module structure in step 3 is composed of two 3×3 regular convolutions in series, and batch normalization and SiLU activation function operations are performed after each convolution, and finally the convolution result is added to the input feature map. Since the Bottleneck module performs regular convolution operations on each channel of the input feature map, while extracting more features, it leads to excessive redundancy of channel information and brings greater computational overhead. By reducing redundant calculations and memory access at the same time, spatial features can be extracted more efficiently.
[0021] like Figure 4 As shown, the FasterNet Block module structure based on partial convolution in step three introduces partial convolution operation, first a partial convolution layer with a convolution kernel size of 3×3, then two point convolution layers with a convolution kernel size of 1×1, and the normalization layer and activation layer are placed after the middle point convolution layer to retain feature diversity, reduce complexity and achieve lower latency. Since the feature maps of different channels are highly similar, partial convolution of the input feature map does not affect the accuracy; unlike conventional convolution, which performs convolution on all channels of the input feature map, PConv only performs convolution on part of the channels of the input feature map, and the remaining channels are not processed. When the ratio of channels involved in the convolution is 1 / 4, the calculation amount of partial convolution is only 1 / 16 of that of ordinary convolution, and the memory access amount is only 1 / 4 of that of ordinary convolution. The C2f-Faster module is used to greatly reduce the number of model parameters and calculations, and ensure high detection accuracy, laying the foundation for lightweight design. Assume that the length, width and channel values of the input feature map are respectively a, b, c, c p is the number of channels involved in the convolution, k is the convolution kernel size, then the amount of computation of the partial convolution is F p The expression is as follows: , memory access M p as follows: , r To participate in the convolution channel ratio, the expression is as follows: .
[0022] Example 1 A seedling image correction method based on image processing, such as Figure 5 As shown in the figure, the attention mechanism module first performs global maximum pooling and global average pooling operations on each channel of the input feature map F to obtain two 1-channel feature maps, and then inputs the channel feature map after global maximum pooling and average pooling into a shared network layer. This shared network layer is used to learn the attention weight of each channel. Through learning, the network can adaptively determine which channels are more important for the current task; then, the feature map output by the shared network layer is added and activated by the sigmoid function to generate the final channel feature map Mc. Finally, Mc is multiplied by the input feature map F to generate the input feature F1 required by the spatial feature map module. Figure 5-c is a spatial attention mechanism module, and the feature map F1 output by the channel attention mechanism module is used as the input feature map of this module. First, the input feature map F1 is subjected to channel-based global maximum pooling and global average pooling operations in sequence to obtain two 1-channel feature maps, and then the two feature maps are subjected to channel splicing operations, and a convolution operation with a convolution kernel size of 7×7 is performed to reduce the dimension to a 1-channel feature map; then the spatial feature map Ms is generated through a sigmoid activation function; finally, the Ms is multiplied with the input feature map F1 of the spatial attention mechanism module to obtain the final generated feature map; therefore, by adding this module, the ability to extract target features is enhanced before the multi-scale feature map is fused, and the detection accuracy of the target is further enhanced.
[0023] Example 2 This embodiment is an improved solution based on the embodiment 1. Its main structure is the same as that of the embodiment 1. The improvement is as follows: Figure 1 As shown, the image types of the cherry image dataset obtained in step 1 mainly include image features of ripe cherries, unripe cherries, cherry fruits blocked by branches and leaves, overlapping occlusion between fruits, backlighting, front light shooting, close-up shooting and long-distance shooting in different situations. The cherry image datasets in different time periods of the daytime, morning, noon and afternoon are obtained by shooting with shooting tools such as mobile phones. The image types include ripe cherries, unripe cherries, cherry fruits blocked by branches and leaves, overlapping occlusion between fruits, backlighting, front light shooting, close-up shooting and long-distance shooting, so as to obtain image features in different situations, enrich the content of the dataset, and lay the foundation for realizing the recognition and detection of fruits in a natural environment.
[0024] like Figure 1 As shown, in step 2, the annotated file is saved in txt format for subsequent model training and verification.
[0025] like Figure 1 As shown, in step 4, the labeled cherry dataset is randomly divided into a training set and a validation set at a ratio of 8:2, and the dataset is loaded with the improved Yolov8n lightweight model for online data enhancement and training and validation to obtain the best detection results. The lightweight model based on the improved YOLOv8n is compared with the minimum versions of the mainstream target detection network models of the YOLO series, such as YOLOv5n, YOLOv6n, YOLOv7-tiny, and YOLOv8n, under the same dataset. The test results are shown in Table 1.
[0026] Table 1 Comparison of test results of different models As can be seen from Table 1, the weight size, parameter size, and computational size of the improved model are the smallest compared to other models. At the same time, it is better than other models in terms of precision (P) and mean average precision (mAP). The recall rate (R) is only 0.4 percentage points lower than YOLOv6n and better than the remaining other models; the overall performance parameters are better than the other models mentioned above.
[0027] It should be noted that the lightweight method described in the present invention is not a limitation of the present invention. Based on this purpose, technicians in this field can use other similar lightweight methods to achieve more effective extraction of spatial features by simultaneously reducing redundant calculations and memory accesses, while greatly reducing the number of model parameters and the amount of calculation, while ensuring high detection accuracy, laying the foundation for lightweight design; achieving the purpose of enhancing the ability to extract target features before the fusion of multi-scale feature maps, and further enhancing the detection accuracy of the target.
[0028] The above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit the same. Those skilled in the art should understand that the specific implementation modes of the present invention may be modified or replaced by equivalents with reference to the above embodiments. Any modifications or equivalent replacements that do not depart from the spirit and scope of the present invention are within the scope of protection of the claims of the present invention.
Claims
1. A lightweight method for cherry classification detection based on improved YOLOv8n, characterized by: Step 1: Obtain cherry image datasets at different time periods; Step 2: The image data collected in step 1 is labeled by software, and ripe cherries are labeled as ripe, and unripe cherries are labeled as unripe; Step 3: Improve the original Yolov8n model by lightweighting it, introduce the FasterNet Block module based on partial convolution to form a new C2f-Faster module, and add the CBAM attention mechanism module in the backbone network area. The CBAM module consists of channel attention and spatial attention. Step 4: Randomly divide the cherry dataset annotated in step 2 into a training set and a validation set. Use the improved Yolov8n lightweight model in step 3 to load the dataset for online data enhancement and conduct training and validation to obtain the best detection results.
2. According to claim 1, a lightweight method for cherry classification detection based on improved YOLOv8n is characterized in that: The image types of the cherry image data set obtained in the step 1 mainly include image features in different situations: ripe cherries, unripe cherries, cherry fruits blocked by branches and leaves, overlapping occlusion between fruits, backlit shooting, frontlit shooting, close-up shooting, and long-distance shooting.
3. According to claim 1, a lightweight method for cherry classification detection based on improved YOLOv8n is characterized in that: In the step 2, the marked file is saved in txt format.
4. According to claim 1, a lightweight method for cherry classification detection based on improved YOLOv8n is characterized in that: In the step 3, firstly, the FasterNet Block module based on partial convolution is introduced to replace the Bottleneck module in the C2f module of YOLOv8n to form a new C2f-Faster module; secondly, the CBAM attention mechanism module is added between the SPPF module and the C2f-Faster module in the backbone network area to capture the correlation between the features; The CBAM module consists of channel attention and spatial attention, and F1 serves as the input of the spatial attention module.
5. According to claim 4, a lightweight method for cherry classification detection based on improved YOLOv8n is characterized in that: The Bottleneck module structure in step 3 is composed of two 3×3 regular convolutions connected in series, and batch normalization and SiLU activation function operations are performed after each convolution. Finally, the result obtained by the convolution is added to the input feature map.
6. According to claim 4, a lightweight method for cherry classification detection based on improved YOLOv8n is characterized in that: The FasterNet Block module structure based on partial convolution in the step 3 introduces a partial convolution operation, first a partial convolution layer with a convolution kernel size of 3×3, then two point convolution layers with a convolution kernel size of 1×1, and the normalization layer and the activation layer are placed after the middle point convolution layer; PConv only convolves a part of the channels of the input feature map, and the remaining channels are not processed. When the proportion of channels involved in the convolution is 1 / 4, the calculation amount of partial convolution is only 1 / 16 of that of ordinary convolution, and the memory access amount is only 1 / 4 of that of ordinary convolution. The C2f-Faster module is used to greatly reduce the amount of model parameters and calculations, and ensure high detection accuracy, laying the foundation for lightweight design.
7. According to claim 4, a lightweight method for cherry classification detection based on improved YOLOv8n is characterized in that: The attention mechanism module first performs global maximum pooling and global average pooling operations on each channel of the input feature map F to obtain two 1-channel feature maps, and then inputs the channel feature map after global maximum pooling and average pooling into a shared network layer; then, the feature map output by the shared network layer is added and activated by the sigmoid function to generate the final channel feature map Mc. Finally, Mc is multiplied by the input feature map F to generate the input feature F1 required by the spatial feature map module.
8. According to claim 1, a lightweight method for cherry classification detection based on improved YOLOv8n is characterized in that: In step 4, the labeled cherry data set is randomly divided into a training set and a validation set in a ratio of 8:2.
Citation Information
Cited By
Instrument reading method and system, computer readable storage medium and electronic equipment
CN120544175A
Lightweight silkworm cocoon classification detection algorithm based on improved YOLOv8 network
CN120563950A
A lightweight silkworm cocoon classification and detection method based on improved YOLOv8 network
CN120563950B
Feature identification method and system for hidden weak signal
CN121435163A
