A micro-expression recognition method based on Transformer motion feature fusion
By using a Transformer-based feature fusion method, the problems of long-distance dependence and redundant information of facial motion units in micro-expression recognition are solved, and higher recognition accuracy is achieved.
Patent Information
- Application Number
- CN202410601437.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-15
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2044-05-15
AI Technical Summary
Existing micro-expression recognition technologies struggle to effectively learn significant and distinctive facial motion features. Convolutional neural networks neglect the long-distance dependencies between different facial motion units, and the input video sequences contain redundant information such as the subject's identity and appearance, affecting recognition accuracy.
A Transformer-based motion feature fusion method is adopted. By sharing the Transformer feature encoder, feature selection fusion module and global cross-attention module, key Patch Tokens are selected from the horizontal and vertical optical flow maps respectively. Motion information is fused using the global cross-attention module, and the model is trained through spatial consistency constraints and cross-entropy loss to improve recognition accuracy.
It effectively extracts and fuses facial motion unit change features in micro-expressions, reduces redundancy in identity and appearance information, and improves the accuracy of micro-expression recognition.
Smart Images

Figure CN118366202B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a micro-expression recognition method based on Transformer motion feature fusion, belonging to the field of deep learning and pattern recognition technology. Background Technology
[0002] Emotional changes are the outward manifestation of human psychological fluctuations, revealing real-time inner thoughts to the outside world. Human emotional information can be conveyed through body language, tone of voice, facial expressions, and even written language. Research shows that when responding to objective events, 55% of the total information conveyed comes from facial expressions, with the remainder primarily originating from language and written text, indicating that facial emotions convey the most direct and richest information. Micro-expressions are generated insidiously and unconsciously, effectively expressing a person's true inner feelings. Due to this unique psychological mechanism, micro-expressions are widely used in fields such as criminal investigation trials, prison management, emotional behavior analysis, and security protection.
[0003] For the micro-expression recognition task, the overall process is divided into three steps: (1) micro-expression data preprocessing; (2) motion feature extraction; and (3) classification and recognition. The preprocessing stage includes video framing, face detection, and alignment cropping. According to the published database, the preprocessing operation has been completed by the database publisher. Therefore, the key factor affecting the correct recognition is whether the significant motion features of micro-expressions can be learned. From the perspective of features, micro-expression recognition technology can be summarized into the following four types: recognition methods based on facial texture changes, facial optical flow changes, frequency domain description, and deep learning.
[0004] Firstly, facial texture feature descriptors were among the first proposed recognition methods. Local Binary Pattern (LBP) is a simple yet highly effective texture operator. It compares the pixel value of the center point within a certain window with the pixel values in its neighborhood. If the neighborhood pixel value is greater than or equal to the center point pixel value, it is recorded as 1; otherwise, it is recorded as 0. The binary code formed by the surrounding points is used as the LBP value of the center point, thus describing the local dynamic texture changes of micro-expressions. However, to address the limitation that LBP features cannot describe the texture changes of micro-expressions in the time dimension, Guo et al. improved upon this by proposing Local Binary Patterns from Three Orthogonal Planes (LBP-TOP), which is an extension of LBP that incorporates information from the time dimension T. For a given video image sequence, calculating the XY, XT, and YT planes to generate corresponding histograms can lead to overlapping planes and information redundancy. Huang et al. proposed a Spatiotemporal Local Binary Pattern based on IntegralProjection (STLBP-IP), which combines LBP-TOP with integral projection (IP). By using IP to obtain horizontal and vertical projections on different images, it provides complementary shape information to enhance facial texture descriptors. However, this work is limited by the assumption that the first frame is a neutral frame, which introduces computational errors. To address this, Huang et al. proposed a novel Discriminative Spatiotemporal Local Binary Pattern with Revisited IntegralProjection (STLBPRIP) by combining shape attributes with dynamic texture information. Compared to STLBP-IP, STLBP-RIP breaks the assumption that the starting frame is always neutral in mood, combines LBP to shape attributes, and considers discriminative information.
[0005] Optical flow algorithms utilize the temporal variations of pixels in an image sequence and the correlation between adjacent frames to find the motion relationship between the previous and current frames, capturing subtle facial changes. Liu et al. proposed the more discriminative Main Directional Mean Optical-flow (MDMO) feature. MDMO is a normalized statistical feature based on the region of interest (ROI). It divides the face into 36 ROIs based on the facial AU and calculates the average optical flow across all frames in each ROI. This considers both local statistical motion information and spatial location, significantly reducing the feature dimensionality. Chaudhry et al. proposed the Histogram of Oriented Optical Flow (HOOF), which has the advantages of being scale-invariant and orientation-independent. To address the vulnerability of HOOF to illumination changes, Happy et al. proposed the Fuzzy Histogram of Optical Flow Orientations (FHOFO). This constructs an appropriate angle histogram along the direction of the optical flow vector to encode temporal patterns, exhibiting good robustness to illumination changes.
[0006] Frequency-domain-based recognition methods treat the input micro-expression sequence as a signal that changes over time. They transform time-domain information into frequency-domain features using methods such as Fourier transform, Laplace transform, and wavelet transform. Huang et al. used Spatiotemporal Local Monogenic Binary Patterns (STLMBP) to analyze and extract the amplitude and direction maps of each frame in the sequence. Appearance information can be obtained from the amplitude, and complementary information can be provided from the direction. The LBP operator is used to encode texture and motion changes through three orthogonal planes. Building on this, Oh et al. employed Riesz wavelet transform to obtain fine-grained information on amplitude, phase, and direction in the sequence at multiple scales, effectively capturing subtle dynamic changes in micro-expressions and extracting useful features. Furthermore, Oh et al. proposed an intrinsic 2-Dimensional (i2D) method based on higher-order Riesz transform to effectively acquire and recognize important facial contour changes caused by facial muscle movements in areas such as the eyes, nose, and lips.
[0007] Due to the significant achievements of deep learning in the image processing field, demonstrating superior deep feature extraction capabilities, it has been widely applied in the field of micro-expression recognition in recent years. DHKim et al. first used convolutional neural networks (CNNs) for micro-expression recognition, employing CNNs to encode the spatial features of micro-expressions, and then using a Long Short-Term Memory (LSTM) recurrent neural network to encode the state features of micro-expressions at different times. However, limited by the small sample size of the database, the recognition accuracy was not very good. To address this, Wang et al. opted to pre-train on a macro-expression database and proposed a Transferring Long-Term Convolutional Neural Network (TLCNN), which improved the recognition results. To simultaneously encode the spatiotemporal relationships of video features, Sai et al. proposed a 3D-CNN model (Spatiotemporal Convolutional Neural Networks, STCNN), using 3D convolution operations to extract both spatial and temporal information from the video. Khor et al. proposed the Enrich Long-term Recurrent Convolutional Network (ELRCN), which uses two feature sequences—micro-expression optical strain and optical flow—and effectively learns temporal information by stacking feature temporal enhancement sets and spatial enhancement sets. This method achieved good recognition results on both cross-micro-expression databases and single databases.
[0008] Currently, recognition algorithms based on handcrafted facial textures and optical flow variations often extract texture or edge information, which is insufficient for fully utilizing the information. Meanwhile, recognition algorithms based on deep learning features often use input video sequences containing redundant information such as identity and appearance, making it difficult to effectively learn motion features that can discern micro-expressions. Summary of the Invention
[0009] To address the shortcomings of existing technologies, this invention provides a micro-expression recognition method based on Transformer motion feature fusion. The network model of this invention learns how to effectively utilize significant and distinctive facial motion features in micro-expression sequences for recognition, reducing redundancy in appearance and identity information from the input data, thereby improving the accuracy of micro-expression recognition. Invention Overview:
[0011] A micro-expression recognition method based on Transformer motion feature fusion includes four parts: dataset preprocessing, optical flow feature extraction, shared Transformer feature learning and fusion module, and classification and recognition module.
[0012] The technical problem addressed by this invention is that micro-expressions are localized, meaning that only some facial muscles change when emotions occur. While convolutional neural networks can capture local features, they neglect the long-range dependencies between different facial motion units. Secondly, extracting motion features from micro-expression video sequences often involves redundant information such as the subject's identity and appearance, hindering the learning of crucial motion representations. Compared to existing methods, this invention combines Transformer slice embedding processing with a feature selection fusion module to select key patch tokens containing changes in facial action units (AUs) from both horizontal and vertical optical flow maps. A global cross-attention module effectively complements the motion information of facial AUs in the horizontal and vertical directions, thereby learning discriminative micro-expression motion features from a limited sample size.
[0013] Terminology Explanation:
[0014] Dataset annotation table: A dataset annotation table is a method of annotation used in micro-expression recognition research. It is usually an Excel spreadsheet that includes the subject number in the micro-expression sequence sample, the position of the micro-expression start frame, climax frame and end frame in the sequence, the category of micro-expression (such as happy, sad, etc.) and the combination of micro-expression facial motion units. It is used to help researchers analyze these micro-expression data and train models.
[0015] Transformer: Transformer is a deep learning model architecture for natural language processing (NLP) and other sequence-to-sequence tasks. It was first proposed by Vaswani et al. in 2017. The Transformer architecture introduces a self-attention mechanism, which makes it perform well when processing sequential data.
[0016] Patch Token: Patch Token indicates that the Vision Transformer divides an image into multiple image blocks.
[0017] The technical solution of the present invention is as follows:
[0018] A micro-expression recognition method based on Transformer motion feature fusion includes the following steps:
[0019] A. Preprocess the micro-expression video, including obtaining the video frame sequence, face detection and localization, face alignment, and extracting the horizontal and vertical optical flow feature maps between the start frame and the climax frame;
[0020] B. Divide the horizontal and vertical optical flow feature maps obtained after preprocessing in step A into a test set and a training set;
[0021] C. Construct a Transformer-based motion feature fusion and recognition model. The Transformer-based motion feature fusion and recognition model includes a shared Transformer feature encoder, a feature selection fusion module, and a global cross-attention module. The feature selection fusion module performs mutual attention calculation on the Patch blocks embedded in the shared Transformer feature encoder and the classification token, and selects the top k Patch blocks with the highest scores, where k is the number of selected Patch blocks. The global cross-attention module supplements the fusion motion information by adding optical flow features in the horizontal and vertical directions.
[0022] D. Construct spatial consistency constraint loss, cross-entropy loss and contrast loss, and use the loss functions to train a Transformer-based motion feature fusion recognition model to obtain a Transformer recognition model with strong discriminative ability;
[0023] E. Classification and recognition: Based on the Transformer recognition model trained in step D, classify and recognize the test set.
[0024] According to a preferred embodiment of the present invention, step A involves preprocessing the micro-expression video, including the following steps:
[0025] 1) Obtain video frame sequence: Perform frame segmentation on the video containing micro-expressions to obtain and store the video frame sequence;
[0026] 2) Face detection and localization: Use the Dlib vision library to perform face detection and localization on video frame sequences, and give the number of faces in the detected video frames and the distance of the faces from the image boundary;
[0027] 3) Face alignment: Using the Dlib vision library, 68 key facial feature points are identified to complete face segmentation and achieve face correction;
[0028] 4) Constructing an RGB frame sequence: Arrange the RGB images after face alignment in sequence to form an RGB frame sequence;
[0029] 5) Obtaining optical flow feature map: Based on the dataset annotation table, select the start frame and climax frame in an RGB sequence, use the TVL1 optical flow algorithm to calculate the horizontal and vertical optical flow between the start frame and the climax frame, and finally construct the optical flow feature map.
[0030] According to a preferred embodiment of the present invention, in step C, the motion feature fusion recognition model based on Transformer includes a shared Transformer feature encoder, a feature selection fusion module, and a global cross-attention module; the Transformer feature encoder includes layer normalization, multi-head attention, and a multilayer perceptron; the feature selection fusion module is a mutual attention calculation process.
[0031] According to a preferred embodiment of the present invention, in step C, constructing a Transformer feature encoder includes:
[0032] In the Transformer encoder, assuming a pair of micro-expression vertical optical flow feature maps x are obtained v ∈R H×W×3 and horizontal optical flow feature map x h ∈R H×W×3 For the input pair of optical flow maps {x h ,x v}∈R H×W×3 Convolution processes are performed separately, with the kernel size set to p×p and the stride s also set to p. The calculation process is shown in formula (1):
[0033]
[0034] In equation (1), H i With W i represents the height and width of the horizontal optical flow feature map and the vertical optical flow feature map, respectively, and k represents the size of the convolution kernel;
[0035] After processing, an image is divided into p×p image blocks, and each image block becomes D=3p in dimension after linear mapping. 2 Where D is also the number of convolution kernels; then, the H and W dimensions are flattened in the horizontal and vertical optical flow features to obtain {x h ,x v}∈R N×D This transforms into a two-dimensional matrix, where... It meets the input requirements of the Transformer encoder;
[0036] After linear mapping, classification is added to the horizontal and vertical optical flow features respectively. and position encoding vector E pos ∈R (N+1)×D ,Classification It is a trainable parameter that includes the classification information of the image sequence. The data size is consistent with other Patch Tokens and is concatenated with the Patch Tokens through the Concat operation. The position encoding vector is directly superimposed on the Tokens sequence. The operation process is shown in formulas (2) and (3):
[0037]
[0038]
[0039] In equations (2) and (3), Represents category tokens, Represents a Patch Token, E∈R 3×D E represents the embedding mapping function for image patches. pos Represents the position encoding vector;
[0040] Next, the micro-expression horizontal and vertical optical flow feature maps are fed into a Transformer feature encoder containing multi-head self-attention and a multilayer perceptron block (MLP), respectively, for deep feature extraction and comprehensive context modeling through a series of Transformer encoders with shared weights; the latent vectors of the same size are maintained in each layer of the Transformer encoder; it is assumed that the output of the Transformer encoder in the l-th layer is given by equations (4) and (5):
[0041]
[0042]
[0043] Where LN(i) is the layer normalization operation. The encoded image representation shows that, after encoding, the horizontal and vertical optical flow maps of micro-expressions are encoded as tensors of size B×(N+1)×D, respectively.
[0044] This represents intermediate feature representation; MSA() represents multi-head self-attention. represents the (l-1)th layer, and MLP() represents the multilayer perceptron.
[0045] According to a preferred embodiment of the present invention, in step C, constructing the feature selection fusion module includes:
[0046] In each Transformer encoder layer, the horizontal optical flow and vertical optical flow feature maps are processed separately. By calculating the mutual attention between the classification token and the patch token, a mutual attention score matrix is obtained, as shown in formulas (6) and (7):
[0047] A = [a0; a1; a2; ... a N (6)
[0048] a i =[a i,0 ,a i,1 ,a i,2 …,a i,j ,…a i,N i = 0…N (7)
[0049] Among them, a i,j The attention score between tokens is represented by the dot product of the query value of i and the key value of j. A represents the attention score matrix, and a i This represents the attention score of the i-th token compared to other Patch tokens;
[0050] The mutual attention weights between the category token and the i-th patch token are shown in equations (8) and (9).
[0051] ma i =a' 0,i *b i ' ,0 (8)
[0052]
[0053] Among them, a' 0,i It is the attention score of the category token to the other patch tokens, b i ' ,0 It is the attention score of other PatchTokens for the category token;
[0054] ma i This refers to the mutual attention score matrix; This indicates that the attention scores are normalized separately.
[0055] The selected Patch Token in the l-th layer Transformer encoder is represented as shown in Equation (10), where k represents the number of Patch Tokens selected in each layer, which is the mutual attention score matrix ma. i The tokens corresponding to the first k index values after sorting are then concatenated with the classification tokens in the last layer to obtain the fused features, as shown in Equation (11):
[0056]
[0057]
[0058] z represents the Patch Token selected in the l-th layer Transformer encoder. ff This represents the tokens selected by the last Transformer encoder before the (l-1)th layer.
[0059] According to a preferred embodiment of the present invention, in step C, constructing a global cross-attention module includes:
[0060] For horizontal optical flow features, firstly, Patch Tokens are aggregated from vertical optical flow features, and then the class token is concatenated with the Patch Tokens of the vertical optical flow branch, as shown in Equation (12):
[0061]
[0062] In equation (12), f h (i) is the projection function used for feature alignment; This represents the classification token in the horizontal optical flow features. x' represents the patch token in vertical optical flow. h This represents the feature representation after aggregation;
[0063] Then, the global cross-attention module in and x' h Cross-attention operations are performed between branches, and under each branch, the category token is a unique query value. The calculation process is shown in formulas (13), (14) and (15):
[0064]
[0065]
[0066] CA(x' h =Av (15)
[0067] In equation (13), W q W k W v ∈R C×(C / h) These are learnable parameters, C and h are the dimension of the embedded features and the number of attention heads, respectively; q represents the lookup vector, k represents the key vector, v represents the value vector, A represents the similarity between q and k, softmax() represents the regression probability mapping function, and CA() represents the cross attention value.
[0068] The output obtained after calculation is shown in formula (16):
[0069]
[0070]
[0071] In equations (16) and (17), f h (i) and g h (i) are the size-aligned projection function and the inverse mapping function, respectively. MCA represents the multi-head cross-attention operation. h This represents the horizontal optical flow characteristics after cross-attention fusion.
[0072] According to a preferred embodiment of the present invention, in step D, constructing the spatial consistency constraint loss includes:
[0073] Spatial Consistency Attention (SCA) is used to linearly project the Patch Token output by the last encoder layer as the key value for Spatial Attention (SPA) operation. The query vector of SPA is the classification Token under the optical flow branch. The calculation process is shown in formula (18).
[0074]
[0075] In equation (18), m∈{h,v}, {R h ,R v}∈R N W Q With W K F represents the weights of the query and key vectors, respectively. m R represents a linear mapping. h and R v These are the distribution response maps of the horizontal and vertical optical flow components, respectively, representing the global-to-local consistency under their respective modal characteristics. The similarity between the two response maps under the horizontal and vertical optical flow branches is calculated using the cosine formula.
[0076] Design the local loss function L local Specifically, this refers to aligning the local semantics of two motion change patterns by limiting the distance between the response maps of two different motion features; as shown in formula (19):
[0077] L local =1-dist cos (R h ,R v (19)
[0078] dist cos () indicates the calculation of cosine distance.
[0079] According to a preferred embodiment of the present invention, in step D, constructing the cross-entropy loss includes:
[0080] The cross-entropy loss function is used to measure the difference between the probability distribution output by the Transformer recognition model and the actual labels, and this difference is minimized to make the predictions of the Transformer recognition model closer to the actual results; an N-class classification task is set, and the cross-entropy loss function L... cross Represented as:
[0081]
[0082] In equation (20), f θ (x i ) represents a classification network with parameters θ, including linear layers and layer normalization operation LN(i), and the corresponding output class prediction value is i when its input is x;
[0083] y represents the encoding vector of the real label. i The predicted value at the i-th position in vector y is represented as:
[0084]
[0085] From formulas (20) and (21), we can deduce that in y i =1 indicates a cross-entropy value, which is located at the label position of the probability distribution vector output by the softmax function; softmax(f θ (x i As shown in formula (22), where,
[0086]
[0087] According to a preferred embodiment of the present invention, a contrast loss L is constructed. con As shown in equation (23):
[0088]
[0089] In equation (23), B represents the batch size, Sim represents similarity calculation, max represents the maximization function, and α represents a constant threshold.
[0090] According to a preferred embodiment of the present invention, the motion feature fusion and recognition model based on Transformer consists of cross-entropy loss L cross , contrast loss L con and Local Consistency Constraint Loss L local The total loss L when training together is added together. total Represented as equation (24):
[0091] Ltotal =L cross +L con +L local (twenty four).
[0092] According to a preferred embodiment of the present invention, in step E, the classification and identification includes:
[0093] After the test set is preprocessed, it is input into the trained Transformer recognition model to classify and recognize the test set.
[0094] The beneficial effects of this invention are as follows:
[0095] This invention calculates horizontal and vertical optical flow feature maps of micro-expressions based on the start and climax frames of the micro-expression sequence. These feature maps are then mapped and embedded into a Transformer encoder via a convolutional network. Through a feature selection and fusion module, in each encoder layer, the patch block with the high mutual attention score between the classification token and the patch token is selected as the input to the final encoder layer. The selected horizontal and vertical optical flow component tokens are fused and supplemented with motion information from different directions through a cross-attention module. Furthermore, by using spatial consistency attention constraints and aligning the local semantics of the two change modes, more discriminative micro-expression facial motion unit change features are effectively acquired and fused. Attached Figure Description
[0096] Figure 1 The flowchart shows the micro-expression recognition method based on Transformer motion feature fusion.
[0097] Figure 2 This is a schematic diagram of the Transformer feature encoder structure;
[0098] Figure 3 A schematic diagram of the feature selection fusion module;
[0099] Figure 4 This is a structural diagram of the global cross-attention module;
[0100] Figure 5 This is a schematic diagram of the recognition results of the method of the present invention under the last parameters of the MMEW micro-expression database;
[0101] Figure 6 This is a schematic diagram of 68 key feature points on the face. Detailed Implementation
[0102] The present invention will be further defined below with reference to the accompanying drawings and embodiments, but is not limited thereto.
[0103] Example 1
[0104] A micro-expression recognition method based on Transformer motion feature fusion, such as Figure 1 As shown, the steps are as follows:
[0105] A. Preprocess the micro-expression video, including obtaining the video frame sequence, face detection and localization, face alignment, and extracting the horizontal and vertical optical flow feature maps between the start frame and the climax frame;
[0106] B. Divide the horizontal and vertical optical flow feature maps obtained after preprocessing in step A into a test set and a training set;
[0107] C. Construct a Transformer-based motion feature fusion and recognition model. The Transformer-based motion feature fusion and recognition model includes a shared Transformer feature encoder, a feature selection fusion module, and a global cross-attention module. The feature selection fusion module performs mutual attention calculation on the Patch blocks embedded in the shared Transformer feature encoder and the classification token, and selects the top k Patch blocks with the highest scores, where k is the number of selected Patch blocks. The global cross-attention module supplements the fusion motion information by adding optical flow features in the horizontal and vertical directions.
[0108] D. Construct spatial consistency constraint loss, cross-entropy loss and contrast loss, and use the loss functions to train a Transformer-based motion feature fusion recognition model to obtain a Transformer recognition model with strong discriminative ability;
[0109] E. Classification and recognition: Based on the Transformer recognition model trained in step D, classify and recognize the test set.
[0110] Example 2
[0111] The micro-expression recognition method based on Transformer motion feature fusion described in Example 1 differs in that:
[0112] Step A involves preprocessing the micro-expression video, including the following steps:
[0113] 1) Obtain video frame sequence: Perform frame segmentation on the video containing micro-expressions to obtain and store the video frame sequence;
[0114] 2) Face detection and localization: Use the Dlib vision library to perform face detection and localization on video frame sequences, and give the number of faces in the detected video frames and the distance of the faces from the image boundary;
[0115] 3) Face alignment: Based on face localization, face alignment uses the Dlib vision library to determine 68 key facial feature points, complete face segmentation, and achieve face correction.
[0116] Face segmentation refers to the use of bounding boxes by the Dlib vision library to segment faces.
[0117] Facial correction refers to the process of identifying 68 key facial feature points, such as... Figure 6 As shown, the line connecting the key feature point 37 at the left corner of the eye and the key feature point 46 at the right corner of the eye has an angle α with the horizontal line. The corresponding rotation matrix is obtained through angle α, and the segmented face is rotated and transformed so that the line connecting the key feature point 37 at the left corner of the eye and the key feature point 46 at the right corner of the eye is parallel to the horizontal line, thereby correcting the face pose. The face is then scaled to obtain a 224*224 resolution video frame.
[0118] 4) Constructing an RGB frame sequence: Arrange the RGB images after face alignment in sequence to form an RGB frame sequence;
[0119] 5) Obtaining optical flow feature map: Based on the dataset annotation table, select the start frame and climax frame in an RGB sequence, use the TVL1 optical flow algorithm to calculate the horizontal and vertical optical flow between the start frame and the climax frame, and finally construct the optical flow feature map.
[0120] In step C, the Transformer-based motion feature fusion recognition model includes a shared Transformer feature encoder, a feature selection fusion module, and a global cross-attention module; such as Figure 2 As shown, the Transformer feature encoder includes layer normalization, multi-head attention, and multilayer perceptron; the feature selection fusion module is a mutual attention computation process.
[0121] In step C, the Transformer feature encoder is constructed, including:
[0122] In the Transformer encoder, assuming a pair of micro-expression vertical optical flow feature maps x are obtained v ∈R H×W×3 and horizontal optical flow feature map x h ∈R H×W×3 For the input pair of optical flow maps {x h ,x v}∈R H×W×3 Convolution processes are performed separately, with the kernel size set to p×p and the stride s also set to p. The calculation process is shown in formula (1):
[0123]
[0124] In equation (1), H i With W i represents the height and width of the horizontal optical flow feature map and the vertical optical flow feature map, respectively, and k represents the size of the convolution kernel;
[0125] After processing, an image is divided into p×p image blocks, and each image block becomes D=3p in dimension after linear mapping. 2 Where D is also the number of convolution kernels; then, the H and W dimensions are flattened in the horizontal and vertical optical flow features to obtain {x h ,x v}∈R N×D This transforms into a two-dimensional matrix, where... It meets the input requirements of the Transformer encoder;
[0126] After linear mapping, classification is added to the horizontal and vertical optical flow features respectively. and position encoding vector E pos ∈R (N+1)×D ,Classification It is a trainable parameter that includes the classification information of the image sequence. The data size is consistent with other Patch Tokens and is concatenated with the Patch Tokens through the Concat operation. The position encoding vector is directly superimposed on the Tokens sequence. The operation process is shown in formulas (2) and (3):
[0127]
[0128]
[0129] In equations (2) and (3), Represents category tokens, Represents a Patch Token, E∈R 3×D E represents the embedding mapping function for image patches. pos Represents the position encoding vector;
[0130] Next, the horizontal and vertical optical flow feature maps of micro-expressions are fed into a Transformer feature encoder containing multi-head self-attention (MSA) and a multilayer perceptron block (MLP), respectively, for deep feature extraction and comprehensive context modeling through a series of Transformer encoders with shared weights; the same size latent vector is maintained in each layer of the Transformer encoder; it is assumed that the output of the Transformer encoder in the l-th layer is given by equations (4) and (5):
[0131]
[0132]
[0133] Where LN(i) is the layer normalization operation. The encoded image representation shows that, after encoding, the horizontal and vertical optical flow maps of micro-expressions are encoded as tensors of size B×(N+1)×D, respectively.
[0134] This represents intermediate feature representation; MSA() represents multi-head self-attention. represents the (l-1)th layer, and MLP() represents the multilayer perceptron.
[0135] In step C, the feature selection fusion module is constructed, including:
[0136] like Figure 3 As shown, in each Transformer encoder layer, the horizontal optical flow and vertical optical flow feature maps are processed separately, and a mutual attention score matrix is obtained by calculating the mutual attention between the classification token and the patch token, as shown in formulas (6) and (7):
[0137] A = [a0; a1; a2; ... a N (6)
[0138] a i =[a i,0 ,a i,1 ,a i,2 …,a i,j ,…a i,N i = 0…N (7)
[0139] Among them, a i,j The attention score between tokens is represented by the dot product of the query value of i and the key value of j. A represents the attention score matrix, and a i This represents the attention score of the i-th token compared to other Patch tokens;
[0140] Constraints are imposed by the feature selection fusion module to ensure that the selected Patch Token contains key motion identification information. The calculation of mutual attention ensures that motion information of surrounding irrelevant Tokens is not included. The mutual attention weights between the classification Token and the i-th Patch Token are shown in equations (8) and (9).
[0141] ma i =a' 0,i *b i ' ,0 (8)
[0142]
[0143] Among them, a' 0,i It is the attention score of the category token to the other patch tokens, b i ' ,0 It is the attention score of other PatchTokens for the category token;
[0144] ma i This refers to the mutual attention score matrix; This indicates that the attention scores are normalized separately.
[0145] The selected Patch Token in the l-th layer Transformer encoder is represented as shown in Equation (10), where k represents the number of Patch Tokens selected in each layer, which is the mutual attention score matrix ma. i The tokens corresponding to the first k index values after sorting are then concatenated with the classification tokens in the last layer to obtain the fused features, as shown in Equation (11):
[0146]
[0147]
[0148] z represents the Patch Token selected in the l-th layer Transformer encoder. ff This represents the tokens selected by the last Transformer encoder before the (l-1)th layer.
[0149] In step C, a global cross-attention module is constructed, including:
[0150] like Figure 4 As shown, the specific calculation process in the global cross-attention module mainly involves the classification token of one branch and the patch token of another branch. For horizontal optical flow features, firstly, the patch tokens are aggregated from the vertical optical flow features, and the classification token of the module is concatenated with the patch token of the vertical optical flow branch, as shown in equation (12):
[0151]
[0152] In equation (12), f h (i) is the projection function used for feature alignment; This represents the classification token in the horizontal optical flow features. x' represents the patch token in vertical optical flow. h This represents the feature representation after aggregation;
[0153] Then, the global cross-attention module in and x' h Cross-attention operations are performed between branches, and under each branch, the category token is a unique query value because the information of the patch token is incorporated into the category token. The calculation process is shown in formulas (13), (14), and (15):
[0154]
[0155]
[0156] CA(x' h =Av (15)
[0157] In equation (13), W q W k W v ∈R C×(C / h) These are learnable parameters, C and h are the dimension of the embedded features and the number of attention heads, respectively; q represents the lookup vector, k represents the key vector, v represents the value vector, A represents the similarity between q and k, softmax() represents the regression probability mapping function, and CA() represents the cross attention value.
[0158] Since only the classification token is used in the query vector, the computational complexity and memory consumption of attention in the cross-attention module are linear. The output obtained after the calculation is shown in formula (16):
[0159]
[0160]
[0161] In equations (16) and (17), f h (i) and g h (i) are the size-aligned projection function and the inverse mapping function, respectively. MCA represents the multi-head cross-attention operation. h This represents the horizontal optical flow characteristics after cross-attention fusion.
[0162] The same calculation process is applied to the vertical optical flow branch, which is then cross-attentionally fused with the horizontal optical flow to supplement motion information.
[0163] In step D, the spatial consistency constraint loss is constructed, including:
[0164] A spatial consistency constraint loss is constructed. The classification token and the patch token are globally aligned under different motion modalities. Considering that the number and position of the selected patch tokens are different from the original distribution, the patch token output by the last encoder is linearly projected as the key value of the spatial attention (SPA) operation through spatial consistency constraint attention (SCA). The query vector of SPA is the classification token under the optical flow branch. The calculation process is shown in formula (18):
[0165]
[0166] In equation (18), m∈{h,v}, {R h ,R v}∈R N W Q With W K F represents the weights of the query and key vectors, respectively. m R represents a linear mapping. h and R v These are the distribution response maps of the horizontal and vertical optical flow components, respectively, representing the global-to-local consistency under their respective modal characteristics. The similarity between the two response maps under the horizontal and vertical optical flow branches is calculated using the cosine formula.
[0167] To constrain the multi-level structured semantic consistency between the two motion modes of horizontal and vertical optical flow, a local loss function L is designed. local Specifically, this refers to aligning the local semantics of two motion change patterns by limiting the distance between the response maps of two different motion features; as shown in formula (19):
[0168] L local =1-dist cos (R h ,R v (19)
[0169] dist cos () indicates the calculation of cosine distance.
[0170] In step D, the cross-entropy loss is constructed, including:
[0171] The cross-entropy loss function is used to measure the difference between the probability distribution output by the Transformer recognition model and the actual labels, and this difference is minimized to make the predictions of the Transformer recognition model closer to the actual results; an N-class classification task is set, and the cross-entropy loss function L... crossRepresented as:
[0172]
[0173] In equation (20), f θ (x i ) represents a classification network with parameters θ, including linear layers and layer normalization operation LN(i), and the corresponding output class prediction value is i when its input is x;
[0174] y represents the encoding vector of the real label. i The predicted value at the i-th position in vector y is represented as:
[0175]
[0176] From formulas (20) and (21), we can deduce that in y i =1 indicates a cross-entropy value, which is located at the label position of the probability distribution vector output by the softmax function; softmax(f θ (x i As shown in formula (22), where,
[0177]
[0178] Construct contrast loss L con As shown in equation (23):
[0179]
[0180] In equation (23), B represents the batch size, Sim represents similarity calculation, max represents the maximization function, and α represents a constant threshold.
[0181] Because micro-expression changes are very subtle and the differences between categories are small, it's easy to mistake one category for another. Therefore, a contrastive loss Li was incorporated during the training phase. con The goal is to minimize the similarity of class tokens corresponding to different labels and maximize the similarity of class tokens for samples with the same label. Furthermore, to prevent the loss from being influenced by easily influenced negative samples (samples from different classes with very low similarity), a constant threshold α is introduced; only negative samples with similarity greater than α contribute to L. con In equation (23), z i and z j It is processed using L2 normalization, Sim(z) i ,z j ) indicates that it is z i and z j The dot product.
[0182] The motion feature fusion and recognition model based on Transformer consists of cross-entropy loss L... cross , contrast loss L con and Local Consistency Constraint Loss L local The total loss L when training together is added together. total Represented as equation (24):
[0183] L total =L cross +L con +L local (twenty four).
[0184] In step E, classification and identification include:
[0185] After preprocessing the test set, it is input into the trained Transformer recognition model to classify and recognize the test set.
[0186] In this embodiment, during the training phase, the feature map size H×W of the input micro-expression horizontal and vertical optical flow is set to 224×224. The number of patches selected in each encoder layer is k=12, the number of encoder layers is set to 4, the number of heads is set to 4, the number of interaction layers in the cross-attention module is set to 2, and the number of heads is set to 2. This method is implemented under the PyTorch framework on Ubuntu, using a 3090 GPU for computation, Python version 3.7, and PyTorch version 1.17. The model is optimized using the Stochastic Gradient Descent (SGD) algorithm, with an initial learning rate set to 1e-5, momentum set to 0.9, weight decay set to 1e-4, batch size set to 16, and a maximum number of iterations of 200. As the number of training iterations increases, the learning rate is dynamically adjusted in a stepwise manner. Every 30 iterations, the learning rate decreases to 0.1. The datasets are all tested using a 50% independent subject partitioning method.
[0187] To verify the advancement of the micro-expression recognition method based on Transformer motion feature fusion proposed in this invention, the invention was compared with existing methods based on traditional learning and deep learning on the SAMM, CASMEII, and MMEW datasets. These methods included FDM, LBP-TOP, MDMO, Sparse MDMO, Transfer Learning, RCN, BNCNN, MMNet, and FeatRef. Table 1 shows the recognition rates of the proposed method and other methods on the SAMM, CASMEII, and MMEW datasets.
[0188] Table 1
[0189]
[0190]
[0191] As shown in Table 1, the method proposed in this invention outperforms other methods in terms of recognition rate on the SAMM, CASMEII, and MMEW datasets. This is because the method proposed in this invention, in the last layer of the Transformer encoder, incorporates key information about micro-expression facial movements into the input PatchToken, without containing redundant Patch blocks. It integrates local low-level and mid-level information from each layer, and through a global cross-attention module, interactively integrates motion information from different directions of facial units, ultimately improving the recognition accuracy.
[0192] In addition, ablation experiments were conducted on the method of this invention. Table 2 shows the ablation experiment results of the method of this invention on the MMEW dataset, verifying the impact of the feature selection module and the cross-attention module on the model. Experiment 1 indicates that no modules were added, using the classic Vision Transformer as the base network, with the cross-entropy loss function. It can be seen that Experiment 2 improved by 3.2 percentage points compared to Experiment 1, verifying the effectiveness of the feature selection fusion module. By calculating the mutual attention between the classification token and the patch token, the token with the larger attention score is selected from all patches. These tokens contain key information for classification and discrimination. It was also found that reducing the input in each layer reduced the model's training time to the optimal level and resulted in faster convergence. Experiment 3 improved by 6.2 percentage points compared to Experiment 1, verifying the effectiveness of the cross-attention module. By performing cross-attention operations on the output of the last layer, the information of the horizontal optical flow branch and the vertical optical flow branch of facial motion are fused as a whole, complementing the facial motion information in different directions of micro-expressions and improving the recognition effect. Experiment 4 verified the effectiveness of the overall network architecture. Key facial motion tokens were selected and fused locally in their respective branches, converging key information from each layer in their respective branches. Classification tokens aggregated low-level and mid-level information, and then global motion learning was supplemented through the cross-attention module.
[0193] Table 2
[0194]
[0195]
[0196] Figure 5The results of this invention's method on the MMEW micro-expression dataset with optimal parameters are shown. The figures reveal that surprise and disgust have high recognition accuracy, at 94% and 69% respectively, indicating that the vast majority of samples can be accurately identified. Fear has a lower recognition accuracy, less than 50%, because surprise and disgust have the largest number of samples in the MMEW database, while fear samples are relatively few, and the model failed to learn key changes. Happiness and fear are easily confused with surprise because facial movements in both are concentrated in the eyebrows and corners of the mouth. Furthermore, anger, sadness, and disgust are a classic group of negative emotions, while happiness, as a positive expression, is more closely approximated by the neutral emotion of surprise in terms of facial muscle movement.
Claims
1. A micro-expression recognition method based on Transformer motion feature fusion, characterized in that, The steps include the following: A. Preprocess the micro-expression video, including obtaining the video frame sequence, face detection and localization, face alignment, and extracting the horizontal and vertical optical flow feature maps between the start frame and the climax frame; B. Divide the horizontal and vertical optical flow feature maps obtained after preprocessing in step A into a test set and a training set; C. Construct a Transformer-based motion feature fusion and recognition model. This model includes a shared Transformer feature encoder, a feature selection fusion module, and a global cross-attention module. The feature selection fusion module performs mutual attention calculations on the Patch blocks embedded in the shared Transformer feature encoder and the classification tokens, selecting the top-scoring tokens. One patch block, To select the number of patch blocks; the global cross-attention module supplements and fuses motion information with optical flow features in the horizontal and vertical directions; D. Construct spatial consistency constraint loss, cross-entropy loss and contrast loss, and use the loss functions to train a Transformer-based motion feature fusion recognition model to obtain a Transformer recognition model with strong discriminative ability; E. Classification and recognition: Based on the Transformer recognition model trained in step D, classify and recognize the test set. In step C, the Transformer-based motion feature fusion recognition model includes a shared Transformer feature encoder, a feature selection fusion module, and a global cross-attention module; the Transformer feature encoder includes layer normalization, multi-head attention, and a multilayer perceptron. Feature selection fusion module is a mutual attention computation process; In step C, a global cross-attention module is constructed, including: For horizontal optical flow features, firstly, patch tokens are aggregated from vertical optical flow features, and then the class token is compared with the patch tokens of the vertical optical flow branch. The splicing is as shown in equation (12): (12); In equation (12), It is a projection function used for feature alignment; This represents the classification token in the horizontal optical flow features. This represents the patch token in the vertical optical flow. This represents the feature representation after aggregation; Then, the global cross-attention module in and Cross-attention operations are performed between branches, and under each branch, the category token is a unique query value. The calculation process is shown in formulas (13), (14) and (15): (13); (14); (15); In equation (13), These are learnable parameters. These are the dimension of the embedded features and the number of attention heads, respectively. This indicates a vector lookup. Represents the key vector. Represents a value vector. Indicates measurement and The similarity between them This represents the regression probability mapping function. Indicates the cross-attention value; The output obtained after calculation is shown in formula (16): (16); (17); In equations (16) and (17), and These are the size-aligned projection function and the inverse mapping function, respectively. This represents multi-head cross-attention operation. This represents the horizontal optical flow characteristics after cross-attention fusion.
2. The micro-expression recognition method based on Transformer motion feature fusion according to claim 1, characterized in that, Step A involves preprocessing the micro-expression video, including the following steps: 1) Obtain video frame sequence: Perform frame segmentation on the video containing micro-expressions to obtain and store the video frame sequence; 2) Face detection and localization: Use the Dlib vision library to perform face detection and localization on video frame sequences, and give the number of faces in the detected video frames and the distance of the faces from the image boundary; 3) Face alignment: Using the Dlib vision library, 68 key facial feature points are identified to complete face segmentation and achieve face correction; 4) Constructing an RGB frame sequence: Arrange the RGB images after face alignment in sequence to form an RGB frame sequence; 5) Obtaining optical flow feature map: Based on the dataset annotation table, select the start frame and climax frame in an RGB sequence, use the TVL1 optical flow algorithm to calculate the horizontal and vertical optical flow between the start frame and the climax frame, and finally construct the optical flow feature map.
3. The micro-expression recognition method based on Transformer motion feature fusion according to claim 1, characterized in that, In step C, the Transformer feature encoder is constructed, including: In the Transformer encoder, a pair of micro-expression vertical optical flow feature maps are obtained. and horizontal optical flow feature map For the input pair of optical flow maps Perform convolution processing separately, with the convolution kernel size set to... Step length Also set to The calculation process is shown in formula (1): (1); In equation (1), and These represent the height and width of the horizontal and vertical optical flow feature maps, respectively. Indicates the size of the convolution kernel; After processing, an image is divided into... Image patches of a certain size, each image patch having a dimension that becomes [value missing] after linear mapping. ,in, It is also the number of convolution kernels; then, in the horizontal and vertical optical flow features, it is... and Flattening the two dimensions yields This transforms into a two-dimensional matrix, where... It meets the input requirements of the Transformer encoder; After linear mapping, classification tokens are added to the horizontal and vertical optical flow features respectively. and position encoding vector Token Classification It is a trainable parameter that includes classification information for the image sequence. The data size is consistent with other Patch Tokens. The operation is concatenated with the Patch Token; the position encoding vector is directly superimposed on the Tokens sequence; the operation process is shown in formulas (2) and (3): (2); (3); In equations (2) and (3), Represents category tokens, Indicates Patch Token, The embedding mapping function represents the image patch. Represents the position encoding vector; Next, the micro-expression horizontal and vertical optical flow feature maps are fed into a Transformer feature encoder containing multi-head self-attention and a multilayer perceptron block (MLP), respectively. Deep feature extraction and comprehensive context modeling are performed through a series of weighted Transformer encoders; the same size latent vector is maintained in each Transformer encoder layer; assuming that in the... The output of the Transformer encoder in the layer is given by equations (4) and (5): (4); (5); in, It is a layer normalization operation. The encoded image represents the micro-expression horizontal and vertical optical flow maps, which are encoded as follows: Tensors of size; This represents intermediate feature representation. Indicates the self-attention of the bulls, Indicates the first layer, This represents a multilayer perceptron.
4. The micro-expression recognition method based on Transformer motion feature fusion according to claim 1, characterized in that, In step C, the feature selection fusion module is constructed, including: In each Transformer encoder layer, the horizontal optical flow and vertical optical flow feature maps are processed separately. By calculating the mutual attention between the classification token and the patch token, a mutual attention score matrix is obtained, as shown in formulas (6) and (7): (6); (7); in, This represents the attention score between tokens, i.e. query and Perform a dot product operation on the key value. Represents the attention score matrix. Indicates the first Attention score of the token to other Patch tokens; Classified Tokens and The mutual attention weights among the Patch Tokens are shown in equations (8) and (9): (8); (9); in, It is the attention score of the category token relative to the other patch tokens. It is the attention score of other Patch Tokens relative to the category Token; This refers to the mutual attention score matrix; , , This indicates that the attention scores are normalized separately. In the The selected Patch Token in the layer Transformer encoder is represented as shown in Equation (10), where, This represents the number of Patch Tokens selected in each layer, which is also known as the mutual attention score matrix. Sort by before The token corresponding to each index value is then concatenated with the category token in the last layer to obtain the fused feature, as shown in Equation (11): (10); (11); Indicates the first The Patch Token selected in the Layer Transformer encoder. This indicates the final Transformer encoder layer before convergence. The token selected by the layer.
5. The micro-expression recognition method based on Transformer motion feature fusion according to claim 1, characterized in that, In step D, the spatial consistency constraint loss is constructed, including: By constraining spatial consistency, the Patch Token output by the last encoder layer is linearly projected as the key value for spatial attention operation. The query vector of the SPA is the classification Token under the optical flow branch. The calculation process is shown in formula (18). (18); In equation (18), , , and These represent the weights of the query and key vectors, respectively. Represents a linear mapping. and These are the distribution response maps of the horizontal and vertical optical flow components, respectively, representing the global-to-local consistency under their respective modal characteristics. The similarity between the two response maps under the horizontal and vertical optical flow branches is calculated using the cosine formula. Design local loss function Specifically, this refers to aligning the local semantics of two motion change patterns by limiting the distance between the response maps of two different motion features; as shown in formula (19): (19); This indicates the calculation of cosine distance.
6. The micro-expression recognition method based on Transformer motion feature fusion according to claim 1, characterized in that, In step D, the cross-entropy loss is constructed, including: The cross-entropy loss function is used to measure the difference between the probability distribution output by the Transformer recognition model and the actual labels, and an attempt is made to minimize this difference, so that the predictions of the Transformer recognition model are closer to the actual results; setting Classification task, cross-entropy loss function Represented as: (20); In equation (20), The classification network parameters are: This includes linear layer and layer normalization operations. When its input is The corresponding output category is The predicted value; This represents the encoded vector of the actual label. In vector Upper The predicted value of the bit is expressed as: (21); From formulas (20) and (21), it is found that in Only then is there a cross-entropy value, that is, in The label position of the probability distribution vector output by the function; As shown in formula (22), where, ; (22)。 7. The micro-expression recognition method based on Transformer motion feature fusion according to claim 1, characterized in that, Constructing contrastive loss As shown in equation (23): (23); In equation (23), B represents the batch size. Represents similarity calculation, Represents the maximization function. Indicates a constant threshold; The Transformer-based motion feature fusion and recognition model is composed of cross-entropy loss. Comparative loss and Local Consistency Constraint Loss The total loss is calculated by combining all training sessions. Represented as equation (24): (24)。 8. A micro-expression recognition method based on Transformer motion feature fusion according to any one of claims 1-7, characterized in that, In step E, classification and identification include: After the test set is preprocessed, it is input into the trained Transformer recognition model to classify and recognize the test set.
