Intelligent home air detection and identification method, system and device based on improved FNN and storage medium
Through the improved FNN algorithm and STM32 hardware platform, combined with Alibaba Cloud IoT platform, the problem of traditional air detection technology in accuracy and response lag is solved, and high-precision and low-latency smart home air detection is achieved, supporting personalized pollution thresholds and device linkage.
Patent Information
- Application Number
- CN202510400956.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-01
- Publication Date
- 2025-07-18
AI Technical Summary
When traditional air detection technology faces complex and changing indoor environments, it lacks accuracy and lags in response, making it difficult to achieve accurate gas recognition and timely information feedback, affecting the practicality and intelligence of smart home systems.
Using an improved feedforward neural network (FNN) algorithm, the Leaky Rectified Linear Unit activation function, batch normalization, Dropout layer and Adam optimizer are used to optimize the model, and combined with the STM32 hardware platform and Alibaba Cloud IoT platform, data collection, processing and identification are realized.
It improves detection accuracy and data visualization effects, meets the real-time response needs of smart homes, optimizes resource utilization, reduces communication costs and delays, is suitable for battery-powered scenarios, and supports personalized pollution threshold settings.
Smart Images

Figure CN120336783A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of smart home, and particularly relates to a smart home air detection and recognition method, system, device and storage medium based on an improved FNN. Background Art
[0002] With the vigorous development of the Internet of Things technology, smart home systems have become increasingly popular and have become an important boost for people to pursue a convenient, comfortable and healthy life. Among the many functional modules of smart home, air quality detection is crucial, which is directly related to the physical health and quality of life of the occupants.
[0003] Traditional air detection technologies mainly rely on simple sensors. When facing a complex and changeable indoor environment, these sensors expose many problems. On the one hand, insufficient accuracy is a relatively prominent defect. There are various components in indoor air, not only common harmful gases such as formaldehyde, benzene, TVOC (total volatile organic compounds), etc., but also the interference of environmental factors such as humidity and temperature. The detection accuracy of ordinary sensors for these gases is limited, and it is easily affected by cross-interference of other gases, resulting in a large deviation between the detection result and the actual concentration. For example, in a newly decorated house, multiple volatile organic compounds coexist, and it is difficult for traditional sensors to accurately distinguish whether a certain gas among multiple gases exists and it is difficult to take effective countermeasures.
[0004] On the other hand, poor data visualization is also a major problem. When the indoor air quality changes, such as someone smoking indoors or new furniture releasing harmful gases, traditional air detection systems cannot promptly transmit information to other smart homes to make the smart home system react quickly. This may cause users to be unknowingly exposed to polluted air for a long time, and their health is potentially threatened. Moreover, due to the response lag, the intelligent environmental control system cannot start the corresponding air purification equipment in time, affecting the overall practicality and intelligence of the smart home system.
[0005] Different from traditional air detection requirements, accuracy and data visualization are widely used as key indicators to quantify the performance of smart home air detection systems. In order to achieve reliable air detection, relevant scholars (Zhu Juxiang, etc. Design and implementation of an indoor air quality detection system based on STM32) have been committed to data acquisition and processing technologies based on sensors, which involve data preprocessing and feature extraction. This solution is designed around the principle of minimizing the errors caused by environmental interference and sensor noise. Although progress has been made theoretically, due to random environmental changes, relying solely on sensor technology may not guarantee the detection performance. Summary of the Invention
[0006] Objective of the Invention: The objective of the present invention is to provide a smart home air detection and recognition method based on an improved FNN, which can effectively improve the detection accuracy and enhance the data visualization effect, providing reliable technical support for the construction of subsequent intelligent environment control systems.
[0007] Technical Solution: The smart home air detection and recognition method based on an improved FNN of the present invention includes the following steps:
[0008] Collect data on pollutants in indoor air, as well as indoor air pressure and temperature data;
[0009] Extract data features and create a data set. The data format in the data set is: gas label; concentration value; feature: observation value; and preprocess the observation values to obtain a data sample set;
[0010] Construct an improved FNN model, train the model based on the sample set to obtain a trained improved FNN model; among them, the model improvement includes: using the Leaky Rectified Linear Unit activation function for each layer, adding batch normalization to normalize the output of each layer, performing a linear transformation on the normalized output to optimize gradient descent or explosion; setting a Dropout layer for each layer to randomly discard some neurons to prevent overfitting; using the Adam optimizer for parameter optimization and using the cross-entropy loss function to train and evaluate the model.
[0011] Classify and recognize the test data based on the trained improved FNN model to obtain classification results.
[0012] Further, in the data set, each gas label corresponds to multiple concentration values and multiple features, and each feature corresponds to multiple observation values. The preprocessing of the observation values includes: using the mean filling strategy to fill in missing data, and normalizing the multiple observation values corresponding to each feature after filling. The normalized data set is the sample set.
[0013] Further, in the improved FNN model, the expression of the Leaky Rectified Linear Unit activation function is:
[0014] f(x) = max(αx, x)
[0015] where f(x) represents the output of the activation function, x represents the input value of the activation function, and αx represents the output value of the activation function;
[0016] The formula for batch normalization is:
[0017]
[0018] where represents the intermediate value after standardization, x represents, μ B is the mean of all inputs on the current batch of data, is the variance of all inputs on the current batch of data, ∈ is an extremely small positive number;
[0019] The linear transformation formula is:
[0020]
[0021] where y represents the final output value after batch normalization, and γ and β are the learned adjustable scaling and translation parameters respectively.
[0022] Furthermore, in the improved FNN model, the operation of the Dropout layer is:
[0023]
[0024] where, represents the output data after being processed by the Dropout layer, x represents the input data of the Dropout layer, and r is a randomly generated binary mask.
[0025] Furthermore, the update rule of the Adam optimizer is:
[0026] m t = β1m t-1 + (1 - β1)g t
[0027]
[0028]
[0029]
[0030] The gradient represents the directional derivative vector of the function at a certain point. It points in the direction where the function value increases fastest, and its magnitude represents the degree of change of the function. In this project, it represents the rate of change of the function in each dimension. Among them, m t is the current momentum (simulating the velocity in physics). Adding an inertia to the gradient during gradient update makes the optimization path smoother and does not overswing. The gradient is accumulated through exponential moving average, m t-1 is the momentum of the previous step, β1 is the exponential decay rate of the first moment, g t is the gradient at the current time step t, that is, the gradient of the loss function with respect to the parameter θ t-1 ; v t is the exponential moving average of the current squared gradient, v t-1 is the exponential moving average of the squared gradient of the previous step, β2 is the exponential decay rate of the second moment, is the momentum after deviation correction, is the squared gradient after deviation correction, is the power of β1 at the t-th step, is the power of β2 at the t-th step, θ t is the updated model parameter, θ t-1 is the parameter of the previous step, α is the learning rate, and ∈ is the numerical stability constant;
[0031] The cross-entropy loss function is:
[0032]
[0033] where L is the loss value, C is the number of classes, y i is the actual label, p i is the probability of class i predicted by the model, log(p i ) represents taking the natural logarithm of the predicted probability p i taking the natural logarithm.
[0034] The present invention also provides a smart home air detection and recognition system based on an improved FNN, including:
[0035] A data collection module for collecting data on pollutants in indoor air, as well as indoor air pressure and temperature data;
[0036] A data processing module for extracting data features and making a data set. The data format in the data set is: gas label; concentration value; feature: observation value; and preprocessing the observation value to obtain a data sample set;
[0037] A model construction and training module for constructing an improved FNN model, training the model based on the sample set to obtain a trained improved FNN model; wherein, the model improvement includes: using the Leaky Rectified Linear Unit activation function for each layer, adding batch normalization to normalize the output of each layer, performing a linear transformation on the normalized output, and optimizing for gradient descent or explosion; setting a Dropout layer for each layer to randomly discard some neurons to prevent overfitting; using the Adam optimizer for parameter optimization, and using the cross-entropy loss function to train and evaluate the model.
[0038] A classification and recognition module for classifying and recognizing test data based on the trained improved FNN model to obtain a classification result.
[0039] Optionally, the data acquisition module includes an STM32 microcontroller, an air detection module, a BMP280 barometer module, a communication module, and an Internet of Things platform. The air detection module is used to detect pollutant data in indoor air. The BMP280 barometer module is used to collect indoor air pressure and temperature data. The pollutant data, air pressure, and temperature data are transmitted to the STM32 microcontroller through the communication module. After processing the data, the STM32 microcontroller uploads it to the Internet of Things platform through the communication module. The Internet of Things platform is used for data display and storage, and to save and display the classification recognition results.
[0040] Optionally, the STM32 microcontroller displays the real-time detection data through an OLED screen;
[0041] The air detection module includes four different air detection sensors, namely TGS2600, TGS2602, TGS2610, and TGS2620. Through a heating circuit and a signal processing circuit, the gas concentration is converted into a measurable voltage signal, and then converted into a digital signal through an ADC for STM32 processing;
[0042] The communication module is an ESP8266-12F WIFI module, which has a built-in microcontroller and a TCP / IP protocol stack and can achieve wireless data transmission.
[0043] The present invention also provides an electronic device, which includes:
[0044] A memory storing executable program code;
[0045] A processor coupled to the memory;
[0046] The processor calls the executable program code stored in the memory and executes the steps of the improved FNN-based smart home air detection and recognition method.
[0047] The present invention also provides a computer-readable storage medium, which stores computer instructions. When the computer instructions are called, they are used to execute the steps of the improved FNN-based smart home air detection and recognition method.
[0048] Beneficial effects: Compared with the prior art, the remarkable technical effects of the present invention are as follows: (1) An improved Feed-Forward Neural Network (FNN) algorithm and its optimized application in an embedded environment; through techniques such as pruning and quantization, the volume of the FNN model is compressed from 10 MB to approximately 200 KB, creating a set of Flash / RAM resources for STM32 while maintaining an accuracy of > 95%; the optimized inference speed reaches the millisecond level (single detection < 50 ms), meeting the real-time response requirements of smart homes; in addition, the model supports online incremental learning (such as updating weights through Alibaba Cloud), and can be adaptively optimized according to different home environments (such as newly renovated houses, pet households); (2) In terms of the system architecture, the low-power characteristics of STM32 are fully utilized and seamlessly connected to the Alibaba Cloud platform, supporting remote monitoring (such as mobile phone apps, smart speakers), covering the smart home ecosystem. When a standard is exceeded, the system can automatically link devices such as air purifiers and fresh air systems to achieve active protection. Long-term cloud data storage and analysis can generate air quality reports, providing users with ventilation and purification strategy suggestions; at the same time, the STM32 runs the FNN model locally, reducing the dependence on cloud computing, lowering communication costs and latency, and further enhancing the stability and response speed of the system; (3) In addition, the low-power design of STM32 effectively extends the device battery life, suitable for battery-powered scenarios. Users can customize pollution thresholds through Alibaba Cloud (such as setting the formaldehyde threshold to 0.05 mg / m 3 in the pregnant woman mode), meeting personalized needs; this addresses the pain points of high cost, low real-time performance, and weak generalization in the field of smart home detection in traditional solutions (such as high latency caused by pure cloud analysis and large resource occupation of unoptimized convolutional neural network models). The present invention is based on the integrated design of embedded AI + Internet of Things, achieving these pain points. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] Figure 1 It is a flowchart of the method of the present invention;
[0050] Figure 2 It is a schematic diagram of the hardware circuit principle of the present invention;
[0051] Figure 3 It is a schematic diagram of the operating structure of the hardware platform based on STM32, the Alibaba Cloud platform, and the improved FNN network;
[0052] Figure 4 It is a schematic diagram of the traditional FNN model structure;
[0053] Figure 5 It is a schematic diagram of the improved FNN model structure;
[0054] Figure 6 It is a detailed flowchart of the method of the present invention;
[0055] Figure 7These are simulation effect diagrams, where (a) is the simulation effect diagram of the traditional FNN model, and (b) is the simulation effect diagram of the improved FNN model;
[0056] Figure 8 These are schematic diagrams of the detection accuracy and loss curves of the improved FNN model, where (a) is the schematic diagram of the model accuracy curve, and (b) is the schematic diagram of the model loss curve. Detailed implementation manners
[0057] The present invention will be described in detail below with reference to the accompanying drawings and specific embodiments.
[0058] As Figure 1 shown, in order to achieve the above-mentioned invention object, the smart home air detection and recognition method based on the improved FNN of the present invention has the following specific process:
[0059] S1. Collect data on pollutants in indoor air, as well as indoor air pressure and temperature data; specifically as follows:
[0060] As Figure 2 shown, an air detection system is used to detect pollutants in indoor air, such as harmful gases like formaldehyde, benzene, ammonia, etc. In this embodiment, the air detection system includes four different air detection sensors, namely TGS2600, TGS2602, TGS2610, and TGS2620, and the TGS2600, TGS2602, TGS2610, and TGS2620 sensors are connected to the ADC pins of the STM32 minimum system board for analog-to-digital signal conversion.
[0061] An air pressure and temperature detection module is used to detect indoor air pressure and temperature. In this embodiment, the air pressure and temperature detection module uses a BMP280 sensor. The detected indoor air pressure and temperature data help improve the accuracy of air detection. Through the I 2 C interface, the BMP280 sensor is connected to the STM32 microcontroller to read the air pressure and temperature data. The BMP280 sensor is a high-precision digital barometer and thermometer, with an in-built ADC and signal processing circuit, capable of providing accurate air pressure and temperature data. Communicating with the STM32 microcontroller through the I 2 C interface simplifies the circuit design.
[0062] The core chip of the STM32 hardware platform is set on the STM32 minimum system board. The STM32 minimum system board includes basic components such as STM32F103ZET6, crystal oscillator circuit, reset circuit, power supply circuit, etc. The STM32 minimum system board is also connected to an OLED display module for real-time display of detection data. The OLED display module uses a 0.96-inch OLED (organic light-emitting diode) screen. The structural schematic diagram of the STM32 minimum system board and the OLED display module is as Figure 2as shown
[0063] Use STM32F103ZET6 as the core processing unit, which is responsible for data acquisition, processing and transmission. Configure the peripheral interfaces of STM32, including ADC (Analog-to-Digital Converter), I 2 C (Serial Communication Bus Protocol) and USART (Asynchronous Serial Receiver-Transmitter Module). Use an OLED screen to display basic data. The STM32 minimum system board uses the USART serial port for information transmission and control, including:
[0064] (1) Start the STM32 minimum system board equipped with STM32F103ZET6, and initialize the AD, OLED, BMP280 MyI 2 C and the serial port modules of TGS2600, TGS2602, TGS2610 and TGS2620, and ESP8266-12F.
[0065] (2) Through the serial port, complete the relevant Alibaba Cloud configuration of the WIFI module (ESP8266), and connect to the network and the Internet of Things platform of Alibaba Cloud;
[0066] (3) Operate the OLED display screen to display static characters;
[0067] (4) Continuously execute the sampling of temperature, air pressure and the characteristic value data of TGS2600, TGS2602, TGS2610 and TGS2620 by STM32, and upload them to the Alibaba Cloud platform through ESP8266; The schematic diagram of the operating structure based on the STM32 hardware platform, the Alibaba Cloud platform and the improved FNN algorithm is as Figure 3 shown
[0068] The communication between the STM32 microcontroller and multiple sensors as well as the Alibaba Cloud platform all uses the ESP8266-12F WIFI module; ESP8266-12F is a low-cost WIFI module with a built-in microcontroller and a TCP / IP protocol stack, which can realize wireless data transmission. Communicate with STM32 through the USART interface to achieve wireless data transmission. Use the ESP8266-12F module to realize the wireless network connection and transmit the collected data to the Alibaba Cloud platform. Configure the firmware of ESP8266 so that it can communicate with STM32 through USART and implement the MQTT protocol stack.
[0069] The Alibaba Cloud platform provides Internet of Things communication functions to realize the data interaction between the STM32 system and the cloud, including data upload and the return of recognition results, such as Figure 3As shown in the figure. The data uploaded by the hardware device is collected and stored on the Alibaba Cloud platform for training and learning the characteristics of air pollutants. The STM is responsible for collecting environmental data, preprocessing it and uploading it to the Alibaba Cloud. Subsequently, further analysis and identification are carried out through an improved FNN algorithm. The signals measured by the sensor are read in the form of a resistance time series, and each measurement forms a multi-channel time series. In this solution, the sensor data in each measurement cycle contains 16 channels, and 8 features are extracted from it, including 2 steady-state features and 6 dynamic features. Finally, a 128-dimensional feature vector (16 sensors × 8 features) is obtained for each measurement. Steady-state features: Include the maximum resistance change and the normalized steady-state resistance change, which are used to describe the stable response of the sensor. Dynamic features: The exponential moving average filter is used to calculate the transient response of the sensor, and a total of 6 features are extracted to reflect the change trend of the sensor to pollutants. After the STM32 completes data collection and feature extraction, the 8-dimensional feature data is uploaded to the Alibaba Cloud platform, and then the improved FNN algorithm is used for pollutant identification and analysis to improve the classification accuracy.
[0070] S2. Extract data features and create a data set. The data format in the data set is: gas label; concentration value; feature: observed value; and preprocess the observed value; obtain a data sample set;
[0071] Crawl data from the Alibaba Cloud. After obtaining the data, further analysis and identification are carried out through an improved FNN algorithm. The entire project is encapsulated using object-oriented programming. A class named GasSensorModel is defined, which includes functions such as data reading, preprocessing, model training, project, and result visualization. First, create this class and initialize the parameters, including initializing the file path, gas name, mapping from gas name to value (encoding), training set, validation set, test set and their corresponding labels, storing the training history, the improved FNN model, etc.
[0072] Batch load multiple.dat files and merge the data. For each.dat file, data processing is performed. The data in the.dat file is read line by line, the data is parsed and converted into a dictionary format, then converted into a Pandas DataFrame, and the data is returned. Add Batch ID, gas category, and concentration to the data, process the feature data, sort the data by gas label and re-index it, and encode the labels, that is, map the gas labels to numerical values. In this project, ethanol, ethylene, ammonia, acetaldehyde, propylene, and toluene are mapped to 1, 2, 3, 4, 5, and 6 respectively. Make the format of each data point: gas label; concentration value Feature 1: Observation value 1 Feature 2: Observation value 2..., that is, the format is Feature X: Observation value x, where the gas label is a numerical value representing different types of gases. Use sklearn.utils.shuffle to shuffle the data to prevent the model from learning fixed patterns in the data distribution.
[0073] Save the data obtained above to a CSV file for convenient data reuse and avoid reading the.dat file repeatedly. This CSV file can be loaded in other environments for data analysis or training different models.
[0074] Each gas label corresponds to multiple concentration values and multiple features, and each feature corresponds to multiple observation values. Preprocessing of the observation values includes: filling missing observation value data using the mean filling strategy, and normalizing the multiple observation values corresponding to each feature after filling. The dataset after normalization is the sample set. Specifically as follows:
[0075] Process the missing values in the observation values, and use the mean filling strategy to fill the missing data. For each feature containing missing values (i.e., Feature 1, Feature 2...), calculate the mean of all the observation value data under this feature, and then fill all the missing values with the mean. Let n represent the total number of observation values in Feature X of the entire dataset. The formula for mean filling is:
[0076]
[0077] where, x i is the i-th observation value in Feature X, μ x represents the mean of n observation values in Feature X, represents the sum of all x i from i = 1 to i = n and perform standardization processing on all the observation values under this Feature X. The data is converted to a standard normal distribution by subtracting the mean and dividing by the standard deviation.
[0078] Let each observation value in a certain Feature X be x1, x2,..., x : , the mean of all the observation values in Feature X is μ9, and the standard deviation of all the observation values in Feature X is σx , then the standardized value of the \(i\)-th observation \(x\) i is \(z\) i :
[0079]
[0080] wherein, it can be seen from formula (1) that \(\mu_9\) is the mean of all observations of feature \(X\), and \(\sigma\) is the standard deviation of all observations of feature \(X\), ensuring that all data in feature \(X\) are trained on the same scale.
[0081] The standardized dataset is the sample set, and the sample set is divided into a training set, a validation set, and a test set for subsequent model training and testing. In this embodiment, 80% of the data in the sample set is randomly selected for training and validation, and 20% of the data is used for testing.
[0082] S3. Construct an improved FNN model, train the model based on the sample set, and obtain the trained improved FNN model; as Figure 4 shown is the schematic diagram of the traditional FNN model structure. As Figure 5 shown, the improved FNN model includes an input layer, four hidden layers, and an output layer. Each hidden layer includes a fully connected layer (performing a linear transformation on the input data), a Leaky Rectified Linear Unit (Leaky ReLU) activation function, a Batch Normalization process, and a Dropout layer; the model improvement includes: each hidden layer uses the Leaky ReLU activation function, adding the Batch Normalization process to normalize the output of each hidden layer, performing a linear transformation on the output after Batch Normalization to optimize the gradient descent or explosion; each hidden layer is set with a Dropout layer to randomly discard some neurons to prevent overfitting; the Adaptive Moment Estimation (Adam) optimizer is used for parameter optimization, and the cross-entropy loss function is used to train and evaluate the model.
[0083] The present invention uses a neural network architecture for classification tasks, and the improved FNN model includes multiple hidden layers. The traditional feedforward neural network (FNN) only includes multiple fully connected layers and activation functions. As Figure 4 shown, it may encounter problems such as gradient disappearance / explosion, overfitting, and slow training speed. To solve the above problems, the present invention proposes an improved FNN model, and the specific improvement points are:
[0084] (1) Each hidden layer replaces the ReLU activation function with the Leaky ReLU activation function, reducing the "neuron death problem" and improving the critical propagation ability, which is used to optimize gradient descent or explosion;
[0085] Let f(c) represent the output of the activation function, and c represent the input value of the activation function (i.e., the value after normalization and the weighted sum of neurons plus the bias term), then:
[0086] f(c) = max(αc, c) (3)
[0087] When c is greater than zero, the output value of the activation function is the same as the input value. When c is less than or equal to zero, the output is αc, preventing the vanishing gradient. Among them, α is a small constant, usually taking a value of 0.01 or 0.1. max represents choosing the larger of the two values. In this way, there can be a non-zero output in the negative value interval, avoiding the "vanishing gradient" problem during model training.
[0088] In addition, Batch Normalization normalizes the output f(c) of the activation function of each hidden layer, making the mean of the output of each layer in each dimension be 0 and the variance be 1. For each small batch of data (a small part of the samples drawn from the entire dataset during each iteration in the training process), use to represent that the standardized Batch Normalization is transformed through the following formula:
[0089]
[0090] Among them: μ B is the mean of the activation values of all samples corresponding to each neuron of a certain hidden layer on the current batch of data, is the variance of all inputs on the current batch of data, and ∈ is an extremely small positive number (such as 10 -K or 10 -L ) to avoid division by zero errors.
[0091] The normalized output is then subjected to a linear transformation. Let y represent the final output value after Batch Normalization:
[0092]
[0093] Among them, γ and β are the learned adjustable scaling and translation parameters respectively, which are used to restore the representational ability of the network. Through these two parameters, the neural network can adjust the scale and offset of the data as needed. In this way, the problem of vanishing gradient or gradient explosion is alleviated, enabling the network to converge faster, and improving the robustness of the model by balancing the distribution of inputs of each layer.
[0094] (2) Overfitting is optimized by adopting the ReduceLROnPlateau mechanism
[0095] The present invention incorporates the ReduceLROnPlateau mechanism, which automatically reduces the learning rate when the validation loss stops decreasing, improving the convergence effect. A monitoring metric is set, and if it has not decreased for multiple consecutive rounds, the current learning rate is multiplied by a factor for decay. The present invention sets an early termination mechanism. During the training process, if the loss value on the validation set does not decrease significantly for multiple consecutive epochs, the training is stopped. Usually, the training is stopped when there is no improvement in the loss to avoid overfitting.
[0096] Dropout prevents overfitting. During training, certain neurons in the neural network are randomly discarded so that they do not participate in the calculation in the current training step. For each hidden layer of the improved FNN model, in each training step, the Dropout layer will randomly discard a part of the neurons, that is, the retention probability of each neuron is set to p, and the values of other neurons are zero. During the training process, for the final output value y after Batch Normalization, use to represent the output data after Dropout processing. The Dropout operation is:
[0097]
[0098] where r is a randomly generated binary mask, a random vector consisting of 0s and 1s. The value of each element is 1 or 0, indicating whether the neuron is "retained" in the current training step. The value of r is randomly generated according to the set p. And where represents the probability. This avoids overfitting of the model. By randomly discarding neurons, the model becomes more generalizable. The robustness of the model is improved, and the problem of over-reliance on certain specific neurons is reduced.
[0099] (3) The training speed is optimized by adopting the Adam optimizer
[0100] The gradient represents the directional derivative vector of the function at a certain point. It points in the direction where the function value increases fastest, and its magnitude represents the degree of change of the function. In this project, it represents the rate of change of the function in each dimension. During training, the Adam optimizer is used to perform bias correction on the gradient of each parameter of the improved FNN model, maintaining the first moment (the mean of the gradient) and the second moment (the mean of the square of the gradient). The update rule of the Adam optimizer is as follows:
[0101] m t = β1m t-1 +(1 - β1)g t (7)
[0102]
[0103]
[0104]
[0105] where m t is the current momentum (velocity in simulated physics), adding an inertia to the gradient during gradient update, making the optimization path smoother and not overly oscillating, accumulating the gradient through exponential moving average, m t-1 is the momentum of the previous step; β1 is the exponential decay rate of the first moment (momentum), controlling the retention ratio of historical gradient information (usually taken as 0.9); g t is the gradient at the current time step t, that is, the gradient of the loss function with respect to the parameter θ t-1 ; ν t is the exponential moving average of the current squared gradient, used to adaptively adjust the learning rate, ν t-1 is the exponential moving average of the squared gradient of the previous step; β2 is the exponential decay rate of the second moment (squared gradient), controlling the retention ratio of historical gradient squares (usually taken as 0.999); is the momentum after bias correction; is the squared gradient after bias correction; θ t is the updated model parameter (representing all the weights and biases of the neural network here, as well as the learnable parameters γ and β of the batch normalization layer), θ t-1 is the model parameter vector of the previous step; s is the learning rate, determining the magnitude of parameter update; is a numerical stability constant to prevent the denominator from being zero (usually taken as 1e - 8).
[0106] The Adam optimizer can adaptively adjust the learning rate, improving the training speed, combining the advantages of the momentum method and Root Mean Square Propagation, and can effectively handle the sparse gradient problem. Using the cross - entropy loss function, for multi - class classification problems, the cross - entropy loss function is defined as:
[0107]
[0108] where: L is the loss value. k is the number of classes. y i is the actual label, usually a one - hot encoding. p μ is the probability of the class predicted by the model u, obtained by outputting through the Softmax function, f S is the linear output of the output layer of the improved FNN model. log(p i ) represents taking the logarithm of the predicted probability pi Take the natural logarithm (base e). This algorithm can effectively measure the gap between the model output probability and the actual label. It is more suitable for classification problems than the mean squared error and can better guide the model learning. In addition, the present invention sets an early termination mechanism. During the training process, if the loss value on the validation set does not decrease significantly for multiple consecutive epochs, the training is stopped. Usually, the training is stopped when the loss does not improve to avoid overfitting. Figure 4 and Figure 5 are the visualized model structures of the FNN and the improved FNN, respectively. Figure 6 is the detailed flowchart of the gas detection and recognition method.
[0109] Train the model, implement dynamic learning rate adjustment, conduct batch training, and use the validation set for evaluation. Calculate the predicted values, calculate the confusion matrix and accuracy. Plot the accuracy curve, loss curve, and confusion matrix in a visual way for model evaluation and improvement. Among them, the confusion matrix is one of the commonly used evaluation metrics in classification problems, which is used to measure the performance of the model on the test set. The confusion matrix can intuitively show the correct classification and misclassification situations of the model, so as to deeply understand the advantages and disadvantages of the model. For multi-classification problems (such as the gas sensor classification task in this project), the confusion matrix is a k×k table, where k is the number of classes. The diagonal of the matrix represents the number of correct classifications, and the off-diagonal elements represent the number of misclassifications.
[0110] S4. Classify and identify the test data based on the trained improved FNN model to obtain the classification results.
[0111] In addition, to illustrate the superiority of the improved FNN proposed by the present invention, the present invention verified the effects of the FNN and the improved FNN models (calculating accuracy and confusion matrix) on the public dataset, specifically as Figure 7 shown in (a) and (b). The upper left corner of the diagonal in the two figures represents the number of correct classifications as ethanol, and so on. The more numbers on the diagonal, the better the model and the more accurate the prediction probability. Figure 8 (a) and (b) in the figure respectively represent the accuracy and loss curves during the training process of the improved FNN model. Among them, the closer the two curves tend to fit, the better the trained model and the higher the recognition accuracy.
[0112] The present invention develops a new type of air detection method through the mutual assistance of the software and hardware platform and the deep learning algorithm (STM32 hardware platform, Alibaba Cloud Internet of Things platform, and improved FNN algorithm), which can effectively improve the detection accuracy and enhance the data visualization effect, providing reliable technical support for the subsequent construction of the intelligent environment control system.
[0113] A smart home air detection and recognition system based on an improved FNN, comprising:
[0114] A data acquisition module is used to collect pollutant data in indoor air, as well as indoor air pressure and temperature data. The data acquisition module includes an STM32 microcontroller, an air detection module, a BMP280 barometer module, a communication module, and an Internet of Things platform. The air detection module is used to detect pollutant data in indoor air, and the BMP280 barometer module is used to collect indoor air pressure and temperature data. The pollutant data, air pressure, and temperature data are transmitted to the STM32 microcontroller through the communication module. After the STM32 microcontroller processes the data, it uploads the data to the Internet of Things platform through the communication module. The Internet of Things platform is used for data display and storage, and to save and display the classification recognition results.
[0115] The STM32 microcontroller displays the real-time detection data through an OLED screen;
[0116] The air detection module includes four different air detection sensors, namely TGS2600, TGS2602, TGS2610, and TGS2620. Through a heating circuit and a signal processing circuit, the gas concentration is converted into a measurable voltage signal, and then converted into a digital signal through an ADC for STM32 processing;
[0117] The communication module is an ESP8266-12F WIFI module, which is built with a microcontroller and a TCP / IP protocol stack and can achieve wireless data transmission.
[0118] The specific hardware structure of the data acquisition module is as described in the above step S1.
[0119] A data processing module is used to extract data features and create a data set. The data format in the data set is: gas label; concentration value; feature: observation value; and preprocess the observation value to obtain a data sample set;
[0120] A model construction and training module is used to construct an improved FNN model and train the model based on the sample set to obtain a trained improved FNN model. Among them, the model improvement includes: using the LeakyReLU activation function for each layer, adding batch normalization to normalize the output of each layer, performing a linear transformation on the normalized output to optimize gradient descent or explosion; setting a Dropout layer for each layer to randomly discard some neurons to prevent overfitting; using the Adam optimizer for parameter optimization and using the cross-entropy loss function to train and evaluate the model.
[0121] A classification recognition module is used to classify and recognize test data based on the trained improved FNN model to obtain a classification result.
[0122] The electronic device described in the present invention includes:
[0123] A memory storing executable program code;
[0124] A processor coupled to the memory;
[0125] The processor calls the executable program code stored in the memory and executes the steps of the improved FNN-based smart home air detection and recognition method.
[0126] A computer-readable storage medium according to the present invention, wherein the computer-readable storage medium stores computer instructions, which are used to execute the steps of the improved FNN-based smart home air detection and recognition method when called.
Claims
1. An intelligent home air detection and recognition method based on an improved FNN, characterized in that It includes the following steps: Collect data on pollutants in indoor air, as well as indoor air pressure and temperature data; Extract data features and create a dataset. The data format in the dataset is: gas label; concentration value ; feature: observation value; and preprocess the observation values to obtain a data sample set; Construct an improved FNN model, train the model based on the sample set to obtain a trained improved FNN model. Among them, the model improvement includes: using the Leaky Rectified Linear Unit activation function for each layer, adding batch normalization to normalize the output of each layer, performing a linear transformation on the normalized output to optimize gradient descent or explosion; setting a Dropout layer for each layer to randomly discard some neurons to prevent overfitting; using the Adam optimizer for parameter optimization and using the cross-entropy loss function to train and evaluate the model. Based on the trained improved FNN model, classify and identify the test data to obtain a classification result.
2. The smart home air detection and recognition method based on the improved FNN according to claim 1, wherein In the dataset, each gas label corresponds to multiple concentration values and multiple features, and each feature corresponds to multiple observation values. The preprocessing of the observation values includes: using the mean filling strategy to fill in missing data, and normalizing the multiple observation values corresponding to each feature after filling. The dataset after normalization is the sample set.
3. The method for detecting and identifying smart home air based on the improved FNN according to claim 1, characterized in that, In the improved FNN model, the expression of the Leaky Rectified Linear Unit activation function is: f(x) = max(αx, x) where f(x) represents the output of the activation function, x represents the input value of the activation function, and αx represents the output value of the activation function; The formula for batch normalization is: Among them, represents the standardized intermediate value, x represents, μ B is the mean of all inputs on the current batch of data, is the variance of all inputs on the current batch of data, and ∈ is an extremely small positive number; The formula for linear transformation is: where y represents the final output value after batch normalization, and γ and β are respectively the learned adjustable scaling and translation parameters.
4. The smart home air detection and recognition method based on the improved FNN according to claim 1, wherein, In the improved FNN model, the operation of the Dropout layer is: Among them, represents the output data processed by the Dropout layer, x represents the input data of the Dropout layer, and r is a randomly generated binary mask.
5. The smart home air detection and recognition method based on the improved FNN according to claim 1, characterized in that The update rule of the Adam optimizer is: m t = β1m t-1 + (1 - β1)g t The gradient represents the directional derivative vector of a function at a certain point. It points in the direction where the function value increases fastest, and its magnitude represents the intensity of the function change. In this project, it represents the rate of change of the function in each dimension. Among them, m t is the current momentum (velocity in simulated physics), which adds an inertia to the gradient during gradient update, making the optimization path smoother and not overly oscillating. The gradient is accumulated through exponential moving average, m t-1 is the momentum of the previous step, β1 is the exponential decay rate of the first moment, g t is the gradient at the current time step t, that is, the gradient of the loss function with respect to the parameter θ t-1 ; v t is the exponential moving average of the current squared gradient, v t-1 is the exponential moving average of the squared gradient of the previous step, β2 is the exponential decay rate of the second moment, is the momentum after bias correction, is the squared gradient after bias correction, is the power of β1 at the t-th step, is the power of β2 at the t-th step, θ t is the updated model parameter, θ t-1 is the parameter of the previous step, α is the learning rate, ∈ is a numerical stability constant; The cross-entropy loss function is: where L is the loss value, C is the number of classes, and y i is the actual label, and p i is the probability of class i predicted by the model, and log(p i ) represents taking the natural logarithm of the predicted probability p i .
6. A smart home air detection and recognition system based on an improved FNN, characterized in that, It includes: A data collection module for collecting data on pollutants in indoor air, as well as indoor air pressure and temperature data; A data processing module for extracting data features and creating a dataset. The data format in the dataset is: gas label; concentration value ; feature: observation value; and preprocessing the observation values to obtain a data sample set; A model construction and training module for constructing an improved FNN model, training the model based on the sample set to obtain a trained improved FNN model. Among them, the model improvement includes: using the Leaky Rectified Linear Unit activation function for each layer, adding batch normalization to normalize the output of each layer, performing a linear transformation on the normalized output to optimize gradient descent or explosion; setting a Dropout layer for each layer to randomly discard some neurons to prevent overfitting; using the Adam optimizer for parameter optimization and using the cross-entropy loss function to train and evaluate the model. A classification and identification module for classifying and identifying test data based on the trained improved FNN model to obtain a classification result.
7. The intelligent home air detection and recognition system based on the improved FNN according to claim 6, characterized in that, The data acquisition module includes an STM32 microcontroller, an air detection module, a BMP280 barometer module, a communication module, and an Internet of Things platform. The air detection module is used to detect pollutant data in indoor air. The BMP280 barometer module is used to collect indoor air pressure and temperature data. The pollutant data, air pressure, and temperature data are transmitted to the STM32 microcontroller through the communication module. After the STM32 microcontroller processes the data, it uploads the data to the Internet of Things platform through the communication module. The Internet of Things platform is used for data display and storage, and to save and display the classification recognition results.
8. The smart home air detection and recognition system based on the improved FNN according to claim 6, characterized in that, The STM32 microcontroller displays the real-time detection data through an OLED screen; The air detection module includes four different air detection sensors, namely TGS2600, TGS2602, TGS2610, and TGS2620. Through a heating circuit and a signal processing circuit, the gas concentration is converted into a measurable voltage signal, and then converted into a digital signal through an ADC for STM32 processing; The communication module is an ESP8266-12F WIFI module, which is built with a microcontroller and a TCP / IP protocol stack and can achieve wireless data transmission.
9. An electronic device, characterized in that, The device includes: A memory storing executable program code; A processor coupled to the memory; The processor calls the executable program code stored in the memory and executes the steps of the method for detecting and identifying indoor air based on the improved FNN according to any one of claims 1-5.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions, which are used to execute the steps of the method for detecting and identifying indoor air based on the improved FNN according to any one of claims 1-5 when the computer instructions are called.