Mushroom image classification method and system based on lightweight network
By adopting a lightweight network structure in the mushroom image classification task, combining deep feature extraction and attention mechanisms, the problem of high computational complexity in the resource-constrained environment is solved, and efficient and robust Image classification effect.
Patent Information
- Application Number
- CN202411298498.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-18
- Publication Date
- 2025-01-14
AI Technical Summary
The existing convolutional neural network has many parameters and high computational complexity in image classification tasks, making it difficult to achieve fast and accurate image classification on resource-constrained hardware, reducing the efficiency and robustness of the network model.
Using the mushroom image classification method based on lightweight network, the image features are gradually extracted and enhanced through standard convolution layers, multiple depth feature extraction modules, global average pooling layer and fully connected layer, combining depth convolution, attention and grouping Convolution mechanism reduces model complexity and parameter quantity, and improves model expression ability and robustness.
The model parameters and calculation volume are significantly reduced while maintaining high classification accuracy, improving the efficiency and robustness of the model, allowing it to operate efficiently on resource-constrained devices.
Smart Images

Figure CN119313942A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image classification, and in particular to a mushroom image classification method and system based on a lightweight network. Background Art
[0002] The task of image classification often occurs in daily life. It distinguishes images of different categories based on their semantic information. It is an important basic problem in computer vision and the basis for other high-level visual tasks such as image detection and image segmentation. The convolutional neural network in the deep learning model retains all the information of the input image to a great extent by directly using the image pixel information as the input of the network, extracts features and performs high-level abstraction through convolution operations, and finally outputs the classification results.
[0003] An image classification method and an image classification system with publication number CN116403047A relate to the field of image processing technology and include the following steps: collecting a number of sample images, preprocessing the sample images to obtain preprocessed images; performing category labeling on the preprocessed images to obtain image labeling results; constructing a training data set based on the preprocessed images and the corresponding image labeling results; constructing an initial image classification model, inputting the training data set into the initial image classification model for model training until the model converges, and obtaining a trained image classification optimization model; and performing category judgment on the image to be classified based on the trained image classification optimization model to determine the category to which the image to be classified belongs.
[0004] Current convolutional neural networks have numerous parameters and high computational complexity in image classification tasks, making it difficult to achieve fast and accurate image classification on resource-constrained hardware, thereby reducing the efficiency and robustness of the network model. Summary of the Invention
[0005] In view of this, the present invention proposes a mushroom image classification method and system based on a lightweight network. Through the lightweight network structure, the number of model parameters and the amount of calculation are significantly reduced, while maintaining a high classification accuracy, thereby ensuring the efficiency and robustness of the model.
[0006] The technical solution of the present invention is implemented as follows: In a first aspect, the present invention provides a mushroom image classification method based on a lightweight network, the method comprising the following steps:
[0007] S1, obtaining a training set of mushroom images, calibrating and preprocessing the mushroom images in the training set to obtain standard images;
[0008] S2, constructing a mushroom recognition model, which includes a standard convolutional layer, multiple deep feature extraction modules, a global average pooling layer, and a fully connected layer. The standard image is input into the standard convolutional layer, which expands the channels of the input standard image to obtain an original feature map; the multiple deep feature extraction modules are sequentially connected end to end to perform deep feature extraction on the original feature map to obtain a target feature map; the global average pooling layer reduces the dimension of the target feature map and inputs it into the fully connected layer, which outputs the classification result of the mushroom image;
[0009] S3, initializing the mushroom recognition model parameters, inputting the standard image into the mushroom recognition model for training, and iteratively optimizing the model parameters to obtain the final mushroom recognition model;
[0010] S4, inputting the mushroom image to be classified into the final mushroom recognition model to obtain the classification result.
[0011] Based on the above technical solution, preferably, the step S1 of obtaining a training set of mushroom images, calibrating and preprocessing the mushroom images in the training set to obtain a standard image includes the following sub-steps:
[0012] S11, obtaining a training set of mushroom images, screening the mushroom images in the training set, and eliminating defective and duplicate images;
[0013] S12, performing format conversion and resizing on the filtered mushroom images to obtain a unified mushroom image;
[0014] S13, calibrating and classifying each unified mushroom image in the training set according to the classification feature information of the mushrooms, to obtain feature sets of mushroom images of different types;
[0015] S14, performing data enhancement on the mushroom images in the mushroom image feature set corresponding to each class to obtain a standard image.
[0016] On the basis of the above technical solution, preferably, the mushroom recognition model in step S2 includes a standard convolution layer, multiple deep feature extraction modules, a global average pooling layer and a fully connected layer, wherein the multiple deep feature extraction modules are connected end to end in sequence, the output end of the standard convolution layer is connected to the input end of the deep feature extraction module at the head end, the input end of the global average pooling layer is connected to the output end of the deep feature extraction module at the tail end, and the output end of the global average pooling layer is connected to the input end of the fully connected layer, and the classification result corresponding to the mushroom image is output.
[0017] On the basis of the above technical solution, preferably, the standard convolution layer expands the channels of the input standard image to obtain the original feature map, wherein the standard convolution layer includes 32 3x3 convolution kernels, the standard convolution layer expands the number of channels of the standard image to 32, and extracts the edge, texture and shape of the standard image. Each convolution kernel slides on the input standard image and performs weight multiplication and bias addition operations at each position to generate the corresponding original feature map. The expression is:
[0018]
[0019] Where, I i is the i-th output original feature map, i∈[1, C out ], C out is the number of output channels, f() is the RELU activation function, M j is the jth channel of the input standard image, i∈[1, C in ], C in is the original number of channels, K i,j is the convolution kernel on the jth input channel corresponding to the i-th output original feature map, B i is the bias term of the i-th output original feature map, is the convolution operation.
[0020] On the basis of the above technical solutions, preferably, each of the deep feature extraction modules includes a deep convolution unit, an attention unit, a grouped convolution unit, a channel rearrangement unit, a splicing unit and a pooling unit connected in sequence, wherein the deep convolution unit performs deep feature extraction on the input original feature map to generate a corresponding convolution feature map; the attention unit performs feature recalibration on the input convolution feature map to generate a corresponding recalibrated feature map; the grouped convolution unit groups the feature channels, performs convolution extraction on the recalibrated feature map by group, and obtains a grouped feature map; the channel rearrangement unit rearranges each grouped feature map in the channel dimension to obtain a reorganized feature map; the splicing unit splices and fuses each reorganized feature map, and inputs the spliced and fused feature map into the pooling layer to obtain a target feature map.
[0021] On the basis of the above technical solution, preferably, the depth convolution unit performs depth feature extraction on the input original feature map to generate a corresponding convolution feature map, wherein each convolution kernel slides on the input standard image and performs weight multiplication and bias addition operations at each position to generate a corresponding convolution feature map, which is expressed as:
[0022] Conv i (I i ,D i )=DepthwiseConv2D(I i,D i );
[0023] Where, Conv i (I i ,D i ) represents the result of depth convolution of the i-th channel, I i is the original feature map of the i-th input, and the size of the original feature map of the input is H×W×C i , H is the height, W is the width, C i is the i-th channel, D i is the depth convolution kernel corresponding to the i-th channel, DepthwiseConv2D() is the depth convolution function;
[0024] According to the result of the depth convolution, the convolution feature map corresponding to each channel is obtained by activating the ReLU6 activation function. The expression is:
[0025] D(I i )=ReLU6(Conv i (I i ,D i )).
[0026] On the basis of the above technical solution, preferably, the attention unit includes a global average pooling, a fully connected layer and an activation function, wherein,
[0027] The convolution feature map is input into the attention unit, and the global average pooling performs average pooling on each channel of the input convolution feature map to obtain the global information feature map; the expression is:
[0028] G=GlobalAvgPool(F)
[0029]
[0030] Where F∈R C×H′×W′ , H′ is the height of the convolution feature map, W′ is the width of the convolution feature map, F(x,y,c) represents the element of the xth row and yth column of the cth channel in the convolution feature map F, is the normalization factor;
[0031] The statistical information of each channel of the convolutional feature map is input into the fully connected layer and normalized using the Sigmoid activation function to obtain the final channel weight, which is expressed as:
[0032] γ=FC(G)
[0033] g(Y)=Sigmoid(MLP(GlobalAvgPool(γ)))
[0034] Where g(γ) is the final channel weight, FC is the fully connected layer, γ is the scaling weight, and MLP stands for multi-layer perceptron.
[0035] Multiply the scaling weights by the convolution feature map channel by channel to obtain the recalibrated feature map, which is expressed as:
[0036] A eca =F⊙γ;
[0037] Where A eca is the recalibrated feature map, and ⊙ represents element-wise multiplication.
[0038] Based on the above technical solution, preferably, the expression of the grouped convolutional layer is:
[0039] G conv (A eca )=GroupConv2D(A eca ,G g ,groups)
[0040] In the formula, GroupConv2D() is the group convolution function, G g It is the group convolution kernel, and groups is the number of groups.
[0041] Based on the above technical solution, preferably, the initialization of the mushroom recognition model parameters in step S3, inputting the standard image into the mushroom recognition model for training, and iteratively optimizing the model parameters to obtain the final mushroom recognition model includes the following sub-steps:
[0042] Randomly initialize the mushroom recognition model parameters and define the loss function;
[0043] Input the standard image into the mushroom recognition model for forward propagation and calculate the prediction result;
[0044] According to the prediction results and the true label, the loss value is calculated using the loss function;
[0045] According to the loss value, the gradient of each layer in the mushroom recognition model is calculated through the back propagation algorithm, and the optimizer is used to update the parameters of the model according to the gradient. The expression is:
[0046]
[0047] Where g t is the gradient at time t; is the first-order moment estimate of the gradient; f t () is the objective function; v t is the second moment estimate of the gradient; It is the bias correction of vt; is the bias correction of mt; β1 is the momentum hyperparameter; β2 is the RMSProp hyperparameter; θ is the solution parameter; θ t is the parameter of the tth iteration, a is the learning rate, and ε is a small constant; is the momentum hyperparameter at time t; is the RMSProp hyperparameter at time t.
[0048] In a second aspect, a mushroom image classification system based on a lightweight network in this embodiment is implemented using the aforementioned mushroom image classification method based on a lightweight network, and the system includes:
[0049] A preprocessing module is used to obtain a training set of mushroom images, calibrate and preprocess the mushroom images in the training set, and obtain standard images;
[0050] A model construction module is used to construct a mushroom recognition model. The mushroom recognition model includes a standard convolution layer, multiple deep feature extraction modules, a global average pooling layer, and a fully connected layer. The standard image is input into the standard convolution layer, which expands the channels of the input standard image to obtain an original feature map. The multiple deep feature extraction modules are sequentially connected end to end to perform deep feature extraction on the original feature map to obtain a target feature map. The global average pooling layer reduces the dimension of the target feature map and inputs it into the fully connected layer, which outputs the classification result of the mushroom image.
[0051] The model training module is used to initialize the parameters of the mushroom recognition model, input standard images into the mushroom recognition model for training, and iteratively optimize the model parameters to obtain the final mushroom recognition model;
[0052] The input recognition module is used to input the mushroom image to be classified into the final mushroom recognition model to obtain the classification result.
[0053] The mushroom image classification method and system based on a lightweight network of the present invention has the following beneficial effects compared with the prior art:
[0054] (1) By stacking multiple deep feature extraction modules, the model can gradually extract and enhance image features and improve classification accuracy; through deep convolution units, attention units, grouped convolution units, channel rearrangement units, splicing units and pooling units, the model can learn more complex and comprehensive features; and through the processing of global average pooling layers and fully connected layers, the model can output the classification results of mushroom images, which not only improves the performance of the model, but also maintains relatively low computational complexity and model size, allowing the model to run efficiently on resource-constrained devices, thereby improving the efficiency and robustness of the network model; (2) By omitting the dimensionality reduction step through the attention unit, cross-channel information exchange is effectively realized, thereby improving the expressive power of the model, and by fusing the grouped convolution and attention mechanisms, the complexity of the model is reduced;
[0055] (3) By adaptively adjusting the learning rate of each parameter, the network can escape from the local minimum and get closer to the global minimum, thereby improving the accuracy of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0057] Figure 1 is a flow chart of the present invention;
[0058] Figure 2 is the image enhancement diagram of the present invention;
[0059] Figure 3 Schematic diagram of the mushroom identification model structure of the present invention;
[0060] Figure 4 Schematic diagram of the structure of the depth feature extraction module of the present invention;
[0061] Figure 5 Schematic diagram of the flow of the attention unit of the present invention;
[0062] Figure 6 Schematic diagram of the flow of the grouped convolution unit and the channel rearrangement unit of the present invention. DETAILED DESCRIPTION
[0063] The following will be combined with the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the embodiments described 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 making creative efforts are within the scope of protection of the present invention.
[0064] like Figure 1 As shown, the present invention provides a mushroom image classification method based on a lightweight network, the method comprising the following steps:
[0065] S1, obtain a training set of mushroom images, calibrate and preprocess the mushroom images in the training set to obtain standard images.
[0066] Step S1 includes the following sub-steps:
[0067] S11, obtaining a training set of mushroom images, screening the mushroom images in the training set, and eliminating defective and duplicate images;
[0068] S12, performing format conversion and resizing on the filtered mushroom images to obtain a unified mushroom image;
[0069] S13, calibrating and classifying each unified mushroom image in the training set according to the classification feature information of the mushrooms, to obtain feature sets of mushroom images of different types;
[0070] S14, performing data enhancement on the mushroom images in the mushroom image feature set corresponding to each class to obtain a standard image.
[0071] It should be noted that after obtaining the mushroom images, they need to be further processed to improve the quality of the dataset. Since the color characteristics of mushrooms are important factors for accurate classification, this paper chooses to retain the RGB three color channel values of the image during the preprocessing process. The specific steps of preprocessing include image screening, format unification and size adjustment, data calibration and data enhancement. Among them, during the image screening process, since the downloaded images may contain mushroom images that do not belong to the target category, they need to be screened. The detailed data selection criteria cover the removal of duplicate images, exclusion of photos of non-target species, processing of images with insufficient clarity, and removal of mushrooms with serious defects. To ensure the quality of the original dataset, we selected 35 common mushroom species from the dataset, totaling 3,500 mushroom images as the training set. During the format unification and size adjustment process, because the crawler program automatically grabs images from search engines, there may be a variety of different file types, such as JPG, PNG, etc. For subsequent data extraction, the format is uniformly converted to JPG format. In addition, all mushroom images in the dataset are scaled to a consistent size of 224×224 pixels through TensorFlow programming to ensure normal data processing in subsequent convolutional layers.
[0072] like Figure 2 As shown, the initial mushroom image set obtained through web crawling is still far behind the million-level image dataset. The dataset contains only 100 images per category, making the number of samples relatively scarce. To avoid overfitting and other issues caused by the small number of images, we use data augmentation to expand the dataset. This includes brightness adjustment, contrast enhancement, sharpening, Gaussian blur, rotation and flipping, cropping, and noise addition. Brightness adjustment adjusts the brightness of an image, brightening or darkening it. This improves the model's robustness to images of varying brightness. Contrast enhancement increases the brightness differences between different regions in an image, making the image clearer. This improves the model's ability to recognize details and textures. This is achieved by convolving a filter with each pixel in the image and its surrounding pixels. For each pixel, the Gaussian filter calculates a weighted average of its weights with those of its surrounding pixels, where the pixel weight is determined by its distance from the center pixel and the parameters of the Gaussian function.
[0073] S2, construct a mushroom recognition model, which includes a standard convolution layer, multiple deep feature extraction modules, a global average pooling layer and a fully connected layer. The standard image is input into the standard convolution layer, and the standard convolution layer expands the channels of the input standard image to obtain an original feature map; multiple deep feature extraction modules are connected end to end in sequence, and deep features are extracted from the original feature map to obtain a target feature map; the global average pooling layer reduces the dimension of the target feature map and inputs it into the fully connected layer, and the fully connected layer outputs the classification result of the mushroom image.
[0074] like Figure 3 As shown, multiple deep feature extraction modules are connected end to end in sequence, the output of the standard convolutional layer is connected to the input of the deep feature extraction module at the head end, the input of the global average pooling layer is connected to the output of the deep feature extraction module at the tail end, and the output of the global average pooling layer is connected to the input of the fully connected layer to output the classification result corresponding to the mushroom image.
[0075] In the embodiment, the standard convolution layer expands the channels of the input standard image to obtain the original feature map, wherein the standard convolution layer includes 32 3x3 convolution kernels, the standard convolution layer expands the number of channels of the standard image to 32, and extracts the edge, texture and shape of the standard image. Each convolution kernel slides on the input standard image and performs weight multiplication and bias addition operations at each position to generate the corresponding original feature map. The expression is:
[0076]
[0077] Where, I i is the i-th output original feature map, i∈[1, C out ], C out is the number of output channels, f() is the RELU activation function, M j is the jth channel of the input standard image, i∈[1, C in ], C in is the original number of channels, K i,j is the convolution kernel on the jth input channel corresponding to the i-th output original feature map, B i is the bias term of the i-th output original feature map, is the convolution operation.
[0078] like Figure 4As shown, each deep feature extraction module in this embodiment includes a deep convolution unit, an attention unit, a grouped convolution unit, a channel rearrangement unit, a splicing unit and a pooling unit connected in sequence, wherein the deep convolution unit performs deep feature extraction on the input original feature map to generate a corresponding convolution feature map; the attention unit performs feature recalibration on the input convolution feature map to generate a corresponding recalibrated feature map; the grouped convolution unit groups the feature channels, and performs convolution extraction on the recalibrated feature map by group to obtain a grouped feature map; the channel rearrangement unit rearranges each grouped feature map in the channel dimension to obtain a recombined feature map; the splicing unit splices and fuses each recombined feature map, and inputs the spliced and fused feature map into the pooling layer to obtain a target feature map.
[0079] It should be noted that the depth convolution unit performs deep feature extraction on the input original feature map to generate the corresponding convolution feature map. The depth convolution uses multiple consecutive small convolution kernels instead of a single larger convolution kernel to reduce the number of model parameters. In addition, the depth convolution uses smaller convolution kernels and deeper channels to capture richer local features and enhance the expressive power of the feature map. The attention unit performs weighted processing on the feature map according to the importance of the features to generate the corresponding recalibrated feature map, so that the model can focus on more important features and suppress unimportant features, thereby improving the classification performance of the model. The grouped convolution unit groups the feature channels, performs convolution on the recalibrated feature map by group to extract features, and obtains the grouped feature map. Grouped convolution can reduce the amount of computation and the number of parameters while improving the performance of the model. Through group processing, the model can learn different feature representations between different groups, increase the diversity of features, and reduce computational costs. The channel rearrangement unit rearranges the feature maps of each group in the channel dimension to obtain a reorganized feature map. Through rearrangement, the model can more flexibly combine the features of different groups, which is conducive to improving the feature fusion effect. The pooling unit performs a pooling operation on the spliced and fused feature map to reduce the spatial size of the feature map and extract important feature information. The global average pooling layer can further reduce the number of parameters, prevent overfitting, and enable the model to process input images of different sizes; at the same time, it can also convert the feature map into a fixed-length feature vector for subsequent fully connected layer processing.
[0080] It is understandable that an efficient channel attention module is embedded in the first 3×3 depth convolution; using grouped convolution to reduce the complexity of the model may cause the model to lose the learning of some features, and the attention module introduced later can solve this problem.
[0081] The depth convolution unit in this embodiment performs depth feature extraction on the input original feature map to generate a corresponding convolution feature map, wherein each convolution kernel slides on the input standard image and performs weight multiplication and bias addition operations at each position to generate the corresponding convolution feature map, which is expressed as:
[0082] Conv i (I i ,D i )=DepthwiseConv2D(I i ,D i );
[0083] Where, Conv i (I i ,D i ) represents the result of depth convolution of the i-th channel, I i is the original feature map of the i-th input, and the size of the original feature map of the input is H×W×C i , H is the height, W is the width, C i is the i-th channel, D i is the depth convolution kernel corresponding to the i-th channel, DepthwiseConv2D() is the depth convolution function;
[0084] According to the result of the depth convolution, the convolution feature map corresponding to each channel is obtained by activating the ReLU6 activation function. The expression is:
[0085] D(I i )=ReLU6(Conv i (I i ,D i )).
[0086] like Figure 5 As shown, the attention unit in this embodiment includes global average pooling, a fully connected layer and an activation function, wherein the convolution feature map is input into the attention unit, and the global average pooling performs average pooling on each channel of the input convolution feature map to obtain a global information feature map; the expression is:
[0087] G=GlobalAvgPool(F)
[0088]
[0089] Where F∈R C×H′×W′ , H′ is the height of the convolution feature map, W′ is the width of the convolution feature map, F(x,y,c) represents the element of the xth row and yth column of the cth channel in the convolution feature map F, is the normalization factor;
[0090] The statistical information of each channel of the convolutional feature map is input into the fully connected layer and normalized using the Sigmoid activation function to obtain the final channel weight, which is expressed as:
[0091] γ=FC(G)
[0092] g(Y)=Sigmoid(MLP(GlobalAvgPool(y)))
[0093] Where g(γ) is the final channel weight, FC is the fully connected layer, γ is the scaling weight, and MLP stands for multi-layer perceptron.
[0094] Multiply the scaling weights by the convolution feature map channel by channel to obtain the recalibrated feature map, which is expressed as:
[0095] A eca =F⊙γ;
[0096] Where A eca is the recalibrated feature map, and ⊙ represents element-wise multiplication.
[0097] It should be noted that since grouped convolution brings a relatively small number of parameters, it will also affect the accuracy of the model. To address this problem, this embodiment introduces an attention unit to improve the expressiveness of the model. The attention unit omits the dimensionality reduction step and effectively realizes cross-channel information exchange, thereby improving the accuracy of the model. By fusing grouped convolution and the attention mechanism, a grouped convolution model that integrates an efficient channel attention mechanism is proposed.
[0098] like Figure 6 As shown, the expression of the grouped convolution layer in this embodiment is:
[0099] G conv (A eca )=GroupConv2D(A eca ,G g ,groups)
[0100] In the formula, GroupConv2D() is the group convolution function, G g It is the group convolution kernel, and groups is the number of groups.
[0101] It should be noted that grouped convolution is used to further extract features while reducing the complexity of the model. Then, the channels of the feature map are rearranged to optimize the representation of the features. A global adaptive statistical operation is performed on the mapped features to obtain global context information. Then, a learnable scaling factor is used to adjust the importance of the global context information. Finally, the adjusted context information is element-wise multiplied with the original feature map to obtain a feature map weighted by channel attention. The global average pooling layer reduces the dimension of the target feature map and inputs it to the fully connected layer. The fully connected layer outputs the classification result of the mushroom image.
[0102] In this embodiment, in order to address the problem that the number of parameters introduced by point-by-point convolution during dimensionality reduction is relatively large, grouped convolution is used to replace point-by-point convolution in this embodiment, thereby making the network lighter. However, there is no connection between different groups of grouped convolution, and the obtained feature map is only related to the input of the corresponding group. Therefore, in order to address the problem that the channels between groups of grouped convolution are independent of each other, this embodiment uses a channel rearrangement operation to realize information flow between feature channels and enhance the expressive power of the model.
[0103] It can be understood that through the stacking of multiple deep feature extraction modules, the model can gradually extract and enhance image features and improve classification accuracy; through deep convolution units, attention units, grouped convolution units, channel rearrangement units, splicing units and pooling units, the model can learn more complex and comprehensive features; and through the processing of global average pooling layers and fully connected layers, the model can output the classification results of mushroom images, which not only improves the performance of the model, but also maintains relatively low computational complexity and model size, enabling the model to run efficiently on resource-constrained devices, thereby improving the efficiency and robustness of the network model.
[0104] S3, initializing the mushroom recognition model parameters, inputting the standard image into the mushroom recognition model for training, and iteratively optimizing the model parameters to obtain the final mushroom recognition model;
[0105] Wherein, step S3 includes the following sub-steps:
[0106] Randomly initialize the mushroom recognition model parameters and define the loss function;
[0107] Input the standard image into the mushroom recognition model for forward propagation and calculate the prediction result;
[0108] According to the prediction results and the true label, the loss value is calculated using the loss function;
[0109] According to the loss value, the gradient of each layer in the mushroom recognition model is calculated through the back propagation algorithm, and the optimizer is used to update the parameters of the model according to the gradient. The expression is:
[0110]
[0111] Where g t is the gradient at time t; is the first-order moment estimate of the gradient; f t () is the objective function; v t is the second moment estimate of the gradient; It is v t Bias correction; It is m t β1 is the momentum hyperparameter; β2 is the RMSProp hyperparameter; θ is the solution parameter; θ t is the parameter of the tth iteration, a is the learning rate, and ε is a small constant; is the momentum hyperparameter at time t; is the RMSProp hyperparameter at time t.
[0112] It should be noted that adaptively adjusting the learning rate of each parameter based on the Adam algorithm helps the network escape from the local minimum and get closer to the global minimum, thereby improving the accuracy of the model.
[0113] S4, inputting the mushroom image to be classified into the final mushroom recognition model to obtain the classification result.
[0114] Specifically, in this embodiment, the standard convolution layer uses 32 3x3 convolution kernels, the network input image size is uniformly set to 224*224, and the batch_size of the single input image in the training process and the test process is set to 128; the learning rate of the model is 0.005, the number of iterations is 100, and the Adam optimization algorithm is used to adaptively adjust the learning rate. The standard convolution layer is used to capture the local features of the image. The original number of channels of the input standard image is 3, corresponding to the RGB three color channels of the color image; the standard convolution layer expands the number of channels from 3 to 32; the stride is 2, each The convolution kernel slides on the input image and generates a feature map through weight multiplication and bias addition operations; therefore, the initial convolution layer will produce 32 original feature maps, which are sequentially passed through the depth convolution unit, attention unit, grouped convolution unit, channel rearrangement unit, splicing unit and pooling unit. The depth convolution kernel in the depth convolution unit is 3x3 with a stride of 2. This operation is repeated 19 times in the depth feature extraction module. The target feature map output by the last pooling unit is input into the global pooling layer to reduce the dimension and then input into the fully connected layer, so that the fully connected layer outputs the classification result corresponding to the mushroom image.
[0115] It should be noted that the classification is at the end of the entire network and is mainly responsible for converting the intermediate representation within the network into the final classification decision. This module consists of two parts: a fully connected layer and a softmax activation function. The fully connected layer has 1280 neurons, and its function is to flatten the feature matrix after a series of convolution and pooling operations to generate a feature vector with a dimension of (1, 1280). Table 1 below shows the parameters used and the input and output of each layer of the model.
[0116] Table 1
[0117] Serial number Reduction ratio Output dimension stride length Number of repetitions Input Dimension operate 1 - 112×112×32 2 1 224×224×3 Conv2D3×3 2 2 56×56×96 2 1 112×112×32 SGEBlock 3 6 56×56×144 1 1 56×56×96 SGEBlock 4 6 28×28×192 2 3 56×56×144 SGEBlock 5 6 14×14×288 2 3 28×28×192 SGEBlock 6 6 14×14×384 1 4 14×14×288 SGEBlock 7 6 7×7×576 2 4 14×14×384 SGEBlock 8 6 7×7×960 1 2 7×7×576 SGEBlock 9 6 7×7×1280 1 1 7×7×960 SGEBlock 10 - 1×1×1280 - 1 7×7×1280 AvgPool7×7 11 - Number of categories - 1 1×1×1280 Conv2D1×1
[0118] Table 2 shows the accuracy of the model on the mushroom dataset:
[0119] Table 2
[0120]
[0121] According to the above table, the mushroom image classification model in this embodiment is ahead of other lightweight networks in terms of parameter quantity and inference speed.
[0122] In a second aspect, a mushroom image classification system based on a lightweight network in this embodiment is implemented using the aforementioned mushroom image classification method based on a lightweight network, and the system includes:
[0123] A preprocessing module is used to obtain a training set of mushroom images, calibrate and preprocess the mushroom images in the training set, and obtain standard images;
[0124] A model construction module is used to construct a mushroom recognition model. The mushroom recognition model includes a standard convolution layer, multiple deep feature extraction modules, a global average pooling layer, and a fully connected layer. The standard image is input into the standard convolution layer, which expands the channels of the input standard image to obtain an original feature map. The multiple deep feature extraction modules are sequentially connected end to end to perform deep feature extraction on the original feature map to obtain a target feature map. The global average pooling layer reduces the dimension of the target feature map and inputs it into the fully connected layer, which outputs the classification result of the mushroom image.
[0125] The model training module is used to initialize the parameters of the mushroom recognition model, input standard images into the mushroom recognition model for training, and iteratively optimize the model parameters to obtain the final mushroom recognition model;
[0126] The input recognition module is used to input the mushroom image to be classified into the final mushroom recognition model to obtain the classification result.
[0127] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A mushroom image classification method based on lightweight network, characterized in that: The method comprises the following steps: S1, obtaining a training set of mushroom images, calibrating and preprocessing the mushroom images in the training set to obtain standard images; S2, constructing a mushroom recognition model, the mushroom recognition model includes a standard convolution layer, multiple deep feature extraction modules, a global average pooling layer and a fully connected layer, inputting a standard image into the standard convolution layer, the standard convolution layer expands the channel of the input standard image to obtain an original feature map; multiple deep feature extraction modules are sequentially connected end to end, deep feature extraction is performed on the original feature map to obtain a target feature map; the global average pooling layer reduces the dimension of the target feature map and inputs it into the fully connected layer, and the fully connected layer outputs the classification result of the mushroom image; S3, initializing the mushroom recognition model parameters, inputting the standard image into the mushroom recognition model for training, and iteratively optimizing the model parameters to obtain the final mushroom recognition model; S4, inputting the mushroom image to be classified into the final mushroom recognition model to obtain the classification result.
2. The mushroom image classification method based on lightweight network as claimed in claim 1, characterized in that: The step S1 includes obtaining a training set of mushroom images, calibrating and preprocessing the mushroom images in the training set, and obtaining a standard image, which includes the following sub-steps: S11, obtaining a training set of mushroom images, screening the mushroom images in the training set, and eliminating defective and repeated images; S12, performing format conversion and size adjustment and scaling on the filtered mushroom images to be consistent, so as to obtain a unified mushroom image; S13, calibrating and classifying the unified mushroom images in the training set according to the classification feature information of the mushrooms, to obtain feature sets of mushroom images of different types; S14, performing data enhancement on mushroom images in mushroom image feature sets corresponding to various categories to obtain standard images.
3. The mushroom image classification method based on lightweight network as claimed in claim 2, characterized in that: The mushroom recognition model in step S2 includes a standard convolution layer, multiple deep feature extraction modules, a global average pooling layer and a fully connected layer, wherein the multiple deep feature extraction modules are connected head to tail in sequence, the output end of the standard convolution layer is connected to the input end of the deep feature extraction module at the head end, the input end of the global average pooling layer is connected to the output end of the deep feature extraction module at the tail end, the output end of the global average pooling layer is connected to the input end of the fully connected layer, and the classification result corresponding to the mushroom image is output.
4. The mushroom image classification method based on lightweight network as claimed in claim 3 is characterized in that: The standard convolution layer expands the channels of the input standard image to obtain the original feature map, wherein the standard convolution layer includes 32 3x3 convolution kernels, the standard convolution layer expands the number of channels of the standard image to 32, and extracts the edge, texture and shape of the standard image. Each convolution kernel slides on the input standard image, and performs weight multiplication and bias addition operations at each position to generate the corresponding original feature map. The expression is: In the formula, I i is the i-th output original feature map, i∈[1, C out ], C out is the number of output channels, f() is the RELU activation function, M j is the jth channel of the input standard image, i∈[1, C in ], C in is the original number of channels, K i,j is the convolution kernel on the jth input channel corresponding to the i-th output original feature map, B i is the bias term of the i-th output original feature map, is the convolution operation.
5. The mushroom image classification method based on lightweight network as claimed in claim 4, characterized in that: Each of the deep feature extraction modules includes a deep convolution unit, an attention unit, a grouped convolution unit, a channel rearrangement unit, a splicing unit and a pooling unit connected in sequence, wherein the deep convolution unit performs deep feature extraction on the input original feature map to generate a corresponding convolution feature map; the attention unit performs feature recalibration on the input convolution feature map to generate a corresponding recalibrated feature map; the grouped convolution unit groups the feature channels, performs convolution extraction on the recalibrated feature map by group, and obtains a grouped feature map; the channel rearrangement unit rearranges each grouped feature map in the channel dimension to obtain a reorganized feature map; the splicing unit splices and fuses each reorganized feature map, and inputs the spliced and fused feature map into the pooling layer to obtain a target feature map.
6. The mushroom image classification method based on lightweight network as claimed in claim 5, characterized in that: The deep convolution unit performs deep feature extraction on the input original feature map to generate a corresponding convolution feature map, wherein each convolution kernel slides on the input standard image and performs weight multiplication and bias addition operations at each position to generate a corresponding convolution feature map, which is expressed as: Conv i (I i ,D i )=DepthwiseConv2D(I i ,D i ); In the formula, Conv i (I i ,D i ) represents the result of the i-th channel after the depth convolution, I i is the original feature map of the i-th input, and the size of the original feature map of the input is H×W×C i , H is the height, W is the width, C i is the ith channel, D i is the depth convolution kernel corresponding to the i-th channel, DepthwiseConv2D() is the depth convolution function; According to the result of deep convolution, the convolution feature map corresponding to each channel is obtained by activating the ReLU6 activation function. The expression is: D(I i )=ReLU6(Conv i (I i ,D i ))。 7. The mushroom image classification method based on lightweight network as claimed in claim 6, characterized in that: The attention unit includes a global average pooling, a fully connected layer and an activation function, where: The convolution feature map is input into the attention unit, and the global average pooling performs average pooling on each channel of the input convolution feature map to obtain the global information feature map; the expression is: G = GlobalAvgPool (F) Where F∈R C× H′× W ′, H′ is the height of the convolution feature map, W′ is the width of the convolution feature map, F(x,y,c) represents the element of the xth row and yth column of the cth channel in the convolution feature map F, is the normalization factor; The statistical information of each channel of the convolutional feature map is input into the fully connected layer and normalized using the Sigmoid activation function to obtain the final channel weight, which is expressed as: γ=FC(G) g(γ)=Sigmoid(MLP(GlobalAvgPool(γ))) Where g(γ) is the final channel weight, FC is the fully connected layer, γ is the scaling weight, and MLP stands for multi-layer perceptron; Multiply the scaling weights by the convolution feature map channel by channel to obtain the recalibrated feature map, which is expressed as: A eca =F⊙γ; In the formula, A eca is the recalibrated feature map, and ⊙ represents element-by-element multiplication.
8. The mushroom image classification method based on lightweight network as claimed in claim 7, characterized in that: The expression of the grouped convolutional layer is: G conv (A eca )=GroupConv2D(A eca ,G g ,groups) In the formula, GroupConv2D() is the group convolution function, G g It is the grouped convolution kernel, and groups is the number of groups.
9. The mushroom image classification method based on lightweight network as claimed in claim 1, characterized in that: Initializing the mushroom recognition model parameters in step S3, inputting the standard image into the mushroom recognition model for training, and iteratively optimizing the model parameters to obtain the final mushroom recognition model includes the following sub-steps: Randomly initialize the mushroom recognition model parameters and define the loss function; Input the standard image into the mushroom recognition model for forward propagation and calculate the prediction result; According to the prediction results and the true labels, the loss value is calculated using the loss function; According to the loss value, the gradient of each layer in the mushroom recognition model is calculated by the back propagation algorithm, and the optimizer is used to update the parameters of the model according to the gradient. The expression is: Where gt is the gradient at time t; is the first-order moment estimate of the gradient; ft() is the objective function; vt is the second-order moment estimate of the gradient; Yes t Bias correction; is m t is the bias correction of ; β1 is the momentum hyperparameter; β2 is the RMSProp hyperparameter; θ is the solution parameter; θ t is the parameter of the tth iteration, a is the learning rate, is a small constant; is the momentum hyperparameter at time t; is the RMSProp hyperparameter at time t.
10. A mushroom image classification system based on a lightweight network, implemented by the mushroom image classification method based on a lightweight network according to any one of claims 1 to 9, characterized in that: The system comprises: A preprocessing module is used to obtain a training set of mushroom images, calibrate and preprocess the mushroom images in the training set, and obtain a standard image; A model building module is used to build a mushroom recognition model, which includes a standard convolution layer, multiple deep feature extraction modules, a global average pooling layer and a fully connected layer. The standard image is input into the standard convolution layer, and the standard convolution layer expands the channel of the input standard image to obtain an original feature map; the multiple deep feature extraction modules are sequentially connected end to end to perform deep feature extraction on the original feature map to obtain a target feature map; the global average pooling layer reduces the dimension of the target feature map and inputs it into the fully connected layer, and the fully connected layer outputs the classification result of the mushroom image; The model training module is used to initialize the parameters of the mushroom recognition model, input the standard image into the mushroom recognition model for training, and iteratively optimize the model parameters to obtain the final mushroom recognition model; The input recognition module is used to input the mushroom image to be classified into the final mushroom recognition model to obtain the classification result.
Citation Information
Patent Citations
Image classification method and image classification system
CN116403047A
Cited By
Image registration method based on homography estimation of lightweight model
CN120259391A