Smile image recognition method and device based on diffusion type generation network and readable medium
Through the method based on the diffusion generation network, the problem of low smile recognition accuracy and noise interference in the existing technology is solved, and the accurate recognition and extraction of the smile in its maximum state is achieved.
Patent Information
- Application Number
- CN202310551942.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-16
- Publication Date
- 2024-09-24
AI Technical Summary
Existing smile image recognition methods have problems such as low accuracy, low tolerance for noise interference, recognition failure in complex situations, and inaccurate EEG-assisted judgment. In particular, it is difficult to accurately capture the natural state when capturing the maximum moment of a smile. smile image.
Using a method based on the diffusion generation network, by acquiring video frames, cropping and aligning face images, building a condition generation module, a UNet noise fitting and removal module and a category generation module, extract smile features and generate a smile score, and then determine the maximum smile frame.
It improves the accuracy and stability of smile recognition, reduces the impact of noise interference, and can accurately obtain images of the maximum smile state in complex situations.
Smart Images

Figure CN118692121A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing, and in particular to a smile image recognition method, device and readable medium based on a diffusion generation network. Background Art
[0002] At present, the photos that cameras can capture are often difficult to reflect the moment when the smile is the biggest. If you want to capture the biggest smile, you often need to go to a studio to complete the shooting, and it requires a high degree of cooperation between the person being photographed and the photographer.
[0003] Video recording can track people's facial expressions for a long time, increasing the possibility of capturing natural smiles. It is very convenient. If the frame with the biggest smile can be generated from the video, the videographer basically gets rid of the dependence on professional photographers. However, due to the high frame rate of current cameras, it is very difficult to manually select the smile frame.
[0004] The methods currently used to evaluate facial expressions include PCA, principal component analysis, and deep learning. PCA is an earlier adopted technology. It uses PCA principal component analysis to extract image features, such as structural position features such as the corners of the eyes, and calculates the weights of different positions and the probability that the image expression is a happy smile through SVM training. At the same time, brain waves assist in judging the probability of happiness. Through dimensionality reduction, the problem of high-dimensional space is converted into low-dimensional space processing, which relatively reduces the computing cost, but there are certain problems with complex fitting. Principal component analysis mainly extracts mouth vectors and facial vectors, calculates the degree of smile through multivariate functions, and then obtains the smile score of the image. With the development of deep learning, the more representative deep learning methods such as residual network ResNet are used to evaluate smiles, which have achieved a certain degree of accuracy. At present, there are several problems with the smile image judgment method:
[0005] 1. The accuracy of principal component analysis may be poor. Principal component analysis needs to extract key information of the image through dimensionality reduction. In this process, the information contained in the image will be lost, resulting in a decrease in recognition accuracy.
[0006] 2. The SVM fitting nonlinearity is low. If the image is drastically twisted, recognition will fail.
[0007] 3. Multiple technology-assisted integrated learning may fail in complex situations. The accuracy of EEG-assisted judgment of happiness state lacks literature support and may be inaccurate.
[0008] 4. Existing deep learning-based image recognition methods, such as residual networks, may have problems with noise interference and have low tolerance for small noise interference. Summary of the invention
[0009] In view of the technical problems mentioned above, the purpose of the embodiments of the present application is to propose a smile image recognition method, device and readable medium based on a diffusion generation network to solve the technical problems mentioned in the above background technology section and realize the function of extracting a face photo with the maximum smile from a video.
[0010] In a first aspect, the present invention provides a smile image recognition method based on a diffusion generation network, comprising the following steps:
[0011] S1, obtain the target video, decompose the target video by frame, obtain a video frame vector, crop a face image from each video frame image in the video frame vector, and obtain a face image vector;
[0012] S2, performing face alignment processing on each face image in the face image vector to obtain a frontal face image vector;
[0013] S3, constructing a diffusion generation network, the diffusion generation network includes a conditional generation module, a UNet noise fitting and removal module and a category generation module, training the UNet noise fitting and removal module to obtain a trained UNet noise fitting and removal module, inputting the front face image vector into the conditional generation module to obtain a corresponding conditional vector, inputting the conditional vector into the trained UNet noise fitting and removal module, predicting an emotion label vector, inputting the emotion label vector into the category generation module, and extracting a smile score vector corresponding to the front face image vector;
[0014] S4, extracting from the frontal face image vector the frontal face image corresponding to the maximum smile score in the smile score vector as the best smile image.
[0015] Preferably, in step S1, a face image is cropped from each video frame image in the video frame vector to obtain a face image vector, which specifically includes:
[0016] Each video frame image in the video frame vector is input into the face region segmentation model to obtain the face region in each video frame image;
[0017] The size of the face region in each video frame image is adjusted to the same size to obtain a face image;
[0018] A face image vector is constructed according to the face image corresponding to each video frame image in the video frame vector.
[0019] Preferably, step S2 specifically includes:
[0020] S21, inputting each face image in the face image vector into a face key point recognition model to extract key points, thereby obtaining a key point vector;
[0021] S22, calculating the face tilt angle corresponding to each face image in the face image vector through the key point vector, and rotating each face image in the face image vector according to the face tilt angle to obtain a frontal face image;
[0022] S23, constructing a frontal face image vector Z according to the frontal face image corresponding to each face image in the face image vector: [pic1, pic2, ..., pic n ], where pic n Indicates the frontal face image corresponding to the face image in the nth video frame.
[0023] Preferably, step S21 specifically includes:
[0024] Each face image in the face image vector is input into the face key point recognition model to identify the left eye position P l , right eye position P r And the philtrum position H, and record the left eye position P l The corresponding horizontal component P lx and the vertical component P ly , denoted as P l (P lx , P ly ), right eye position P r The corresponding horizontal component P rx and the vertical component P ry , denoted as P r (P rx , P ry ), and the horizontal component P corresponding to the philtrum position H rx and the vertical component P ry , denoted as H(H x , H y ), and obtain the key point coordinates G(P l ,P r ,H);
[0025] The key point vector G is constructed according to the key point coordinates corresponding to each face image in the face image vector: [G1, G2, ..., G n ], G n Indicates the coordinates of the key points corresponding to the face image in the nth video frame.
[0026] Preferably, step S22 specifically includes:
[0027] Calculate the binocular connection vector Co according to the key point coordinates corresponding to each face image in the face image vector:
[0028] Co=(P lx -P rx ,Ply -P ry );
[0029] Calculate the angle between the eye-line vector Co and the horizontal vector (1,0) to get the face tilt angle;
[0030] Each face image in the face image vector is reversely rotated pixel by pixel according to the face tilt angle to perform face alignment so that the midline of the aligned face is parallel to the longitudinal axis of the face image to obtain a frontal face image.
[0031] Preferably, the UNet noise fitting and removal module includes a UNet network and an output list. The UNet network includes an input layer, a contraction path, a connection layer, an expansion path and an output layer connected in sequence. The input layer is used to receive a conditional vector, a step number or an emotion label vector after adding noise. The contraction path includes three contraction layers connected in series in sequence, and the expansion path includes four expansion layers connected in series in sequence. The output list is used to store or extract feature maps generated during the UNet network calculation process.
[0032] Preferably, the training process of the UNet noise fitting and removal module in step S3 specifically includes:
[0033] Obtain training data consisting of an initial frontal face image and an initial emotion label vector, add random noise that matches the dimension of the vector to the initial emotion label vector, and add it cyclically for a total of m steps, where the random noise added in the tth step is ε t , obeys the normal distribution N(0,1), from x t-1 to x t The noise addition calculation process is as follows:
[0034]
[0035]
[0036] Among them, x t-1 is the emotion label vector obtained after adding random noise in step t-1, x t is the emotion label vector obtained after adding random noise in step t, is the mean of the normal distribution, β t I is the variance of the normal distribution, β t is a hyperparameter, I is the identity matrix;
[0037] After adding noise cyclically, the emotion label vector group X=[x1,x2,…,x t ];
[0038] Input the initial frontal face image into the conditional generation module to obtain the corresponding conditional vector y;
[0039] x t , t and y are input into the UNet noise fitting and removal module, and the noise added in the tth step is predicted by the noise fitting function to obtain the predicted value ε θ (x t ,t,y), where θ is a parameter related to its own internal structure;
[0040] According to the predicted value ε θ (x t ,t,y) and the actual noise ε t Noise fitting uses the following loss function to calculate the loss value L:
[0041]
[0042] Where E represents the mean square error of the predicted value;
[0043] Back propagation adjusts the internal parameters of the model and obtains the trained ε θ (x t ,t,y).
[0044] Preferably, in step S3, the conditional vector is input into a trained UNet noise fitting and removal module to predict the emotion label vector, which specifically includes:
[0045] The conditional vector is input into the trained UNet noise fitting and removal module, and a Gaussian noise map is randomly generated, denoted as x m ;
[0046] x m , m inputs the trained UNet noise fitting and removal module, and passes the trained ε θ (x t ,t,y) predict the noise of step t, and repeat the denoising process continuously, starting from step t=m from x t Calculate x t-1 , the specific calculation formula is as follows:
[0047]
[0048] α t =1-β t ;
[0049]
[0050] Where i = 1, 2, 3, …, t;
[0051] Finally, the emotion label vector corresponding to the target video is predicted.
[0052] Preferably, in step S3, the emotion label vector is input into a category generation module to extract a smile score vector corresponding to the frontal face image vector, specifically including:
[0053] The score of each emotion in the emotion label vector is calculated according to the following formula:
[0054]
[0055] Among them, size(A) is the size of the emotion label vector A, that is, the product of the number of rows and columns, k is the kth emotion, a mn is the element in the mth row and nth column of the emotion label vector A, where m refers to the mth row and n refers to the nth column;
[0056] Sort the scores of each emotion from large to small, extract the first score as the smile score, and record the smile score obtained from the nth frame image of the target video as grade n , and get the smile score vector grade1, grade2,…, grade n .
[0057] In a second aspect, the present invention provides a smile image recognition device based on a diffusion generation network, comprising:
[0058] The video processing module is configured to obtain a target video, decompose the target video by frame to obtain a video frame vector, and crop a face image from each video frame image in the video frame vector to obtain a face image vector;
[0059] A face image processing module is configured to perform face alignment processing on each face image in the face image vector to obtain a frontal face image vector;
[0060] A prediction module is configured to construct a diffusion generation network, the diffusion generation network includes a conditional generation module, a UNet noise fitting and removal module and a category generation module, the UNet noise fitting and removal module is trained to obtain a trained UNet noise fitting and removal module, a front face image vector is input into the conditional generation module to obtain a corresponding conditional vector, the conditional vector is input into the trained UNet noise fitting and removal module, an emotion label vector is predicted, the emotion label vector is input into the category generation module, and a smile score vector corresponding to the front face image vector is extracted;
[0061] The image extraction module is configured to extract the front face image corresponding to the maximum smile score in the smile score vector from the front face image vector as the best smile image.
[0062] In a third aspect, the present invention provides an electronic device comprising one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any implementation manner in the first aspect.
[0063] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in any implementation manner in the first aspect.
[0064] Compared with the prior art, the present invention has the following beneficial effects:
[0065] (1) The present invention uses a diffusion-based generative network to analyze each frame of the target video to generate a smile score. The diffusion-based generative network has fewer parameters, is easy to tune, has better performance, and is combined with the deep feature extraction capability of ResNet to better extract smile features.
[0066] (2) The UNet noise fitting and removal module in the present invention can help avoid the influence of jitter, muscle tremor and other problems in the video on the accuracy of the judgment result, thereby improving the accuracy of the judgment.
[0067] (3) The present invention uses a face region segmentation model to accurately segment and crop a face image, and uses a face key point recognition model to identify the coordinates of face key points to perform precise face alignment, so that the final judgment result is more accurate. BRIEF DESCRIPTION OF THE DRAWINGS
[0068] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0069] Figure 1 is an exemplary device architecture diagram to which an embodiment of the present application may be applied;
[0070] Figure 2 A schematic diagram of a flow chart of a smile image recognition method based on a diffusion generation network according to an embodiment of the present application;
[0071] Figure 3 A schematic diagram of the training and operation process of a diffusion-based generative network of a smile image recognition method based on a diffusion-based generative network according to an embodiment of the present application;
[0072] Figure 4A schematic diagram of the structure of a UNet network of a smile image recognition method based on a diffusion generation network according to an embodiment of the present application;
[0073] Figure 5 A schematic diagram of the structure of the contraction layer of the smile image recognition method based on the diffusion generation network according to an embodiment of the present application;
[0074] Figure 6 A schematic diagram of the structure of an expansion layer of a smile image recognition method based on a diffusion generation network according to an embodiment of the present application;
[0075] Figure 7 A schematic diagram of storage and extraction of feature maps in an output list of a smile image recognition method based on a diffusion generation network according to an embodiment of the present application;
[0076] Figure 8 A schematic diagram of a smiling image recognition device based on a diffusion generation network according to an embodiment of the present application;
[0077] Fig. 9 It is a schematic diagram of the structure of a computer device suitable for implementing the electronic device of the embodiment of the present application. DETAILED DESCRIPTION
[0078] In order to make the purpose, technical scheme and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0079] Figure 1 An exemplary device architecture 100 is shown to which a smiling image recognition method based on a diffusion-based generative network or a smiling image recognition device based on a diffusion-based generative network according to an embodiment of the present application can be applied.
[0080] like Figure 1 As shown, the device architecture 100 may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0081] Users can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Various applications, such as data processing applications, file processing applications, etc., can be installed on terminal devices 101, 102, 103.
[0082] Terminal devices 101, 102, 103 can be hardware or software. When terminal devices 101, 102, 103 are hardware, they can be various electronic devices, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, etc. When terminal devices 101, 102, 103 are software, they can be installed in the electronic devices listed above. They can be implemented as multiple software or software modules (for example, software or software modules used to provide distributed services), or they can be implemented as a single software or software module. No specific limitation is made here.
[0083] The server 105 may be a server that provides various services, such as a background data processing server that processes files or data uploaded by the terminal devices 101, 102, and 103. The background data processing server may process the acquired files or data and generate processing results.
[0084] It should be noted that the smile image recognition method based on the diffusion generation network provided in the embodiment of the present application can be executed by the server 105, and can also be executed by the terminal devices 101, 102, and 103. Accordingly, the smile image recognition device based on the diffusion generation network can be set in the server 105, and can also be set in the terminal devices 101, 102, and 103.
[0085] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided as required. In the case where the processed data does not need to be obtained remotely, the above device architecture may not include a network, but only a server or a terminal device.
[0086] In recent years, diffusion-based generative networks have developed rapidly, such as stable diffusion, which performs well in the problem of generating images from text. This type of network has excellent multimodal generation capabilities and is more interpretable than the earlier proposed adversarial generative network technology. It also has fewer parameters and is less difficult to train, and is currently attracting more and more attention from scholars.
[0087] Figure 2 A smile image recognition method based on a diffusion generation network provided by an embodiment of the present application is shown, comprising the following steps:
[0088] S1, obtain the target video, decompose the target video by frame, obtain a video frame vector, crop a face image from each video frame image in the video frame vector, and obtain a face image vector.
[0089] In a specific embodiment, in step S1, a face image is cropped from each video frame image in the video frame vector to obtain a face image vector, which specifically includes:
[0090] Each video frame image in the video frame vector is input into the face region segmentation model to obtain the face region in each video frame image;
[0091] The size of the face region in each video frame image is adjusted to the same size to obtain a face image;
[0092] A face image vector is constructed according to the face image corresponding to each video frame image in the video frame vector.
[0093] Specifically, the target video can be obtained through a video upload module or a video recording module. In one embodiment, a user can upload a video shot through a video upload module set on a terminal and input the user's name. The program verifies whether the name is positive. If the verification is qualified, the video is saved in a specified path of a specified server. Then the target video is decomposed into a number of video frame images: image1, image2, ..., image n , and combined into a video frame vector I: [image1,image2,…,image n ], where n is the total number of frames in the video, image n Represents the nth video frame image. A face region segmentation model is used to identify and segment the face region in the video frame image. The face region segmentation model includes a ResNet34 network. In one embodiment, the position and size of the face region in each video frame image in the video frame vector I can be segmented by the ResNet34 network of the dlib library. The segmented face image is cropped and adjusted to the same size. In one embodiment, the size of the face image can be scaled to 896×896 pixels, which is recorded as the face image area, where area n Represents the nth video frame image n The rectangular area where the face is located in the image is not recorded if the face cannot be recognized. All face images are combined into a face image vector X: [area1, area2, …, area n In other embodiments, the residual network in the face region segmentation model may also use a deeper network or other deep networks, such as ResNet-52, or transformer, etc., and be cropped to other uniform sizes.
[0094] S2, performing face alignment processing on each face image in the face image vector to obtain a frontal face image vector.
[0095] In a specific embodiment, step S2 specifically includes:
[0096] S21, inputting each face image in the face image vector into a face key point recognition model to extract key points, thereby obtaining a key point vector;
[0097] S22, calculating the face tilt angle corresponding to each face image in the face image vector through the key point vector, and rotating each face image in the face image vector according to the face tilt angle to obtain a frontal face image;
[0098] S23, constructing a frontal face image vector Z according to the frontal face image corresponding to each face image in the face image vector: [pic1, pic2, ..., pic n ], where pic n Indicates the frontal face image corresponding to the face image in the nth video frame.
[0099] In a specific embodiment, step S21 specifically includes:
[0100] Each face image in the face image vector is input into the face key point recognition model to identify the left eye position P l , right eye position P r And the philtrum position H, and record the left eye position P l The corresponding horizontal component P lx and the vertical component P ly , denoted as P l (P lx , P ly ), right eye position P r The corresponding horizontal component P rx and the vertical component P ry , denoted as P r (P rx , P ry ), and the horizontal component P corresponding to the philtrum position H rx and the vertical component P ry , denoted as H(H x , H y ), and obtain the key point coordinates G(P l ,P r ,H);
[0101] The key point vector G is constructed based on the key point coordinates corresponding to each face image in the face image vector:
[0102] [G1,G2,…,G n ], G n Indicates the coordinates of the key points corresponding to the face image in the nth video frame.
[0103] In a specific embodiment, step S22 specifically includes:
[0104] Calculate the binocular connection vector Co according to the key point coordinates corresponding to each face image in the face image vector:
[0105] Co=(P lx -P rx ,P ly -P ry );
[0106] Calculate the angle between the eye-line vector Co and the horizontal vector (1,0) to get the face tilt angle;
[0107] Each face image in the face image vector is reversely rotated pixel by pixel according to the face tilt angle to perform face alignment so that the midline of the aligned face is parallel to the longitudinal axis of the face image to obtain a frontal face image.
[0108] Specifically, the face key point recognition model includes a dlib face key point recognizer. In one embodiment, the face image vector X is passed to the dlib face key point recognizer, and the face key point recognizer can recognize the left eye position, the right eye position, and the philtrum position, and record the corresponding left eye position and its horizontal component P lx and the vertical component P ly , denoted as P l (P lx , P ly ), right eye position P r and its horizontal component P rx and the vertical component P ry , denoted as (P rx , P ry ), and the philtrum position H(H x , H y ). Get the face image [area1,area2,…,area n ] corresponding to the key point coordinate data G(P l ,P r ,H)(left eye position, right eye position, philtrum position): G1,G2,…,G n , and form a key point vector G: [G1,G2,…,G n ].
[0109] Further, the face tilt angle is calculated by the key point coordinates and the face is rotated to a corresponding angle to restore the face to its normal position, including the following steps:
[0110] 1) Calculate the face tilt angle: Calculate the eye connection vector Co according to the key point coordinates: Co = (P lx -P rx ,P ly -Pry ), and calculate the angle between the eye-line vector Co and the horizontal vector (1,0), which is the face tilt angle.
[0111] 2) Rotate and align the face in the face image: reversely rotate the face frame vector element by element according to the face tilt angle, and align the face. After alignment, the face midline is parallel to the vertical axis of the image.
[0112] 3) Save the front face image vector: combine all the new pixel blocks obtained by rotation into a front face image vector N: [pic1, pic2, ..., pic n ],pic n Represents the frontal face image of the nth video frame.
[0113] In other embodiments, other facial key points may be used to calculate the inclination angle, such as the inclination angle of the nose midline.
[0114] S3, construct a diffusion generation network, the diffusion generation network includes a conditional generation module, a UNet noise fitting and removal module and a category generation module, train the UNet noise fitting and removal module to obtain a trained UNet noise fitting and removal module, input the front face image vector into the conditional generation module to obtain the corresponding conditional vector, input the conditional vector into the trained UNet noise fitting and removal module, predict the emotion label vector, input the emotion label vector into the category generation module, and extract the smile score vector corresponding to the front face image vector.
[0115] For more details, please refer to the training and operation process of the diffusion generation network. Figure 3 The purpose of the conditional generation module is to scale the frontal face image in the frontal face image vector, match the emotion label vector, make the number of rows and columns consistent, and obtain the conditional vector.
[0116] In a specific embodiment, the UNet noise fitting and removal module includes a UNet network and an output list. The UNet network includes an input layer, a contraction path, a connection layer, an expansion path and an output layer connected in sequence. The input layer is used to receive a conditional vector, a step number and an emotion label vector after adding noise. The contraction path includes three contraction layers connected in series in sequence, and the expansion path includes four expansion layers connected in series in sequence. The output list is used to store or extract feature maps generated during the UNet network calculation process.
[0117] Specifically, the UNet noise fitting and removal module includes a UNet network and an output list. The UNet network is used to receive the emotion label vector after adding noise, the condition vector, the number of steps, and the time step embedding vector generated by the time step embedding vector generation layer obtained by subsequent calculation, and calculate the feature map for subsequent calculation. The output list is used to store the feature map generated during the UNet calculation process.
[0118] refer to Figure 4 The UNet network consists of an input layer, two paths (a contraction path and an expansion path), a connection layer, and an output layer. The input layer is used to receive the emotion label vector after adding noise and convert it into the dimension required by the UNet network; at the same time, it receives the number of steps and obtains the time step embedding vector through calculation and conversion. Specifically, it is completed by a two-dimensional convolution layer with a convolution kernel size of 3x3, a padding of 1, and an output dimension of 320. This layer takes the initial emotion label vector as input and outputs the vector to the first contraction layer of the contraction path of the UNet network. The time step embedding vector is calculated by the number of steps, mainly through the following three-layer neural network connected to each other:
[0119] 1. The first fully connected layer (layer 1): has an output dimension of 1280 and receives the time step embedding vector preliminarily calculated by the following formula:
[0120]
[0121] Among them, t is the number of steps, d is 320, which is the input dimension of the first fully connected layer of the input layer.
[0122] 2. siLU function activation layer (layer 2): The output of the fully connected layer 1 is calculated through the siLU function to obtain the activated vector. If the input of this layer is x, the output is x*sigmoid(x);
[0123] 3. The second fully connected layer (layer 3): The output dimension is 1280. The output of the second layer is used as input. The vector output by the second fully connected layer is input to the first contraction layer of the UNet contraction path and connected to it.
[0124] The contraction path contains three contraction layers connected in series to compute feature maps and store them in the output list.
[0125] A contraction layer is composed of several residual layers, spatial domain Transformer layers, and downsampling layers. Each of the following steps corresponds to a layer of the network. Each layer receives the output from other layers and outputs the result to other layers after calculation. For example, if the mth layer receives the output of the nth layer as the input of this layer, then the mth layer is said to be connected to the nth layer. (m, n are any integers greater than 0, and m and n are not equal) The specific operation layers are:
[0126] 1. First residual layer (layer 1):
[0127] Receive the input vector x and the time step embedding vector embeddings, and calculate the output result outputs;
[0128] If the contraction layer is not connected to the connection layer, the output result outputs and the conditional vector y are input to the second layer, and the output result outputs is stored in the output list;
[0129] If the contraction layer is connected to the connection layer, the second layer is skipped, the output result is directly input to the third layer, and the output result outputs is stored in the output list.
[0130] 2. First spatial Transformer layer (layer 2):
[0131] (If not skipped by layer 1) The first spatial domain Transformer layer accepts the input vector and the conditional vector y, calculates the feature map, and stores it in the output list;
[0132] 3. Second residual layer (layer 3):
[0133] Receive feature maps and time step embeddings, and calculate outputs;
[0134] If the contraction layer is not connected to the connection layer, the output result outputs and the conditional vector y are input to the 4th layer, and the output result outputs is stored in the output list;
[0135] If the contraction layer is connected to the connection layer, skip the 4th and 5th layers, directly input the output result outputs as input to the connection layer connected to the contraction layer, and store the output result ouputs in the output list.
[0136] 4. Second spatial domain Transformer layer (layer 4):
[0137] (If not skipped by layer 3) Accept the input vector and conditional vector y, calculate the feature map outputs, and store it in the output list;
[0138] 5. Downsampling layer (layer 5):
[0139] (If not skipped by layer 3) Receive the feature map obtained by layer 4, pass it through a 2D convolutional layer with a kernel of 3×3, a stride of 2, and padding of 1, calculate the feature map outputs, pass it to the next layer and store the outputs in the output list.
[0140] Models without skipping such as Figure 5 shown.
[0141] The expansion path contains four expansion layers connected in series, which take feature maps from the output list and perform calculations. The contraction path and the expansion path are connected by a connection layer, which receives the output of the contraction layer and calculates the feature map and passes it as input to the expansion path; the expansion path passes the calculation map level by level, and after completing the calculation, passes the obtained feature map to the output layer.
[0142] An expansion layer consists of several concatenation layers, residual layers, spatial domain Transformer layers, and upsampling layers. Each of the following steps corresponds to a layer of the network. Each layer receives the output from other layers and outputs the result to other layers after calculation. If the mth layer receives the output of the nth layer as the input of this layer, then the mth layer is said to be connected to the nth layer. (m, n are any integers greater than 0, and m and n are not equal) The specific operation layers are:
[0143] 1. The first splicing layer (layer 1):
[0144] Extract the element pointed to by the index in the output list, update the index, and concatenate it with the output of the previous layer to output the concatenated vector;
[0145] 2. The third residual layer (layer 2):
[0146] Receive the vector output by the first layer and the time step embedding vector embeddings, and calculate the calculation result outputs;
[0147] If the expansion layer is not connected to the connection layer, the output result and the conditional vector y are input to the third layer as input;
[0148] If the expansion layer is connected to the connection layer, the third layer is skipped and the output result is directly input to the fourth layer as input.
[0149] 3. Third spatial domain Transformer layer (layer 3):
[0150] (If not skipped by the second layer) Receive the result obtained by the second layer and the conditional vector y input, calculate the feature map, and output it to the fourth layer;
[0151] 4. Second splicing layer (layer 4):
[0152] Extract the element pointed to by the index in the output list, update the index, and concatenate it with the output of the previous step connected to it, and output the concatenated vector;
[0153] 5. Fourth residual layer (5th layer):
[0154] Receive the vector output by the 4th layer and the time step embedding vector embeddings, and calculate the result;
[0155] If the expansion layer is not connected to the connection layer, the output result and the conditional vector y are input to the sixth layer as input;
[0156] If the expansion layer is connected to the connection layer, the 6th layer is skipped and the output result is directly input to the 7th layer as input.
[0157] 6. Fourth spatial domain Transformer layer (layer 6):
[0158] Receive the result obtained in the 5th layer and the conditional vector y input, and calculate the feature map;
[0159] 7. The third splicing layer (layer 7):
[0160] Extract the element at the position pointed by the index in the output list, update the index, and concatenate it with the output of the previous step connected to it, and output the concatenated vector;
[0161] 8. Fifth residual layer (8th layer):
[0162] Receive the vector output by the 7th layer and the time step embedding vector embeddings, and calculate the result;
[0163] If the expansion layer is not connected to the connection layer, the output result and the conditional vector y are input into the 9th spatial domain Transformer layer;
[0164] If the expansion layer is connected to the connection layer, the 9th layer is skipped and the output result is directly input to the concatenation layer of the 10th layer. If the expansion layer is connected to the output layer, the 10th layer is skipped and the output result is directly output to the output layer.
[0165] 9. The fifth spatial domain Transformer layer (layer 9): (if not skipped by layer 8) receives the result obtained by layer 8 and the conditional vector y input, and calculates the feature map;
[0166] 10. Upsampling layer: (if not skipped by layer 8) upsamples the output of the previous layer connected to it and outputs the output result to the next step;
[0167] Models without skipping such as Figure 6 shown.
[0168] The connection layer connects the contraction path and the expansion path, and is composed of a residual layer and a spatial domain Transformer layer. The specific structure includes the following:
[0169] 1. The sixth residual layer (layer 1): The output dimension is 1280, the input is the output of the last layer of the last contraction layer of the contraction path and the time step embedding vector, and the output vector is input to the second layer;
[0170] 2. The sixth spatial domain Transformer layer (layer 2): the number of attention heads is 20, the attention head size is 64, the output of layer 1 and the conditional vector y are used as input, and the output vector is sent to layer 3;
[0171] 3. The seventh residual layer (layer 3): The output dimension is 1280, the input is the output of the second layer and the time step embedding vector, and the output vector is sent to the first layer of the expansion path.
[0172] The residual layer receives an input vector x and a time step embedding vector embeddings, sets the output dimension to output_dim, and then performs the following calculation transformation. The specific structure of the first residual layer to the seventh residual layer includes:
[0173] 1. The first set of normalization layers (layer 1): input is x, output is X1;
[0174] 2. The first activation function layer (layer 2): the input is X1, the activation value is calculated by the siLU function, and the output is X2;
[0175] 3. The first two-dimensional convolution layer (layer 3): the input is X2, the convolution kernel size is 3x3, the padding is 1, the output dimension is output_dim, and the output is X3;
[0176] 4. The second activation function layer (layer 4): the input is embeddings, the activation function is siLU, and the calculated output is Z1;
[0177] 5. The output dimension of the third fully connected layer (layer 5) is output_dim, and the output result is Z2;
[0178] 6. The second normalization layer (layer 6): the input is the sum of X3 and Z2, and the output is O1;
[0179] 7. The third activation function layer (layer 7): the input is O1, the activation function is siLU, and the output result is O2;
[0180] 8. The second two-dimensional convolution layer (layer 8): the input is O2, the convolution kernel size is 3×3, the padding is 1, the output dimension is output_dim, the output vector is O3, and O3 plus x is the output result of the residual layer.
[0181] The spatial domain Transformer layer receives the set number of attention heads num_heads and the size of attention heads head_size, takes the conditional vector y as the guiding condition, and receives the upper layer output z connected to the layer. Through the group normalization layer, convolution layer, cross attention layer, feedforward neural network layer, etc., the following calculation transformation is performed. The specific structure of the first spatial domain Transformer layer to the seventh spatial domain Transformer layer includes:
[0182] 1. The third group normalization layer (layer 1): receives input z, performs group normalization, and the output is recorded as Z1;
[0183] 2. The third two-dimensional convolution layer (layer 2): the input is Z1, the convolution kernel size is 1×1, the padding is 1, the output dimension is num_heads*head_size, and the output is recorded as Z2;
[0184] 3. The first normalization layer (layer 3): the input is Z2 and the output is Z3;
[0185] 4. The first cross attention layer (layer 4): the input is Z3 and None value, the output is Z4; Z4 plus Z2 is recorded as Z5;
[0186] 5. The second normalization layer (layer 5): input is Z5 and output is Z6;
[0187] 6. Second cross attention layer (layer 6): input is Z6 and conditional vector y, output is Z7; Z7 is added to Z5 to get Z8;
[0188] 7. The third normalization layer (layer 7): input is Z8 and output is Z9;
[0189] 8. Feedforward neural network layer (layer 8): input is Z9 and output is Z10;
[0190] 9. The fourth fully connected layer (layer 9): The input is Z10, the output is added to Z8, and the output is obtained and output to the next layer.
[0191] Among them, the calculation process of the first cross attention layer and the second cross attention layer is as follows:
[0192] 1. Receive input tensor x and condition tensor y, then convert the input tensor x into query tensor Q, key tensor K, and value tensor V by passing the input tensor x through the fully connected layer q with the number of output channels num_heads*head_size, and the condition tensor y through the fully connected layers k and v with the number of channels num_heads*head_size.
[0193] 2. Divide the last dimension of the query tensor, key tensor, and value tensor into num_heads small dimensions, then transpose the query tensor and key tensor, calculate the dot product between them, and divide by the scaling factor (the scaling factor size is the result of square root of head_size) to get the score matrix;
[0194] 3. The score matrix passes through the softmax activation function layer to obtain the attention weight matrix;
[0195] 4. The attention weight matrix is multiplied by the value tensor and reshaped to the same shape as the input tensor. The final output is obtained by passing it through a fully connected layer with an output channel number of num_heads*head_size.
[0196] The target output dimension of the feedforward neural network layer is output_dim. The feedforward neural network layer receives the input vector inputs. The calculation process of the feedforward neural network layer is as follows:
[0197] 1. Pass the input through a fully connected layer with an output dimension of output_dim*2 to project the input vector into a higher-dimensional space;
[0198] 2. Divide the output of the fully connected layer into two parts of size output_dim, namely the activation value and the gating signal gate;
[0199] 3. Use the tanh function to calculate the scaling factor tanh_res related to the gate signal gate. The calculation formula is: tanh_res = gate*0.7978845608*(1+0.044715*(gate 2 )).
[0200] 4. Output outputs vector, the calculation formula is: outputs = x*0.5*gate*(1+tanh_res).
[0201] The specific structure of the upsampling layer includes:
[0202] 1. Bilinear interpolation layer (layer 1): The input is the output of the previous layer, and the output length and width are doubled by bilinear interpolation and output to the second layer;
[0203] 2. The fourth two-dimensional convolution layer (layer 2): the input is the output of layer 1, the convolution kernel size is 3×3, the padding is 1, the number of channels is the same as the input channel number, and the output is to the next layer.
[0204] The output layer is connected to the expansion path and consists of a group normalization layer, a siLU activation function layer, and a two-dimensional convolution layer. The specific structure includes the following:
[0205] 1. The fourth group normalization layer (layer 1): takes the output of the expansion path as input, performs group normalization, and outputs to the second layer;
[0206] 2. The fourth activation function layer (layer 2): takes the output of layer 1 as input, calculates the activation value using the siLU function, and outputs it to layer 3;
[0207] 3. The fifth two-dimensional convolution layer (layer 3): performs two-dimensional convolution with the output of layer 2 as input. The convolution kernel size is 3×3, the padding is 1, the number of output channels is 4, and the output vector is the noise predicted by the UNet module.
[0208] refer to Figure 7 , the output list is used to store feature maps, which is connected to the UNet network and has two operating states: storage and extraction. The UNet network connected to it accesses its internal data through indexes, and the index of the i-th element is recorded as [i]. In the initial state, when no element is stored, the index points to the first position of the output list, recorded as [1].
[0209] When storing: UNet accesses the space pointed to by index [k] and stores the feature map in this space. After the storage is completed, the index automatically moves back to [k+1], allocates memory and waits for the next feature map element to be stored;
[0210] During extraction: UNet accesses the space pointed to by index [m] and extracts the feature map stored in the space. After the extraction is completed, the index releases the space pointed to by the index, and the index automatically moves forward to [m-1], which is called index update, waiting for the next access.
[0211] In a specific embodiment, the training process of the UNet noise fitting and removal module in step S3 specifically includes:
[0212] Obtain training data consisting of an initial frontal face image and an initial emotion label vector, add random noise that matches the dimension of the vector to the initial emotion label vector, and add it cyclically for a total of m steps, where the random noise added in the tth step is ε t , obeys the normal distribution N(0,1), from x t-1 to x t The noise addition calculation process is as follows:
[0213]
[0214]
[0215] Among them, x t-1 is the emotion label vector obtained after adding random noise in step t-1, x t is the emotion label vector obtained after adding random noise in step t, is the mean of the normal distribution, β t I is the variance of the normal distribution, β t is a hyperparameter, I is the identity matrix;
[0216] After adding noise cyclically, the emotion label vector group X=[x1,x2,…,x t ];
[0217] Input the initial frontal face image into the conditional generation module to obtain the corresponding conditional vector y;
[0218] x t , t and y are input into the UNet noise fitting and removal module, and the noise added in the tth step is predicted by the noise fitting function to obtain the predicted value ε θ (x t ,t,y), where θ is a parameter related to its own internal structure;
[0219] According to the predicted value ε θ (x t ,t,y) and the actual noise ε t Noise fitting uses the following loss function to calculate the loss value L:
[0220]
[0221] Where E represents the mean square error of the predicted value;
[0222] Back propagation adjusts the internal parameters of the model and obtains the trained ε θ (x t ,t,y).
[0223] In a specific embodiment, in step S3, the conditional vector is input into the trained UNet noise fitting and removal module to predict the emotion label vector, which specifically includes:
[0224] The conditional vector is input into the trained UNet noise fitting and removal module, and a Gaussian noise map is randomly generated, denoted as x m ;
[0225] x m , m inputs the trained UNet noise fitting and removal module, and passes the trained ε θ (x t ,t,y) predict the noise of step t, and repeat the denoising process continuously, starting from step t=m from x t Calculate x t-1 , the specific calculation formula is as follows:
[0226]
[0227] α t=1-β t (5)
[0228]
[0229] Where i = 1, 2, 3, …, t;
[0230] Finally, the emotion label vector corresponding to the target video is predicted.
[0231] In a specific embodiment, in step S3, the emotion label vector is input into the category generation module to extract the smile score vector corresponding to the frontal face image vector, which specifically includes:
[0232] The score of each emotion in the emotion label vector is calculated according to the following formula:
[0233]
[0234] Among them, size(A) is the size of the emotion label vector A, that is, the product of the number of rows and columns, k is the kth emotion, a mn is the element in the mth row and nth column of the emotion label vector A, where m refers to the mth row and n refers to the nth column;
[0235] Sort the scores of each emotion from large to small, extract the first score as the smile score, and record the smile score obtained from the nth frame image of the target video as grade n , and get the smile score vector grade1, grade2,…, grade n .
[0236] Specifically, refer to Figure 3 ,In the training process of the UNet noise fitting and removal module, a training data reading module, a noise adding module, and a loss calculation module are also used.
[0237] In the training data reading module, a frontal face image-emotion label vector pair is randomly extracted from the training set whose constituent elements are frontal face image-emotion label vector pairs, and the emotion label vector x0 is input into the noise adding module. The emotion label vector is a vector of length 7, corresponding to 7 emotion components: happiness, anger, contempt, disgust, fear, sadness and surprise, and the format is [happy, angry, contempt, disgust, fear, sadness, surprise]. If the frontal face image has the corresponding emotion, the corresponding emotion component is 1, otherwise it is 0. If a frontal face image is a happy emotion, the corresponding emotion label vector is [1,0,0,0,0,0,0]. Repeat the vector 128 times horizontally and 896 times vertically, and expand the vector to a vector of size 896×896. This module passes the expanded vector into the noise adding module. At the same time, the face photo is input into the conditional generation module.
[0238] In the noise adding module, noise that matches the dimension of the input emotion label vector x0 is added, and the loop is repeated for a total of 1000 steps. The noise ε added in step t (t is any number from 1 to 1000) t Random, following normal distribution N(0,1). t-1 to x t The noise addition calculation process obeys the normal distribution shown in formula 1. According to formula 2, x1 is calculated based on x0, x2 is calculated based on x1, and so on. The calculation process is repeated continuously to finally obtain x 1000 , the noise is added. Finally, x1,x2,…,x t Combine to generate the emotion label vector group X = [x1, x2, ..., x t ].
[0239] In the conditional generation module, refer to Figure 3 In the path shown by the solid line, the conditional generation module includes a ResNet18 network, which generates a conditional vector y from the frontal face image. t After the training data consisting of , t and y are obtained, the training process of the UNet noise fitting and removal module is as follows:
[0240] Input x to the UNet noise fitting and removal module t , t and y, the UNet noise fitting and removal module includes a UNet network, and the prediction value is calculated by the UNet network. This process can be expressed as a t , t and y and the noise fitting function ε related to all internal parameters θ = ε θ (x t ,t,y), represents the prediction of the UNet network for the t-th step of adding noise, also known as fitting. The loss value calculated based on the predicted value adjusts its internal parameters through back propagation. Specifically, the noise fitting function ε at the t-th step is θ (x t ,t,y) predicted noise and actual noise ε t Subtract and calculate the mean square error, which is the loss value L of the noise fitting, and pass the loss value L back to the UNet noise fitting and removal module for back propagation to adjust the internal parameters of the model. In other embodiments, the UNet noise fitting and removal module can also use a variational autoencoder or a transformer model.
[0241] In the loss calculation module, repeat the above steps to train the UNet noise fitting and removal module. Back propagation makes the loss value L of noise fitting continuously decrease. The default cycle is 30 times, and the number of cycles can be adjusted by yourself. When the loss value L is less than the set value, the model is considered to have converged, and the UNet network is considered to have learned the characteristics of noise well and can be used for subsequent operations. At this time, the training of the UNet noise fitting and removal module is completed.
[0242] After the UNet noise fitting and removal module training is completed, the operation process of the diffusion generation network is referenced Figure 3 As shown in the dotted line process, the following steps are included:
[0243] Each frontal face image in the frontal face image vector is input into the conditional generation module to generate the conditional vector corresponding to each frame, that is, the frontal face images pic1, pic2, ... pic n The corresponding conditional vector is y1,y2,…y n .
[0244] The conditional vector guides the UNet noise fitting and removal module to perform step-by-step denoising: The conditional vector y is input into the UNet noise fitting and removal module, and a Gaussian noise map is randomly generated, denoted as x 1000 , x 1000 ,1000 are input into the UNet noise fitting and removal module, and the trained fitting function ε = ε θ (x t ,t,y) predict the noise of step t, and repeat the denoising process, starting from step t=1000 from x t Calculate x t-1 Finally, we get x0, which is the predicted emotion label vector. The emotion label vector is a vector of length 7, corresponding to the seven emotions of happiness, anger, contempt, disgust, fear, sadness and surprise. The format is [happy, angry, contempt, disgust, fear, sadness, surprise].
[0245] The category generation module extracts the smile score in the predicted emotion label vector x0, denoted as grade, and the smile score calculated in the nth frame of the video frame is grade n . Extract the conditional vectors y1, y2, …, y corresponding to the 1st, 2nd, …, nth video frame images n The corresponding smile scores are grade1, grade2,…, grade n , and form a smile score vector K: [grade1,grade2,…,grade n ].
[0246] S4, extracting from the frontal face image vector the frontal face image corresponding to the maximum smile score in the smile score vector as the best smile image.
[0247] Specifically, first compare the frontal face images pic of different frames n Smile score grade n , the front face image pic n Arrange them from large to small according to the smile score, and then take the frontal face image with the largest smile score as the best smile image.
[0248] Further references Figure 8 As an implementation of the methods shown in the above figures, the present application provides an embodiment of a smile image recognition device based on a diffusion generation network. Figure 2 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0249] The embodiment of the present application provides a smiling image recognition device based on a diffusion generation network, comprising:
[0250] The video processing module 1 is configured to obtain a target video, decompose the target video by frames to obtain a video frame vector, and crop a face image from each video frame image in the video frame vector to obtain a face image vector;
[0251] The face image processing module 2 is configured to perform face alignment processing on each face image in the face image vector to obtain a frontal face image vector;
[0252] Prediction module 3 is configured to construct a diffusion generation network, the diffusion generation network includes a conditional generation module, a UNet noise fitting and removal module and a category generation module, the UNet noise fitting and removal module is trained to obtain a trained UNet noise fitting and removal module, the front face image vector is input into the conditional generation module to obtain a corresponding conditional vector, the conditional vector is input into the trained UNet noise fitting and removal module, an emotion label vector is predicted, the emotion label vector is input into the category generation module, and a smile score vector corresponding to the front face image vector is extracted;
[0253] The image extraction module 4 is configured to extract the front face image corresponding to the maximum smile score in the smile score vector from the front face image vector as the best smile image.
[0254] Reference below Fig. 9 , which shows an electronic device (eg Figure 1 A schematic diagram of the structure of a computer device 900 (a server or terminal device as shown). Fig. 9The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0255] like Fig. 9 As shown, the computer device 900 includes a central processing unit (CPU) 901 and a graphics processing unit (GPU) 902, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 903 or a program loaded from a storage part 909 to a random access memory (RAM) 904. In the RAM 904, various programs and data required for the operation of the device 900 are also stored. The CPU 901, GPU 902, ROM 903 and RAM 904 are connected to each other through a bus 905. An input / output (I / O) interface 906 is also connected to the bus 905.
[0256] The following components are connected to the I / O interface 906: an input section 907 including a keyboard, a mouse, etc.; an output section 908 including a display such as a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 909 including a hard disk, etc.; and a communication section 910 including a network interface card such as a LAN card, a modem, etc. The communication section 910 performs communication processing via a network such as the Internet. A drive 911 can also be connected to the I / O interface 906 as needed. A removable medium 912, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 911 as needed, so that a computer program read therefrom is installed into the storage section 909 as needed.
[0257] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication part 910, and / or installed from a removable medium 912. When the computer program is executed by a central processing unit (CPU) 901 and a graphics processing unit (GPU) 902, the above-mentioned functions defined in the method of the present application are executed.
[0258] It should be noted that the computer-readable medium described in the present application may be a computer-readable signal medium or a computer-readable medium or any combination of the above two. The computer-readable medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared or semiconductor device, device or component, or any combination of the above. More specific examples of computer-readable media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution device, device or device. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium may also be any computer-readable medium other than a computer-readable medium that can send, propagate or transmit a program for use by or in conjunction with an instruction execution device, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0259] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0260] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the devices, methods and computer program products according to various embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based device that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0261] The modules involved in the embodiments described in this application may be implemented by software or hardware, and the modules described may also be set in a processor.
[0262] As another aspect, the present application further provides a computer-readable medium, which may be included in the electronic device described in the above embodiment; or may exist independently without being assembled into the electronic device. The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device: obtains a target video, decomposes the target video by frame, obtains a video frame vector, crops a face image from each video frame image in the video frame vector, and obtains a face image vector; performs face alignment processing on each face image in the face image vector to obtain a front face image vector; constructs a diffusion generation network, the diffusion generation network includes a conditional generation module, a UNet noise fitting and removal module, and a category generation module, trains the UNet noise fitting and removal module to obtain a trained UNet noise fitting and removal module, inputs the front face image vector into the conditional generation module to obtain a corresponding conditional vector, inputs the conditional vector into the trained UNet noise fitting and removal module, predicts an emotion label vector, inputs the emotion label vector into the category generation module, and extracts a smile score vector corresponding to the front face image vector; extracts the front face image corresponding to the maximum smile score in the smile score vector from the front face image vector as the best smile image.
[0263] The above description is only a preferred embodiment of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the present application is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above invention concept. For example, the above features are replaced with the technical features with similar functions disclosed in this application (but not limited to) by each other to form a technical solution.
Claims
1. A smile image recognition method based on a diffusion generation network, characterized in that: The following steps are involved: S1, obtaining a target video, decomposing the target video by frames to obtain a video frame vector, and cropping a face image from each video frame image in the video frame vector to obtain a face image vector; S2, performing face alignment processing on each face image in the face image vector to obtain a frontal face image vector; S3, constructing a diffusion generation network, the diffusion generation network comprising a condition generation module, a UNet noise fitting and removal module and a category generation module, training the UNet noise fitting and removal module to obtain a trained UNet noise fitting and removal module, inputting the front face image vector into the condition generation module to obtain a corresponding condition vector, inputting the condition vector into the trained UNet noise fitting and removal module, predicting an emotion label vector, inputting the emotion label vector into the category generation module, and extracting a smile score vector corresponding to the front face image vector; S4, extracting from the frontal face image vector the frontal face image corresponding to the maximum smile score in the smile score vector as the best smile image.
2. The smile image recognition method based on diffusion generative network according to claim 1 is characterized in that: The step S1 in which a face image is cropped from each video frame image in the video frame vector to obtain a face image vector specifically includes: Each video frame image in the video frame vector is input into a face region segmentation model to obtain a face region in each video frame image; Adjusting the size of the face region in each video frame image to the same size to obtain a face image; The face image vector is constructed according to the face image corresponding to each video frame image in the video frame vector.
3. The smile image recognition method based on diffusion generation network according to claim 1 is characterized in that: The step S2 specifically includes: S21, inputting each face image in the face image vector into a face key point recognition model to extract key points, thereby obtaining a key point vector; S22, calculating the face tilt angle corresponding to each face image in the face image vector by using the key point vector, and rotating each face image in the face image vector according to the face tilt angle to obtain a frontal face image; S23, constructing a frontal face image vector Z according to the frontal face image corresponding to each face image in the face image vector: [pic1, pic2, ..., pic n ], where pic n Indicates the frontal face image corresponding to the face image in the nth video frame.
4. The smile image recognition method based on diffusion generation network according to claim 3 is characterized in that: The step S21 specifically includes: Each face image in the face image vector is input into the face key point recognition model to identify the left eye position P l , right eye position P r And the philtrum position H, and record the left eye position P l The corresponding horizontal component P lx and the vertical component P ly , denoted as P l (P lx , P ly ), right eye position P r The corresponding horizontal component P rx and the vertical component P ry , denoted as P r (P rx , P ry ), and the horizontal component P corresponding to the philtrum position H rx and the vertical component P ry , denoted as H(H x , H y ), and obtain the key point coordinates G(P l ,P r ,H); The key point vector G is constructed according to the key point coordinates corresponding to each face image in the face image vector: [G1, G2, ..., G n ], G n Indicates the coordinates of the key points corresponding to the face image in the nth video frame.
5. The smile image recognition method based on diffusion generation network according to claim 4 is characterized in that: The step S22 specifically includes: The binocular line vector Co is calculated according to the key point coordinates corresponding to each face image in the face image vector: Co=(P lx -P rx ,P ly -P ry ); Calculate the angle between the eye-line vector Co and the horizontal vector (1,0) to obtain the face tilt angle; Each face image in the face image vector is reversely rotated pixel by pixel according to the face tilt angle to perform face alignment so that the aligned face midline is parallel to the longitudinal axis of the face image to obtain a frontal face image.
6. The smile image recognition method based on diffusion generation network according to claim 1 is characterized in that: The UNet noise fitting and removal module includes a UNet network and an output list. The UNet network includes an input layer, a contraction path, a connection layer, an expansion path and an output layer connected in sequence. The input layer is used to receive the conditional vector, the number of steps or the emotion label vector after adding noise. The contraction path includes three contraction layers connected in series in sequence. The expansion path includes four expansion layers connected in series in sequence. The output list is used to store or extract feature maps generated during the UNet network calculation process.
7. The smile image recognition method based on diffusion generation network according to claim 1 is characterized in that: The training process of the UNet noise fitting and removal module in step S3 specifically includes: Obtain training data consisting of an initial frontal face image and an initial emotion label vector, add random noise that matches the dimension of the vector to the initial emotion label vector, and repeat the addition for a total of m steps, where the random noise added in the tth step is ε t , obeys the normal distribution N(0,1), from x t-1 to x t The noise addition calculation process is as follows: Among them, x t-1 is the emotion label vector obtained after adding random noise in step t-1, x t is the emotion label vector obtained after adding random noise in step t, is the mean of the normal distribution, β t I is the variance of the normal distribution, β t is a hyperparameter, I is the identity matrix; After adding noise cyclically, the emotion label vector group X=[x1,x2,…,x t ]; Inputting the initial frontal face image into the condition generation module to obtain a corresponding condition vector y; x t , t and y are input into the UNet noise fitting and removal module, and the noise added in the tth step is predicted by the noise fitting function to obtain the predicted value ε θ (x t ,t,y), where θ is a parameter related to its own internal structure; According to the predicted value ε θ (x t ,t,y) and the actual noise ε t Noise fitting uses the following loss function to calculate the loss value L: Where E represents the mean square error of the predicted value; Back propagation adjusts the internal parameters of the model and obtains the trained ε θ (x t ,t,y).
8. The smile image recognition method based on diffusion generation network according to claim 7 is characterized in that: In step S3, the conditional vector is input into the trained UNet noise fitting and removal module to predict the emotion label vector, which specifically includes: The conditional vector is input into the trained UNet noise fitting and removal module, and a Gaussian noise map is randomly generated, denoted as x m ; The x m , m inputs the trained UNet noise fitting and removal module, and passes the trained ε θ (x t ,t,y) predict the noise of step t, and repeat the denoising process continuously, starting from step t=m from x t Calculate x t-1 , the specific calculation formula is as follows: α t =1-β t ; Where, i = 1, 2, 3, …, t; Finally, the emotion label vector A corresponding to the target video is predicted.
9. The smile image recognition method based on diffusion generative network according to claim 1 is characterized in that: In step S3, the emotion label vector is input into a category generation module to extract a smile score vector corresponding to the frontal face image vector, specifically including: The score of each emotion in the emotion label vector is calculated according to the following formula: Among them, size(A) is the size of the emotion label vector A, that is, the product of the number of rows and columns, k is the kth emotion, a mn is the element in the mth row and nth column of the emotion label vector A, where m refers to the mth row and n refers to the nth column; Sort the scores of each emotion from large to small, extract the first score as the smile score, and record the smile score obtained from the nth frame image of the target video as grade n , and get the smile score vector grade1, grade2,…, grade n .
10. A smile image recognition device based on a diffusion generation network, characterized in that: include: The video processing module is configured to obtain a target video, decompose the target video by frames to obtain a video frame vector, and crop a face image from each video frame image in the video frame vector to obtain a face image vector; A face image processing module is configured to perform face alignment processing on each face image in the face image vector to obtain a frontal face image vector; A prediction module is configured to construct a diffusion generation network, wherein the diffusion generation network includes a condition generation module, a UNet noise fitting and removal module, and a category generation module, the UNet noise fitting and removal module is trained to obtain a trained UNet noise fitting and removal module, the front face image vector is input into the condition generation module to obtain a corresponding condition vector, the condition vector is input into the trained UNet noise fitting and removal module, an emotion label vector is predicted, the emotion label vector is input into the category generation module, and a smile score vector corresponding to the front face image vector is extracted; The image extraction module is configured to extract the front face image corresponding to the maximum smile score in the smile score vector from the front face image vector as the best smile image.
11. An electronic device, comprising: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 9.
12. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 9 is implemented.
Citation Information
Cited By
Film and television role face age reduction remodeling method and system based on deep learning
CN120450997A
