Peanut mildew classification method based on improved YOLOv8n-cls
By improving the YOLOv8n-cls model, replacing the module and adding attention mechanism, building the YOLOv8n-cls-CGS model, the problems of low classification efficiency of peanut mold and difficulty in deploying the model are solved, and high accuracy and efficient peanut mold detection are achieved .
Patent Information
- Application Number
- CN202411225212.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-03
- Publication Date
- 2024-12-06
- Estimated Expiration
- 2044-09-03
AI Technical Summary
In the prior art, the classification of peanut mold mainly relies on manual screening, is inefficient and cannot meet the needs of the peanut processing industry, and the image classification model has large parameters and is not easy to deploy on terminal equipment with limited computing resources.
By improving the YOLOv8n-cls model, replacing some C2f modules and Conv modules with C3Ghost modules and GhostConv modules, and adding the SimAM module without parameters to the backbone network, building the YOLOv8n-cls-CGS model to reduce model complexity and parameter quantity , enhance feature extraction ability.
It realizes the accuracy while ensuring the accuracy and the detection efficiency of peanut mold classification, and is suitable for terminal equipment with limited computing resources.
Smart Images

Figure CN119091216A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image classification, and in particular to a peanut mildew classification method based on improved YOLOv8n-cls. Background Art
[0002] Improper storage conditions during the picking, processing, and transportation of peanuts can easily lead to peanut mold and the production of aflatoxin. Aflatoxin is a highly toxic compound produced by parasitic Aspergillus and Aspergillus flavus, and is classified as a naturally occurring Class I carcinogen by the World Health Organization. Therefore, the effective classification of moldy peanuts is of great practical significance for ensuring food safety.
[0003] At present, the classification of moldy peanuts mainly relies on manual screening. Due to the low efficiency of manual screening, it cannot meet the needs of the peanut processing industry. An efficient and accurate classification method is needed. With the development of deep learning technology, image classification models can be applied to the field of peanut mold. In view of the problems of large number of parameters, difficult deployment and limited computing resources of terminal devices in current image classification models, a peanut mold classification method based on improved YOLOv8n-cls is proposed. Summary of the invention
[0004] In view of the needs of the application field and the shortcomings of the background technology, the object of the present invention is to provide a peanut mold classification method based on improved YOLOv8n-cls.
[0005] In order to achieve the above object, the technical solution adopted by the present invention is:
[0006] Step 1: Obtain peanut images and perform data augmentation on the peanut images by image flipping, image rotation, and image translation to generate a peanut dataset;
[0007] Step 2: Divide the peanut dataset into a training set and a validation set in a ratio of 8:2;
[0008] Step 3: Build an improved YOLOv8n-cls model, replace some C2f modules and Conv modules in the backbone network of the YOLOv8n-cls model with C3Ghost modules and GhostConv modules respectively; add a parameter-free attention mechanism SimAM module to the backbone network to obtain the improved YOLOv8n-cls-CGS model;
[0009] Step 4: Use the training set and validation set to train and validate the YOLOv8n-cls-CGS model to obtain a trained peanut mold classification model;
[0010] Step 5: Obtain the peanut image to be classified, and input the trained peanut mold classification model to obtain the classification detection result;
[0011] The process of constructing the improved YOLOv8n-cls model in step 3 is as follows:
[0012] The 3rd and 4th C2f modules in the backbone network of the YOLOv8n-cls model are replaced by C3Ghost modules; the 4th and 5th Conv modules are replaced by GhostConv modules, using fewer parameters and calculations to extract features, reducing the complexity and training difficulty of the model; a parameter-free attention mechanism SimAM module is added after the 2nd C2f module in the backbone network to enhance the network's ability to capture features without adding additional parameters, thereby obtaining an improved YOLOv8n-cls-CGS model; the 0th to 9th layers in the backbone network of the YOLOv8n-cls-CGS model are connected in sequence as Conv, Conv, C2f, Conv, C2f, SimAM, GhostConv, C3Ghost, GhostConv, and C3Ghost; the 9th layer C3Ghost is connected to a classification head Classify.
[0013] Compared with the background technology, the gain effect of the present invention is:
[0014] 1. The YOLOv8n-cls-CGS model proposed in the present invention reduces the model size while ensuring the accuracy, and can be deployed in terminal devices with limited computing resources.
[0015] 2. The improved YOLOv8n-cls-CGS model has enhanced feature extraction capabilities and improved the accuracy of peanut mold classification. Compared with manual screening, it has the characteristics of high accuracy and high detection efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 is a flow chart of the present invention;
[0017] Figure 2 is an example image of the peanut dataset;
[0018] Figure 3 This is the YOLOv8n-cls model structure diagram;
[0019] Figure 4 This is the YOLOv8n-cls-CGS model structure diagram;
[0020] Figure 5 It is the structure diagram of GhostConv;
[0021] Figure 6 It is the SimAM structure diagram;
[0022] Figure 7 This is the result of peanut mold detection. DETAILED DESCRIPTION
[0023] The present invention is further described below in conjunction with the accompanying drawings and specific implementation methods (examples), but they are not intended to limit the present invention.
[0024] The main steps of the present invention are as follows Figure 1 As shown, specifically:
[0025] Step 1: Get the peanut image, such as Figure 2 As shown in the figure, the peanut image is augmented by image flipping, image rotation and image translation to generate a peanut dataset.
[0026] In this embodiment, the number of images before data enhancement is 159, and the number of images after data enhancement is 1431.
[0027] Step 2: Divide the peanut dataset into training set and validation set in a ratio of 8:2.
[0028] Step 3: Build an improved YOLOv8n-cls model, replace some C2f modules and Conv modules in the backbone network of the YOLOv8n-cls model with C3Ghost modules and GhostConv modules respectively; add the SimAM module with no-parameter attention mechanism to the backbone network to obtain the improved YOLOv8n-cls-CGS model. Specifically:
[0029] like Figure 3 As shown in the figure, the structure diagram of the YOLOv8n-cls model is shown. The 3rd and 4th C2f modules in the backbone network of the YOLOv8n-cls model are replaced with C3Ghost modules; the 4th and 5th Conv modules are replaced with GhostConv modules, using fewer parameters and calculations to extract features, reducing the complexity and training difficulty of the model; a parameter-free attention mechanism SimAM module is added after the 2nd C2f module in the backbone network, and the network's ability to capture features is enhanced without adding additional parameters, resulting in an improved YOLOv8n-cls-CGS model. Figure 4 As shown in the figure, the 0th to 9th layers in the backbone network of the YOLOv8n-cls-CGS model are connected to Conv, Conv, C2f, Conv, C2f, SimAM, GhostConv, C3Ghost, GhostConv, and C3Ghost respectively; the 9th layer C3Ghost is connected to a classification head Classify.
[0030] like Figure 5As shown in the figure, the convolution structure of the GhostConv module reduces feature redundancy and parameter amount by decomposing the conventional convolution operation into two parts. The module uses point-to-point convolution operation to generate some feature maps, and uses these generated feature maps to construct the remaining feature maps. In this way, GhostConv convolution greatly reduces parameters and calculation amount without reducing model performance.
[0031] like Figure 6 As shown in the figure, SimAM is a 3-D parameter-free attention module. Compared with 1-D attention and 2-D attention, it focuses on the importance of both channel and spatial features, and can derive three-dimensional weights without adding additional parameters to the network. While improving the overall performance of the model, it can effectively avoid the problem of increasing model parameters.
[0032] Step 4: Use the training set and validation set to train and validate the YOLOv8n-cls-CGS model to obtain a trained peanut mold classification model.
[0033] In this embodiment, an experimental comparison is performed on the models before and after improvement under the same data set, and the epochs is 100, as shown in Table 1, where YOLOv8n-cls is the unimproved basic model, and YOLOv8n-cls-CGS is an improved model using C3Ghost, GhostConv and SimAM modules.
[0034] Table 1 Experimental results of the model before and after improvement
[0035] Model Accuracy Model size / MB YOLOv8n-cls 0.965 2.82 YOLOv8n-cls-CGS 0.993 1.60
[0036] As can be seen from the above table, compared with YOLOv8n-cls, the improved model has an accuracy increase of 2.8% and a model size reduction of 1.22MB. It can more accurately identify peanut mold and is more conducive to deployment in terminal devices with limited computing resources.
[0037] Step 5: Obtain the peanut image to be classified, and input the trained peanut mold classification model to obtain the classification detection result.
[0038] In this embodiment, there are two types of peanuts, namely, moldy peanuts (bad) and non-moldy peanuts (good). Figure 7 As shown, the classification result of peanut mold is moldy peanuts.
[0039] The above is only a preferred specific embodiment of the present invention, but the protection scope of the present invention 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 by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A peanut mold classification method based on improved YOLOv8n-cls, characterized by: The following steps are involved: Step 1: Obtain peanut images and perform data augmentation on the peanut images by image flipping, image rotation, and image translation to generate a peanut dataset; Step 2: Divide the peanut dataset into a training set and a validation set in a ratio of 8:2; Step 3: Build an improved YOLOv8n-cls model, replace some C2f modules and Conv modules in the backbone network of the YOLOv8n-cls model with C3Ghost modules and GhostConv modules respectively; add a parameter-free attention mechanism SimAM module to the backbone network to obtain the improved YOLOv8n-cls-CGS model; Step 4: Use the training set and validation set to train and validate the YOLOv8n-cls-CGS model to obtain a trained peanut mold classification model; Step 5: Obtain the peanut image to be classified, and input the trained peanut mold classification model to obtain the classification detection result; The process of constructing the improved YOLOv8n-cls model in step 3 is as follows: The 3rd and 4th C2f modules in the backbone network of the YOLOv8n-cls model are replaced by C3Ghost modules; the 4th and 5th Conv modules are replaced by GhostConv modules, using fewer parameters and calculations to extract features, reducing the complexity and training difficulty of the model; a parameter-free attention mechanism SimAM module is added after the 2nd C2f module in the backbone network to enhance the network's ability to capture features without adding additional parameters, thereby obtaining an improved YOLOv8n-cls-CGS model; the 0th to 9th layers in the backbone network of the YOLOv8n-cls-CGS model are connected in sequence as Conv, Conv, C2f, Conv, C2f, SimAM, GhostConv, C3Ghost, GhostConv, and C3Ghost; the 9th layer C3Ghost is connected to a classification head Classify.
Citation Information
Patent Citations
Peanut mildew identification method and system based on neural network
CN114067314A
GIS infrared image recognition system and method based on improved YOLOv5
CN117975040A
Image detection classification method based on deep learning
CN118351354A
