A method and system for facial expression recognition of stroke patients based on self-attention
By constructing an expression recognition model based on the ViT self-attention mechanism, using the facial expression data set for pre-training and using the stroke patient data set for enhanced training, the problem of low expression recognition rate in stroke patients was solved, and the recognition accuracy and accuracy were improved. Texture interpretation capabilities are suitable for the field of rehabilitation medicine.
Patent Information
- Application Number
- CN202210087537.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-25
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2042-01-25
AI Technical Summary
The existing technology has a low expression recognition rate for stroke patients in the field of rehabilitation medicine. Equipment limitations make it difficult to popularize facial expression recognition technology. In particular, the texture information interpretation ability is weak and the model parameters are large, making it difficult to apply to the field of expression recognition.
Using the self-attention mechanism based on Vision Transformer (ViT), by constructing an expression recognition model consisting of a convolution embedding module, a Transformer module, a multi-channel feature extraction module and an output module that are connected in sequence, and after pre-training using the facial expression data set, Enhanced training was performed with the stroke patient expression data set to identify the expression categories of stroke patients.
It improves the accuracy and interpretation ability of expression recognition of stroke patients, reduces the number of model parameters, adapts to the expression recognition task of lightweight stroke patients, and the model's ability to interpret texture information has been improved, making it suitable for the field of rehabilitation medicine.
Smart Images

Figure CN114429659B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence, and in particular to a method and system for recognizing facial expressions of stroke patients based on self-attention. Background Art
[0002] Facial expression is the main way for humans to express their emotions and plays an important role in interpersonal communication. Therefore, facial expression recognition (FER) is the mainstream emotion perception method. Compared with emotion perception methods based on physiological indicators such as heart rate and blood pressure, facial expression recognition technology has the advantages of non-contact, simple measurement, and high accuracy. It is one of the research hotspots in the field of human-computer interaction. As early as the 1970s, Ekman and Friesen defined six basic emotions based on cross-cultural research: anger, disgust, happiness, sadness, fear and surprise. Later generations added contempt on this basis, which became the current mainstream 7 basic expressions. The main task of facial expression recognition is to classify expression images into these 7 basic expressions. The application of expression recognition technology is also very extensive, such as fatigue driving, human-computer interaction, personalized recommendation, online teaching, etc. Through expression recognition and analysis of user's emotional information, it is possible to provide more personalized products. However, in the field of rehabilitation medicine, the application of expression recognition is still in its infancy. Due to the low recognition rate of patients' expressions and equipment limitations, the further popularization of expression recognition technology in the medical field is hindered.
[0003] Transformer, as a deep learning model based on self-attention mechanism, has achieved great success in natural language processing (NPL). Since then, this emerging model has become a hot topic in the field of machine learning. Due to its excellent robustness and interpretability, Transformer is also widely used in other disciplines such as computer vision (CV), audio processing and life sciences. In the field of computer CV, various studies based on Transformer have made significant breakthroughs in visual fields such as image classification, object detection, semantic segmentation, and image super-resolution reconstruction. Among them, through pre-training on large datasets, ViT (Vision Transformer) has surpassed the mainstream convolutional neural network (CNN) model in classification tasks, and studies have found that ViT has strong anti-occlusion and shape interpretation capabilities. However, due to ViT's weaker ability to interpret texture information than CNN, as well as the large number of model parameters and the need for pre-training on large datasets, ViT is difficult to use in the field of expression recognition. Summary of the invention
[0004] The purpose of the present invention is to provide a method and system for recognizing facial expressions of stroke patients based on self-attention, which can recognize the facial expressions of patients with mild stroke.
[0005] To achieve the above object, the present invention provides the following solutions:
[0006] A method for facial expression recognition of stroke patients based on self-attention, the method comprising:
[0007] Obtain a dataset of facial expressions of stroke patients;
[0008] Build an expression recognition model based on ViT;
[0009] The ViT-based expression recognition model is trained using a human facial expression dataset and a stroke patient expression dataset;
[0010] The categories of stroke patients’ expressions are identified through the trained ViT-based expression recognition model.
[0011] Optionally, the step of acquiring a stroke patient facial expression dataset specifically includes:
[0012] Obtain videos of stroke patients’ expressions;
[0013] Annotating the expression video to obtain segmented videos of various expressions;
[0014] Convert each of the segmented videos into images to obtain image groups of various expressions; the images in the image groups include an expression start state, an expression end state, and an expression peak state;
[0015] Frame the faces of people in the picture groups of the various types of expressions to obtain face pictures;
[0016] The facial image is scaled to obtain the stroke patient expression dataset.
[0017] Optionally, the ViT-based expression recognition model includes: a convolutional embedding module, a Transformer module, a multi-channel feature extraction module and an output module connected in sequence.
[0018] Optionally, the Transformer module includes: an Encoder and a block integration network.
[0019] Optionally, the training of the ViT-based expression recognition model using the facial expression dataset and the stroke patient expression dataset specifically includes:
[0020] Taking the facial expression data set as input and the confidence of each type of expression as output, the ViT-based expression recognition model is pre-trained to obtain a pre-trained model; the expression category with the highest confidence is the prediction result of the pre-trained model;
[0021] enhancing the expression dataset of the stroke patient to obtain an enhanced expression dataset;
[0022] The pre-trained model is trained with the enhanced expression data set as input and the confidence of each type of expression as output to obtain a trained ViT-based expression recognition model; the expression category with the highest confidence is the prediction result of the trained ViT-based expression recognition model.
[0023] A stroke patient expression recognition system based on self-attention, the system comprising:
[0024] A data set acquisition unit, used for acquiring a stroke patient expression data set;
[0025] A construction unit, used to construct an expression recognition model based on ViT;
[0026] A training unit, used for training the ViT-based expression recognition model through a human facial expression dataset and a stroke patient expression dataset;
[0027] The recognition unit is used to recognize the category of the expression of the stroke patient through the trained ViT-based expression recognition model.
[0028] Optionally, the data set acquisition unit includes:
[0029] An expression video acquisition subunit, used for acquiring expression videos of stroke patients;
[0030] A labeling subunit, used to label the expression video to obtain segmented videos of various expressions;
[0031] A picture processing subunit is used to process each of the segmented videos into pictures to obtain picture groups of various expressions; the pictures in the picture group include the expression start state, expression end state and expression peak state;
[0032] A facial picture determination subunit is used to frame the faces of people in the picture group of various types of expressions to obtain facial pictures;
[0033] The data set determination subunit is used to scale the facial image to obtain the stroke patient expression data set.
[0034] Optionally, the ViT-based expression recognition model includes: a convolutional embedding module, a Transformer module, a multi-channel feature extraction module and an output module connected in sequence.
[0035] Optionally, the Transformer module includes: an Encoder and a block integration network.
[0036] Optionally, the training unit includes:
[0037] A pre-training model determination subunit is used to pre-train the ViT-based expression recognition model using a facial expression data set as input and confidence levels of various expressions as output to obtain a pre-training model; the expression category with the highest confidence level is the prediction result of the pre-training model;
[0038] An enhanced data set subunit is used to enhance the expression data set of the stroke patient to obtain an enhanced expression data set;
[0039] The expression recognition model determination subunit is used to train the pre-trained model with the enhanced expression data set as input and the confidence of each type of expression as output to obtain a trained ViT-based expression recognition model; the expression category with the highest confidence is the prediction result of the pre-trained model.
[0040] According to the specific embodiments provided by the present invention, the present invention discloses the following technical effects:
[0041] The present invention provides a method and system for self-attention-based expression recognition of stroke patients, comprising: obtaining a stroke patient expression data set, constructing a ViT-based expression recognition model, training the ViT-based expression recognition model through a facial expression data set and the stroke patient expression data set, and identifying the category of the stroke patient's expression through the trained ViT-based expression recognition model. The present invention constructs a ViT-based expression recognition model, uses the facial expression data set as input for pre-training to obtain a pre-trained model, and then uses the data set enhanced from the stroke patient expression data set as input to train the pre-trained model, so that the ViT-based expression recognition model can recognize lightweight stroke patient expressions. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0043] Figure 1 This is a flow chart of the method for recognizing facial expressions of stroke patients based on self-attention of the present invention;
[0044] Figure 2The category and quantity bar graph of the expression data set of stroke patients in the present invention;
[0045] Figure 3 This is a structural diagram of the expression recognition model based on ViT of the present invention;
[0046] Figure 4 Integrate the network structure diagram for the block of the present invention;
[0047] Figure 5 This is a block diagram of the stroke patient expression recognition system based on self-attention of the present invention;
[0048] Figure 6 It is a confusion matrix diagram of the expression recognition model based on ViT in the present invention on RAF-DB;
[0049] Figure 7 Confusion matrix diagram for ViT on RAF-DB.
[0050] Explanation of symbols:
[0051] Dataset acquisition unit—1, construction unit—2, training unit—3, recognition unit—4. DETAILED DESCRIPTION
[0052] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0053] The purpose of the present invention is to provide a method and system for recognizing facial expressions of stroke patients based on self-attention, which can recognize the facial expressions of patients with mild stroke.
[0054] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0055] like Figure 1 As shown, the method for recognizing facial expressions of stroke patients based on self-attention provided by the present invention comprises:
[0056] Step S1: Obtain a stroke patient facial expression dataset.
[0057] Step S1 specifically includes:
[0058] Step S11: Obtaining a video of the expression of a stroke patient.
[0059] Specifically, the stroke patient expression data set was obtained by collecting expression data from 37 real stroke patients in the rehabilitation department of a rehabilitation hospital. The process of collecting the expression data of the collected objects is as follows: the collected objects are required to imitate 7 basic expressions according to the software prompts, the basic expressions imitated by the collected objects are collected, and the expression changes of the collected objects in the process of imitating the basic expressions are also collected, and a total of 568 expression videos with a resolution of 1280*720 and a frame rate of 20FPS are obtained.
[0060] Step S12: labeling the expression video to obtain segmented videos of various expressions.
[0061] Specifically, the basic expression videos were annotated by five coders who had received expression recognition and coding training. The same type of expression videos were annotated with the same label, and each type of expression video of each stroke patient was a segmented video of each type of expression. In addition, two types of expressions, difficulty in exerting force and pain, were captured from the patient's real training video segments, for a total of nine types of expression video segments.
[0062] Step S13: converting each segmented video into a picture to obtain a picture group of each type of expression; the pictures in the picture group include an expression start state, an expression end state and an expression peak state.
[0063] Specifically, the segmented videos are processed into images to obtain image groups of various expressions of each stroke patient, and 3-5 representative images are selected from the image group of each video. The content of the images includes: expression starting state, expression ending state and expression peak state.
[0064] Step S14: Frame the faces of people in the picture groups of various expressions to obtain facial pictures.
[0065] Specifically, the face of a person in the image is cut out separately to obtain a face image.
[0066] Step S15: scaling the facial image to obtain a stroke patient expression dataset.
[0067] Specifically, the size of the facial images was uniformly scaled to 128*128, and 1143 facial expression images were obtained as the stroke patient expression dataset. The stroke patient expression dataset was randomly divided into a training set and a validation set in a ratio of 4:1. Figure 2 shown.
[0068] Step S2: Construct an expression recognition model based on ViT.
[0069] Specifically, Figure 3As shown in FIG. 1 , the expression recognition model based on ViT includes: a convolutional embedding module, a Transformer module, a multi-channel feature extraction module and an output module which are connected in sequence.
[0070] Furthermore, the convolutional embedding module specifically includes:
[0071] The model input is a three-channel grayscale image with 128*128 pixels, that is, a 3*128*128 grayscale image. The image is converted into the block feature vector required by the Transformer network through convolution through the Convolutional Embedding Block (CE Block). The Convolutional Embedding Block is divided into two parts: feature convolution and block embedding.
[0072] Among them, the feature convolution (Feature Conv) performs convolution with a step size of 2 through a 64*7*7 convolution kernel, and outputs a 64*64*64 image feature map through a 2*2 pooling layer.
[0073] Patch Embedding uses multiple 64*2*2 convolution kernels to perform convolution with a stride of 2, compressing the input into a Patch input TF network with a sequence length N of 16*16.
[0074] Furthermore, the Transformer module specifically includes:
[0075] The Transformer module (TF Block) is the backbone network of the ViT-based expression recognition model, which is used to process the feature vector output by the convolutional embedding module. The Transformer module is divided into two parts: Transformer Encoder and Patch Aggregate.
[0076] Among them, the Transformer Encoder (self-attention network encoder) converts the input feature block into a 3×k×d feature vector through linear transformation and then divides it into feature matrices Q (Queries), K (Keys) and V (values) through dimensional transformation. d is the parameter of each attention head, thereby realizing the self-attention mechanism of the Transformer. The calculation formula of the self-attention module is: Among them, D K Represents the latitude value of K, k is the set number of attention heads, and A is the self-attention matrix.
[0077] By analyzing this matrix, we can analyze the area that the model focuses on, and after outputting the self-attention matrix, we can visualize the model's attention. The output of the Transformer Encoder is integrated and passed to the block integration structure through a forward feedback network consisting of a 1*1 convolution and a Gaussian Error Linear Unit (GELU).
[0078] Among them, the patch aggregation network compresses the amount of block feature data, such as Figure 4 As shown in the figure, the network contains 3*3 convolution, convolution with a stride of 2, BN layer, and pooling layer with a size of 2*2 to extract vector features and accelerate the training of the model. After two rounds of TF modules, the output feature vector is 576*4*4, where d i is the number of input channels, d o is the number of output channels, h is the length of the feature block, and w is the width of the feature block.
[0079] Since the computational complexity and memory usage of the self-attention matrix is equal to the square of the input sequence length N, that is, N 2 ,The calculation of the self-attention matrix A has become the bottleneck of the model. The designed block integration network can reduce the complexity of the self-attention matrix calculation and the memory occupied, thereby accelerating the calculation and improving the fitting speed.
[0080] Furthermore, the multi-channel feature extraction module specifically includes:
[0081] The Multi-Channels Feature Extraction Block (MCFE Block) extracts the processed feature vectors by channel to reduce data loss during feature extraction. The Multi-Channels Feature Extraction Block includes Patch Reconstruction and Channel Feature Pooling (CFP).
[0082] Among them, block reconstruction increases the spatial dimension of the feature vector to 4*48*48 by upsampling, and uses a 12*12 convolution kernel to perform convolution with a step size of 14 on each layer of features to obtain a 4*10*10 feature map.
[0083] Channel feature pooling outputs a 1*10*10 channel feature vector, and the calculation formula is: in are the average and maximum values of the channels at positions i and j respectively, and a is the maximum value weight that can be trained by the model.
[0084] Furthermore, the output module specifically includes:
[0085] The output module reorganizes the 10*10 feature values into one dimension and obtains the confidence of 7 basic expressions through full connection, normalization and Sigmoid function. The one with the highest confidence is the model prediction result. The output module is also called a linear classifier.
[0086] Step S3: Train the ViT-based expression recognition model using the facial expression dataset and the stroke patient expression dataset.
[0087] Step S3 specifically includes:
[0088] Step S31: using the facial expression dataset as input and the confidence of each type of expression as output, pre-training the ViT-based expression recognition model to obtain a pre-trained model; the expression category with the highest confidence is the prediction result of the pre-trained model.
[0089] Specifically, the Fer2013 dataset is used to pre-train the ViT-based expression recognition model. The facial expression dataset includes 7 basic expressions and 35,886 facial expression images. 28,708 images are selected for model training and 3,589 images are used for model verification. The images are grayscale images of 48*48 pixels each, and the faces are not standardized. During training, the images are converted into three-channel images of 224*224 pixels, and the pixel values are normalized from [0, 255] to [0, 1] according to the mean and variance of all images in the dataset. The model is pre-trained using BatchSize set to 120, Lr is 0.0003 for 100 rounds of training, the cross entropy loss function is used to calculate the loss, and the Adam optimizer is used for optimization.
[0090] Among them, the facial expression dataset has 7 types of expression labels, and the corresponding relationships are:
[0091] 0: anger: angry; 1: disgust: disgust; 2: fear: fear; 3: happy: happy; 4: normal: normal; 5: sad: sad; 6: surprised: surprised.
[0092] Step S32: enhancing the stroke patient expression dataset to obtain an enhanced expression dataset.
[0093] Specifically, since the expression recognition model based on ViT has strong explanatory power, it is easy to have overfitting problems on small data sets. In order to alleviate the overfitting of the model, the data set needs to be enhanced to obtain an enhanced expression data set. The method of enhancing the data set includes: horizontally flipping 50% of the pictures, randomly blocking 2%-10% of the pictures, and adding Gaussian white noise with a mean of 0 and a variance of 30. According to the above operations, the phenomenon of model overfitting is effectively reduced.
[0094] Step S33: Using the enhanced expression data set as input and the confidence of each type of expression as output, the pre-trained model is trained to obtain a trained ViT-based expression recognition model; the expression category with the highest confidence is the prediction result of the trained ViT-based expression recognition model.
[0095] Specifically, the pre-trained model is used for transfer learning to optimize the parameters, the model parameters except the output module in the model are locked, and the enhanced expression dataset is used to transfer the pre-trained model. That is, the pixel values are normalized from [0, 255] to [0, 1] according to the mean and variance calculated by the entire dataset and input into the model. The cross entropy loss is calculated based on the model output results and the correct results, and the network is iteratively optimized using the Adam optimizer.
[0096] During the training process, the self-attention matrix A of the ViT-based expression recognition model will be output, and the attention heat map of the ViT-based expression recognition model will be calculated and plotted, which can help us understand the learning of the ViT-based expression recognition model for the expression recognition task. Adjust the number of model blocks and model depth, and repeat the training to achieve a more ideal model accuracy.
[0097] Step S4: Identify the category of the stroke patient's expression through the trained ViT-based expression recognition model. Specifically, the expression category with the highest confidence is the prediction result of the trained ViT-based expression recognition model.
[0098] like Figure 5 As shown, the stroke patient expression recognition system based on self-attention provided by the present invention includes: a data set acquisition unit 1, a construction unit 2, a training unit 3 and a recognition unit 4.
[0099] Specifically, the data set acquisition unit 1 is used to acquire the facial expression data set of stroke patients.
[0100] Construction unit 2 is used to construct an expression recognition model based on ViT.
[0101] The training unit 3 is used to train the ViT-based expression recognition model using a human facial expression dataset and a stroke patient expression dataset.
[0102] The recognition unit 4 is used to recognize the category of the expression of the stroke patient through the trained ViT-based expression recognition model.
[0103] The data set acquisition unit 1 specifically includes:
[0104] The expression video acquisition subunit is used to acquire the expression video of the stroke patient.
[0105] The annotation subunit is used to annotate the expression video to obtain segmented videos of various expressions.
[0106] The picture processing subunit is used to process each segmented video into pictures to obtain picture groups of various expressions; the pictures in the picture group include the expression start state, expression end state and expression peak state.
[0107] The facial image determination subunit is used to frame the faces of people in the image group of various expressions to obtain facial images.
[0108] The data set determination subunit is used to scale the facial images to obtain a data set of facial expressions of stroke patients.
[0109] Among them, the expression recognition model based on ViT specifically includes:
[0110] The convolutional embedding module, the Transformer module, the multi-channel feature extraction module and the output module are connected in sequence. Specifically, the Transformer module includes: Encoder and block integration network.
[0111] Among them, training unit 3 includes:
[0112] The pre-training model determination subunit is used to pre-train the ViT-based expression recognition model with the facial expression dataset as input and the confidence of each type of expression as output to obtain a pre-training model; the expression category with the highest confidence is the prediction result of the pre-training model.
[0113] The enhanced data set subunit is used to enhance the expression data set of stroke patients to obtain an enhanced expression data set.
[0114] The expression recognition model determination subunit is used to train the pre-trained model with the enhanced expression data set as input and the confidence of each type of expression as output to obtain a trained ViT-based expression recognition model; the expression category with the highest confidence is the prediction result of the pre-trained model.
[0115] This application tests the proposed model on different mainstream face datasets: RAF-DB and FERPlus, and compares it with mainstream expression recognition models in terms of parameter quantity and accuracy. The performance of the model is analyzed by analyzing confusion matrix, model attention heat map, etc., and then the model is trained on a self-made stroke patient expression dataset to verify the model's advantage in identifying stroke patients.
[0116] First, this application uses the mainstream convolution-based neural network in the current expression recognition direction for comparison. In the comparison process, a model without pre-training is used to start training from scratch. The same data enhancement method as other models is used during training. The cross entropy loss function is used to calculate the Loss. The adam optimizer is used for optimization. Lr (learning rate) is 0.0003. Due to the optimization of the model parameter quantity, the Batch Size during training can be increased from 20 of ViT to 120, which greatly improves the training speed of the model. The accuracy comparison of the model on the RAF-DB dataset is shown in Table 2. Ours* in Table 2 is the expression recognition model based on ViT provided by this application. It can be seen from Table 2 that even without pre-training, the expression recognition model based on ViT provided by this application has a strong explanatory ability, and the overall accuracy even exceeds that of the pre-trained ViT. And the expression recognition model based on ViT provided by this application has a high explanatory ability for normal expressions (Neutral), which is of great help in correctly interpreting the expressions of stroke patients.
[0117] Table 2 Comparison of accuracy of ViT-based expression recognition models on the RAF-DB dataset
[0118]
[0119] The comparison of model parameters and accuracy on the FERplus dataset is shown in Table 3. Ours* in Table 3 is the expression recognition model based on ViT provided by this application, and M represents 10 6 As can be seen from Table 3, compared with ViT, the expression recognition model based on ViT provided by this application is more suitable for expression recognition tasks, and can achieve performance far exceeding ViT with a parameter reduction of nearly 8 times. At the same time, the model is less sensitive to Lr (learning rate), and is easy to train to achieve better results.
[0120] Table 3. Comparison of parameter quantities and accuracy on the FERplus dataset
[0121]
[0122] like Figure 6 and Figure 7As shown, by comparing the confusion matrices of various expression recognition models on the RAF-DB dataset, it can be seen that the ViT-based expression recognition model provided by the present application exceeds ViT in overall accuracy and reaches 99% in the recognition of normal expressions. This feature can effectively help identify the emotional baseline of stroke patients.
[0123] The ViT-based expression recognition model provided in this application uses more convolutions, and the feature pixels no longer completely correspond to the image pixels one by one. However, from the visualization of the model's attention, it can be seen that the ViT-based expression recognition model provided in this application still retains the ViT self-attention mechanism, and has a larger discrimination weight for the corners of the mouth and the eyes.
[0124] Considering that the emotions of patients during the rehabilitation process are relatively simple, five types of expressions (three basic expressions and two special expressions) are selected as recognition targets, namely: 1. Happy, 2. Sad, 3. Normal, 4. Strength, 5. Pain. After testing, the ViT-based expression recognition model provided by this application achieved an accuracy rate of 83.88% on a private dataset, which is a certain improvement compared to ResNet18's 80.26%.
[0125] According to the facial features of stroke patients, a facial expression recognition model based on ViT is designed. The influence of hemiplegic area on recognition is reduced by adding regional attention mechanism. While the model has the characteristics of high explanatory power of ViT through self-attention mechanism, the convolution-based block embedding structure (Conv Patch Embedding) and block integration structure (PatchAggregate) are designed to realize the pyramid structure of ViT backbone network. In the facial expression recognition task, the number of parameters of this network is reduced from 86,095,879 to 12,576,579 compared with the original ViT, and the amount of calculation is reduced by nearly 8 times. Through the convolution-based block embedding structure, the model's ability to interpret texture is improved to adapt to the facial expression recognition task. Finally, without pre-training, the accuracy rate in the general facial expression dataset FRF-DB reached 88.17% (higher than the original ViT 86.14%), and the model is insensitive to Lr (learning rate) during training, making it easier to train.
[0126] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0127] The principles and implementation methods of the present invention are described in this article using specific examples. The description of the above embodiments is only used to help understand the method and core idea of the present invention. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting the present invention.
Claims
1. A method for facial expression recognition of stroke patients based on self-attention, characterized in that: The method comprises: Obtain a dataset of facial expressions of stroke patients; Constructing a ViT-based expression recognition model, the ViT-based expression recognition model comprises: a convolutional embedding module, a Transformer module, a multi-channel feature extraction module and an output module connected in sequence; wherein the convolutional embedding module specifically comprises: the model input is a grayscale image with three-channel pixels of 128*128, and the image is converted into a block feature vector required by the Transformer network through convolution by the convolutional embedding module, and the convolutional embedding module is divided into two parts: feature convolution and block embedding; the feature convolution is performed with a step length of 2 through a 64*7*7 convolution kernel, and a 64*64*64 image feature map is output through a 2*2 pooling layer; the block embedding uses multiple 64*2*2 convolution kernels to perform convolution with a step length of 2, and compresses the input into a Patch with a sequence length of 16*16 and inputs it into the TF network; The Transformer module specifically includes: The Transformer module is divided into two parts: Transformer Encoder and Block Integration; Among them, the Transformer Encoder converts the input feature block into a 3×k×d feature vector through linear transformation, and then divides it into feature matrices Q, K and V through dimensional transformation. d is the parameter of each attention head. The calculation formula of the self-attention module is: Among them, D K is the latitude value of K, k is the number of attention heads set, and A is the self-attention matrix; The output of TransformerEncoder is integrated through a forward feedback network composed of 1*1 convolution and Gaussian error linear rectification function and passed to block integration; block integration compresses the block feature data volume, and the network contains 3*3 convolution, convolution with a step size of 2, BN layer, and a pooling layer with a size of 2*2; after two rounds of TF network, the output feature vector is 576*4*4, where d i is the number of input channels, d o is the number of output channels, h is the length of the feature block, and w is the width of the feature block; The multi-channel feature extraction module specifically includes: It includes block reconstruction and channel feature pooling. Block reconstruction upsamples the feature vector to increase the spatial dimension to 4*48*48, and uses a 12*12 convolution kernel to perform convolution with a step length of 14 on each layer of features to obtain a 4*10*10 feature map; channel feature pooling outputs a 1*10*10 channel feature vector, and the calculation formula is: in are the average and maximum values of the channels at positions i and j respectively, and a is the maximum value weight; The ViT-based expression recognition model is trained using a human facial expression dataset and a stroke patient expression dataset; The categories of stroke patients’ expressions are identified through the trained ViT-based expression recognition model.
2. The method for facial expression recognition of stroke patients based on self-attention according to claim 1, characterized in that: The step of obtaining a stroke patient expression dataset specifically includes: Obtain videos of stroke patients’ expressions; Annotating the expression video to obtain segmented videos of various expressions; Convert each of the segmented videos into images to obtain image groups of various expressions; the images in the image groups include an expression start state, an expression end state, and an expression peak state; Frame the faces of people in the picture groups of the various types of expressions to obtain face pictures; The facial image is scaled to obtain the stroke patient expression dataset.
3. The method for facial expression recognition of stroke patients based on self-attention according to claim 1, characterized in that: The ViT-based expression recognition model includes: a convolutional embedding module, a Transformer module, a multi-channel feature extraction module and an output module connected in sequence.
4. The method for facial expression recognition of stroke patients based on self-attention according to claim 3, characterized in that: The Transformer module includes: Encoder and block integration network.
5. The method for facial expression recognition of stroke patients based on self-attention according to claim 3, characterized in that: The step of training the ViT-based expression recognition model using the facial expression dataset and the stroke patient expression dataset specifically includes: Taking the facial expression data set as input and the confidence of each type of expression as output, the ViT-based expression recognition model is pre-trained to obtain a pre-trained model; the expression category with the highest confidence is the prediction result of the pre-trained model; enhancing the expression dataset of the stroke patient to obtain an enhanced expression dataset; The pre-trained model is trained with the enhanced expression data set as input and the confidence of each type of expression as output to obtain a trained ViT-based expression recognition model; the expression category with the highest confidence is the prediction result of the trained ViT-based expression recognition model.
6. A stroke patient expression recognition system based on self-attention, characterized in that: The system comprises: A data set acquisition unit, used for acquiring a stroke patient expression data set; A construction unit is used to construct an expression recognition model based on ViT, wherein the expression recognition model based on ViT includes: a convolution embedding module, a Transformer module, a multi-channel feature extraction module and an output module connected in sequence; wherein the convolution embedding module specifically includes: the model input is a grayscale image with three-channel pixels of 128*128, and the image is converted into a block feature vector required by the Transformer network through convolution by the convolution embedding module, and the convolution embedding module is divided into two parts: feature convolution and block embedding; the feature convolution is performed with a step length of 2 through a 64*7*7 convolution kernel, and a 64*64*64 image feature map is output through a 2*2 pooling layer; the block embedding uses multiple 64*2*2 convolution kernels to perform convolution with a step length of 2, and compresses the input into a Patch with a sequence length of 16*16 and inputs it into the TF network; The Transformer module specifically includes: The Transformer module is divided into two parts: Transformer Encoder and Block Integration; Among them, the Transformer Encoder converts the input feature block into a 3×k×d feature vector through linear transformation, and then divides it into feature matrices Q, K and V through dimensional transformation. d is the parameter of each attention head. The calculation formula of the self-attention module is: Among them, D K is the latitude value of K, k is the number of attention heads set, and A is the self-attention matrix; The output of TransformerEncoder is integrated through a forward feedback network composed of 1*1 convolution and Gaussian error linear rectification function and passed to block integration; block integration compresses the block feature data volume, and the network contains 3*3 convolution, convolution with a step size of 2, BN layer, and a pooling layer with a size of 2*2; after two rounds of TF network, the output feature vector is 576*4*4, where d i is the number of input channels, d o is the number of output channels, h is the length of the feature block, and w is the width of the feature block; The multi-channel feature extraction module specifically includes: It includes block reconstruction and channel feature pooling. Block reconstruction upsamples the feature vector to increase the spatial dimension to 4*48*48, and uses a 12*12 convolution kernel to perform convolution with a step length of 14 on each layer of features to obtain a 4*10*10 feature map; channel feature pooling outputs a 1*10*10 channel feature vector, and the calculation formula is: in are the average and maximum values of the channels at positions i and j respectively, and a is the maximum value weight; A training unit, used for training the ViT-based expression recognition model through a human facial expression dataset and a stroke patient expression dataset; The recognition unit is used to recognize the category of the expression of the stroke patient through the trained ViT-based expression recognition model.
7. The stroke patient expression recognition system based on self-attention according to claim 6, characterized in that: The data set acquisition unit comprises: An expression video acquisition subunit, used for acquiring expression videos of stroke patients; A labeling subunit, used to label the expression video to obtain segmented videos of various expressions; A picture processing subunit is used to process each of the segmented videos into pictures to obtain picture groups of various expressions; the pictures in the picture group include the expression start state, expression end state and expression peak state; A facial picture determination subunit is used to frame the faces of people in the picture group of various types of expressions to obtain facial pictures; The data set determination subunit is used to scale the facial image to obtain the stroke patient expression data set.
8. The stroke patient expression recognition system based on self-attention according to claim 6, characterized in that: The ViT-based expression recognition model includes: a convolutional embedding module, a Transformer module, a multi-channel feature extraction module and an output module connected in sequence.
9. The stroke patient expression recognition system based on self-attention according to claim 8, characterized in that: The Transformer module includes: Encoder and block integration network.
10. The stroke patient expression recognition system based on self-attention according to claim 8, characterized in that: The training unit comprises: A pre-training model determination subunit is used to pre-train the ViT-based expression recognition model using a facial expression data set as input and confidence levels of various expressions as output to obtain a pre-training model; the expression category with the highest confidence level is the prediction result of the pre-training model; An enhanced data set subunit is used to enhance the expression data set of the stroke patient to obtain an enhanced expression data set; The expression recognition model determination subunit is used to train the pre-trained model with the enhanced expression data set as input and the confidence of each type of expression as output to obtain a trained ViT-based expression recognition model; the expression category with the highest confidence is the prediction result of the pre-trained model.
