Improved capsule network facial expression recognition method and device
Through the improved capsule network method and affinity loss function, the problem of difficulty in distinguishing between inter-class differences and intra-class changes in facial expression recognition is solved, the recognition accuracy is improved, and the full extraction and accurate classification of facial image features are achieved.
Patent Information
- Application Number
- CN202210295485.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-24
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2042-03-24
AI Technical Summary
Existing facial expression recognition algorithms are difficult to effectively distinguish subtle inter-category differences and intra-category changes in facial expressions, resulting in low recognition accuracy.
An improved capsule network method is used to perform multi-level feature extraction and attention mechanism fusion through the MFFAM-CapsNet network, to amplify the weight of capsule features that contribute greatly to expression recognition, reduce the weight of small contributions, and use an improved affinity loss function to adjust the network Parameters to maximize inter-class feature spacing and minimize intra-class feature spacing.
It improves the accuracy of facial expression recognition, enhances the ability to extract facial image features, and effectively distinguishes different categories of expressions and changes in the same category.
Smart Images

Figure CN114694219B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of facial expression recognition, and in particular to a facial expression recognition method and device with an improved capsule network. Background Art
[0002] Facial expression recognition has the following significant characteristics: facial expressions have subtle inter-class differences and strong intra-class changes. The current facial expression recognition algorithm mainly relies on the framework of deep convolutional neural networks. However, when deep convolutional neural networks are classified in the fully connected layer, the relative relationship between the features of various parts of the face in the input image, such as the relative position information, relative size relationship and direction information of the features of various parts of the face, etc., will be lost, resulting in the network being unable to effectively distinguish the differences between different categories of expressions and the different changes within the same category of expressions, that is, it is unable to effectively distinguish the subtle inter-class differences and intra-class changes of facial expressions.
[0003] In order to solve this problem, a capsule network algorithm uses its dynamic routing algorithm to reflect the relative relationship between the features of various parts of the face in the update of the coupling coefficient, preserving the relative relationship between the features of various parts of the face, so as to distinguish the subtle inter-class differences and intra-class changes of facial expressions. However, since the traditional capsule network can only extract a single level of facial image features, the facial image feature extraction is insufficient, resulting in low accuracy of facial expression recognition. Summary of the invention
[0004] The purpose of the present invention is to overcome the shortcomings and deficiencies of the prior art and provide a facial expression recognition method based on an improved capsule network, which can distinguish subtle inter-class differences and strong intra-class changes in facial expressions and can fully extract facial image features, thereby achieving high accuracy in facial expression recognition.
[0005] The present invention is achieved through the following technical solution: a facial expression recognition method based on an improved capsule network, comprising the steps of:
[0006] Obtain a face image to be recognized;
[0007] Input the face image to be recognized into the MFFAM-CapsNet network for recognition, and obtain the expression category to which the face image to be recognized belongs;
[0008] The MFFAM-CapsNet network includes an MFEM module, an MCAFM module and a classification prediction module, wherein the MFEM module is used to perform multi-level facial image feature extraction on the facial image to be identified;
[0009] The MCAFM module includes a spatial attention submodule, a channel attention submodule, a main capsule submodule, a dynamic routing submodule and a weighted fusion submodule. The spatial attention submodule is used to obtain a spatial feature map based on the spatial domain according to the facial image features; the channel attention submodule is used to obtain a channel feature map based on the channel domain according to the spatial feature map; the main capsule submodule is used to obtain preliminary capsule features according to the channel feature map; the dynamic routing submodule is used to obtain predicted capsule features through a dynamic routing algorithm according to the preliminary capsule features; the weighted fusion submodule is used to calculate the weight of the predicted capsule feature through a self-attention mechanism according to the predicted capsule feature, and multiply the obtained weight with the corresponding predicted capsule feature, and add multiple predicted capsule features with weights corresponding to the same face image to be identified to obtain a total capsule feature;
[0010] The classification prediction module is used to obtain the expression category to which the face image to be recognized belongs according to the total capsule feature.
[0011] Compared with the prior art, the present invention provides a facial expression recognition method based on an improved capsule network, wherein the MCAFM module of the MFFAM-CapsNet network fuses multi-level capsule features through an attention mechanism for capsules, thereby being able to amplify the weights of capsule features that contribute greatly to facial expression recognition and reduce the weights of capsule features that contribute less, thereby increasing the inter-class differences in facial expressions and reducing the intra-class differences in facial expressions, thereby effectively improving the accuracy of facial expression recognition.
[0012] Furthermore, the expression of the weight of the predicted capsule feature is:
[0013]
[0014] Where W j is the weight of the jth feature vector in the predicted capsule feature, v j is the j-th feature vector in the predicted capsule feature.
[0015] Furthermore, the MFFAM-CapsNet network also includes a parameter adjustment module, the parameter adjustment module includes a loss feedback submodule, the loss feedback submodule is used to establish a loss function, and feed back the loss function to the back propagation network parameter update of the MFFAM-CapsNet network;
[0016] The loss function includes an improved affinity loss function L iaf , improved affinity loss function L iaf The expression is:
[0017]
[0018] Wherein, M is the number of face images to be recognized; For the yth i The class center of the expression category, y i ∈{1,2,...,K}, K is the total number of expression categories, Class Center Randomly sample from a d-dimensional Gaussian distribution; x i is the i-th deep face image feature among the M face images to be recognized; σ c is the standard deviation between the class centers of K different expression categories.
[0019] Furthermore, the classification prediction module is used to obtain a prediction result vector of each expression category according to the total capsule feature, and determine that the expression category corresponding to the prediction result vector with the longest modulus is the expression category to which the face image to be recognized belongs;
[0020] The parameter adjustment module further includes a decoder, and the decoder is used to reconstruct the face image to be identified according to the prediction result vector to obtain a reconstructed face image;
[0021] The expression of the loss function is:
[0022] L=0.95*L c +0.05*L r +L iaf
[0023] Among them, L is the loss function; L c is the marginal loss function, the marginal loss function L c The expression is:
[0024] L c =T c max(0, m + -||v c ||)+λ(1-T c )max(0,||v c ||-m - ) 2
[0025] Where c is the expression category; T c is the indicator function of expression category c. When c is not empty, T c is 1, when c is empty, T c =0; m + is the upper boundary; m - is the lower boundary; v c is the prediction result vector of expression category c; λ is the hyperparameter used to adjust the weight;
[0026] Lr is the reconstruction loss function, the reconstruction loss function L r The expression is:
[0027]
[0028] Wherein, m is the number of face images to be identified; x i is the i-th face image to be identified among the m face images to be identified; is the reconstructed face image corresponding to the i-th face image to be recognized.
[0029] Further, the MFEM module includes a plurality of MFEM convolutional layers with different numbers of channels;
[0030] The step of inputting the face image to be identified into the MFFAM-CapsNet network for identification and obtaining the expression category to which the face image to be identified belongs comprises the following steps:
[0031] Inputting the face image to be recognized into the MFEM module to obtain shallow face image features, middle face image features and deep face image features output by different MFEM convolutional layers;
[0032] Inputting the shallow face image features, the middle face image features and the deep face image features into the MCAFM module to obtain the total capsule features;
[0033] The total capsule feature is input into the classification prediction module to obtain the expression category to which the face image to be recognized belongs.
[0034] Further, after obtaining the face image to be recognized, the steps include:
[0035] Flipping the face image to be recognized horizontally with a preset probability;
[0036] and / or rotating the face image to be recognized within a certain angle range with a preset probability;
[0037] and / or filling a preset number of pixels outward from the boundary of the face image to be identified with a preset probability, and cropping a random area of the face image to be identified to adjust the face image to be identified to the same size;
[0038] And / or randomly masking the face image to be recognized by using a masking block.
[0039] Furthermore, after obtaining the face image to be recognized, the following steps are also included:
[0040] Adjusting the face images to be recognized to the same size;
[0041] A normalization operation is performed on the pixel values of the face image to be recognized.
[0042] Based on the same inventive concept, the present invention also provides a facial expression recognition device using an improved capsule network, comprising:
[0043] An image acquisition module is used to acquire a face image to be recognized;
[0044] An image recognition module is used to input the face image to be recognized into the MFFAM-CapsNet network for recognition, and obtain the expression category to which the face image to be recognized belongs;
[0045] The MFFAM-CapsNet network includes an MFEM module, an MCAFM module and a classification prediction module, wherein the MFEM module is used to perform multi-level facial image feature extraction on the facial image to be identified;
[0046] The MCAFM module includes a spatial attention submodule, a channel attention submodule, a main capsule submodule, a dynamic routing submodule and a weighted fusion submodule. The spatial attention submodule is used to obtain a spatial feature map based on the spatial domain according to the facial image features; the channel attention submodule is used to obtain a channel feature map based on the channel domain according to the spatial feature map; the main capsule submodule is used to obtain preliminary capsule features according to the channel feature map; the dynamic routing submodule is used to obtain predicted capsule features through a dynamic routing algorithm according to the preliminary capsule features; the weighted fusion submodule is used to calculate the weight of the predicted capsule feature through a self-attention mechanism according to the predicted capsule feature, and multiply the obtained weight with the corresponding predicted capsule feature, and add multiple predicted capsule features with weights corresponding to the same face image to be identified to obtain a total capsule feature;
[0047] The classification prediction module is used to obtain the expression category to which the face image to be recognized belongs according to the total capsule feature.
[0048] Furthermore, the expression of the weight of the predicted capsule feature is:
[0049]
[0050] Where W j is the weight of the jth feature vector in the predicted capsule feature, v j is the j-th feature vector in the predicted capsule feature.
[0051] Furthermore, the classification prediction module is used to obtain a prediction result vector of each expression category according to the total capsule feature, and determine that the expression category corresponding to the prediction result vector with the longest modulus is the expression category to which the face image to be recognized belongs;
[0052] The MFFAM-CapsNet network also includes a parameter adjustment module, which includes a decoder and a loss feedback submodule. The decoder is used to reconstruct the face image to be recognized according to the prediction result vector to obtain the reconstructed face image; the loss feedback submodule is used to establish a loss function, and feed back the loss function to the back propagation network parameter update of the MFFAM-CapsNet network; the expression of the loss function is:
[0053] L=0.95*L c +0.05*L r +L iaf
[0054] Among them, L is the loss function; L c is the marginal loss function, the marginal loss function L c The expression is:
[0055] L c =T c max(0, m + -||v c ||)+λ(1-T c )max(0,||v c ||-m - ) 2
[0056] Where c is the expression category; T c is the indicator function of expression category c. When c is not empty, T c is 1, when c is empty, T c =0; m + is the upper boundary; m - is the lower boundary; v c is the prediction result vector of expression category c; λ is the hyperparameter used to adjust the weight;
[0057] L r is the reconstruction loss function, the reconstruction loss function L r The expression is:
[0058]
[0059] Wherein, m is the number of face images to be identified; x i is the i-th face image to be identified among the m face images to be identified; is the reconstructed face image corresponding to the i-th face image to be recognized;
[0060] L iaf is the improved affinity loss function, the improved affinity loss function Liaf The expression is:
[0061]
[0062] Wherein, M is the number of face images to be recognized; For the yth i The class center of the expression category, y i ∈{1,2,...,K}, K is the total number of expression categories, Class Center Randomly sample from a d-dimensional Gaussian distribution; x i is the i-th deep face image feature among the M face images to be recognized; σ c is the standard deviation between the class centers of K different expression categories.
[0063] For better understanding and implementation, the present invention is described in detail below with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0064] Figure 1 A schematic diagram of a flow chart of a facial expression recognition method using an improved capsule network according to an embodiment of the present invention;
[0065] Figure 2 It is a schematic diagram of the structure of the MFFAM-CapsNet network of the embodiment;
[0066] Figure 3 It is a structural schematic diagram of a spatial attention submodule of a specific embodiment;
[0067] Figure 4 It is a structural schematic diagram of a channel attention submodule of a specific embodiment;
[0068] Figure 5 is a schematic diagram of an exemplary flow chart of a dynamic routing submodule;
[0069] Figure 6 It is a structural schematic diagram of a facial expression recognition device with an improved capsule network according to an embodiment;
[0070] Figure 7 It is a schematic diagram of the t-SNE visualization effect of the method of the present invention;
[0071] Figure 8 This is a schematic diagram of the t-SNE visualization effect of the facial expression recognition method that does not use the improved affinity loss function of the present invention. DETAILED DESCRIPTION
[0072] In order to make the objectives, technical solutions and advantages of the present application more clear, the embodiments of the present application will be further described in detail below with reference to the accompanying drawings.
[0073] It should be clear that the described embodiments are only some embodiments of the present invention, not all 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.
[0074] When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Instead, they are only examples of devices and methods consistent with some aspects of the present application as detailed in the attached claims.
[0075] In the description of the present application, it should be understood that the terms "first", "second", "third", etc. are only used to distinguish similar objects, and do not have to be used to describe a specific order or sequence, nor can they be understood as indicating or implying relative importance. For those of ordinary skill in the art, the specific meanings of the above terms in the present application can be understood according to the specific circumstances. In addition, in the description of the present application, unless otherwise specified, "multiple" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist, for example, A and / or B, which can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the front and back associated objects are an "or" relationship. It should also be noted that the terms "include", "comprise" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also includes other elements that are not explicitly listed, or also includes elements inherent to such a process, method, commodity or device. In the absence of more constraints, an element defined by the phrase "comprises a ..." does not exclude the existence of additional identical elements in the process, method, product or apparatus comprising the element.
[0076] The present invention extracts the shallow, middle and deep layers of the facial expression image to fully extract the image features of the facial expression image, and adopts the attention mechanism to amplify the weights of the key features that can distinguish different categories of expressions, thereby solving the problem of low accuracy of facial expression recognition caused by small differences between classes and large changes within classes. At the same time, the parameters of the entire network are adjusted by a loss function including an improved affinity loss function to maximize the spacing between features and minimize the spacing between features within a class, thereby improving the accuracy of face recognition. This is specifically described by the following embodiments.
[0077] See also Figure 1 , which is a flow chart of the improved capsule network facial expression recognition method of this embodiment, the method comprises the steps of:
[0078] S1: Obtain a face image to be recognized.
[0079] The face image to be identified is an image taken by an entity and includes a face subject. In a specific implementation, the face image to be identified can be collected by a mobile phone terminal, a tablet terminal, or a PC terminal that has a data transmission relationship with a camera, and transmitted to a processor, which can implement the method of the present invention when executing a computer program, and the computer program can be stored in a memory or a computer-readable storage medium.
[0080] S2: Preprocessing the acquired face image to be recognized.
[0081] The preprocessing of the face images to be recognized specifically includes: adjusting the face images to be recognized to the same size. In this embodiment, the face images to be recognized are uniformly adjusted to 224×224; normalizing the pixel values of all face images to be recognized, and the normalized expression is channel=(channel-mean) / std, where channel is the channel, channel-mean is the mean of each channel, and std is the variance. In this embodiment, the normalization operation includes 3 channels, and the mean channel-mean of each channel is set to (0.485, 0456, 0.406), and the variance std is set to (0.229, 0.224, 0.225). Then, the size of the normalized face images to be recognized is 224×224×3.
[0082] In order to further increase the generalization performance of the training model, in a preferred embodiment, the preprocessing of the face image to be identified for the training model also includes horizontally flipping the face image to be identified with a preset probability. In this embodiment, the preset probability is set to 0.5; rotating the face image to be identified within a certain angle range with a preset probability. In this embodiment, the preset probability is set to 0.2, and the rotation angle range is set to -45° to 45°; filling a preset number of pixels outward from the boundary of the face image to be identified with a preset probability, and cropping a random area of the filled image, the cropping size is consistent with the image before filling, so as to adjust the face image to be identified to the same size; and randomly occluding the face image to be identified by using an occlusion block.
[0083] S3: Input the preprocessed face image to be recognized into the MFFAM-CapsNet network (Capsule Network Based on Multi-level Feature Fusion Attention Mechanism) for expression recognition to obtain the expression category to which the face image to be recognized belongs.
[0084] See also Figure 2 , which is a structural diagram of the MFFAM-CapsNet network, the MFFAM-CapsNet network includes an MFEM (Multi-level Feature Extraction Module, multi-level feature extraction) module, an MCAFM (Multi-level Capsule Attention Fusion Module, multi-level capsule attention) module, a classification prediction module and a parameter adjustment module, wherein the MFEM module is used to extract multi-level facial image features for the face image to be recognized; the MCAFM module is used to perform capsule processing based on the attention mechanism according to the multi-level facial image features extracted by the MFEM module, to obtain capsule features; the classification prediction module is used to perform classification probability prediction according to the capsule features obtained by the MCAFM module, to obtain a prediction result vector of each expression category; the parameter adjustment module is used to adjust the network parameters of the MFFAM-CapsNet network back propagation.
[0085] Specifically, the MFEM module includes a plurality of MFEM convolutional layers with different numbers of channels. The face image to be identified is input into the MFEM module, and the face image to be identified is convolved through a plurality of MFEM convolutional layers with different numbers of channels in turn, and face image features output by several MFEM convolutional layers are obtained and input into the MCAFM module. In a preferred embodiment, the face image features obtained by the MFEM module include shallow face image features, middle face image features, and deep face image features. More specifically, the present embodiment adopts the Resnet18 network to perform multi-level facial image feature extraction of the face image to be recognized. The MFEM convolution layer of the Resnet18 network specifically includes Conv1 layer, Layer1 layer, Layer2 layer, Layer3 layer and Layer4 layer, wherein the Conv1 layer includes a convolution layer with 64 channels and a convolution kernel size of 7×7; the Layer1 layer includes two BasicBlocks, each BasicBlock includes two convolution layers with 64 channels and a convolution kernel size of 3×3 and a shortcut connection layer; L The layer 2 includes two BasicBlocks, each of which contains two convolution layers with 128 channels and a convolution kernel size of 3×3, and a shortcut connection layer; the layer 3 includes two BasicBlocks, each of which contains two convolution layers with 256 channels and a convolution kernel size of 3×3, and a shortcut connection; the layer 4 includes two BasicBlocks, each of which contains two convolution layers with 512 channels and a convolution kernel size of 3×3, and a shortcut connection. The facial image features output by the layer 2, layer 3, and layer 4 are shallow facial image features, middle facial image features, and deep facial image features, respectively.
[0086] The face image to be recognized is input into the MFEM module, and convolution is performed on the face image to be recognized through the Conv1 layer, Layer1 layer, Layer2 layer, Layer3 layer and Layer4 layer in sequence. For the face image to be recognized with an input size of 224×224×3, the feature dimensions of the output of the Conv1 layer are 64×112×112, the feature dimensions of the output of the Layer1 layer are 64×56×56, the feature dimensions of the output of the Layer2 layer are 128×28×28, the feature dimensions of the output of the Layer3 layer are 256×14×14, and the feature dimensions of the output of the Layer4 layer are 512×7×7.
[0087] The MCAFM module includes multiple spatial attention submodules, multiple channel attention submodules, multiple primary capsule submodules, multiple dynamic routing submodules and vector weighting submodules. The multiple levels of facial image features of the same face image to be recognized are input into the MCAFM module, and the multiple levels of facial image features of the same face image to be recognized are processed by the spatial attention submodule, the channel attention submodule, the primary capsule submodule, the dynamic routing submodule and the weighted fusion submodule in sequence to obtain the total capsule features. Among them, the spatial attention submodule is used to obtain a spatial feature map based on the spatial domain according to the facial image features; the channel attention submodule is used to obtain a channel feature map based on the channel domain according to the spatial feature map; the primary capsule submodule is used to obtain preliminary capsule features according to the channel feature map; the dynamic routing submodule is used to obtain the predicted capsule features through the dynamic routing algorithm according to the preliminary capsule features; the weighted fusion submodule is used to perform weighted operations on the predicted capsule features, and sum up the multiple weighted predicted capsule features corresponding to the same face image to be recognized to obtain the total capsule features. In a preferred embodiment, the MCAFM module includes three spatial attention submodules, three channel attention submodules, three main capsule submodules, three dynamic routing submodules and one weighted fusion submodule.
[0088] See also Figure 3 , which is a structural diagram of a spatial attention submodule of a specific embodiment, the spatial attention submodule includes a first convolutional layer (Conv2), a second convolutional layer (Conv3), a third convolutional layer (Conv4), a fourth convolutional layer (Conv5) and an activation function (Activation), wherein the convolution kernel size of the first convolutional layer is 1×1, the convolution kernel size of the second convolutional layer is 3×3, the convolution kernel size of the third convolutional layer is 1×3, and the convolution kernel size of the fourth convolutional layer is 3×1.
[0089] The facial image features are input into the spatial attention module. The facial image features are first convolved through the first convolutional layer to reduce the number of channels by half, thereby reducing the amount of calculation. The features output by the first convolutional layer are then convolved and summed through the second, third, and fourth convolutional layers respectively. The resulting features are processed through an activation function. The output features of the activation function are dot-producted with the input facial image features to obtain a spatial feature map based on the spatial domain.
[0090] See also Figure 4, which is a schematic diagram of the structure of a channel attention submodule of a specific embodiment, and the channel attention submodule includes a global average pooling layer (Pooling), a fifth convolutional layer (Conv6) and an activation function (Activation). The spatial feature map is input into the channel attention submodule, and each channel of the spatial feature map is compressed into 1 weight through the global average pooling layer; after being processed by the convolution layer and the activation function in turn, the output feature of the activation function is dot-producted with the input spatial feature map to obtain a channel feature map based on the channel domain. In a specific implementation, the feature dimension of the channel feature map is 512×7×7.
[0091] The main capsule submodule includes a convolution layer with a convolution kernel size of 2×2, a step size of 1, and a padding of 0. The channel feature map is input into the main capsule submodule, and the channel feature map is convolved a preset number of times through the convolution layer to obtain a preliminary capsule feature. In a preferred embodiment, the preset number of convolution operations is set to 8 times, and 8 preliminary capsule features are obtained accordingly. For a channel feature map with a feature dimension of 512×7×7, the feature dimension after convolution of the convolution layer of the main capsule submodule is 6×6×32. The feature vectors of the convolution results of 8 convolutions are concatenated to obtain a preliminary capsule feature with a feature dimension of 6×6×32×8, that is, the preliminary capsule feature includes 6×6×32 8-dimensional feature vectors, that is, 1152 8-dimensional feature vectors.
[0092] See also Figure 5 , which is an exemplary flow chart of a dynamic routing submodule, which calculates the preliminary capsule features through a dynamic routing algorithm to obtain the predicted capsule features. Among them, the j-th parent node output vector S obtained by the dynamic routing algorithm on the preliminary capsule features j The expression is:
[0093]
[0094] In the formula, c ij is the coupling coefficient, the coupling coefficient c ij The sum of is 1; is the predicted feature vector, the predicted feature vector The expression is:
[0095]
[0096] In the formula, u i is the i-th feature vector of the preliminary capsule feature, w ij is the weight matrix.
[0097] Output vector S to the parent node through squashing function j Calculate and obtain the predicted capsule feature vj , predict capsule feature v j The expression is:
[0098]
[0099] When the prediction vector Output vector S with all possible parent nodes j The larger the cosine value of , the closer the prediction vector is to the parent node, thereby increasing the coupling coefficient of the prediction vector and reducing the coupling coefficients of other prediction vectors. ij The adjustment expression is:
[0100]
[0101] In the formula, the current b ij The value is the original b ij The value of plus the prediction vector and the predicted capsule feature v j The product of b ij The initial value of is 0.
[0102] In a specific implementation, a preliminary capsule feature including 1152 8-dimensional feature vectors is input into the dynamic routing submodule, and the feature dimension of the predicted capsule feature output by the dynamic routing submodule is 1152×8.
[0103] The weighted fusion submodule calculates the corresponding weight based on the predicted capsule feature through the self-attention mechanism, and multiplies the obtained weight with the predicted capsule feature; multiple predicted capsule features with weights corresponding to the same face image to be recognized are added together to obtain the total capsule feature. Among them, the weight of the predicted capsule feature W j The expression is:
[0104]
[0105] In a specific implementation, the predicted capsule features with a feature dimension of 1152×8 are input into the weighted fusion submodule, and the feature dimension of the total capsule features output by the weighted fusion submodule is 1152×8.
[0106] The classification prediction module calculates the prediction probability of the face image to be identified for each expression category based on the total capsule features, and determines the expression category with the highest prediction probability as the expression category to which the face image to be identified belongs. The total capsule features are input into the classification prediction module to obtain the prediction result vector corresponding to each expression category. The modulus of the prediction result vector of each expression category is the prediction probability of the face image to be identified for the expression category. The expression category corresponding to the prediction result vector with the longest modulus is the expression category with the highest prediction probability.
[0107] In one specific implementation, the total capsule features with a feature dimension of 1152×8 are input into the classification prediction module, and the classification prediction module outputs a 7×16 prediction result vector, that is, a 16-dimensional prediction result vector of 7 expression categories, where the expression categories may include anger, disgust, fear, happiness, sadness, surprise, and natural state.
[0108] The parameter adjustment module includes a decoder and a loss feedback submodule. The decoder is used to reconstruct the face image to be recognized according to the prediction result vector to obtain the reconstructed face image. The decoder includes FC1 fully connected layer, FC2 fully connected layer and FC3 fully connected layer, wherein the activation functions of FC1 fully connected layer and FC2 fully connected layer are ReLU function, and the activation function of FC3 fully connected layer is Sigmoid function. The prediction result vector is input into FC1 fully connected layer, FC2 fully connected layer and FC3 fully connected layer in sequence. For the 7×16 prediction result vector, the vector feature dimension of the output of FC1 fully connected layer is 512, the vector feature dimension of the output of FC2 fully connected layer is 1024, and the vector feature dimension of the output of FC3 fully connected layer is 150528 (3×224×224).
[0109] The loss feedback submodule is used to establish the loss function, which is fed back to the network parameter update of the MFFAM-CapsNet network back propagation. The expression of the loss function L is:
[0110] L=0.95*L c +0.05*L r +L iaf
[0111] Among them, L c is the marginal loss function, and its expression is:
[0112] L c =T c max(0, m + -||v c ||)+λ(1-T c )max(0,||v c ||-m - ) 2
[0113] Where c is the expression category; T c is the indicator function of expression category c. When c is not empty, T c is 1, when c is empty, T c =0; m + is the upper boundary, the value is 0.9; m - is the lower boundary, with a value of 0.1; v cis the prediction result vector of expression category c; λ is a hyperparameter used to adjust the weight, and its value is 0.5.
[0114] L r To reconstruct the loss function, reconstruct the loss function L r The reconstruction loss function L is obtained based on the Euclidean distance between the pixels of the reconstructed face image and the preprocessed face image to be identified. r The expression is:
[0115]
[0116] In the formula, m is the number of face images to be recognized, that is, batchsize; x i is the i-th preprocessed face image to be recognized among the m face images to be recognized; Reconstruct a facial image corresponding to the preprocessed facial image to be recognized.
[0117] L iaf is the improved affinity loss function, the improved affinity loss function L iaf Used to calculate and minimize the face image feature x i The class center c of the expression category to which it belongs yi distance to minimize the intra-class distance; calculate the standard deviation σ of the class center of all expression categories c , and minimize 1 / σ c Since the standard deviation of the class centers of all expression categories can describe the degree of dispersion of all categories, by maximizing the standard deviation, the distribution of all class centers can be made more discrete, thereby expanding the distance between classes; calculate and expand the distance between each class center and the average value of all other class centers to further expand the gap between classes.
[0118] Improved affinity loss function L iaf The expression is:
[0119]
[0120] Where M is the number of face images to be recognized, that is, batchsize; For the yth i The class center of the expression category, y i ∈{1,2,...,K}, K is the total number of expression categories, Class Center Randomly sample from a d-dimensional Gaussian distribution; x i is the facial image feature output by Layer4 of the i-th MFEM module among the M facial images to be recognized; σ c is the standard deviation between the class centers of K different expression categories.
[0121] In addition, the class center It is updated as the deep features change. Due to the huge amount of training set data, it is difficult to load all the face images to be recognized in the training set at one time. Therefore, in a specific implementation, the data of the training set is divided into batches, and the class center is updated in batches according to the number of face images to be recognized in each batch. Then the reconstruction loss function L r m in and the improved affinity loss function L iaf The M in it is the number of face images to be recognized in each batch.
[0122] Based on the same inventive concept, the present invention also provides a facial expression recognition device with an improved capsule network, see Figure 6 The device includes an image acquisition module 10, an image preprocessing module 20 and an image recognition module 30, wherein the image acquisition module 10 is used to acquire a face image to be recognized; the image preprocessing module 20 is used to preprocess the face image to be recognized acquired by the image acquisition module; the image recognition module 30 is used to input the face image to be recognized preprocessed by the image preprocessing module into an MFFAM-CapsNet network for expression recognition, and obtain the expression category to which the face image to be recognized belongs. The MFFAM-CapsNet network is the same as the MFFAM-CapsNet network in the above-mentioned improved capsule network facial expression recognition method embodiment.
[0123] More specifically, the image recognition module 30 includes a feature extraction module 31, a feature fusion module 32 and a prediction category acquisition module 33. The feature extraction module 31 is used to input the face image to be recognized into the MFEM module of the MFFAM-CapsNet network, and sequentially convolve the face image to be recognized through a plurality of MFEM convolutional layers with different numbers of channels, obtain the face image features output by several MFEM convolutional layers, and input them into the MCAFM module of the MFFAM-CapsNet network. In a preferred embodiment, the face image features obtained by the MFEM module include shallow face image features, middle face image features and deep face image features.
[0124] The feature fusion module 32 is used to input the facial image features of multiple levels of the same facial image to be identified into the MCAFM module of the MFFAM-CapsNet network, and process the facial image features of multiple levels of the same facial image to be identified through the spatial attention submodule, channel attention submodule, main capsule submodule, dynamic routing submodule and weighted fusion submodule of the MCAFM module respectively to obtain the total capsule features.
[0125] The prediction category acquisition module 33 is used to input the total capsule features into the classification prediction module of the MFFAM-CapsNet network to obtain a prediction result vector corresponding to each expression category. The modulus of the prediction result vector of each expression category is the prediction probability of the face image to be recognized for the expression category. The expression category corresponding to the prediction result vector with the longest modulus is the expression category with the highest prediction probability.
[0126] As for the device embodiment, since it basically corresponds to the method embodiment, all relevant details can be found in the description of the method embodiment, which will not be repeated here.
[0127] The following three experiments are used to illustrate the technical effects of the present invention:
[0128] Experiment 1: The public RAF-DB (Real-world Affective Faces Database) dataset is processed using the facial expression recognition method of the improved capsule network of the present invention and the existing popular facial expression recognition method. The RAF-DB dataset is a real-world facial expression dataset, which contains 29,672 highly diverse facial images downloaded from the Internet. This experiment uses a single-label subset of 7 basic emotions, which contains a total of 15,339 images, including 12,271 training samples and 3,068 test samples. The accuracy of the processing results is compared. As shown in Table 1, the accuracy of the method of the present invention reaches 89.13%, which is higher than other facial expression recognition methods, especially 13.01% higher than the face recognition method based on Capsnet (capsule network) proposed by Hinton in 2017.
[0129] Table 1
[0130]
[0131]
[0132] It can be seen that, compared with the prior art, the MFEM module of the present invention extracts multi-level capsule features such as shallow capsule features, middle capsule features and deep capsule features of the face image to be identified, fully extracts the features of the face image to be identified, and improves the model's ability to extract multi-level features of the image. Since facial expression recognition has subtle inter-class differences, that is, different expressions usually share most of the same facial features, only the differences in facial features of key parts can be used to determine the expression category to which the face image to be identified belongs. Therefore, the MCAFM module fuses multi-level capsule features through the attention mechanism for capsules, which can amplify the weight of the capsule features that contribute greatly to facial expression recognition and reduce the weight of the capsule features that contribute less, thereby increasing the inter-class differences of facial expressions and reducing the intra-class differences of facial expressions, effectively improving the accuracy of facial expression recognition.
[0133] Experiment 2: The RAF-DB dataset was processed using the method of the present invention using the improved affinity loss function and the facial expression recognition method without the improved affinity loss function of the present invention, and the processing results were color-coded for the members of each expression category using the t-SNE visualization algorithm. Figure 7 and Figure 8 ,in Figure 7 It is a schematic diagram of the t-SNE visualization effect of the method of the present invention; Figure 8 This is a schematic diagram of the t-SNE visualization effect of the facial expression recognition method without using the improved affinity loss function of the present invention. It can be seen that the method of the present invention can effectively expand the distance between different expression categories and aggregate different members of the same expression category by adjusting parameters through the improved affinity loss function.
[0134] Experiment 3: The loss function in the method of the present invention is replaced by no loss function, center loss, and the existing affinity loss function, and the RAF-DB dataset is processed; the RAF-DB dataset is processed using the method of the present invention using the improved affinity loss function; the accuracies of the processing results are compared. As shown in Table 2, the accuracy of the method of the present invention using the improved affinity loss function is 1.01%, 0.62%, and 0.51% higher than that of the method of the present invention in which the loss function is replaced by no loss function, center loss, and the existing affinity loss function, respectively.
[0135] Table 2
[0136] Loss Function Accuracy No loss function is used 88.12% Center loss 88.51% Existing affinity loss functions 88.62% Improved affinity loss function 89.13%
[0137] It can be seen that compared with the prior art, the present invention combined with the improved affinity loss function can better maximize the inter-class distances of different expression categories and minimize the intra-class distances of the same expression category, thereby further improving the accuracy of facial expression recognition.
[0138] The above-mentioned embodiments only express several implementation methods of the present invention, and the description is relatively specific and detailed, but it cannot be understood as limiting the scope of the invention patent. It should be pointed out that for ordinary technicians in this field, several modifications and improvements can be made without departing from the concept of the present invention, and the present invention is also intended to include these modifications and modifications.
Claims
1. A facial expression recognition method based on an improved capsule network, characterized in that: Includes steps: Obtaining a face image to be recognized; Input the face image to be recognized into a capsule network based on a multi-level feature fusion attention mechanism, MFFAM-CapsNet network, for recognition, and obtain the expression category to which the face image to be recognized belongs; The MFFAM-CapsNet network includes an MFEM module, an MCAFM module and a classification prediction module, wherein the MFEM module is used to perform multi-level facial image feature extraction on the facial image to be identified; The MCAFM module includes a spatial attention submodule, a channel attention submodule, a main capsule submodule, a dynamic routing submodule and a weighted fusion submodule. The spatial attention submodule is used to obtain a spatial feature map based on the spatial domain according to the facial image features; the channel attention submodule is used to obtain a channel feature map based on the channel domain according to the spatial feature map; the main capsule submodule is used to obtain preliminary capsule features according to the channel feature map; the dynamic routing submodule is used to obtain predicted capsule features through a dynamic routing algorithm according to the preliminary capsule features; the weighted fusion submodule is used to calculate the weight of the predicted capsule feature through a self-attention mechanism according to the predicted capsule feature, and multiply the obtained weight with the corresponding predicted capsule feature, and add multiple predicted capsule features with weights corresponding to the same face image to be identified to obtain a total capsule feature; The classification prediction module is used to obtain the expression category to which the face image to be identified belongs according to the total capsule features; wherein the classification prediction module is used to obtain the prediction result vector of each expression category according to the total capsule features, and determine that the expression category corresponding to the prediction result vector with the longest modulus is the expression category to which the face image to be identified belongs; The MFFAM-CapsNet network also includes a parameter adjustment module, which includes a loss feedback submodule, which is used to establish a loss function and feed back the loss function to the back propagation network parameter update of the MFFAM-CapsNet network; wherein the parameter adjustment module also includes a decoder, which is used to reconstruct the face image to be recognized according to the prediction result vector to obtain a reconstructed face image; The expression of the loss function is: L=0.95*L c +0.05*L r +L iaf Among them, L is the loss function; L c is the marginal loss function, the marginal loss function L c The expression is: L c =T c max(0,m + -||v c ||)+λ(1-T c )max(0,||v c ||-m - ) 2 Where c is the expression category; T c is the indicator function of expression category c. When c is not empty, T c is 1, when c is empty, T c =0; m + is the upper boundary; m - is the lower boundary; v c is the prediction result vector of expression category c; λ is the hyperparameter used to adjust the weight; L r is the reconstruction loss function, the reconstruction loss function L r The expression is: Wherein, m is the number of face images to be identified; x i is the i-th face image to be identified among the m face images to be identified; is the reconstructed face image corresponding to the i-th face image to be recognized; L iaf is the improved affinity loss function, the improved affinity loss function L iaf The expression is: Wherein, M is the number of face images to be recognized; For the yth i The class center of the expression category, y i ∈{1, 2, ..., K}, K is the total number of expression categories, Class Center Randomly sample from a d-dimensional Gaussian distribution; x i is the i-th deep face image feature among the M face images to be recognized; σ c is the standard deviation between the class centers of K different expression categories.
2. The method according to claim 1, characterized in that: The expression for the weight of the predicted capsule feature is: Where W j is the weight of the jth feature vector in the predicted capsule feature, v j is the j-th feature vector in the predicted capsule feature.
3. The method according to any one of claims 1 to 2, characterized in that: The MFEM module includes a plurality of MFEM convolutional layers with different numbers of channels; The step of inputting the face image to be identified into the MFFAM-CapsNet network for identification and obtaining the expression category to which the face image to be identified belongs comprises the following steps: Inputting the face image to be recognized into the MFEM module to obtain shallow face image features, middle face image features and deep face image features output by different MFEM convolutional layers; Inputting the shallow face image features, the middle face image features and the deep face image features into the MCAFM module to obtain the total capsule features; The total capsule feature is input into the classification prediction module to obtain the expression category to which the face image to be recognized belongs.
4. The method according to any one of claims 1 to 2, characterized in that: After obtaining the face image to be recognized, the following steps are included: Flipping the face image to be recognized horizontally with a preset probability; and / or rotating the face image to be recognized within a certain angle range with a preset probability; and / or filling a preset number of pixels outward from the boundary of the face image to be identified with a preset probability, and cropping a random area of the face image to be identified to adjust the face image to be identified to the same size; And / or randomly masking the face image to be recognized by using a masking block.
5. The method according to claim 4, characterized in that: After obtaining the face image to be recognized, the following steps are also included: Adjusting the face images to be recognized to the same size; A normalization operation is performed on the pixel values of the face image to be recognized.
6. A facial expression recognition device based on an improved capsule network, characterized in that: include: An image acquisition module is used to acquire a face image to be recognized; An image recognition module is used to input the face image to be recognized into a capsule network based on a multi-level feature fusion attention mechanism, MFFAM-CapsNet network, for recognition, and obtain the expression category to which the face image to be recognized belongs; The MFFAM-CapsNet network includes an MFEM module, an MCAFM module and a classification prediction module, wherein the MFEM module is used to perform multi-level facial image feature extraction on the facial image to be identified; The MCAFM module includes a spatial attention submodule, a channel attention submodule, a main capsule submodule, a dynamic routing submodule and a weighted fusion submodule. The spatial attention submodule is used to obtain a spatial feature map based on the spatial domain according to the facial image features; the channel attention submodule is used to obtain a channel feature map based on the channel domain according to the spatial feature map; the main capsule submodule is used to obtain preliminary capsule features according to the channel feature map; the dynamic routing submodule is used to obtain predicted capsule features through a dynamic routing algorithm according to the preliminary capsule features; the weighted fusion submodule is used to calculate the weight of the predicted capsule feature through a self-attention mechanism according to the predicted capsule feature, and multiply the obtained weight with the corresponding predicted capsule feature, and add multiple predicted capsule features with weights corresponding to the same face image to be identified to obtain a total capsule feature; The classification prediction module is used to obtain the expression category to which the face image to be identified belongs according to the total capsule features; wherein, The classification prediction module is used to obtain a prediction result vector of each expression category according to the total capsule feature, and determine that the expression category corresponding to the prediction result vector with the longest modulus is the expression category to which the face image to be recognized belongs; The MFFAM-CapsNet network also includes a parameter adjustment module, which includes a decoder and a loss feedback submodule. The decoder is used to reconstruct the face image to be recognized according to the prediction result vector to obtain the reconstructed face image; the loss feedback submodule is used to establish a loss function, and feed back the loss function to the back propagation network parameter update of the MFFAM-CapsNet network; the expression of the loss function is: L=0.95*L c +0.05*L r +L iaf Among them, L is the loss function; L c is the marginal loss function, the marginal loss function L c The expression is: L c =T c max(0,m + -||v c ||)+λ(1-T c )max(0,||v c ||-m - ) 2 Where c is the expression category; T c is the indicator function of expression category c. When c is not empty, T c is 1, when c is empty, T c =0; m + is the upper boundary; m - is the lower boundary; v c is the prediction result vector of expression category c; λ is the hyperparameter used to adjust the weight; L r is the reconstruction loss function, the reconstruction loss function L r The expression is: Wherein, m is the number of face images to be identified; x i is the i-th face image to be identified among the m face images to be identified; is the reconstructed face image corresponding to the i-th face image to be recognized; L iaf is the improved affinity loss function, the improved affinity loss function L iaf The expression is: Wherein, M is the number of face images to be recognized; For the yth i The class center of the expression category, y i ∈{1, 2, ..., K}, K is the total number of expression categories, Class Center Randomly sample from a d-dimensional Gaussian distribution; x i is the i-th deep face image feature among the M face images to be recognized; σ c is the standard deviation between the class centers of K different expression categories.
7. The device according to claim 6, characterized in that: The expression for the weight of the predicted capsule feature is: Where W j is the weight of the jth feature vector in the predicted capsule feature, v j is the j-th feature vector in the predicted capsule feature.
