A peanut mildew classification method based on improved YOLOv8n-cls
Patent Information
- Application Number
- CN202411225212.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-03
- Publication Date
- 2026-10-09
- Estimated Expiration
- 2044-09-03
AI Technical Summary
针对目前图像分类模型参数量大、不易部署和终端设备计算资源有限等问题,提出一种基于改进YOLOv8n-cls的花生霉变分类方法
[0014] 1. The YOLOv8n-cls-CGS model proposed in this invention reduces the model size while maintaining accuracy, and can be deployed on terminal devices with limited computing resources.
Smart Images

Figure CN119091216B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image classification, and more particularly to a method for classifying peanut mold based on an improved YOLOv8n-cls. Background Technology
[0002] Improper storage conditions during harvesting, processing, and transportation can easily lead to peanut mold and the production of aflatoxin. Aflatoxin is a highly toxic compound produced by Aspergillus parasiticus and Aspergillus flavus, and is classified as a naturally occurring Group 1 carcinogen by the World Health Organization. Therefore, the effective classification of moldy peanuts is of great practical significance for ensuring food safety.
[0003] Currently, the classification of moldy peanuts mainly relies on manual screening. However, manual screening is inefficient and cannot meet the needs of the peanut processing industry, necessitating a more efficient and accurate classification method. With the development of deep learning technology, image classification models can be applied to the field of peanut mold. Addressing the problems of large parameter count, difficulty in deployment, and limited computing resources on terminal devices in current image classification models, this paper proposes a peanut mold classification method based on an improved YOLOv8n-cls. Summary of the Invention
[0004] In view of the needs of the application field and the shortcomings of the background technology, the purpose of this invention is to provide a peanut mold classification method based on improved YOLOv8n-cls.
[0005] To achieve the above objectives, the technical solution adopted by the present invention is as follows:
[0006] Step 1: Obtain peanut images and perform data augmentation on them, specifically 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 an 8:2 ratio;
[0008] Step 3: Construct an improved YOLOv8n-cls model by replacing some C2f and Conv modules in the backbone network of the YOLOv8n-cls model with C3Ghost and GhostConv modules respectively; add a parameterless attention mechanism SimAM module to the backbone network to obtain the improved YOLOv8n-cls-CGS model.
[0009] Step 4: Train and validate the YOLOv8n-cls-CGS model using the training and validation sets to obtain a trained peanut mold classification model;
[0010] Step 5: Obtain the peanut image to be classified, input it into 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 third and fourth C2f modules in the YOLOv8n-cls model backbone are replaced with C3Ghost modules; the fourth and fifth Conv modules are replaced with GhostConv modules. This reduces the complexity and training difficulty of the model by using fewer parameters and computations to extract features. A parameterless attention mechanism, SimAM, is added after the second C2f module in the backbone to enhance the network's feature capture ability without adding extra parameters, resulting in the improved YOLOv8n-cls-CGS model. In the YOLOv8n-cls-CGS model backbone, layers 0 to 9 are connected sequentially 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 prior art, the gain effect of the present invention is as follows:
[0014] 1. The YOLOv8n-cls-CGS model proposed in this invention reduces the model size while maintaining accuracy, and can be deployed on terminal devices with limited computing resources.
[0015] 2. The improved YOLOv8n-cls-CGS model enhances feature extraction capabilities and improves the accuracy of peanut mold classification. Compared with manual screening, it has the characteristics of high accuracy and high detection efficiency. Attached Figure Description
[0016] Figure 1 This is a flowchart of the present invention;
[0017] Figure 2 These are example images from the peanut dataset;
[0018] Figure 3 This is a diagram of the YOLOv8n-cls model structure;
[0019] Figure 4 This is a diagram of the YOLOv8n-cls-CGS model structure;
[0020] Figure 5 This is a GhostConv structure diagram;
[0021] Figure 6 This is a SimAM structure diagram;
[0022] Figure 7 This is a picture showing the results of peanut mold detection. Detailed Implementation
[0023] The present invention will be further described below with reference to the accompanying drawings and specific embodiments (examples), but these descriptions are not intended to limit the scope of the invention.
[0024] The main steps of this invention are as follows Figure 1 As shown, specifically:
[0025] Step 1: Obtain the peanut image, such as... Figure 2 As shown, data augmentation is performed on peanut images using image flipping, rotation, and translation to generate a peanut dataset.
[0026] In this embodiment, the number of images before data augmentation is 159, and the number of images after data augmentation is 1431.
[0027] Step 2: Divide the peanut dataset into a training set and a validation set in an 8:2 ratio.
[0028] Step 3: Construct an improved YOLOv8n-cls model by replacing some C2f and Conv modules in the YOLOv8n-cls backbone network with C3Ghost and GhostConv modules, respectively; add a parameterless attention mechanism, SimAM, to the backbone network to obtain the improved YOLOv8n-cls-CGS model. Specifically:
[0029] like Figure 3 The diagram shows the structure of the YOLOv8n-cls model. The 3rd and 4th C2f modules in the backbone network are replaced with C3Ghost modules; the 4th and 5th Conv modules are replaced with GhostConv modules. This uses fewer parameters and computations to extract features, reducing model complexity and training difficulty. A parameterless attention mechanism, SimAM, is added after the 2nd C2f module in the backbone network to enhance the network's feature capture ability without adding extra parameters, resulting in the improved YOLOv8n-cls-CGS model. Figure 4 As shown, in the backbone network of the YOLOv8n-cls-CGS model, layers 0 to 9 are connected sequentially as Conv, Conv, C2f, Conv, C2f, SimAM, GhostConv, C3Ghost, GhostConv, and C3Ghost; layer 9, C3Ghost, is connected to a classification head, Classify.
[0030] like Figure 5As shown, the GhostConv module convolutional structure reduces feature redundancy and parameter quantity by decomposing the regular convolutional operation into two parts. This module uses point-to-point convolutional operations to generate some feature maps, and uses these generated feature maps to construct the remaining feature maps. In this way, GhostConv convolution significantly reduces parameters and computational cost without reducing model performance.
[0031] like Figure 6 As shown, SimAM is a 3-D parameterless attention module. Compared with 1-D attention and 2-D attention, it focuses on the importance of both channel and spatial features. It can derive three-dimensional weights without adding extra parameters to the network, which can effectively avoid the problem of increasing model parameters while improving the overall performance of the model.
[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, experiments were conducted to compare the models before and after the improvement on the same dataset, with 100 epochs, as shown in Table 1. YOLOv8n-cls is the unimproved base model, and YOLOv8n-cls-CGS is the improved model using the C3Ghost, GhostConv and SimAM modules.
[0034] Table 1 Experimental results of the model before and after improvement
[0035] YOLOv8n-cls 0.965 2.82 YOLOv8n-cls-CGS 0.993 1.60
[0036] As shown in the table above, compared with YOLOv8n-cls, the improved model has a 2.8% higher accuracy and a 1.22MB smaller size, making it more accurate in identifying peanut mold and more suitable for deployment on terminal devices with limited computing resources.
[0037] Step 5: Obtain the peanut image to be classified, input it into the trained peanut mold classification model to obtain the classification detection result.
[0038] In this embodiment, peanuts are categorized into two types: moldy peanuts (bad) and non-moldy peanuts (good). Figure 7 As shown, the peanut mold classification result is moldy peanut.
[0039] The above description is merely a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for classifying peanut mold based on an improved YOLOv8n-cls, characterized in that: Includes the following steps: Step 1: Obtain peanut images and perform data augmentation on them, specifically 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 an 8:2 ratio; Step 3: Construct an improved YOLOv8n-cls model by replacing some C2f and Conv modules in the backbone network of the YOLOv8n-cls model with C3Ghost and GhostConv modules respectively; add a parameterless attention mechanism SimAM module to the backbone network to obtain the improved YOLOv8n-cls-CGS model. Step 4: Train and validate the YOLOv8n-cls-CGS model using the training and validation sets to obtain a trained peanut mold classification model; Step 5: Obtain the peanut image to be classified, input it into 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 third and fourth C2f modules in the YOLOv8n-cls model backbone are replaced with C3Ghost modules; the fourth and fifth Conv modules are replaced with GhostConv modules. This reduces the complexity and training difficulty of the model by using fewer parameters and computations to extract features. A parameterless attention mechanism, SimAM, is added after the second C2f module in the backbone to enhance the network's feature capture ability without adding extra parameters, resulting in the improved YOLOv8n-cls-CGS model. In the YOLOv8n-cls-CGS model backbone, layers 0 to 9 are connected sequentially 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
Image detection classification method based on deep learning
CN118351354A