Student real-time emotion recognition method based on fusion attention mechanism
By adding the channel spatial attention module and GRN layer to the ConvNeXt V2 model, combined with LDAM and Focal loss functions, the problem of global feature extraction and class distribution imbalance in facial expression recognition is solved, achieving high performance in complex classroom scenarios. Accuracy and robust expression recognition support teachers in adjusting their teaching.
Patent Information
- Application Number
- CN202410659875.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-27
- Publication Date
- 2024-08-23
AI Technical Summary
It is difficult to extract the global features of students' facial expressions in complex classroom scenes with existing technology in facial expression recognition, and it is easily affected by changes in light and posture, resulting in insufficient recognition accuracy. The problem of unbalanced class distribution also affects the generalization of the model. ability.
A real-time student emotion recognition method based on the fusion attention mechanism is adopted. By adding the channel spatial attention module and GRN layer to the ConvNeXt V2 model, and combining the LDAM and Focal loss functions, the local and global feature extraction of students' facial expressions is achieved and enhanced. Model robustness and generalization ability.
Accurately extracting students' facial expression features in complex classroom scenarios improves the recognition rate, effectively alleviates the problem of unbalanced class distribution, improves expression recognition performance and robustness, and provides strong support for teachers to adjust teaching strategies.
Smart Images

Figure CN118537907A
Abstract
Description
Technical Field
[0001] The present invention relates to a student real-time emotion recognition method based on a fusion attention mechanism, and belongs to the technical field of recognizing biological features, human-related or animal-related patterns in image or video data. Background Art
[0002] Facial expressions are an important part of human emotional communication. By analyzing facial expressions, we can infer a person's emotions and understand his or her inner emotional state. As an extremely important task in the field of computer vision, facial expression recognition plays a vital role in various applications such as medical diagnosis, driver fatigue monitoring, and human-computer interaction. With the promotion and implementation of digital education, expression recognition technology has also been widely used in classroom teaching to analyze the emotional state of students in the classroom, thereby helping teachers improve teaching and improve teaching effectiveness. Therefore, using expression recognition technology to analyze student emotions in the classroom provides strong support for building a smart classroom.
[0003] ConvNeXt is a pure ConvNet model based on the ResNet architecture and upgraded with reference to the ideas of Swin-T. Starting from ResNet-50, it borrows the ideas of Swin Transformer from five perspectives: macro design, depthwise separable convolution (ResNeXt), inverse bottleneck layer (MobileNet v2), large convolution kernel and detail design, and then trains and evaluates on ImageNet-1K, finally achieving a recognition accuracy that can compete with Transformer. However, due to the complexity of facial expression image features, expressions are easily affected by factors such as light intensity. If we only focus on the key points of facial expressions, we will not be able to grasp the global information representation of facial expression changes.
[0004] The attention mechanism is an important deep learning technology that is widely used in models in different fields to enhance the model's attention and learning of important information, thereby improving the performance and efficiency of the model. In computer vision tasks, the attention mechanism is widely used in tasks such as image classification, object detection, and image generation. Through the attention mechanism, the model can automatically select important areas in the image and process local areas according to task requirements.
[0005] CBAM (Convolutional Block Attention Module) is a new attention mechanism that combines channel attention and spatial attention to make the model more flexible in image processing and can adaptively extract the most important features in the image. However, its algorithm based on local feature extraction is too simple and often loses some complex and significant features, resulting in insufficient feature representation ability.
[0006] The loss function is a very core concept in both machine learning and deep learning. It is used to quantify the difference between the model's predictions and the actual results, and serves as a goal for optimizing the algorithm during the training process. In simple terms, the loss function measures the degree of prediction error of the model. Therefore, the loss function can help the algorithm adjust parameters by minimizing the loss function, thereby improving the model's prediction performance.
[0007] LDAM loss (Label-Distribution-Aware Margin Loss) is a loss function that alleviates the problem of imbalanced class distribution by introducing stronger regularization for minority classes than for majority classes to reduce their generalization error. In this way, the loss function maintains the model's ability to learn majority classes and emphasize minority classes. In addition, FL (Focal Loss) is an improved loss function for the first-level object detector, which adjusts the number and difficulty of samples by introducing a regulation factor so that the model can focus on learning minority classes. However, if the model focuses too much on specific categories and cannot focus more on general classification tasks, it will affect the model's generalization ability in various categories, and thus affect the model's expression classification recognition rate. Summary of the invention
[0008] In order to solve the above technical problems, the present invention provides a real-time emotion recognition method for students based on a fusion attention mechanism. The real-time emotion recognition method for students based on a fusion attention mechanism can fully extract the local and global features of students' facial expressions even in complex classroom teaching scenarios. The recognition ability and advantages are more prominent when there is a lot of image noise and large posture changes.
[0009] The present invention is achieved through the following technical solutions.
[0010] The present invention provides a method for real-time student emotion recognition based on a fusion attention mechanism, comprising the following steps:
[0011] S1. Obtaining datasets: Obtaining facial expression datasets from public channels;
[0012] S2. Data distribution: label the facial expression dataset and divide the facial expression dataset into a training set and a test set;
[0013] S3, adjusting image pixels: scaling the size of each image in the facial expression dataset to a preset size;
[0014] S4. Build the backbone network: Build the recognition model based on ConvNeXt V2, and add a GRN layer to the last layer of ConvNeXt V2;
[0015] S5. Additional channel spatial attention module: The channel spatial attention module is placed at the output layer of the convolutional layer in the recognition model;
[0016] S6. Setting loss function module: Setting a joint loss function module that only runs during training in the output layer of the recognition model;
[0017] S7, training model: using the training set to train the recognition model, and using the test set to test the trained recognition model;
[0018] S8, verification: verify the trained recognition model;
[0019] S9, load and execute: load the verified recognition model to the teacher video monitoring video stream processing terminal for execution.
[0020] The facial expression datasets include the FERPlus dataset and the RAF-DB dataset.
[0021] In step S3, the preset size is 224*224 pixels.
[0022] In step S4, a residual connection is added before the output of the GRN layer.
[0023] In step S5, a sigmoid activation function in the channel space attention module is changed to a GELU activation function.
[0024] In step S6, the loss function of the joint loss function module includes LDAM loss.
[0025] The loss function is a linear combination of LDAM loss and Focal loss.
[0026] The step S8 is verified by using ablation experiments and comparative experiments.
[0027] The number of training times in step S7 is 60 epochs.
[0028] The present invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the method for real-time student emotion recognition based on a fusion attention mechanism as described above.
[0029] The beneficial effects of the present invention are: it can accurately extract students' facial expression features in complex classroom scenes, and obtain a high recognition rate even when the image has posture changes and noise; it effectively alleviates the problem of class distribution imbalance in face data sets, and realizes sentiment analysis that dynamically considers hard samples and class distribution; it has relatively advanced expression recognition performance and robustness, and a high student expression recognition rate provides a strong guarantee for students to adjust their learning status and teachers to improve their teaching strategies. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 is a schematic diagram of a process of at least one embodiment of the present invention;
[0031] Figure 2 It is a schematic diagram of the architecture of a system for implementing the present invention;
[0032] Figure 3 It is a recognition model architecture diagram obtained by at least one implementation manner of the present invention. DETAILED DESCRIPTION
[0033] The technical solution of the present invention is further described below, but the scope of protection claimed is not limited to the description.
[0034] A first embodiment of the present invention relates to Figure 1 A student real-time emotion recognition method based on a fusion attention mechanism is shown, comprising the following steps:
[0035] S1. Obtaining datasets: Obtaining facial expression datasets from public channels;
[0036] S2. Data distribution: label the facial expression dataset and divide the facial expression dataset into a training set and a test set;
[0037] S3, adjusting image pixels: scaling the size of each image in the facial expression dataset to a preset size;
[0038] S4. Build the backbone network: Build the recognition model based on ConvNeXt V2, and add a GRN layer to the last layer of ConvNeXt V2;
[0039] S5. Additional channel spatial attention module: The channel spatial attention module is placed at the output layer of the convolutional layer in the recognition model;
[0040] S6. Setting loss function module: Setting a joint loss function module that only runs during training in the output layer of the recognition model;
[0041] S7, training model: use the training set to train the above steps. Figure 3 The recognition model shown is trained, and the trained recognition model is tested using a test set;
[0042] S8, verification: verify the trained recognition model;
[0043] S9, load and execute: load the verified recognition model to the teacher video monitoring video stream processing terminal for execution.
[0044] The second embodiment of the present invention is substantially the same as the first embodiment, mainly in that the facial expression dataset includes a FERPlus dataset and a RAF-DB dataset.
[0045] Furthermore, in step S3, the preset size is 224*224 pixels.
[0046] Furthermore, in step S4, a residual connection is added before the output of the GRN layer.
[0047] Furthermore, in step S5, a sigmoid activation function in the channel spatial attention module is changed to a GELU activation function.
[0048] Furthermore, in step S6, the loss function of the joint loss function module includes LDAM loss.
[0049] Furthermore, the loss function is a linear combination of LDAM loss and Focal loss.
[0050] Furthermore, step S8 is verified by using ablation experiments and comparative experiments.
[0051] Furthermore, the number of training times in step S7 is 60 epochs.
[0052] The third embodiment of the present invention is substantially the same as the first embodiment, mainly in that a specific implementation scheme comprises the following steps:
[0053] Step 1: Download two large public facial expression datasets, FERPlus and RAF-DB, from the official website.
[0054] Step 2: Use labels 0-7 to correspond to the eight facial expressions included in the FERPlus dataset; at the same time, use digital labels 0-6 to correspond to the seven expressions included in the RAF-DB dataset; further, according to the allocation rules, divide the dataset into a training set and a test set.
[0055] Step 3: In the training and validation of all datasets, resize each image to 224*224 pixels.
[0056] Step 4: With the support of ConvNeXt V2 technology, GRN is combined to complete the task of face recognition. The specific process is as follows:
[0057] First, the spatial feature X is transformed into i Aggregate into a vector gx, as shown in Formula 1. Each channel feature can get a value, and finally get a set of aggregate values G(X) = gx = {||X1||,...,||XC||}∈RC. Where G(X) i =||X i || is a scalar that aggregates the statistics of the ith channel.
[0058] G(X): = X∈R H×W×C →gx∈R C (1)
[0059] Furthermore, the scalar of the statistical information of the i-th channel is normalized as shown in Formula 2, where ||X i || is the L2 norm of the ith channel.
[0060]
[0061] Furthermore, feature calibration, as shown in Formula 3, uses the feature normalization scores calculated previously to calibrate the original input response.
[0062] X i =X i *N(G(X) i )∈R H×W (3)
[0063] Finally, to simplify and optimize the formula calculation, feature calibration adds two learnable parameters γ and β and initializes them to zero. In addition, a residual connection X is added before the output of the GRN layer. i , the specific calculation is shown in Formula 4.
[0064] X i =γ*X i *N(G(X) i )+β+X i (4)
[0065] Step 5: With the support of the channel spatial attention (CSA) module, the complex features of facial expressions are extracted. The specific process is as follows:
[0066] First, the feature vector (F) extracted by the convolutional block in the backbone network is used as the input of the channel-spatial attention module, and then the channel and spatial feature extraction are performed simultaneously.
[0067] Furthermore, the use of activation functions is reduced, and one of the sigmoid activation functions is changed to a GELU activation function, and finally the channel weight (Mc) is generated; and the spatial weight (Ms) is generated through a series of operations of spatial feature extraction.
[0068] Furthermore, the sum of Mc and Ms obtained by parallel feature extraction is multiplied by the original feature vector (F) to obtain F′, as shown in Formula 5.
[0069]
[0070] Finally, F′ is added to the original feature vector F to obtain the final feature vector F″ as shown in Formula 6.
[0071] F″=F+F′ (6)
[0072] Step 6: After training the recognition model, use the joint loss function module to tune the model to improve the ability of data set image classification. The specific process is as follows:
[0073] First, we assign a certain weight ω (value 0.001) to the LDAM loss. The LDAM loss function formula is as follows:
[0074]
[0075] Furthermore, the LDAM loss is linearly combined with the Focal loss, and the FL loss function formula is:
[0076] FL(pt)=-(1-pt) γ log(pt) (8)
[0077] The final LF joint loss function is as follows:
[0078] L LF =ωL LDAM +L FL (9)
[0079] Among them, ω is the weight coefficient, and the value in this paper is 0.001.
[0080] Step 7. Adjust the number of model training times to 60 epochs. At the same time, adjust the learning rate to 2e-5 to improve the expression recognition accuracy of the model.
[0081] Step 8. Use ablation experiments and comparative experiments to verify the effectiveness and superiority of the model on the FERPlus and RAF-DB datasets.
[0082] The fourth embodiment of the present invention is substantially the same as the first embodiment, mainly in another specific implementation scheme, comprising the following steps:
[0083] Step 1: Collect and process video stream data from classroom video surveillance, obtain key frames in the video stream data according to sampling rules, and obtain student classroom pictures after processing.
[0084] Step 2: Resize each image to 224*224 pixels. At the same time, protect the students' faces to protect their privacy.
[0085] Step 3: With the support of ConvNeXt V2 technology, GRN is combined to complete the task of face recognition. The specific process is as follows:
[0086] First, the spatial feature X is transformed into i Aggregate into a vector gx, as shown in Formula 1. Each channel feature can get a value, and finally get a set of aggregate values G(X) = gx = {||X1||,...,||XC||}∈RC. Where G(X) i =||X i || is a scalar that aggregates the statistics of the ith channel.
[0087] G(X): = X∈R H×W×C →gx∈R c (1)
[0088] Furthermore, the scalar of the statistical information of the i-th channel is normalized as shown in Formula 2, where ||X i || is the L2 norm of the ith channel.
[0089]
[0090] Furthermore, feature calibration, as shown in Formula 3, uses the feature normalization scores calculated previously to calibrate the original input response.
[0091] X i =X i *N(G(X) i )∈R H×W (3)
[0092] Finally, to simplify and optimize the formula calculation, feature calibration adds two learnable parameters γ and β and initializes them to zero. In addition, a residual connection X is added before the output of the GRN layer. i , the specific calculation is shown in Formula 4.
[0093] X i =γ*X i *N(G(X) i )+β+X i (4)
[0094] Step 4: With the support of the Channel Spatial Attention (CSA) module, the complex features of facial expressions are extracted. The specific process is as follows:
[0095] First, we take the feature vector (F) extracted by the convolutional block in the backbone network as the input of the CSA module, and then perform channel and spatial feature extraction simultaneously.
[0096] Furthermore, the use of activation functions is reduced, and one of the sigmoid activation functions is changed to a GELU activation function, and finally the channel weight (Mc) is generated; and the spatial weight (Ms) is generated through a series of operations of spatial feature extraction.
[0097] Furthermore, the sum of Mc and Ms obtained by parallel feature extraction is multiplied by the original feature vector (F) to obtain F′, as shown in Formula 5.
[0098]
[0099] Finally, F′ is added to the original feature vector F to obtain the final feature vector F″ as shown in Formula 6.
[0100] F″=F+F′ (6)
[0101] Step 5: After training the recognition model, use the joint loss function module to tune the model to improve the ability of image classification of the data set. The specific process is as follows:
[0102] First, we assign a certain weight ω (value 0.001) to the LDAM loss. The LDAM loss function formula is as follows:
[0103]
[0104] Furthermore, the LDAM loss is linearly combined with the Focal loss, and the FL loss function formula is:
[0105] FL(pt)=-(1-pt) γ log(pt) (8)
[0106] The final LF joint loss function is as follows:
[0107] L LF =ωL LDAM +L FL (9)
[0108] Among them, ω is the weight coefficient, and the value in this paper is 0.001.
[0109] Step 6. Adjust the number of model training times to 60 epochs. At the same time, adjust the learning rate to 2e-5 to improve the expression recognition accuracy of the model.
[0110] Experimental example results analysis:
[0111] First, in the ablation experiment, the recognition accuracy of ConvNeXt V2 on the two datasets was 89.09% and 87.81% respectively. After adding the LF Loss module and the CSA module, the accuracy of the new model LCANet we proposed reached 91.43% and 90.03% respectively, which was 2.34% and 2.22% higher than the recognition accuracy of the original model.
[0112] Furthermore, in comparative experiments, the LCANet model proposed in the present invention has significantly improved accuracy compared with advanced methods (ResNet, SCN, RAN, MVT, etc.) on FERPlus and RAF-DB datasets.
[0113] Finally, the role of the network in facial expression recognition is further illustrated by giving the confusion matrix of the facial expression recognition results obtained on the FERPlus and RAF-DB datasets. The confusion matrix of the FERPlus dataset shows that the model has advantages in neutral, surprised, happy, disgusted, fearful, and angry expressions, especially in happy, angry, surprised, and neutral expressions, with recognition effects exceeding 90%. The confusion matrix of the RAF-DB dataset shows that the model has advantages in neutral, surprised, happy, disgusted, and angry expressions, especially in happy, disgusted, and neutral expressions, with recognition effects exceeding 90%.
[0114] A series of experiments have shown that the recognition model obtained by the above method can also well recognize students' facial emotions in complex real classroom scenarios. The information obtained can be fed back to teachers in real time, providing technical support for teachers to adjust and improve their teaching.
[0115] A fifth embodiment of the present invention relates to a computer-readable storage medium storing a computer program, wherein the computer program implements the above embodiment when executed by a processor.
Claims
1. A method for real-time student emotion recognition based on fusion attention mechanism, It is characterized in that The following steps are involved: S1. Obtaining datasets: Obtaining facial expression datasets from public channels; S2. Data allocation: label the facial expression dataset and divide the facial expression dataset into a training set and a test set; S3, adjusting image pixels: scaling the size of each image in the facial expression dataset to a preset size; S4. Build the backbone network: Build the recognition model based on ConvNeXt V2, and add a GRN layer to the last layer of ConvNeXt V2; S5. Additional channel spatial attention module: The channel spatial attention module is placed at the output layer of the convolutional layer in the recognition model; S6. Setting loss function module: Setting a joint loss function module that only runs during training in the output layer of the recognition model; S7, training model: using the training set to train the recognition model, and using the test set to test the trained recognition model; S8, verification: verify the trained recognition model; S9, load and execute: load the verified recognition model to the teacher video monitoring video stream processing terminal for execution.
2. The method for real-time student emotion recognition based on the fusion attention mechanism as claimed in claim 1, It is characterized in that The facial expression datasets include the FERPlus dataset and the RAF-DB dataset.
3. The student real-time emotion recognition method based on the fusion attention mechanism as claimed in claim 1, It is characterized in that In step S3, the preset size is 224*224 pixels.
4. The method for real-time student emotion recognition based on the fusion attention mechanism as claimed in claim 1, It is characterized in that In step S4, a residual connection is added before the output of the GRN layer.
5. The method for real-time student emotion recognition based on fusion attention mechanism as claimed in claim 1, It is characterized in that In step S5, a sigmoid activation function in the channel space attention module is changed to a GELU activation function.
6. The method for real-time student emotion recognition based on the fusion attention mechanism as claimed in claim 1, It is characterized in that In step S6, the loss function of the joint loss function module includes LDAM loss.
7. The method for real-time student emotion recognition based on fusion attention mechanism as claimed in claim 6, It is characterized in that The loss function is a linear combination of LDAM loss and Focal loss.
8. The method for real-time student emotion recognition based on the fusion attention mechanism as claimed in claim 1, It is characterized in that The step S8 is verified by using ablation experiments and comparative experiments.
9. The method for real-time student emotion recognition based on fusion attention mechanism as claimed in claim 1, It is characterized in that The number of training times in step S7 is 60 epochs.
10. A computer-readable storage medium storing a computer program, It is characterized in that When the computer program is executed by a processor, the method for real-time student emotion recognition based on a fusion attention mechanism described in any one of claims 1 to 9 is implemented.
Citation Information
Patent Citations
Semantic segmentation method based on self-attention and convolution feature fusion
CN117036686A
Infant spasm clinical attack video identification method based on deep learning
CN117058584A
Leaf vegetable crop detection method and device based on Mask R-CNN
CN117765370A
Method, device and equipment for intelligently identifying and evaluating implant of revision surgical robot
CN117853458A
Cited By
Juvenile face attribute analysis method based on Ret attention and ConvNeXt network
CN119600657A
