Gas recognition method based on light-weight convolutional neural network of memristor stochastic computing
By using a lightweight convolutional neural network based on memristor random computation, the problems of fluctuation and data drift in memristor devices are solved, thereby improving the gas identification speed and simplifying hardware deployment, making it suitable for small devices.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHONGQING PERKINS TECHNOLOGY CO LTD
- Filing Date
- 2023-05-18
- Publication Date
- 2026-04-21
AI Technical Summary
Existing gas identification methods suffer from difficulties in deployment due to the fluctuation of memristor devices, sensor data drift has not been effectively addressed at the hardware level, and the devices are large in size and slow in processing speed.
A lightweight convolutional neural network based on memristor random computation is adopted. A bit stream is generated through a memristor array for convolution and fully connected operations. Logic gates are used to implement multiply-accumulate operations, and a counter is used to convert the data into binary numbers for gas classification.
It improves gas recognition speed, reduces the difficulty of hardware deployment, has the ability to resist data drift, and enables efficient recognition on smaller devices.
Smart Images

Figure CN116578906B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of gas classification technology, and in particular to a gas recognition method based on a lightweight convolutional neural network with memristor random computation. Background Technology
[0002] In various aspects of life, we may be exposed to dangerous toxic gases. Prolonged exposure poses safety hazards, and gas explosions can cause injury or death. Therefore, real-time gas monitoring and identification are crucial to prevent unnecessary harm and losses. While traditional gas identification methods can address the nonlinearity issues in gas identification, fully connected layers lead to more weight parameters, resulting in increased floating-point operations, slower inference, and more difficult hardware deployment. Chen et al. used a hybrid convolutional neural network to classify six gases, reducing the number of parameters by sharing weight parameters, achieving good results. However, the fluctuations between the memristor devices mentioned in their paper presented deployment challenges.
[0003] On the other hand, during the use of sensors, the data collected by the sensors is often affected by the environment and equipment, which causes the data to drift. Existing methods to solve drift mainly focus on the software level, with little research on the hardware level.
[0004] Disadvantages of existing technologies: fluctuations between memristor devices make deployment difficult; existing methods for solving drift are rarely studied at the hardware level; and existing devices for gas identification are large in size and have slow processing speed. Summary of the Invention
[0005] The main objective of this invention is to provide a gas identification method based on a lightweight convolutional neural network using memristor random computation, which can accelerate network computation speed, resist data drift, and better enable hardware deployment.
[0006] To achieve the above objectives, the gas recognition method based on a lightweight convolutional neural network using memristor random computation, as described in this invention, is characterized by the following key steps:
[0007] Step 1: This step involves using 16 gas sensors arranged in the following order to collect 16 gas characteristic data points: TGS2602; TGS2602; TGS2600; TGS2600; TGS2610; TGS2610; TGS2620; TGS2620; TGS2602; TGS2602; TGS2600; TGS2600; TGS2610; TGS2610; TGS2620; TGS2620.
[0008] Step 2: This step transforms the 16 gas feature data dimensions into a 4×4 gas feature matrix, then performs a round of zero-filling to transform it into a 6×6 matrix, and obtains a 36-bit stream through a memristor array.
[0009] Step 3: This step generates a bitstream from a 3×3 convolution kernel using a memristor array, resulting in a 9-bit bitstream.
[0010] Step 4: This step involves convolving the 36 bit streams with the 9 bit streams to obtain a 4×4 matrix, which is a 16 bit stream.
[0011] Step 5: This step transforms the 4×4 matrix obtained in Step 4 and the 4×4 gas feature matrix in Step 2 into a 2×4×4 solid matrix, resulting in a 32-bit stream.
[0012] Step 6: This step involves using a 3×3 pooling kernel to process the 32 bit streams through a maximum value circuit to obtain 8 bit streams.
[0013] Step 7: This step generates a bitstream from the 8×6 fully connected layer matrix using a memristor array, resulting in a 48-bit bitstream.
[0014] Step 8: This step involves performing a full connection operation on the 48 bit streams and the 8 bit streams to obtain 6 bit streams.
[0015] Step 9: This step involves converting the 6 bit streams into binary and then comparing them to achieve classification.
[0016] Further, in step 6, 3×3 pooling is performed using a maximum value circuit to reduce parameters while retaining sufficient features, making the model smaller and faster to operate; in step 8, each bit stream is used to define a gas classification result, and 6 bit streams result in six gas classification results.
[0017] Through the above design, memristor random computation is used in lightweight convolutional neural networks for gas recognition, which not only improves the gas recognition speed, but also makes it easier to deploy the invention on smaller devices and has the ability to resist data drift.
[0018] Preferably, the six bitstreams are used to define six types of gases, arranged in the following order: ammonia, acetaldehyde, acetone, ethylene, ethanol, and toluene. The specific gas category to which the gas characteristic data belongs is determined by comparing the number of 1s in the six bitstreams; the bitstream with the most 1s belongs to that gas category. For example, if the second bitstream has the most 1s, then the gas characteristic data belongs to the second gas category, acetaldehyde.
[0019] As a preferred option: all multiplication and addition operations involved in steps 4 and 8 are implemented using logic gates, with multiplication using XNOR gates and addition using MUX gates;
[0020] In XNOR gate calculation, considering that the probabilities represented by bit streams a and b of the same length are Pa and Pb, the output after passing through the XNOR gate at the corresponding position is Pa×Pb. In MUX gate, to calculate the sum of the two bit streams Pa and Pb, an additional bit stream Pc is needed as an auxiliary scaling, because the values represented by random numbers Pa and Pb are both in the range [-1,1]. Direct addition results in the range [-2,2], so it is necessary to remap back to [-1,1]. Usually, Pc = 1 / 2, provided by SNG, and the final output is Pa×Pc+(1-Pc)Pb.
[0021] To elaborate further, the multiply-accumulate operation occurs within the convolution and fully connected operations, and internally it involves matrix multiplication. In the lightweight convolutional neural network based on memristor random computation, all parameters have been converted into bitstream representations by the memristor array, so the multiply-accumulate operation can be implemented using logic gates.
[0022] As a preferred embodiment, the process of generating a bitstream using a memristor array includes the following steps:
[0023] A1: The step used to input a number x between [-1, 1] into the memristor array;
[0024] A2: The step used to calculate the actual probability P of the bitstream based on the input x;
[0025] A3: Steps for calculating the pulse voltage V or pulse width t required to generate the actual probability P;
[0026] A4: Steps for passing pulses through a memristor array;
[0027] A5: The step of reading the state of the memristor array switches to obtain the bit stream ends. Preferably: In step A2, the formula for calculating the actual probability of the bit stream is:
[0028] P = (x + 1) ÷ 2
[0029] Where P represents the actual probability of the bitstream, and x represents the number of inputs;
[0030] In step A3, the formula for calculating the pulse voltage V or pulse width t required to generate the actual probability P is as follows:
[0031]
[0032] Where V0 and τ0 represent fitting parameters, determined by the memristor device; V represents the applied pulse voltage, t represents the pulse width, and P represents the actual probability of the bit stream;
[0033] Given a pulse voltage V, the actual probability P of the bit stream is controlled by controlling the pulse width t; given a pulse width t, the actual probability P of the bit stream is controlled by controlling the pulse voltage V.
[0034] To further describe, a memristor is a variable resistor with two states: high resistance and low resistance, referred to as the off and on states, respectively, conforming to the following formula:
[0035]
[0036] In other words, the transition between two states can be controlled by controlling pulses, and this transition is a random behavior. The transition between the two states can be controlled by controlling the pulse voltage and pulse width. When a pulse is applied to a memristor, the switching state of the memristor will change. Therefore, the current can be read to determine which state the switch belongs to, thus obtaining a bit stream. The on state is recorded as 0, and the off state is recorded as 1. Similarly, when a row or column of memristor devices are pulsed simultaneously, a bit stream can be obtained based on the state of the row or column.
[0037] Through the above design, a bit stream is generated in the circuit by applying pulses to the memristor array and controlling the switches. This bit stream is the bit stream required for random calculations. Using the bit stream to perform operations through logic gates can improve the calculation speed.
[0038] As a preferred option: In step 9, after converting the random number of the bitstream into a binary number using a counter, the probability that the gas feature data belongs to the gas category of the bitstream can be calculated using the binary number converted from the bitstream. Specifically, the probability of belonging to the gas category can be obtained using the softmax function.
[0039] For example, these 6 bit streams are 0110010100010010, 0001011000010000, 1011110011011010, 1000101101001000, 1000100101001000, 0001011000010000. The length of these 6 bit streams is 16. The number of 1s obtained by each bit stream after being countered is 6, 10, 6, 6, 5, 4 respectively. To determine the probability of belonging to a certain gas class, first calculate the values of the six bitstreams as follows: 6 / 16, 10 / 16, 6 / 16, 6 / 16, 5 / 16, 4 / 16. Then calculate the actual represented values as: 6 / 16×2-1=-4 / 16, 10 / 16×2-1=4 / 16, 6 / 16×2-1=-4 / 16, 6 / 16×2-1=-4 / 16, 5 / 16×2-1=-6 / 16, 4 / 16×2-1=-8 / 16. Finally, the specific probability of belonging to a certain gas class can be obtained using the softmax function.
[0040] As a preferred approach, a lightweight convolutional neural network is trained to obtain the optimal parameter values for the convolutional kernel and fully connected layer through the following steps:
[0041] Step 1: This step involves transforming the 16 gas feature data into 4×4 feature data through dimensionality changes, and then transforming them into 6×6 feature data through a zero-filling loop.
[0042] Step 2: This step involves convolving the 6×6 feature data with a 3×3 convolution kernel parameter to obtain a 4×4 feature map.
[0043] Step 3: A step for stacking the 4×4 feature map with the 4×4 feature data to obtain a 2×4×4 feature map;
[0044] Step 4: This step involves max pooling the 2×4×4 feature map with a 3×3 pooling kernel parameter to obtain a 2×2×2 feature cube.
[0045] Step 5: The step used to transform the 2×2×2 feature cube into a 1×8 vector;
[0046] Step 6: This step involves performing a full connection operation between the 1×8 vector and the parameters of the 8×6 fully connected layer to obtain a 1×6 classification result.
[0047] Step 7: The step used to input the 1×6 classification results into the lightweight convolutional neural network and calculate the loss function;
[0048] Step 8: The step used to calculate the loss based on the loss function and update the corresponding parameters;
[0049] Step 9: The step used to determine whether the 1000th iteration has been reached;
[0050] If the number of iterations has not been reached, return to step 1; if the number of iterations has been reached, proceed to the step of saving the parameters as the optimal parameter values.
[0051] Further, in step 2, to ensure the output feature map after convolution is 4×4, zero-padding is used to perform a 3×3 convolution on the 4×4 feature data; in step 3, to prevent feature loss during the next step of 3×3 max pooling, the original feature data is added for feature compensation, that is, the corresponding positions of the 4×4 feature map and the 4×4 feature data are superimposed to obtain a 2×4×4 feature map; in step 4, the 2×4×4 feature map is subjected to 3×3 max pooling with a pooling stride of 1, which yields a 2×2×2 feature cube.
[0052] Through the above design, the parameters of the convolutional kernel and fully connected layer are continuously updated through 1000 iterations of training to obtain the optimal parameter values, making the final gas classification results more accurate.
[0053] Preferably, in step 7, the loss function is the cross-entropy loss function, and the loss value is calculated using the cross-entropy loss function. The formula for the cross-entropy loss function is:
[0054]
[0055] Where N represents the number of samples; M represents the number of categories; y ic The sign function (0 or 1) is set to 1 if the true class of sample i is equal to c, and 0 otherwise; pic represents the predicted probability that observed sample i belongs to class c.
[0056] The beneficial effects of this invention are: using convolutional neural networks to reduce parameters through weight parameter sharing, thereby reducing the number of parameters in the model; employing random computation for hardware acceleration, which not only speeds up the network computation speed of the hardware and enhances its ability to resist data drift, but also enables better hardware deployment; and using the random switching characteristics of memristors to generate random bit streams, further reducing energy consumption. Attached Figure Description
[0057] Figure 1 This is a schematic diagram of a lightweight convolutional neural network structure;
[0058] Figure 2 A derivation diagram for using memristor random computation;
[0059] Figure 3 This is a schematic diagram of logic gate calculation and binary number conversion in this invention;
[0060] Figure 4 This is a schematic diagram of a structure for generating a random bit stream using a memristor. Detailed Implementation
[0061] The present invention will be further described in detail below with reference to the accompanying drawings and specific examples. The following embodiments or drawings are used to illustrate the present invention, but are not intended to limit the scope of the present invention.
[0062] like Figure 1 As shown: The input consists of 16 gas feature data collected by 16 gas sensors arranged in the order TGS2602; TGS2602; TGS2600; TGS2600; TGS2610; TGS2610; TGS2620; TGS2620; TGS2602; TGS2602; TGS2600; TGS2600; TGS2610; TGS2610; TGS2620; TGS2620. These data are transformed into a 4×4 matrix through dimensionality changes, and then convolved with a 3×3 kernel. To achieve the 4×4 result, zero-padding is used for convolution. To prevent feature loss during the next 3×3 max pooling step, original feature data is added for feature compensation, resulting in a 2×2×2 feature cube. This cube is then transformed into a 1×8 vector, and a fully connected layer is used to perform six-class classification.
[0063] The specific steps are as follows:
[0064] Step 1: This step involves using 16 gas sensors arranged in the following order to collect 16 gas characteristic data points: TGS2602; TGS2602; TGS2600; TGS2600; TGS2610; TGS2610; TGS2620; TGS2620; TGS2602; TGS2602; TGS2600; TGS2600; TGS2610; TGS2610; TGS2620; TGS2620.
[0065] Step 2: This step transforms the 16 gas feature data dimensions into a 4×4 gas feature matrix, then performs a round of zero-filling to transform it into a 6×6 matrix, and obtains a 36-bit stream through a memristor array.
[0066] Step 3: This step generates a bitstream from a 3×3 convolution kernel using a memristor array, resulting in a 9-bit bitstream.
[0067] Step 4: This step involves convolving the 36 bit streams with the 9 bit streams to obtain a 4×4 matrix, which is a 16 bit stream.
[0068] Step 5: This step transforms the 4×4 matrix obtained in Step 4 and the 4×4 gas feature matrix in Step 2 into a 2×4×4 solid matrix, resulting in a 32-bit stream.
[0069] Step 6: This step involves using a 3×3 pooling kernel to process the 32 bit streams through a maximum value circuit to obtain 8 bit streams.
[0070] Step 7: This step generates a bitstream from the 8×6 fully connected layer matrix using a memristor array, resulting in a 48-bit bitstream.
[0071] Step 8: This step involves performing a full connection operation on the 48 bit streams and the 8 bit streams to obtain 6 bit streams.
[0072] Step 9: This step involves converting the 6 bit streams into binary and then comparing them to achieve classification.
[0073] like Figure 2 As shown: In lightweight convolutional neural networks, memristor random computation is used for gas identification to facilitate deployment in smaller devices and achieve faster recognition speeds. In the circuit, pulses are applied to the memristor array to control switches and generate bitstreams. These bitstreams are the bitstreams required for random computation, and using these bitstreams to perform operations through logic gates can improve the computation speed. Figure 2 In this context, bitstreams are represented using bipolar representations.
[0074] The specific process of generating a bitstream using a memristor array includes the following steps:
[0075] A1: The step used to input a number x between [-1, 1] into the memristor array;
[0076] A2: The step used to calculate the actual probability P of the bitstream based on the input x;
[0077] A3: Steps for calculating the pulse voltage V or pulse width t required to generate the actual probability P;
[0078] A4: Steps for passing pulses through a memristor array;
[0079] A5: This step involves reading the state of the memristor array switches to obtain the bitstream, and then the process ends. In step A2, the formula for calculating the actual probability of the bitstream is:
[0080] P = (x + 1) ÷ 2
[0081] Where P represents the actual probability of the bitstream, and x represents the number of inputs;
[0082] In step A3, the formula for calculating the pulse voltage V or pulse width t required to generate the actual probability P is as follows:
[0083]
[0084] Where V0 and τ0 represent fitting parameters, determined by the memristor device; V represents the applied pulse voltage, t represents the pulse width, and P represents the actual probability of the bit stream;
[0085] Given a pulse voltage V, the actual probability P of the bit stream is controlled by controlling the pulse width t; given a pulse width t, the actual probability P of the bit stream is controlled by controlling the pulse voltage V.
[0086] like Figure 3 As shown: Figure 3 (a) shows a randomized multiplication, where the AND gate is suitable for multiplication in unipolar representation and the XNOR gate is suitable for multiplication in bipolar representation. Considering that bit streams a and b of the same length represent probabilities Pa and Pb, the output after passing through the AND / XNOR gate at the corresponding position is Pa×Pb.
[0087] exist Figure 3 In (b), calculating the sum of the two bitstreams Pa and Pb requires an additional bitstream Pc for scaling. This is because the values represented by the random numbers Pa and Pb both belong to the range [-1, 1], and the result obtained by direct addition is in the range [-2, 2]. Therefore, it is necessary to remap them back to [-1, 1]. Typically, Pc = 1 / 2, provided by the SNG, and the final output is Pa × Pc + (1 - Pc)Pb.
[0088] Figure 3 (c) is a schematic diagram of converting a bitstream random number into a binary number, which can be done using a counter.
[0089] like Figure 4 As shown: Each pulse is passed through one line, and a random bit stream is generated based on the switch state. It needs to be restored after each use to ensure it can be used again.
[0090] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A gas recognition method based on a lightweight convolutional neural network using memristor random computation, characterized in that, Includes the following steps: Step 1: This step involves using 16 gas sensors arranged in the following order to collect 16 gas characteristic data points: TGS2602; TGS2602; TGS2600; TGS2600; TGS2610; TGS2610; TGS2620; TGS2620; TGS2602; TGS2602; TGS2600; TGS2600; TGS2610; TGS2610; TGS2620; TGS2620. Step 2: This step transforms the 16 gas feature data dimensions into a 4×4 gas feature matrix, then performs a round of zero-filling to transform it into a 6×6 matrix, and obtains a 36-bit stream through a memristor array. Step 3: This step generates a bitstream from a 3×3 convolution kernel using a memristor array, resulting in 9 bitstreams. Step 4: This step involves convolving the 36 bit streams with the 9 bit streams to obtain a 4×4 matrix, which is a 16 bit stream. Step 5: This step transforms the 4×4 matrix obtained in Step 4 and the 4×4 gas feature matrix in Step 2 into a 2×4×4 solid matrix, resulting in a 32-bit stream. Step 6: This step involves using a 3×3 pooling kernel to process the 32 bit streams through a maximum value circuit to obtain 8 bit streams. Step 7: This step generates a bitstream from an 8×6 fully connected layer matrix using a memristor array, resulting in a 48-bit bitstream. Step 8: This step involves performing a full connection operation on the 48 bit streams and the 8 bit streams to obtain 6 bit streams. Step 9: This step involves converting the 6 bit streams into binary data and then comparing them to achieve classification. The six bitstreams are used to define six types of gases, which are ammonia, acetaldehyde, acetone, ethylene, ethanol, and toluene in that order. The specific gas category to which the gas feature data belongs is distinguished by comparing the number of 1s in the six bitstreams. The bitstream with the most 1s belongs to the gas category. In step 9, after converting the random number of the bitstream into a binary number using a counter, the probability of the gas feature data belonging to the corresponding gas category of the bitstream is calculated using the binary number converted from the bitstream. Specifically, the probability of belonging to the gas category is obtained by using the softmax function.
2. The gas recognition method based on a lightweight convolutional neural network using memristor random computation according to claim 1, characterized in that: All multiplication and addition operations involved in steps 4 and 8 are implemented using logic gates, with multiplication using XNOR gates and addition using MUX gates; In XNOR gate computation, the probabilities represented by bit streams a and b of the same length are Pa and Pb, respectively. The output after passing through the XNOR gate at the corresponding position is Pa×Pb. In MUX gate computation, the sum of two bit streams Pa and Pb is calculated, which requires an additional bit stream Pc as an auxiliary scaling. Pc=1 / 2, provided by SNG, and the final output is Pa×Pc+(1-Pc)Pb.
3. The gas recognition method based on a lightweight convolutional neural network using memristor random computation according to claim 1, characterized in that: The process of generating a bitstream using a memristor array includes the following steps: A1: The step used to input a number x between [-1, 1] into the memristor array; A2: The step used to calculate the actual probability P of the bitstream based on the input x; A3: Steps for calculating the pulse voltage V or pulse width t required to generate the actual probability P; A4: Steps for passing pulses through a memristor array; A5: This step is used to read the state of the memristor array switches to obtain the bit stream, and then the process ends.
4. The gas recognition method based on a lightweight convolutional neural network using memristor random computation according to claim 3, characterized in that: In step A2, the formula for calculating the actual probability of the bitstream is: ; Where P represents the actual probability of the bitstream, and x represents the number of inputs; In step A3, the formula for calculating the pulse voltage V or pulse width t required to generate the actual probability P is as follows: ; in, and The fitting parameters are determined by the memristor device. Indicates pulse voltage. Indicates the pulse width. This represents the actual probability of the bitstream; Given a pulse voltage V, the actual probability P of the bit stream is controlled by controlling the pulse width t; given a pulse width t, the actual probability P of the bit stream is controlled by controlling the pulse voltage V.
5. The gas recognition method based on a lightweight convolutional neural network using memristor random computation according to claim 1, characterized in that: Lightweight convolutional neural networks are trained to obtain the optimal parameter values for convolutional kernels and fully connected layers through the following steps: Step 1: This step involves transforming the 16 gas feature data into 4×4 feature data through dimensionality changes, and then transforming them into 6×6 feature data through a zero-filling loop. Step 2: This step involves convolving the 6×6 feature data with a 3×3 convolution kernel parameter to obtain a 4×4 feature map. Step 3: A step for stacking the 4×4 feature map with the 4×4 feature data to obtain a 2×4×4 feature map; Step 4: This step involves max pooling the 2×4×4 feature map with a 3×3 pooling kernel parameter to obtain a 2×2×2 feature cube. Step 5: The step used to transform the 2×2×2 feature cube into a 1×8 vector; Step 6: This step involves performing a full connection operation between the 1×8 vector and the parameters of the 8×6 fully connected layer to obtain a 1×6 classification result. Step 7: The step used to input the 1×6 classification results into the lightweight convolutional neural network and calculate the loss function; Step 8: The step used to calculate the loss based on the loss function and update the corresponding parameters; Step 9: The step used to determine whether the 1000th iteration has been reached; If the number of iterations has not been reached, return to step 1; if the number of iterations has been reached, proceed to the step of saving the parameters as the optimal parameter values.
6. The gas recognition method based on a lightweight convolutional neural network using memristor random computation according to claim 5, characterized in that: In step 7, the loss function is the cross-entropy loss function. The loss value is calculated using the cross-entropy loss function, and the formula for the cross-entropy loss function is: ; Where N represents the number of samples; M represents the number of categories; The sign function is 0 or 1; it takes 1 if the true class of sample i is equal to c, and 0 otherwise. This represents the predicted probability that observed sample i belongs to category c.