A lightweight gas classification method based on electronic nose device
By building teacher and student models, combining stratified direct distillation and graph embedded distillation technology, the electronic nasal gas classification model is optimized, and the problems of large size and low accuracy of the model are solved, achieving application and accuracy improvement on portable devices.
Patent Information
- Application Number
- CN202310768453.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-27
- Publication Date
- 2025-08-08
- Estimated Expiration
- 2043-06-27
AI Technical Summary
The existing electronic nasal gas classification model is large in size and cannot be equipped with portable equipment. The manual feature selection flexibility is poor, so it cannot adapt to different working environments.
The lightweight gas classification method based on electronic nose equipment is adopted, and by constructing teacher models and student models, combining stratified direct distillation and graph embedded distillation technology, the model structure is optimized, multi-channel feature extraction is performed, the model volume is reduced, and the classification accuracy is maintained.
On the basis of maintaining classification accuracy, the model volume is greatly compressed to adapt to portable equipment, to various working environments, and to improve classification accuracy.
Smart Images

Figure CN116992358B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of electronic noses, and in particular to a lightweight gas classification method based on electronic nose gas equipment. Background Art
[0002] Electronic nose technology, a device combining a sensor array with a classification algorithm, is typically used in scenarios requiring rapid and accurate gas classification. For example, in the aftermath of an earthquake or fire, where physical access to hazardous areas is difficult, unmanned devices carrying electronic noses can be deployed to rapidly detect gases and determine if there are any survivors. The electronic nose's applications extend beyond this, with potential applications in areas such as food safety classification. Numerous researchers have experimented with this device to improve its classification accuracy.
[0003] Existing technologies typically use feature-based classification methods and deep learning-based classification methods to achieve gas classification using electronic noses. However, these technologies require manual feature selection, are inflexible, and cannot adapt to different actual situations. Summary of the Invention
[0004] The present invention provides a lightweight gas classification method based on an electronic nose device, which solves the problem in the prior art that manual feature selection is required and is greatly affected by the working environment. It then realizes multi-channel feature capture of the gas, thereby improving the classification accuracy. While maintaining the original accuracy, the volume of the model is reduced so that it can be carried on smaller equipment and adapt to different working environments.
[0005] The present invention provides a lightweight gas classification method based on an electronic nose device, the method comprising:
[0006] Acquiring initial gas data of the gas, and preprocessing the gas data to obtain image data;
[0007] The teacher model specifically includes a sensor association module, a temporal attention module, a channel attention module and a fully connected module connected in sequence; the sensor association module is used to perform sensor-dimensional feature extraction on the image data through different constructed sensor combinations to obtain multiple feature map matrices, and superimpose the multiple feature map matrices to obtain a first feature map matrix; the temporal attention module is used to perform temporal-dimensional feature extraction on the image data to obtain a first weight feature map matrix; the channel attention module is used to perform channel-dimensional feature extraction on the second feature map matrix to obtain a second weight feature map matrix, wherein the first feature map matrix is superimposed on the first weight feature map matrix to obtain the second feature map matrix; the fully connected module is used to calculate the probability vector of the second weight feature map matrix to obtain the probability distribution matrix of the image data;
[0008] The image data is input into the optimization model to obtain a probability distribution matrix; wherein obtaining the optimization model includes performing model optimization according to hierarchical direct distillation and graph embedding distillation, specifically including: constructing a teacher model and a student model, replacing each channel attention layer in the student model with each channel attention layer in the corresponding teacher model to obtain a hybrid model; performing hierarchical direct distillation on the hybrid model to obtain a hybrid model after hierarchical direct distillation, and synchronizing each channel attention layer of the hybrid model after hierarchical direct distillation to a corresponding position of the student model until all the channel attention layers in the student model are replaced to obtain a student model, completing the preliminary model compression of the classification model, and using the student model as a compressed model; calculating the probability matrix of the compressed model and the probability matrix of the teacher model; constructing a distance matrix of the compressed classification model, and constructing a teacher distance matrix of the teacher model; calculating the distance between the compressed distance matrix and the teacher distance matrix, calculating the graph embedding distillation loss of the compressed classification model based on the distance, and performing refinement training to obtain a refined student model, that is, obtaining the optimization model;
[0009] According to the maximum value in the probability distribution matrix, the gas category corresponding to the probability distribution matrix is obtained.
[0010] In a possible implementation, the sensor association module includes multiple parallel dilated convolution modules, and the dilated convolution modules all have different dilated rates.
[0011] The different sensor combinations constructed are used to capture multi-dimensional information of the image data to obtain multiple feature map matrices, including:
[0012] copying a plurality of copies of the image data;
[0013] Multiple copies of the image data are respectively input into the multiple parallel void convolution modules, each of the void convolution modules performs feature extraction on the information of the multiple sensor combinations of the received image data, and each of the void convolution modules outputs the feature map matrix accordingly.
[0014] In one possible implementation, the temporal attention module includes a first residual attention module, which includes a plurality of convolutional layers, a first fully connected layer, a global pooling layer, a second fully connected layer, a third fully connected layer, and a first activation function layer connected in sequence;
[0015] The performing a dimension transformation operation on the image data to obtain a first weight feature map matrix includes:
[0016] Performing a convolution operation on the image data using the multiple convolutional layers to obtain a first intermediate feature map matrix;
[0017] Using the first fully connected layer to transform the dimension of the first intermediate feature map matrix to obtain a first dimension-transformed feature map matrix;
[0018] Performing global pooling on the first dimension change feature map matrix using the global pooling layer to obtain a pooled feature map matrix;
[0019] Using the second fully connected layer to perform a dimensionality reduction operation on the pooled feature map matrix to obtain a second-dimensional change feature map matrix;
[0020] Using the third fully connected layer to perform a dimensionality increase operation on the second-dimensional change feature map matrix to obtain a third-dimensional change feature map matrix;
[0021] The first activation function layer is used to multiply the third-dimensional change feature map matrix and the image data to obtain the first weight feature map matrix.
[0022] In a possible implementation, the channel attention module includes a plurality of channel attention layers connected in sequence, and the number of second residual modules in all the channel attention layers is different;
[0023] The second residual module includes a plurality of convolutional layers, a fourth fully connected layer, a fifth fully connected layer and a second activation function layer connected in sequence;
[0024] The globally pooling of the second feature map matrix to obtain a second weighted feature map matrix includes:
[0025] Performing a convolution operation on the second feature map matrix using the multiple convolutional layers to obtain a second intermediate feature map matrix;
[0026] Performing a dimensionality reduction operation on the second intermediate feature map matrix using the fourth fully connected layer to obtain a third-dimensional change feature map matrix;
[0027] Then, using the fifth fully connected layer, a dimensionality increase operation is performed on the third-dimensional change feature map matrix to obtain a fourth-dimensional change feature map matrix;
[0028] The second activation function layer is then used to multiply the fourth-dimensional change feature map matrix and the second feature map matrix to obtain the first weight feature map matrix.
[0029] In one possible implementation, the fully connected module includes a plurality of neurons connected in sequence;
[0030] The calculating the probability vector of the second weight feature map matrix to obtain the probability distribution matrix of the image data includes:
[0031] Mapping the second weighted feature map matrix into a probability vector having the same dimension as the corresponding gas category using the multiple neurons;
[0032] The probability distribution of the probability vector is calculated using a softmax function to obtain a probability distribution matrix of the image data.
[0033] In one possible implementation, the training method of the optimization model includes:
[0034] Processing the plurality of sample data to obtain a plurality of sample image data;
[0035] The optimization model is trained according to the plurality of sample image data to converge the objective function and obtain a trained optimization model.
[0036] In a possible implementation, the objective function is expressed as:
[0037]
[0038] Among them, N represents the number of samples, pi represents the sample probability vector, and y i is represented as the true label.
[0039] In one possible implementation,
[0040] The step of performing layered direct distillation on the mixed model to obtain a mixed model after layered direct distillation comprises:
[0041] The student model is determined by increasing or decreasing the number of second residual modules in the channel attention layer of each of the channel attention modules.
[0042] One or more technical solutions provided in the present invention have at least the following technical effects or advantages:
[0043] The present invention adopts a lightweight gas classification method based on an electronic nose device, which includes: obtaining initial gas data of the gas, preprocessing the gas data to obtain image data, and converting the invisible gas into a visible image for image analysis, so as to more intuitively process the classified gas; inputting the image data into an optimization model to obtain a probability distribution matrix; wherein obtaining the optimization model includes model optimization according to hierarchical direct distillation and graph embedding distillation, and adopting these two methods to optimize the existing model can reduce the size of the model without significantly reducing the accuracy; specifically including: constructing a teacher model and a student model, and replacing each channel attention layer in the student model with each channel attention layer in the corresponding teacher model to obtain a hybrid model; the channel attention layer of the student model has fewer residual modules than the channel attention layer of the teacher model, and changing the number of residual modules will not have a particularly large impact on the accuracy, and the size of the teacher model is reduced; hierarchical direct distillation is performed on the hybrid model, and the image data is converted into a visible image for image analysis, so as to more intuitively process the classified gas; Then distillation is performed to obtain a hybrid model after hierarchical direct distillation, and each channel attention layer of the hybrid model after hierarchical direct distillation is synchronized to the corresponding position of the student model until all channel attention layers in the student model are replaced to obtain the student model, complete the preliminary model compression of the classification model, and use the student model as the compression model; calculate the probability matrix of the compression model and the probability matrix of the teacher model; hierarchical distillation is used for the sensor dimension and time dimension and the final fully connected layer part to maintain the classification accuracy of the teacher model unchanged and reduce the volume of the teacher model; construct the distance matrix of the compressed classification model and the teacher distance matrix of the teacher model; calculate the distance between the compression distance matrix and the teacher distance matrix, calculate the graph embedding distillation loss of the compressed classification model based on the distance, and perform refinement training to obtain the refined student model, that is, the optimized model, and construct their respective distance matrices according to the probability matrices of the outputs of the student model and the teacher model. Each value in the distance matrix is the Euclidean distance between two samples. The distance between the two matrices is calculated and added to the distillation loss to compensate for the reduction in accuracy due to layered direct distillation. This effectively solves the problem of large classification models contained in existing technologies, such as direct compression models, which will significantly reduce classification accuracy. Feature extraction is performed from three dimensions: sensor, timing, and channel, to further improve classification accuracy. It achieves a significant compression of the model size while effectively maintaining classification accuracy, allowing the classification model to be carried on portable devices, thus adapting to working environments in various real-world scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] 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 of the present invention or the description of the prior art. Obviously, the drawings described below are 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.
[0045] Figure 1 A flowchart of the steps of compressing a model based on an existing model provided by the present invention;
[0046] Figure 2 A flow chart of the steps for obtaining multiple feature map matrices in the sensor combination module provided by the present invention;
[0047] Figure 3 A flowchart of the steps of performing a dimensionality transformation operation on image data to obtain a first weighted feature map matrix in obtaining multiple feature map matrices provided by the present invention;
[0048] Figure 4 A flowchart of the steps of performing global pooling on the second feature map matrix to obtain the second weighted feature map matrix in the road attention module provided by the present invention;
[0049] Figure 5 A flowchart of the steps of calculating the probability vector of the second weighted feature map matrix in the fully connected module provided by the present invention to obtain the probability distribution matrix of the image data;
[0050] Figure 6 This is a flow chart of the steps for training the classification model provided by the present invention. DETAILED DESCRIPTION
[0051] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making any creative efforts are within the scope of protection of the present invention.
[0052] Existing electronic nose-based gas classification models are bulky and cannot be incorporated into portable gas detection devices such as electronic noses, limiting their flexibility and versatility in practical applications. Using conventional compression techniques would also reduce the model's classification accuracy. Therefore, the present invention addresses the following issues: how to accommodate large models in portable electronic nose devices and how to compress the model while maintaining classification accuracy.
[0053] In academic research, implementations of feature-based and deep learning-based classification methods include the following: Huichun Yu used Fisher discriminant analysis to classify the origins of six types of liquor; Vera Schroeder used K-nearest neighbor (KNN) and RF to distinguish volatile gases produced by different foods, exploring the feasibility of electronic noses in food inspection. When the dimensionality of the original data is too high, principal component analysis (PCA) and linear discriminant analysis (LDA) are used for dimensionality reduction. For example, Jordan Voss used PCA+SVM to determine whether peaches in an orchard were ready for harvest, thereby reducing the economic losses caused by farmers' mistaken picking; Ali Amkor used PCA+KNN to determine whether mint in a mint garden had been sprayed with pesticides; Yan Shi used convolutional neural networks (CNNs) and support vector machines to classify various beers, demonstrating that CNNs outperformed feature-based classification algorithms in terms of classification accuracy across multiple metrics; and Xiaofang Pan combined attention mechanisms with recurrent neural networks to extract potential temporal information from response values, which were then classified using CNNs.
[0054] Chongqing University of Posts and Telecommunications has disclosed a classification method based on feature-based adaptive feature selection in its patent application, "An Electronic Nose Array Optimization Method for Adaptive Feature Selection" (Patent Application Number: CN202210607576.9, Patent Publication Number: CN115168792A). This method continuously calculates the correlation, redundancy, and other indicators between each feature and the data sample, and selects the features with the highest evaluation scores to add to the feature subset, thereby selecting the features that contribute most to the classification. Finally, machine learning methods can be used to classify the selected features to obtain the final gas classification results. This method manually extracts features and cannot automatically capture potential information from the data.
[0055] Beijing Technology and Business University disclosed a method for electronic nose gas classification based on a traditional convolutional neural network algorithm in its patent application, "A method for identifying mixed gases based on a convolutional neural network algorithm." This method maps the original data into image-formatted data and then uses a residual network to perform gas classification. This method is based on the classification advantages of convolutional neural networks and is applied to the field of electronic nose gas classification of gas data. It uses the automatic feature extraction mechanism of the convolutional neural network's convolution kernel to capture deep, more comprehensive potential features in the gas data, with faster inference speed and higher accuracy. This method relies on the automatic feature extraction mechanism of the convolutional neural network and cannot significantly outperform classification algorithms based on feature extraction in terms of classification accuracy; large models are also difficult to be installed on real portable devices.
[0056] The present invention provides a lightweight gas classification method based on an electronic nose device, which includes the following steps S101 to S103.
[0057] S101, acquiring initial gas data of the gas, and preprocessing the gas data to obtain image data.
[0058] Specifically, the raw data is sampled at equal intervals, with the sampled data sharing the same greatest common multiple as the number of sensors. For an 8-sensor system, 32 data points can be sampled and laid out four times on the sensor scale, resulting in a 32x32 pixel size. The sampled data is normalized and mapped to standard RGB values, converting it into image data. This image data is referred to as image data.
[0059] In a specific embodiment provided by the present invention, the raw data is gas time series data collected by a group of sensors, and its specific format is: N*D*T. N is the number of samples in the group of data, D is the number of sensors in each test, and T is the total sampling time.
[0060] For example, if CO gas is placed in 10 sensors for 400 seconds and the sampling frequency is 1 Hz, 1*10*400 dimensional data can be collected.
[0061] To sample the timestamps, we sample 40 data points at equal intervals (e.g., 10 seconds apart) from the 400-dimensional space in the example above. This means that 1*10*400 becomes 1*10*40. This is a standard sampling method for this type of task.
[0062] Finally, we insert one more dimension, N*C*D*T. This is the dimension required to process image data, i.e., the number of channels. At this point, the initial number of channels for each sample is 1, i.e., C = 1.
[0063] Normalization uses "0-1 normalization" to map the data to (0, 1). The formula is: x normalized to: Here, x represents the data to be normalized; min represents the minimum value in the normalized dataset, and max represents the maximum value. Multiplying f by 255 maps the data to (0, 255), converting the original data into image data. This allows gas classification to be equivalent to image classification, transforming the unintuitive distinction between gases into intuitive images.
[0064] In a specific embodiment provided by the present invention, not only can the existing gas classification model based on deep learning be compressed, but the existing model can also be improved and then compressed. The existing model can be directly compressed by adopting step S102.
[0065] S102: Input the image data into the optimization model to obtain a probability distribution matrix.
[0066] Obtaining the optimized model in S102 includes performing model optimization according to hierarchical direct distillation and graph embedding distillation, specifically including: constructing a teacher model and a student model, replacing each channel attention layer in the student model with each channel attention layer in the corresponding teacher model to obtain a hybrid model; performing hierarchical direct distillation on the hybrid model to obtain a hybrid model after hierarchical direct distillation, and synchronizing each channel attention layer of the hybrid model after hierarchical direct distillation to the corresponding position of the student model until all channel attention layers in the student model are replaced to obtain a student model, completing the preliminary model compression of the classification model, and using the student model as the compressed model; calculating the probability matrix of the compressed model and the probability matrix of the teacher model; constructing the distance matrix of the compressed classification model, and constructing the teacher distance matrix of the teacher model; calculating the distance between the compressed distance matrix and the teacher distance matrix, calculating the graph embedding distillation loss of the compressed classification model based on the distance, and performing refinement training to obtain the refined student model, that is, the optimized model.
[0067] When improving an existing model, the existing model is optimized as a teacher model, and then the teacher model is optimized through layered direct distillation and graph embedding distillation. The teacher model specifically includes a sensor joint module, a temporal attention module, a channel attention module, and a fully connected module connected in sequence. The present invention provides a specific embodiment, such as Figure 1 As shown, the initial gas data is first preprocessed to obtain image data. The multi-channel feature extraction technology proposed in this application is used to extract features from the sensor dimension, timing dimension, and channel dimension. The multi-channel extracted data ensures that after the teacher model is compressed, the accuracy of the student model obtained only loses a part. When compressing the teacher model, hierarchical direct distillation and graph embedding distillation are used to obtain a lightweight student model, and the student model is used to classify the gas.
[0068] In another embodiment of the present invention, the existing model is improved and then compressed to classify the gas. The improved model is called a classification model, which includes a sensor combination module, a time sequence attention module, and a channel attention module.
[0069] The sensor combination module is used to capture multi-dimensional information of image data by constructing different sensor combinations, obtain multiple feature map matrices, and superimpose multiple feature map matrices to obtain a first feature map matrix. The sensor combination module includes multiple parallel void convolution modules, and the void ratios of all void convolution modules are different. By constructing different sensor combinations, the image data is captured in multiple dimensions to obtain multiple feature map matrices, such as Figure 2 As shown, step S102 includes steps S201 to S202.
[0070] S201, copying multiple copies of image data.
[0071] S202: Input multiple copies of image data into multiple parallel dilated convolution modules respectively. Each dilated convolution module captures multi-dimensional information of the received image data, and each dilated convolution module corresponds to an output feature map matrix.
[0072] In a specific embodiment provided by the invention, the classification model uses three dilated convolution kernels, each of which represents a sensor combination. If the convolution kernel size is 3 and the dilation ratio is 2, the potential information captured is the sensor combination consisting of the first, third, and fifth sensors in the original data.
[0073] In actual use, different sensors contribute differently to the electronic nose's gas classification. Different dilated convolution kernels specifically capture features of sensor-dimensional data. Using different dilated convolution kernels can extract deeper information, thereby improving the final classification accuracy.
[0074] The temporal attention module is used to perform a dimensionality transformation operation on the image data to obtain a first weighted feature map matrix. The temporal attention module includes a first residual attention module, which includes multiple convolutional layers, a first fully connected layer, a global pooling layer, a second fully connected layer, a third fully connected layer, and a first activation function layer connected in sequence.
[0075] Among them, the dimension transformation operation is performed on the image data to obtain the first weight feature map matrix, such as Figure 3 As shown, the process includes the following steps S301 to S306.
[0076] S301, using multiple convolutional layers to perform a convolution operation on the image data to obtain a first intermediate feature map matrix.
[0077] In a specific embodiment provided by the present invention, the temporal attention module includes three consecutive convolutional layers with depthwise separable convolutions of kernel sizes of 1, 3, and 1. The channel number before and after the convolution is 1. The number of neurons in the connection layer is the same as the size of the image data.
[0078] S302: Use the first fully connected layer to change the dimension of the first intermediate feature map matrix to obtain a first dimension-changed feature map matrix.
[0079] Specifically, after three consecutive convolutions, the first intermediate feature map matrix is obtained. The number of convolution kernels and the number of channels remain unchanged. When the first dimension is changed, the first intermediate feature map matrix changes from N*C*D*T to the first dimension change feature map matrix N*T*D*C.
[0080] S303: Use a global pooling layer to globally pool the first dimension change feature map matrix to obtain a pooled feature map matrix.
[0081] Specifically, the dimension of the pooled feature map matrix generated after global pooling is N*T*1.
[0082] S304: Use the second fully connected layer to perform a dimensionality reduction operation on the pooled feature map matrix to obtain a second-dimensional change feature map matrix.
[0083] Specifically, when performing this step, the first dimension change feature map matrix is transformed so that its dimension is reduced to 1 / 4*T.
[0084] S305: Use the third fully connected layer to perform a dimensionality increase operation on the second-dimensional change feature map matrix to obtain a third-dimensional change feature map matrix.
[0085] Specifically, when performing this step, the dimension of the second-dimensional change feature map matrix is restored to the original matrix dimension.
[0086] S306: Multiply the third-dimensional change feature map matrix and the image data using the first activation function layer to obtain a first weight feature map matrix.
[0087] The temporal attention module can capture the parts of each sample data that are more beneficial to the classification task, and distribute the weights in step S306, giving greater weights to the beneficial parts to improve the classification accuracy.
[0088] The channel attention module is used to extract features from the channel dimension of the second feature map matrix to obtain a second weighted feature map matrix, where the first feature map matrix is superimposed on the first weighted feature map matrix to obtain the second feature map matrix. The fully connected module is used to calculate the probability vector of the second weighted feature map matrix to obtain the probability distribution matrix of the image data. The channel attention module includes multiple channel attention layers connected in sequence, and the number of second residual modules in all channel attention layers is different. The second residual module includes multiple convolutional layers, a fourth fully connected layer, a fifth fully connected layer, and a second activation function layer connected in sequence.
[0089] Perform global pooling on the second feature map matrix to obtain the second weight feature map matrix, such as Figure 4 As shown, the process includes the following steps S401 to S404.
[0090] S401: Perform a convolution operation on the second feature map matrix using multiple convolution layers to obtain a second intermediate feature map matrix.
[0091] In a specific embodiment provided by the present invention, the number of second residual modules in the three convolutional layers is 3, 4, 6, and 3, respectively, to form a model with a total depth of 50. The number of channels of the output of each layer is: 256, 512, 1024, and 2048. The input of the channel attention module is a feature map with 4 channels.
[0092] S402: Use the fourth fully connected layer to perform a dimensionality reduction operation on the second intermediate feature map matrix to obtain a third-dimensional change feature map matrix.
[0093] S403: Use the fifth fully connected layer to perform a dimensionality increase operation on the third-dimensional change feature map matrix to obtain a fourth-dimensional change feature map matrix.
[0094] S404: Multiply the fourth-dimensional change feature map matrix and the second feature map matrix by the second activation function layer to obtain a first weight feature map matrix.
[0095] The channel attention module has four layers. It is unidirectional. After the first layer, the number of channels increases to 256, and so on. In this step, the channel attention module does not perform dimensionality conversion but directly performs a series of operations on N*C*D*T to capture the potential weights of the channel dimensions, thereby capturing black-box knowledge and improving classification accuracy.
[0096] In a specific embodiment provided by the present invention, the depth is 50, but it does not have to be 50. The total depth is determined by the number of second residual modules contained in each layer of the channel attention module. Various depths can be combined according to different practical applications. The depths adopted by the present invention are 18 and 50, and the model with a depth of 18 is actually used. Adjustment basis: The depth of the deep learning model will determine the overall size of the model. Therefore, the overall depth can be adaptively adjusted according to the needs of the actual application. If a high-precision model is required and the device can accommodate a large model, it can be stacked deep, and 104 layers are also acceptable. However, there is always a threshold for accuracy, so a reasonable choice of depth is something that needs to be considered in practical applications.
[0097] The fully connected module is used to calculate the probability vector of the second weight feature map matrix to obtain the probability distribution matrix of the image data. The fully connected module includes multiple neurons connected in sequence.
[0098] Among them, the probability vector of the second weight feature map matrix is calculated to obtain the probability distribution matrix of the image data, such as Figure 5 As shown, the process includes the following steps S501 to S502.
[0099] S501, using multiple neurons to map the second weight feature map matrix into a probability vector with the same dimension as the corresponding gas category.
[0100] Specifically, the fully connected module sets the number of neurons to 4096 and maps the input second weight feature map matrix to a probability vector with the same dimension as the number of corresponding gas categories.
[0101] S502 , using a softmax function to perform probability distribution calculation on the probability vector to obtain a probability distribution matrix of the image data.
[0102] Specifically, a softmax function is connected to calculate the probability distribution. The output value of the channel attention module is 2048-dimensional data, with the data dimensions N*C*D*T (N is the number of samples and remains constant. D and T are constantly changing during the convolution process, and the final values of D and T are much smaller than the original values, and the value of C is 2048).
[0103] The N*C*D*T data is converted to N*C (C=2048), then a fully connected layer is used to reduce it to N*C (C=4096). Finally, another fully connected layer is used to reduce it to N*C. The value of C varies depending on the type of gas to be classified. Ultimately, we get an output of N*C, where C is the type of gas to be classified, which is a probability vector.
[0104] In a specific embodiment provided by the present invention, Figure 6 As shown, training the classification model includes the following steps S601 to S602.
[0105] S601: Process a plurality of sample data to obtain a plurality of sample image data.
[0106] S602: Train the classification model based on multiple sample image data to converge the objective function and obtain a trained classification model. The objective function is expressed as:
[0107]
[0108] Among them, N represents the number of samples, pi represents the sample probability vector, and y i is represented as the true label.
[0109] In step S102 , the image data is input into the optimization model to obtain the probability distribution matrix, which specifically includes the following steps S701 to S705 .
[0110] S701, construct a teacher model and a student model. When compressing an existing model, the teacher model is the existing model. When compressing a classification model, the teacher model is the classification model. Each channel attention layer in the student model is replaced by each channel attention layer in the corresponding teacher model to obtain a hybrid model. The parts used for the sensor and time dimensions and the final fully connected layer in the hybrid model will maintain the parts of the teacher model unchanged, increase or decrease the number of second residual modules in the channel attention layer of each channel attention module, and determine the hybrid model. Construct a small model with the number of second residual modules in the channel attention module being 2, 2, 2, and 2 respectively, let it be the initial student model, and train it. In S102, the number of second residual modules in the channel attention layer of the optimized model is 3, 4, 6, and 3 respectively, and the model trained in S102 is used as the teacher model.
[0111] S702: Perform layer-by-layer direct distillation on the hybrid model to obtain a layer-by-layer direct distilled hybrid model. Each channel attention layer of the layer-by-layer direct distilled hybrid model is synchronized to the corresponding position in the student model until all channel attention layers in the student model are replaced. This completes the initial model compression of the classification model and uses the student model as the compressed model. Specifically, this includes sequentially replacing the corresponding parts of the teacher model with the second and third layers of the hybrid model and performing training. After training, the parameters of the corresponding parts of the hybrid model are loaded into the initial student model to obtain a compressed initial model.
[0112] S703, calculate the probability matrix of the compression model and the probability matrix of the teacher model, obtain the probability matrix of the compression model according to the compression model, and obtain the probability matrix of the classification model according to the teacher model.
[0113] S704: Construct a distance matrix for the compressed classification model and a teacher distance matrix for the teacher model. Each value in the distance matrix represents the Euclidean distance between the two matrices. Calculate the distance between the compressed distance matrix and the initial probability matrix. At this point, the N*C-dimensional probability matrix can be used to construct an N*N-dimensional distance matrix, where each value represents the distance between each two vectors.
[0114] S705, calculate the distance between the compression distance matrix and the teacher distance matrix, calculate the graph embedding distillation loss of the compression classification model based on the distance, and perform refinement training to obtain a refined student model, that is, an optimized model.
[0115] The model depth of the teacher model is 50, and the model depth of the compressed classification model is 18. The advantage of the teacher model is its large depth and high accuracy, but its disadvantage is its large size. The advantage of the compressed classification model is its small size, but its accuracy is also affected due to its reduced depth.
[0116] The goal of model compression is to ensure that the classification accuracy of the compressed classification model is as close to that of the teacher model as possible without changing its depth. Modifying the channel attention module can bridge the depth gap between large and small models, effectively improving classification accuracy and being easy to implement.
[0117] The model optimization provided in the invention is to further improve the classification accuracy of the compressed classification model while keeping the model size unchanged.
[0118] The model in this invention consists of a teacher model and a compressed classification model. When computing power is unlimited, the teacher model is selected. When computing power is low and high accuracy is required, the compressed classification model is selected. While maintaining the original accuracy, the model size is reduced to enable it to be installed on smaller devices and adapt to different working environments.
[0119] S103: Obtain the gas category corresponding to the probability distribution matrix based on the maximum value in the probability distribution matrix. The gas represented by the item with the largest value in the output result is the gas category to which the current sample belongs.
[0120] In terms of practicality, the method provided by this invention compresses the classification model to a smaller size, enabling the existing model to be effectively installed on real-world portable devices, even in confined environments, and offering high environmental adaptability. In terms of accuracy, the model proposed by this invention improves classification accuracy over existing technologies and is compatible with compression technology, maintaining classification accuracy even after model compression. On a real-world dataset, the compression technology and model proposed by this invention were able to compress the model by 78% while only losing approximately 0.5% to 1% of accuracy.
[0121] The various embodiments in this specification are described in a progressive manner. References to the same or similar parts between the various embodiments are sufficient. Each embodiment focuses on the differences from other embodiments. All or part of the present invention can be used in a variety of general or specialized computer system environments or configurations. For example, personal computers, server computers, handheld or portable devices, tablet devices, mobile communication terminals, multiprocessor systems, microprocessor-based systems, programmable electronic devices, network PCs, minicomputers, mainframe computers, and distributed computing environments that include any of the above systems or devices.
[0122] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, it should be understood by those skilled in the art that the technical solutions described in the aforementioned embodiments may still be modified, or some or all of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the present invention.
Claims
1. A lightweight gas classification method based on an electronic nose device, characterized in that: include: Acquiring initial gas data of the gas, and preprocessing the gas data to obtain image data; The teacher model specifically includes a sensor association module, a temporal attention module, a channel attention module and a fully connected module connected in sequence; the sensor association module is used to perform sensor-dimensional feature extraction on the image data through different constructed sensor combinations to obtain multiple feature map matrices, and superimpose the multiple feature map matrices to obtain a first feature map matrix; the temporal attention module is used to perform temporal-dimensional feature extraction on the image data to obtain a first weight feature map matrix; the channel attention module is used to perform channel-dimensional feature extraction on the second feature map matrix to obtain a second weight feature map matrix, wherein the first feature map matrix is superimposed on the first weight feature map matrix to obtain the second feature map matrix; the fully connected module is used to calculate the probability vector of the second weight feature map matrix to obtain the probability distribution matrix of the image data; The image data is input into the optimization model to obtain a probability distribution matrix; wherein obtaining the optimization model includes performing model optimization according to hierarchical direct distillation and graph embedding distillation, specifically including: constructing a teacher model and a student model, replacing each channel attention layer in the student model with each channel attention layer in the corresponding teacher model to obtain a hybrid model; performing hierarchical direct distillation on the hybrid model to obtain a hybrid model after hierarchical direct distillation, and synchronizing each channel attention layer of the hybrid model after hierarchical direct distillation to a corresponding position of the student model until all the channel attention layers in the student model are replaced to obtain a student model, completing the preliminary model compression of the classification model, and using the student model as a compressed model; calculating the probability matrix of the compressed model and the probability matrix of the teacher model; constructing a distance matrix of the compressed classification model, and constructing a teacher distance matrix of the teacher model; calculating the distance between the compressed distance matrix and the teacher distance matrix, calculating the graph embedding distillation loss of the compressed classification model based on the distance, and performing refinement training to obtain a refined student model, that is, obtaining the optimization model; According to the maximum value in the probability distribution matrix, the gas category corresponding to the probability distribution matrix is obtained.
2. The method according to claim 1, characterized in that The sensor combination module includes multiple parallel dilated convolution modules, and the dilated convolution modules all have different dilated rates. The different sensor combinations constructed are used to capture multi-dimensional information of the image data to obtain multiple feature map matrices, including: copying a plurality of copies of the image data; Multiple copies of the image data are respectively input into the multiple parallel void convolution modules, each of the void convolution modules performs feature extraction on the information of the multiple sensor combinations of the received image data, and each of the void convolution modules outputs the feature map matrix accordingly.
3. The method according to claim 1, characterized in that The temporal attention module includes a first residual attention module, which includes a plurality of convolutional layers, a first fully connected layer, a global pooling layer, a second fully connected layer, a third fully connected layer and a first activation function layer connected in sequence; The performing a dimension transformation operation on the image data to obtain a first weight feature map matrix includes: Performing a convolution operation on the image data using the multiple convolutional layers to obtain a first intermediate feature map matrix; Using the first fully connected layer to transform the dimension of the first intermediate feature map matrix to obtain a first dimension-transformed feature map matrix; Performing global pooling on the first dimension change feature map matrix using the global pooling layer to obtain a pooled feature map matrix; Using the second fully connected layer to perform a dimensionality reduction operation on the pooled feature map matrix to obtain a second-dimensional change feature map matrix; Using the third fully connected layer to perform a dimensionality increase operation on the second-dimensional change feature map matrix to obtain a third-dimensional change feature map matrix; The first activation function layer is used to multiply the third-dimensional change feature map matrix and the image data to obtain the first weight feature map matrix.
4. The method according to claim 1, wherein The channel attention module includes a plurality of channel attention layers connected in sequence, and the number of second residual modules in all the channel attention layers is different; The second residual module includes a plurality of convolutional layers, a fourth fully connected layer, a fifth fully connected layer and a second activation function layer connected in sequence; The globally pooling of the second feature map matrix to obtain a second weighted feature map matrix includes: Performing a convolution operation on the second feature map matrix using the multiple convolutional layers to obtain a second intermediate feature map matrix; Performing a dimensionality reduction operation on the second intermediate feature map matrix using the fourth fully connected layer to obtain a third-dimensional change feature map matrix; Then, using the fifth fully connected layer, a dimensionality increase operation is performed on the third-dimensional change feature map matrix to obtain a fourth-dimensional change feature map matrix; The second activation function layer is then used to multiply the fourth-dimensional change feature map matrix and the second feature map matrix to obtain the first weight feature map matrix.
5. The method according to claim 1, wherein The fully connected module includes a plurality of neurons connected in sequence; The calculating the probability vector of the second weight feature map matrix to obtain the probability distribution matrix of the image data includes: Mapping the second weighted feature map matrix into a probability vector having the same dimension as the corresponding gas category using the multiple neurons; The probability distribution of the probability vector is calculated using a softmax function to obtain a probability distribution matrix of the image data.
6. The method according to claim 1, characterized in that The training method of the optimization model includes: Processing the plurality of sample data to obtain a plurality of sample image data; The optimization model is trained according to the plurality of sample image data to converge the objective function and obtain a trained optimization model.
7. The method according to claim 6, characterized in that The objective function is expressed as: Among them, N represents the number of samples, pi represents the sample probability vector, and y i is represented as the true label.
8. The method according to claim 1, characterized in that The constructing of the student model includes: The student model is determined by increasing or decreasing the number of second residual modules in the channel attention layer of each of the channel attention modules in the teacher model.
Citation Information
Patent Citations
Electronic nose array optimization method based on adaptive feature selection
CN115168792A
Efficient and accurate grassland spodoptera frugiperda image recognition method
CN115713755A
Hyperspectral ground feature classification method based on lightweight multi-domain combined distillation
CN116109918A