Driver drowsiness judgment method combining perspective correction and improved vivit
The FGR-ViViT model is used to perform 3D localization and frontal posture correction of facial feature points of the driver, and to construct line image sequences of the eyes, eyebrows and mouth. By combining fine-grained classification and improved loss function, the problems of viewpoint and illumination effects in the existing technology are solved, and the accuracy and stability of driver fatigue detection are improved.
Patent Information
- Application Number
- CN202311274565.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-28
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2043-09-28
AI Technical Summary
Existing technologies for driver fatigue detection have high requirements for camera placement and driver head angle, and are easily affected by glasses and lighting conditions, resulting in unsatisfactory detection accuracy and stability.
The FGR-ViViT model is used to construct a sequence of line images of the eyes, eyebrows and mouth by locating three-dimensional facial feature points and performing frontal pose correction. Combined with fine-grained classification and an improved loss function, the influence of factors such as viewing angle and lighting is reduced.
It reduces reliance on camera placement and driver head angle, improves detection accuracy and stability, and has a wider range of applications, including healthcare, factory assembly lines, hazardous operations, and security patrols.
Smart Images

Figure CN117351468B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of facial image recognition technology, and in particular relates to a method for judging driver drowsiness by combining perspective correction and improvement of ViViT. Background Technology
[0002] Fatigue is a biologically dangerous behavior, typically referring to the accumulation of sleep deprivation, prolonged wakefulness, and disruption of the circadian rhythm. Persistent fatigue can lead to sleep deprivation. Driver fatigue warning and detection systems will reduce the probability of accidents, and fatigue detection has become an important part of automotive safety research.
[0003] Currently, machine vision-based detection can categorize behavioral carriers into two types: images and videos. The mainstream idea of the first type is to directly classify the current behavioral state by capturing the driver's current behavior. Phan et al. analyzed the fatigue state of people in images in two ways: first, by calculating the EAR (eye aspect ratio) and MAR (mouth aspect ratio) of the driver's face in each video frame; second, by using MobileNet-V2 and ResNet-50V2 models to classify the captured images. However, fatigue is a continuous process, and images often only provide static, instantaneous information, failing to capture the driver's dynamic changes. Furthermore, people's external manifestations in a fatigued state may vary from person to person, potentially leading to misjudgments. The mainstream idea of the second type is to analyze the driver's video behavior over a given period, using image frame sequences to determine the driver's fatigue state. Image sequences can capture dynamic changes in the driver's state, including minute instantaneous changes, which helps to more accurately identify fatigue states. By analyzing video or image sequences, multiple features can be considered simultaneously, thereby improving the accuracy of fatigue state assessment. Chandiwala et al. quantified sleepiness by calculating the change sequences of EAR and MAR values. The calculation is relatively simple, requiring only the location of key points of the eyes and mouth, and applying a specific formula to determine the result through a threshold, thus providing timely monitoring of fatigue status. However, the shape and characteristics of the eyes and mouth differ among individuals, which may lead to different degrees of change in EAR and MAR values in different people under the same fatigue state. Therefore, it is difficult to determine a universal threshold, resulting in a relatively high probability of misjudgment. Experiments show that this type of method has good performance.
[0004] In 2020, researchers introduced the Vision Transformer (ViT) model. Many subsequent models based on ViT have achieved state-of-the-art performance in various image recognition tasks, becoming an effective alternative to CNNs. ViViT adds spatial and temporal processing to ViT, exploring its application in video classification. It extracts spatiotemporal markers from input videos using the spatiotemporal features of frame sequences, decomposing the spatial and temporal dimensions of the input and encoding them through a series of Transformer layers. Arnab et al. conducted a thorough ablation study of ViViT and achieved state-of-the-art results on multiple video classification benchmarks, including Kinetics 400 and 600, Epic Kitchens, Something-Something v2, and Moments in Time, outperforming previous methods based on deep 3D convolutional networks.
[0005] While the ViViT model currently offers relatively good recognition of driver fatigue, in practice, most cameras used to collect driver head information are positioned at a fixed viewpoint, and their datasets consist of driver facial information from that specific viewpoint. This means that deep learning-based fatigue detection models either achieve their best performance only at that specific viewpoint, limiting camera placement and driver head posture, or they require training with data from various viewpoints to achieve optimal performance. This means the training set must include various driver head postures and angles, but due to individual differences and personal habits, this approach requires massive amounts of training data to achieve satisfactory results. Furthermore, factors such as eyeglasses and lighting conditions can also affect the model's fatigue recognition. In summary, current technologies for driver fatigue detection are highly demanding in terms of camera placement and driver head angle, and their detection accuracy is affected by factors such as eyeglasses and lighting conditions, resulting in unsatisfactory accuracy and stability in practical applications.
[0006] Therefore, how to reduce the dependence on camera placement and driver head angle when detecting driver fatigue, while minimizing the impact of factors such as glasses obstruction and lighting, and ensuring the accuracy and stability of detection in practical applications, has become an urgent problem to be solved. Summary of the Invention
[0007] To address the shortcomings of the existing technologies, this invention provides a driver drowsiness detection method that combines perspective correction and improved ViViT. This method reduces dependence on camera placement and driver head angle, while also minimizing the impact of factors such as eyeglass obstruction and lighting conditions, ensuring accuracy and stability in practical applications.
[0008] To solve the above-mentioned technical problems, the present invention adopts the following technical solution:
[0009] Combining perspective correction and improvements to ViViT's driver drowsiness detection method, the following steps are included:
[0010] S1. Construct an FGR-ViViT model based on the ViViT model to perform fatigue recognition based on image sequences of eye, eyebrow and mouth shapes from a frontal view.
[0011] S2. Obtain the driver's face image sequence and perform preset preprocessing on each image to obtain the training image sequence;
[0012] S3. Train the FGR-ViViT model using the training image sequence;
[0013] S4. Collect the driver's real-time face image sequence and perform the preprocessing in S2. After obtaining the real-time image sequence, use the trained FGR-ViViT model to identify driver fatigue.
[0014] In S2, the preprocessing includes:
[0015] S21. Obtain feature points on the face image, perform 3D localization and frontal pose correction, and obtain a mesh of face feature points from the frontal view.
[0016] S22. Project the corrected feature points onto the surface mesh and extract the shapes of the eyes, eyebrows, and mouth. Construct line images of the eyes, eyebrows, and mouth based on the corrected coordinates. Use the resulting eye, eyebrow, and mouth line image sequence as the training image sequence.
[0017] Compared with the prior art, the present invention has the following beneficial effects:
[0018] 1. Using this method, after acquiring the driver's facial image sequence, it is preprocessed. This includes two aspects: first, locating the three-dimensional facial feature points and correcting them to a frontal view; second, using a sequence of image frames showing the eyebrow and mouth lines of the frontal face as the training set for the FGR-ViViT model. The FGR-ViViT model is then trained. In practical use, after acquiring real-time driver facial image sequences and performing the above preprocessing, driver fatigue is identified using the FGR-ViViT model.
[0019] Because the preprocessing locates and corrects 3D facial feature points to a frontal view, the ViViT model's dependence on different viewpoint datasets is reduced in multi-view scenarios. This allows for flexible camera placement and lowers the requirements on driver head posture, enabling drivers to drive according to their personal habits. Furthermore, this setup allows for model training with a smaller amount of data. On the other hand, this method only extracts the eyebrow and mouth lines relevant to fatigue, reducing interference from other objects in the image. This removes redundant information from the data, emphasizing only the state of the eyes and mouth, minimizing the impact of head posture, glasses occlusion, and lighting conditions. This strengthens the feature information learned by the model, ensuring detection accuracy and stability in practical applications.
[0020] In summary, compared with existing technologies, this method reduces the dependence on camera placement and driver head angle when detecting driver fatigue, while also minimizing the impact of factors such as eyeglass obstruction and lighting conditions, thus ensuring the accuracy and stability of detection in practical applications.
[0021] 2. Because this method uses contour maps that eliminate redundant information and offers a flexible detection perspective, the detector can be placed anywhere that detects most faces, and it can detect the fatigue state of different individuals during various actions. Therefore, this method can also be extended to other industries, such as healthcare, factory assembly lines, hazardous operations, and security patrols, reducing the occurrence of safety accidents. Compared with existing technologies, this method has a wider range of applications.
[0022] Preferably, in S21, the three-dimensional positioning and frontal posture correction includes:
[0023] S211, use a preset facial feature point detection model to detect feature points of a facial image and perform three-dimensional localization;
[0024] S212, Select the feature point where the chin tip is located as the new origin of the coordinate system, and translate the original origin of the coordinate system to the new origin; the original coordinate system is a three-dimensional coordinate system;
[0025] S213, rotate the face to obtain a mesh of facial feature points from a frontal view.
[0026] This setup allows for the association and processing of key feature points with the original coordinate system, enabling stable frontal pose correction of facial images. Choosing the feature point where the chin tip is located as the new origin of the coordinate system not only ensures accurate recognition under various head poses but also guarantees that the corrected face does not exceed the image display range.
[0027] Preferably, in S211, the preset face feature point detection model is MediaPipe Face Mesh, which detects 468 key feature points on the face image and performs three-dimensional localization.
[0028] MediaPipe Face Mesh is a mature facial geometry solution that can estimate 468 3D facial landmarks in real time, even on mobile devices (dlib can only detect 68 points). It uses machine learning (ML) to infer 3D surface geometry, requiring only a single camera input and no dedicated depth sensor. This setup ensures comprehensive and accurate facial landmark detection while reducing hardware requirements.
[0029] Preferably, in S212, when translating the origin of the original coordinate system to the new origin, the translation vector is as follows:
[0030] ;
[0031] in, , , These are the coordinates of the feature point where the chin tip is located in the original coordinate system.
[0032] This setting allows for accurate and rapid face translation.
[0033] Preferably, in S212, after translating the origin of the original coordinate system to the new origin, a new coordinate system is established according to the left-handed screw rule. The positive axis is horizontal to the right. The positive axis points vertically downwards. The positive axis points vertically outward.
[0034] This setting provides a reference coordinate system for subsequent face rotation, thereby ensuring the effectiveness of subsequent frontal pose correction.
[0035] Preferably, in S213, when rotating the face, the inverse matrix of the face pose matrix is used. As a rotation matrix; the feature points of the face are rotated from the original coordinate system using the following formula. Convert coordinates to the new coordinate system :
[0036] ;
[0037] In the formula, It is a 3x1 translation vector. It is a 3x3 identity matrix; It is a 3x3 rotation matrix.
[0038] This setup, using the new coordinate system and the original coordinate system as the link for rotation, ensures the effectiveness and accuracy of the rotation. Furthermore, since the new coordinate system uses the chin tip as the origin, and the chin tip is located at the bottom of the face, the rotation is simpler and more efficient compared to using feature points such as the tip of the nose.
[0039] Preferably, in S213, the inverse matrix of the attitude matrix The generation process includes:
[0040] Feature points at the forehead vertices detected by Mediapipe Face Mesh are selected, and the vector obtained by connecting them to the origin of a new coordinate system is normalized and used as the face pose. vector Take the connection vector from the center point of the left eye to the center point of the right eye in the image and normalize it, as the face pose. vector ;
[0041] After that, and The normal vector of the face pose is obtained by cross product of the left-hand spiral rule. And generate the attitude matrix. ; and then the inverse matrix of the attitude matrix is obtained. .
[0042] In this way, the pose matrix is constructed using feature points at the forehead apex and chin tip (new coordinate origin), as well as feature points from the center of the left eye to the center of the right eye. Since the above feature points are all very obvious key feature points, the pose matrix can be obtained quickly, thereby ensuring the efficiency and accuracy of frontal pose correction.
[0043] Preferably, in S1, the process of constructing the FGR-ViViT model includes: adding a component selection module to the TemporalTransformer Encoder of the ViViT model;
[0044] The Temporal Transformer Encoder includes L Temporal Transformer Layers, and the component selection module is added before the last Temporal Transformer Layer; the processing of the component selection module includes:
[0045] First, matrix multiplication is recursively applied to the raw attention weights in all layers preceding the last Temporal Transformer Layer, thus combining the attention weights of each layer: ;in, Refers to the first layer Each self-attention head weight, where C is the number of self-attention heads in the FGR-ViViT model;
[0046] Next, select middle The maximum value of different attention heads The index is used to extract The corresponding token in; the These are the hidden features input before the last Temporal Transformer Layer;
[0047] Then, the selected token and the category token are concatenated to obtain a new input sequence. ;Convert the new sequence to Input to the last Temporal Transformer Layer.
[0048] For fatigue detection, facial changes in drivers, especially eye changes, are extremely subtle, even difficult for humans to discern. These localized changes often play a crucial role in distinguishing driving states. Because the objects being detected may only exhibit minute visual differences, a fine-grained classification algorithm is introduced to improve detection accuracy and sensitivity. Fine-grained classification aims to distinguish categories that are visually and semantically very similar. For example, a person slightly closing their eyes or blinking frequently might indicate fatigue, but these features are very similar to facial expressions in a normal state. Therefore, by performing fine-grained classification, these subtle differences can be distinguished more accurately, which is particularly beneficial for content analysis.
[0049] Most fine-grained classification tasks deal with images, which are unsuitable for time-varying state determination. Therefore, this invention adds a part selection module to the ViViT model. Furthermore, since this method focuses more on subtle differences in images over time, a part selection module is added to the Temporal Transformer Encoder of FGR-ViViT. This setup enables fine-grained classification of image sequences, more efficiently analyzing and extracting differential features in the time dimension while removing redundant information. The model pays more attention to subtle changes in the image sequence, thus better capturing dynamic features and improving the accuracy and robustness of the classification task.
[0050] Preferably, the hidden features input before the last Temporal Transformer Layer for:
[0051] ;
[0052] in, This represents the learnable category token output by the (L-1)th Temporal Transformer Layer; This represents the N feature vectors output by the (L-1)th Temporal Transformer Layer;
[0053] The new input sequence is obtained by concatenation. for:
[0054] ;
[0055] in, Represents the maximum value of different attention heads. The token selected by the index;
[0056] No. layer Individual attention head weights for:
[0057] ;
[0058] ;
[0059] in, Indicates the first The first layer The weight of each self-attention head;
[0060] Indicates the first The weights of learnable category tokens in each attention head of the layer. Indicates the first The weights of N feature vectors in each attention head of the layer.
[0061] Preferably, in S1, when constructing the FGR-ViViT model, an improved loss function is also introduced; the improved loss function is:
[0062] ;
[0063] in, ;
[0064] ;
[0065] In the formula, The cross-entropy loss is the difference between the predicted and true labels of a sample. These are the weighting coefficients; This represents the average KL divergence after two dropouts; Represent two distributions and KL divergence between them; and For the same sample, pass the same model twice with Dropout. The model then predicted two distributions, with the training data being... ;
[0066] To compare loss functions, Indicates batch size, and Indicates the process Normalized eigenvectors Represents cosine similarity. This is a preset constant; Indicates the true label, and These represent the actual labels for different categories.
[0067] In ViViT models, the model typically has many parameters, making it prone to overfitting when training samples are insufficient. Dropout allows certain neurons to stop working with a certain probability during forward propagation, reducing the complex co-adaptation relationships between neurons. This effectively reduces the model's dependence on local features and helps prevent overfitting.
[0068] In this method, the cross-entropy loss function in the traditional ViViT model is replaced with a new loss function that combines two dropouts and an improved contrastive loss function. This prevents the model from overfitting and also helps the model learn more discriminative feature representations. Attached Figure Description
[0069] To make the objectives, technical solutions, and advantages of the invention clearer, the invention will now be described in further detail with reference to the accompanying drawings, wherein:
[0070] Figure 1 This is a flowchart of the method;
[0071] Figure 2 This is a schematic diagram illustrating the three-dimensional coordinate localization of a face in the MediaPipe Face Mesh embodiment under multiple viewing angles.
[0072] Figure 3 This is a schematic diagram of the coordinate system and pose vector of the human face in the embodiment;
[0073] Figure 4 is a schematic diagram of the key points before and after face posture correction in the embodiment;
[0074] Figure 5This is a schematic diagram of the face correction results under various perspectives or postures in the embodiment;
[0075] Figure 6 This is a schematic diagram of the FGR-ViViT model structure;
[0076] Figure 7 This is a diagram illustrating the overall architecture of the loss function of FGR-ViViT in the embodiment;
[0077] Figure 8 This is a schematic diagram of some samples from the YawDD and DROZY datasets used in the experimental analysis of the example.
[0078] Figure 9 This is a schematic diagram illustrating the changes in F1 score and loss during training of the YawDD dataset in the experimental analysis of the example.
[0079] Figure 10 This is a schematic diagram illustrating the changes in F1 score and loss during training of the DROZY dataset in the experimental analysis of the example.
[0080] Figure 11 This is a schematic diagram of the uncorrected portion of the face line graphs in the YawDD dataset used in the experimental analysis of this example. Detailed Implementation
[0081] The following detailed explanation illustrates the specific implementation methods:
[0082] Example:
[0083] like Figure 1 As shown, this embodiment discloses a method for determining driver drowsiness that combines perspective correction and improved ViViT, including the following steps:
[0084] S1. Construct an FGR-ViViT model based on the ViViT model to perform fatigue recognition based on image sequences of eye, eyebrow, and mouth shapes from a frontal view.
[0085] S2. Obtain the driver's face image sequence and perform preset preprocessing on each image to obtain the training image sequence.
[0086] The preprocessing includes:
[0087] S21. Obtain feature points on the face image, and perform 3D localization and frontal pose correction to obtain a mesh of face feature points from a frontal view. The 3D localization and frontal pose correction include:
[0088] S211, Detect feature points of the face image using a preset face feature point detection model and perform 3D localization. In specific implementation, the preset face feature point detection model is MediaPipe Face Mesh, which detects 468 key feature points on the face image and performs 3D localization.
[0089] In the field of fatigue detection, parameters that need to be considered are the driver's eye and mouth features, which have been proven to be directly related to the driver's state. To eliminate geometrical spatial changes caused by posture variations, facial feature points need to be corrected. MediaPipe Face Mesh is a detector that can estimate 468 3D facial coordinate points in real time, providing a reliable and accurate facial coordinate localization solution for drivers with large head angles in multi-view scenarios, with localization results such as... Figure 2 As shown.
[0090] S212, Select the feature point where the chin tip is located as the new origin of the coordinate system, and translate the original origin of the coordinate system to the new origin; the original coordinate system is a three-dimensional coordinate system.
[0091] When translating the origin of the original coordinate system to the new origin, the translation vector is as follows:
[0092] ;
[0093] in, , , These are the coordinates of the feature point where the chin tip is located in the original coordinate system.
[0094] After translating the origin of the original coordinate system to the new origin, a new coordinate system is established using the left-handed screw rule. The positive axis is horizontal to the right. The positive axis points vertically downwards. The positive axis points vertically outward.
[0095] The head pose correction process is a rigid body transformation, which does not cause facial deformation. Only rotation and translation are needed to correct the face from other viewpoints or poses to a frontal view or pose and display it in the image. To ensure the corrected face does not exceed the image display area, feature point 152, where the chin tip is located, is selected as the new origin of the coordinate system. The original coordinate system origin is translated to the new origin before the face is rotated.
[0096] S213, rotate the face to obtain a mesh of facial feature points from a frontal view.
[0097] When rotating a face, the inverse of the face pose matrix is used. As a rotation matrix; the feature points of the face are rotated from the original coordinate system using the following formula. Convert coordinates to the new coordinate system :
[0098] ;
[0099] In the formula, It is a 3x1 translation vector. It is a 3x3 identity matrix; It is a 3x3 rotation matrix.
[0100] Wherein, the inverse matrix of the attitude matrix The generation process includes:
[0101] Feature points at the forehead vertices detected by Mediapipe Face Mesh are selected, and the vector obtained by connecting them to the origin of a new coordinate system is normalized and used as the face pose. vector Take the connection vector from the center point of the left eye to the center point of the right eye in the image and normalize it, as the face pose. vector ;
[0102] After that, and The normal vector of the face pose is obtained by cross product of the left-hand spiral rule. And generate the attitude matrix. ; and then the inverse matrix of the attitude matrix is obtained. .
[0103] Establish a new coordinate system according to the left-handed spiral rule, as follows: Figure 3 As shown, among them The positive axis is horizontal to the right. The positive axis points vertically downwards. The positive axis points vertically outward.
[0104] After facial landmark correction is completed, the eyes and mouth in the image are not affected by head posture, but only by the degree of opening of the eyes and mouth. The comparison before and after correction is shown in Figure 4, where (a) is the captured face image; (b) is the 3D coordinate mesh detected in the face image; (c) is the coordinate of the mesh in the original coordinate system; and (d) is the coordinate of the mesh after correcting it to a frontal view in the new coordinate system.
[0105] S22. Project the corrected feature points onto the surface mesh and extract the shapes of the eyes, eyebrows, and mouth. Construct line images of the eyes, eyebrows, and mouth based on the corrected coordinates. Use the resulting eye, eyebrow, and mouth line image sequence as the training image sequence.
[0106] The corrected facial mesh is projected onto a central image, and the shapes of the eyes, eyebrows, and mouth are captured. The final facial correction effect is as follows: Figure 5 As shown.
[0107] Among them, the camera is directly in front: (a) female, at night, eyes and mouth slightly open, head tilted upward; (b) male, at night, eyes open, yawning, head tilted to the upper left.
[0108] The camera is located below the rearview mirror: (c) Male, daytime, speaking with eyes open, looking straight ahead; (d) Male, daytime, smiling with eyes closed, tilting his head downwards.
[0109] The camera is above the dashboard: (e) Female, daytime, speaking with eyes open and head tilted to the right; (f) Male, daytime, yawning with eyes slightly open and head tilted to the upper right.
[0110] S3. Train the FGR-ViViT model using the training image sequence.
[0111] S4. Collect real-time facial image sequences of the driver and perform the preprocessing in S2. After obtaining the real-time image sequence, use the trained FGR-ViViT model to identify driver fatigue.
[0112] In practice, the process of building the FGR-ViViT model includes: adding a component selection module to the TemporalTransformer Encoder of the ViViT model; and introducing an improved loss function.
[0113] FGR-ViViT Backbone Network
[0114] For fatigue detection, facial changes in drivers, especially eye changes, are extremely subtle, even difficult for humans to perceive. However, these localized changes often play a crucial role in distinguishing driving states. Because the objects being detected may only exhibit minute visual differences, this invention introduces a fine-grained classification algorithm to improve detection accuracy and sensitivity. Fine-grained classification aims to distinguish categories that are visually and semantically very similar. For example, a person slightly closing their eyes or blinking frequently may indicate fatigue, but these features are very similar to facial expressions in a normal state. Therefore, by performing fine-grained classification, these subtle differences can be distinguished more accurately, which is particularly beneficial for content analysis.
[0115] Most fine-grained classification objects are images, which cannot be applied to time-varying state judgments. This method adds a part selection module to the ViViT model, enabling fine-grained recognition of image sequences, allowing the model to focus more on subtle changes within the image sequence. Since this method focuses on subtle differences in images over time, a part selection module is added to the Temporal Transformer Encoder of FGR-ViViT. The overall architecture is as follows: Figure 6 As shown.
[0116] In FGR-ViViT, the input image sequence is fed into an Embed to tokens layer for spatiotemporal tube sampling to fuse temporal and spatial features, which are then linearly projected into a multidimensional space. Subsequently, a class token is inserted at the beginning of the token sequence for classification, and positional encodings are combined with the input sequence to obtain the positional information of each token. The Spatial Transformer Encoder models tokens with the same spatial index and outputs new class tokens. The output class tokens and frame-dimensional representation tokens are then concatenated and input into the Temporal Transformer Encoder.
[0117] The Temporal Transformer Encoder contains multiple Temporal Transformer Layers. Before being input to the last Temporal Transformer Layer, the feature sequence enters the part selection module. Assume the model has... Each self-attention head, the hidden features input to the last Temporal Transformer Layer are: middle, and Let represent the learnable category token and N feature vectors output by the (L-1)th TemporalTransformer Layer, respectively. The attention weights of the previous layers are shown in the following equation:
[0118] ;
[0119] ;
[0120] in, Refers to the first layer Each self-attention head weight, Indicates the first The first layer The weight of each self-attention head. Indicates the first The weights of the learnable category tokens of the layer. Indicates the first The weights of N feature vectors in each attention head of the layer.
[0121] Because the embedded tokens are not sufficiently identifiable, the original attention weights may not correspond to the importance of the input tokens. Therefore, matrix multiplication is recursively applied to the original attention weights in all layers, and the attention weights of each layer are combined as shown in the following formula.
[0122] ;
[0123] It captures the entire information from the Temporal Transformer Encoder input to deeper layers, relative to the raw attention weights of a single layer. It is more advantageous to select areas that are easily identifiable. middle The maximum value of different attention heads Indexes, these indexes are used to extract The corresponding token in the database. The selected token and category token are concatenated and input into the last Temporal Transformer Layer. The new input sequence is shown in the following formula.
[0124] ;
[0125] in, Represents the maximum value of different attention heads. The token selected by the index;
[0126] Replacing the original input sequence with the maximum response token selected through attention weights not only preserves global information but also causes the final Transformer layer to discard tokens with smaller weights, focusing on subtle differences in features over time. Finally, the category token is extracted from the output of the Temporal Transformer Encoder and passed through an MLP Head to obtain the final classification result.
[0127] Improved loss function
[0128] The ViViT model uses the cross-entropy loss function, assuming the training data is... The model is The cross-entropy loss between the predicted label and the true label for each sample is shown in the following formula.
[0129] ;
[0130] However, in ViViT models, the number of parameters is generally large, making overfitting prone to occur when training samples are insufficient. Dropout can cause certain neurons to stop working with a certain probability during forward propagation, reducing the complex co-adaptation relationships between neurons and effectively reducing the model's dependence on local features, thus helping to prevent overfitting. This method introduces R-Drop, which uses Dropout twice to... Performing two forward passes in the model—that is, passing the same sample through the same model with Dropout twice—can yield two distributions with significantly different model predictions. and Then use KL divergence The model predictions are regularized to make them as consistent as possible, and the two are weighted to obtain the R-Drop loss function, as shown in the following formula.
[0131] ;
[0132] in, These are weighting coefficients; This represents the average KL divergence after two dropouts; Represent two distributions and KL divergence between them;
[0133] Meanwhile, since the features of different categories are very similar in the fine-grained domain, this method introduces a contrastive loss function. By integrating with the R-Drop function, the model learns discriminative feature representations by maximizing the similarity of classification tokens corresponding to the same category and minimizing the similarity of classification tokens corresponding to different categories, thereby extracting the essential features of the data. To reduce the impact of simple negative samples on the loss, A constant was introduced. To regulate negative samples that contribute to the loss, i.e., only those with a similarity greater than [a certain value] are considered negative samples. Only negative samples contribute to the loss, as shown in the following formula.
[0134] ;
[0135] in, Indicates batch size, and Indicates the process Normalized eigenvectors Indicates cosine similarity; Indicates the true label, and These represent the actual labels for different categories.
[0136] Finally, the loss function of FGR-ViViT is derived from... Comparative loss function The sum is composed as shown in the following formula:
[0137] .
[0138] The improved loss function architecture is as follows: Figure 7 As shown.
[0139] To more fully illustrate the effectiveness of this method, the following experimental analysis was conducted.
[0140] Experimental Analysis
[0141] 1. Dataset
[0142] Tests were conducted on the YawDD video dataset and the DROZY video dataset, respectively.
[0143] The YawDD video dataset. The scenes were filmed inside a car in a bright environment, with the in-car cameras positioned on the dashboard and below the rearview mirror, providing two perspectives. Volunteers performed various actions based on instructions, such as normal driving, speaking, and yawning. Some volunteers had their faces obscured by glasses or sunglasses. The dataset contains 351 videos at 30 FPS and a resolution of 640x480. This dataset is used to evaluate the fatigue classification performance of a model based on mouth movements.
[0144] The DROZY video dataset, also known as the "ULg Multimodal Sleepiness Database," is a database containing various types of sleepiness-related data (such as signals, videos, etc.). This dataset contains spectral video recordings (NIR) of 14 subjects, each of whom underwent up to three psychomotor alertness tests. All subjects were kept awake for 1 day, 5 hours, and 30 minutes. Before each test, subjects completed a questionnaire to determine their level of drowsiness. The dataset contains 36 videos at an FPS of 30 and a resolution of 512x424. This dataset was used to evaluate the performance of models classifying fatigue based on eyebrow, eye, and mouth states.
[0145] In the DROZY video dataset, since each video only simply labels the driver's overall fatigue level without specifying the specific fatigue-related actions, 3600 samples were extracted from the DROZY dataset to extract precise fatigue features for model training. The extracted DROZY dataset and all YawDD datasets were randomly divided into training and test sets in a 4:1 ratio using uniform random sampling, with no overlap between the two sets. Samples from both datasets are shown below. Figure 8 As shown.
[0146] 2 Evaluation Indicators
[0147] To comprehensively evaluate the proposed method, this paper uses three metrics: precision, recall, and F1 score, defined by formulas (1) to (3). Here, FN (false negative) refers to the number of fatigue states incorrectly identified as conscious states. False positive (FP) refers to the number of conscious states incorrectly identified as fatigue. True positive (TP) represents the number of correctly identified fatigue states.
[0148] Precision: The ratio of the number of fatigue samples correctly predicted to the number of samples predicted as fatigue.
[0149] (1)
[0150] Recall: The ratio of the number of correctly predicted fatigue samples to the actual number of fatigue samples.
[0151] (2)
[0152] F1 score: a weighted average of precision and recall.
[0153] (3)
[0154] Precision reflects the model's ability to distinguish between conscious and unconscious samples; higher precision indicates a stronger ability to distinguish between conscious and unconscious samples. Recall reflects the model's ability to identify fatigued samples; higher recall indicates a stronger ability to identify fatigued samples. The F1-score is the harmonic mean of the two; a higher F1-score indicates stronger model robustness.
[0155] 3. Model Training
[0156] Because the Transformer does not have the same inductive bias as CNNs, ViViT only demonstrates effectiveness on large-scale datasets. Considering the limited availability of labeled fatigue classification video datasets and the difficulty of training a model from scratch, the experiments employed transfer learning, using a pre-trained ViT-B / 16x2 model trained on the ImageNet21K dataset to initialize the parameters of the ViViT model, allowing for fine-tuning on a relatively small dataset.
[0157] The DROZY dataset includes human eyes for detection. Since closing one's eyes while driving is a potentially serious action requiring timely warning, each sample contains 16 consecutive images with a learning rate of 0.01 and a batch size of 16. In contrast, the YawDD dataset only detects mouth movements. Too few images per sample would waste computational resources, so each sample contains 40 consecutive images with a learning rate of 0.03 and a batch size of 8.
[0158] The facial contour images have had most of the redundant information removed, so the image size can be reduced to 48x48. A 13x cross-validation factor was selected for all samples. The experimental environment is shown in Table 1.
[0159] Table 1 Experimental Environment Configuration Table
[0160]
[0161] 4. Model Training Results and Analysis
[0162] The YawDD video dataset primarily distinguishes yawning from other actions such as speaking and laughing. The F1 score and loss curves during training are shown below. Figure 9 As shown in the figure. The DROZY video dataset primarily distinguishes between awake and fatigued states, and the curves showing the changes in F1-score and loss are as follows. Figure 10 As shown.
[0163] To verify the effectiveness of the facial contour images and the corrected facial contour images, related ablation experiments were conducted, and the results are shown in Table 2. The facial image represents the original facial image directly extracted from the video; the uncorrected facial line image represents the extracted eyebrow, eye, and mouth line images without frontal correction; and the corrected facial line image represents the line image after correcting the aforementioned facial features to a frontal view.
[0164] Table 2. F1-score results of different input data in FGR-ViViT
[0165]
[0166] For samples in YawDD with multiple viewpoints, multiple head poses, and a large number of mouth state categories, and for DROZY samples with multiple head poses and a large number of eyebrow and mouth movement categories against a dark background, the experimental results of the corrected face line images are superior to those of the uncorrected face line images and the original face images. Especially for monochrome image sequences in DROZY, the performance of identifying fatigue states using only small 48x48 face images is poor, with an F1-score 10.4% lower than that of the corrected face line images. The detection performance of the uncorrected face line images varies depending on the pose. In the YawDD dataset, due to the large head angle of the person, the extracted facial feature lines are sometimes too distorted, such as... Figure 11 As shown, the detection results are actually 1.2% lower than the original face detection results. In the DROZY dataset, the uncorrected face line image, which emphasizes the changes in the eyes, eyebrows and mouth, with smaller subject poses, is 2.7% higher than the original face image.
[0167] The experimental results above show that, under small poses, line drawings of key facial features are more conducive to the extraction of fatigue features because they shield against interference from changes in facial brightness and texture, especially in small-sized samples. However, as the pose increases, changes in the size of facial features at different distances can severely interfere with classification, leading to a decline in performance. Reducing this interference through pose correction can restore performance.
[0168] To verify the effectiveness of FGR-ViViT, we conducted ablation experiments on corrected facial contour images. The F1-scores are shown in Table 3. Under the same parameters, ViViT represents the baseline model without any modifications, R-ViViT represents the model with an improved loss function, FG-ViViT represents the model with a part selection module, and FGR-ViViT represents the improved model presented in this paper, which incorporates a part selection module and an improved loss function.
[0169] Table 3. F1-score results of different models on the test set.
[0170]
[0171] The results show that the improved model outperforms both the baseline model and the model that only incorporates some modules.
[0172] 5. Comparative Experiment
[0173] Table 4 shows the comparison results of our proposed method with other methods on the corrected face line images of the YawDD and DROZY datasets. The results indicate that our proposed method significantly outperforms other methods in all performance metrics on the DROZY dataset. On the YawDD dataset, although JHPFA has a 2.3% higher precision than our proposed method, its recall is 3.4% lower than FGR-ViViT; similarly, CNN has a 2.2% higher recall than our proposed method, but its precision is 6.4% lower. In comparison, our proposed method achieves the best overall F1-score.
[0174] Table 4 Comparison results with recent related work
[0175]
[0176] This method analyzes the feasibility and complexity of current methods for studying driver fatigue and ultimately selects a computer vision detection method based on image sequences to achieve automatic classification of driver states. The proposed FGR-ViViT model primarily judges driver behavior based on the state changes of corrected eye, eyebrow, and mouth line image frame sequences. A fine-grained classification method for image sequences is designed, and a new loss function integrating two dropout techniques and an improved contrastive loss function is proposed. Experiments show that the proposed method outperforms other methods in the comprehensive evaluation index F1-score, demonstrating the effectiveness of face coordinate correction and the FGR-ViViT framework. Furthermore, this method, due to its flexible camera placement, can meet the needs of different application scenarios and has broad application prospects in multiple fields.
[0177] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit the technical solutions. Those skilled in the art should understand that any modifications or equivalent substitutions to the technical solutions of the present invention without departing from the spirit and scope of the present invention should be covered within the scope of the claims of the present invention.
Claims
1. A driver drowsiness detection method combining perspective correction and improved ViViT, characterized in that, Includes the following steps: S1. Construct an FGR-ViViT model based on the ViViT model to perform fatigue recognition based on image sequences of eye, eyebrow and mouth shapes from a frontal view. S2. Obtain the driver's face image sequence and perform preset preprocessing on each image to obtain the training image sequence; S3. Train the FGR-ViViT model using the training image sequence; S4. Collect the driver's real-time face image sequence and perform the preprocessing in S2. After obtaining the real-time image sequence, use the trained FGR-ViViT model to identify driver fatigue. In S2, the preprocessing includes: S21. Obtain feature points on the face image, perform 3D localization and frontal pose correction, and obtain a mesh of face feature points from the frontal view. S22. Project the corrected feature points onto the surface mesh and extract the shapes of the eyes, eyebrows, and mouth. Construct line images of the eyes, eyebrows, and mouth based on the corrected coordinates. Use the resulting eye, eyebrow, and mouth line image sequence as the training image sequence. In S1, the process of building the FGR-ViViT model includes adding a component selection module to the Temporal TransformerEncoder of the ViViT model; The Temporal Transformer Encoder includes L Temporal Transformer Layers, and the component selection module is added before the last Temporal Transformer Layer; the processing of the component selection module includes: First, matrix multiplication is recursively applied to the raw attention weights in all layers preceding the last Temporal Transformer Layer, thus combining the attention weights of each layer: ;in, Refers to the first layer Each self-attention head weight, where C is the number of self-attention heads in the FGR-ViViT model; Next, select middle The maximum value of different attention heads The index is used to extract The corresponding token in; the These are the hidden features input before the last Temporal Transformer Layer; Then, the selected token and the category token are concatenated to obtain a new input sequence. ;Convert the new sequence to Input to the last Temporal Transformer Layer.
2. The driver drowsiness detection method combining perspective correction and improved ViViT as described in claim 1, characterized in that: In S21, the three-dimensional positioning and frontal posture correction include: S211, use a preset facial feature point detection model to detect feature points of a facial image and perform three-dimensional localization; S212, Select the feature point where the chin tip is located as the new origin of the coordinate system, and translate the original origin of the coordinate system to the new origin; the original coordinate system is a three-dimensional coordinate system; S213, rotate the face to obtain a mesh of facial feature points from a frontal view.
3. The driver drowsiness detection method combining perspective correction and improved ViViT as described in claim 2, characterized in that: In S211, the preset facial feature point detection model is MediaPipe Face Mesh. MediaPipe Face Mesh detects 468 key feature points on the facial image and performs three-dimensional localization.
4. The driver drowsiness detection method combining perspective correction and improved ViViT as described in claim 3, characterized in that: In S212, when the origin of the original coordinate system is translated to the new origin, the translation vector is as follows: ; in, , , These are the coordinates of the feature point where the chin tip is located in the original coordinate system.
5. The driver drowsiness detection method combining perspective correction and improved ViViT as described in claim 4, characterized in that: In S212, after translating the origin of the original coordinate system to the new origin, a new coordinate system is established according to the left-handed screw rule. The new coordinate system... The positive axis is horizontal to the right. The positive axis points vertically downwards. The positive axis points vertically outward.
6. The driver drowsiness detection method combining perspective correction and improved ViViT as described in claim 5, characterized in that: In S213, when rotating the face, the inverse matrix of the face pose matrix is used. As a rotation matrix; the feature points of the face are rotated from the original coordinate system using the following formula. Convert coordinates to the new coordinate system : ; In the formula, It is a 3x1 translation vector. It is a 3x3 identity matrix; It is a 3x3 rotation matrix.
7. The driver drowsiness detection method combining perspective correction and improved ViViT as described in claim 6, characterized in that: In S213, the inverse matrix of the attitude matrix The generation process includes: Feature points at the forehead vertices detected by Mediapipe Face Mesh are selected, and the vector obtained by connecting them to the origin of a new coordinate system is normalized and used as the face pose. vector Take the connection vector from the center point of the left eye to the center point of the right eye in the image and normalize it, as the face pose. vector ; After that, and The normal vector of the face pose is obtained by cross product of the left-hand spiral rule. And generate the attitude matrix. ; and then the inverse matrix of the attitude matrix is obtained. .
8. The driver drowsiness detection method combining perspective correction and improved ViViT as described in claim 1, characterized in that: Hidden features input before the last Temporal Transformer Layer for: ; in, This represents the learnable category token output by the (L-1)th Temporal Transformer Layer; This represents the N feature vectors output by the (L-1)th Temporal Transformer Layer; The new input sequence is obtained by concatenation. for: ; in, Represents the maximum value of different attention heads. The token selected by the index; No. Layer Individual attention head weights for: ; ; in, Indicates the first The first layer The weight of each self-attention head; Indicates the first The weights of learnable category tokens in each attention head of the layer. Indicates the first The weights of N feature vectors in each attention head of the layer.
9. The driver drowsiness judgment method combining perspective correction and improved ViViT as described in claim 1, characterized in that: In S1, when constructing the FGR-ViViT model, an improved loss function is also introduced; the improved loss function is as follows: ; in, ; ; In the formula, The cross-entropy loss is the difference between the predicted and true labels of a sample. These are the weighting coefficients; This represents the average KL divergence after two dropouts; Represent two distributions and KL divergence between them; and For the same sample, pass the same model twice with Dropout. The model then predicted two distributions, with the training data being... ; To compare loss functions, Indicates batch size, and Indicates the process Normalized eigenvectors Represents cosine similarity. This is a preset constant; Indicates the true label, and These represent the actual labels for different categories.
Citation Information
Patent Citations
ViT and StarGAN-based driver expression recognition method
CN114005154A
Lightweight video continuous emotion recognition method based on deformable key point attention
CN116343304A
