Face live body detection method, system, medium and product based on scene optimization
By training a teacher model using physics-driven transformation and scene contrast loss, and combining scene-aware knowledge distillation to generate a lightweight face liveness detection model, the performance degradation problem of the lightweight model in specific scenarios is solved, achieving high-precision and robust liveness detection with self-optimization capabilities, and is suitable for resource-constrained edge devices.
Patent Information
- Application Number
- CN202511630383.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-10
- Publication Date
- 2026-02-06
- Estimated Expiration
- 2045-11-10
AI Technical Summary
Existing lightweight face liveness detection models suffer from performance degradation in specific deployment scenarios, particularly their insufficient ability to distinguish interference or attack samples in specific scenarios, leading to increased false positive or false negative rates.
The teacher model is trained using physical-driven transformation and scene contrast loss to learn scene-independent liveness features. Scene representation capabilities are used to select a subset of data from the mixed dataset that highly matches the target deployment scene. Lightweight models are generated by combining scene-aware knowledge distillation. A two-branch architecture and decoupling regularization terms are used to force the model to learn independent scene and liveness information. Attention masks are generated by using the scene branch of the teacher model to modulate the distillation loss, thus generating a liveness detection model.
It significantly improves the accuracy and robustness of the model in the target scene for liveness detection. It can actively perceive environmental changes and perform self-optimization, avoid the performance degradation of static models, reduce the cost of expensive manual retraining and deployment, and ensure the high performance and stability of the system in dynamic environments.
Smart Images

Figure CN121096033B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of computer systems based on specific computing models, and in particular to a face liveness detection method and system based on scene optimization, a medium and a product. BACKGROUND
[0002] Face liveness detection technology is a key link in the biological recognition security system, aiming to distinguish whether the face in front of the camera is from the real user himself or from a photo, video or mask attack. At present, financial payment, intelligent access control and social security authentication applications are migrating to mobile terminals and various edge devices. These edge devices have strict limitations on computing power, power consumption and memory, and can only deploy lightweight models. Therefore, it is very important to deploy a lightweight and high-performance liveness detection model on a resource-constrained platform.
[0003] In related technologies, to realize the deployment of a lightweight model on an edge device, a knowledge distillation technology is generally used. First, a teacher model with complex structure and huge number of parameters is trained on a large general-purpose dataset. The dataset usually contains a large number of real human images and various attack samples from different scenes (such as indoor, outdoor, different light, different background), to ensure that the teacher model has strong generalization ability and high detection accuracy. Then, a student model with simple structure and small calculation amount is designed and trained on the same general-purpose dataset. During the training process, the student model not only learns to fit the real labels of the data, but also imitates the output probability distribution of the teacher model through an additional distillation loss function, so as to transfer the knowledge of the teacher model to the student model, and to inherit the performance of the teacher model while maintaining a small size.
[0004] However, due to the domain shift between the distribution of the training data (source domain) and the real data distribution of the specific deployment scene (target domain), in related technologies, the performance of the student model in the specific deployment scene (such as the front camera of a certain bank ATM or a certain brand of mobile phone) has the risk of performance degradation, that is, the student model has insufficient discrimination ability for the interference or attack samples specific to the specific scene, which will cause the false recognition rate or the missed rate to rise. SUMMARY
[0005] The present application provides a face liveness detection method and system based on scene optimization, a medium and a product, for improving the liveness detection performance of the model in a specific deployment scene.
[0006] In a first aspect, the present application provides a face liveness detection method based on scene optimization, applied to a face liveness detection system. The method comprises: extracting mixed image samples in a mixed training data set of a basic model, applying physical driving transformation to the mixed image samples to obtain enhanced image samples; taking the enhanced image samples derived from the same image sample as positive sample pairs and the enhanced image samples derived from different image samples as negative sample pairs, and calculating a scene contrast loss; taking the liveness classification loss of the mixed image samples and the scene contrast loss to form a total loss function, training the basic model to obtain a teacher model; inputting scene samples in a predefined target scene sample set into a scene branch of the teacher model, extracting and aggregating the features of the scene samples to obtain a scene target vector; inputting each mixed image sample in the mixed training data set into the scene branch of the teacher model one by one, extracting multiple scene feature vectors to form a scene vector set; calculating the vector similarity of the scene target vector and each vector in the scene vector set, and filtering out corresponding image samples from the mixed training data set according to the vector similarity to obtain a scene matching data subset; taking the teacher model as supervision, performing knowledge distillation on the scene matching data subset, and generating a liveness detection model by modulating the distillation loss with the attention mask output by the scene branch of the teacher model; inputting a face image to be detected into the liveness detection model for forward propagation calculation to obtain a classification result representing the liveness confidence.
[0007] In the above embodiment, the face liveness detection system uses the teacher model trained by the physical driving transformation and contrast learning to learn scene-independent liveness features. Then, the scene representation capability is used to accurately filter out a data subset highly matched with the target deployment scene from a large amount of mixed data. Finally, through scene-aware knowledge distillation, a lightweight model optimized for a specific scene is generated, which significantly improves the liveness detection accuracy and robustness of the model in the target scene.
[0008] In combination with some embodiments of the first aspect, in some embodiments, the step of taking the liveness classification loss of the mixed image samples and the scene contrast loss to form a total loss function, training the basic model to obtain a teacher model, specifically comprises: decomposing the basic model into a shared encoder, a scene branch and a liveness branch; inputting the mixed image samples into the shared encoder to obtain shared feature representations; inputting the shared feature representations into the scene branch to determine a scene loss component in combination with the scene contrast loss; inputting the shared feature representations into the liveness branch to determine a liveness loss component in combination with the liveness classification loss of the mixed image samples; calculating the correlation of the scene loss component and the liveness loss component to obtain a decoupling regularization component; determining the total loss function according to the scene loss component, the liveness loss component and the decoupling regularization component to adjust the model parameters of the basic model and obtain the teacher model.
[0009] In the above embodiment, the face living body detection system adopts the technical solution, constructs a double-branch architecture, and introduces a decoupling regularization term to force the model to learn independent feature representations that distinguish scene information and living body information. This avoids the model from misjudging specific background or lighting as living body clues, and makes the teacher model understand the essence of the living body more purely, thereby providing a high-quality and unambiguous knowledge source for subsequent knowledge distillation and ensuring the reliability of the final generated model.
[0010] In combination with some embodiments of the first aspect, in some embodiments, the step of generating the living body detection model supervised by the teacher model and performing knowledge distillation on the scene matching data subset with the attention mask output by the scene branch of the teacher model modulating the distillation loss includes: inputting a predefined target scene sample set into the scene branch of the teacher model to obtain a reference attention mask; inputting samples in the scene matching data subset into the scene branch of the teacher model to obtain a real-time attention mask; fusing the real-time attention mask and the reference attention mask to obtain a modulation mask; applying the modulation mask to the calculation process of the distillation loss to obtain a modulated distillation loss, and performing knowledge distillation based on the modulated distillation loss to generate the living body detection model.
[0011] In the above embodiment, the face living body detection system adopts the technical solution, uses the scene branch of the teacher model to generate an attention mask to guide the distillation process, so that the student model can focus on the most critical area in the image for living body judgment in a specific scene like the teacher, and improves the efficiency and accuracy of knowledge transfer.
[0012] In combination with some embodiments of the first aspect, in some embodiments, after the step of applying the modulation mask to the calculation process of the distillation loss to obtain a modulated distillation loss, and performing knowledge distillation based on the modulated distillation loss to generate the living body detection model, the method further includes: calculating a distribution difference measure between the reference attention mask and the real-time attention mask to obtain a scene drift index; when the scene drift index exceeds a preset drift threshold, extracting key scene feature components based on a preset high-activation area in the modulation mask; performing similarity calculation on the key scene feature components and a pre-stored target scene feature template to generate a scene consistency evaluation report; and adjusting the weight parameters of the scene-related layers in the living body detection model according to the deviation degree in the scene consistency evaluation report.
[0013] In the above embodiment, the face living body detection system adopts the technical solution, can actively perceive changes in the deployment environment and make precise and small-range weight adjustments before performance degradation, can maintain high peak performance in a dynamically changing environment for a long time, and avoids performance degradation after deployment of a static model.
[0014] In conjunction with some embodiments of the first aspect, in some embodiments, before calculating the distribution difference measure between the baseline attention mask and the real-time attention mask to obtain the scene drift index, the method further includes: performing cluster analysis on the target scene sample set to obtain multiple typical scene subcategories, and constructing a corresponding reference attention mask template for each typical scene subcategory; calculating the matching degree between the attention mask corresponding to each sample in the scene matching data subset and each reference attention mask template to determine the best matching scene category; dividing the scene matching data subset into multiple scene subsets based on the best matching scene category and the matching degree; calculating the mean of the attention mask for each scene subset as an adaptive baseline mask for the best matching scene category to replace the baseline attention mask for scene drift detection.
[0015] In the above embodiments, the face liveness detection system adopts the above technical solution, and by classifying the target scene into more granular subcategories, the detection benchmark for scene drift becomes more flexible and accurate. It can distinguish between normal fluctuations within the scene (such as changes in light between morning and evening) and real environmental changes, avoiding unnecessary model updates and improving the stability and efficiency of the adaptive mechanism.
[0016] In conjunction with some embodiments of the first aspect, in some embodiments, before the steps of extracting hybrid image samples from the hybrid training dataset of the base model, applying physical-driven transformations to the hybrid image samples to obtain enhanced image samples, the method further includes: extracting features from a predefined target scene sample set to obtain scene environment parameters, and constructing a generator network based on the scene environment parameters; inputting a preset attack image into the generator network for conversion processing to obtain a synthetic attack sample, and supplementing the synthetic attack sample to the hybrid training dataset.
[0017] In the above embodiments, the face liveness detection system, by adopting the above technical solution, generates synthetic attack samples that are highly consistent with the characteristics of the target scene environment, which greatly enriches the high-difficulty negative samples in the training data, enabling it to anticipate and defend against those highly deceptive attack methods that are most likely to appear in specific scenarios, thereby significantly enhancing the model's security and anti-spoofing capabilities.
[0018] In conjunction with some embodiments of the first aspect, in some embodiments, after the step of inputting the face image to be detected into the liveness detection model for forward propagation calculation to obtain a classification result characterizing the liveness confidence, the method further includes: when the liveness confidence is within the uncertainty range, re-inputting the face image to be detected into the liveness detection model to perform multiple forward propagation calculations to obtain multiple reclassification results; calculating the consistency index of the multiple reclassification results, and determining the liveness detection result based on the consistency index.
[0019] In the above embodiments, the face liveness detection system, by adopting the above technical solution, can make more prudent and reliable judgments on these boundary cases by repeatedly calculating and evaluating the consistency of the results for fuzzy samples with low confidence in the model output, effectively reducing the security risks caused by a single misjudgment.
[0020] In a second aspect, embodiments of this application provide a face liveness detection system, which includes: one or more processors and a memory; the memory is coupled to the one or more processors, and the memory is used to store computer program code, which includes computer instructions, and the one or more processors call the computer instructions to cause the face liveness detection system to perform the method described in the first aspect and any possible implementation thereof.
[0021] Thirdly, embodiments of this application provide a computer program product containing instructions that, when the computer program product is run on a face liveness detection system, cause the face liveness detection system to perform the method described in the first aspect and any possible implementation thereof.
[0022] Fourthly, embodiments of this application provide a computer-readable storage medium including instructions that, when executed on a face liveness detection system, cause the face liveness detection system to perform the method described in the first aspect and any possible implementation thereof.
[0023] Understandably, the face liveness detection system provided in the second aspect, the computer program product provided in the third aspect, and the computer storage medium provided in the fourth aspect are all used to execute the methods provided in the embodiments of this application. Therefore, the beneficial effects they can achieve can be referred to the beneficial effects in the corresponding methods, and will not be repeated here.
[0024] One or more technical solutions provided in the embodiments of this application have at least the following technical effects or advantages:
[0025] 1. This method employs a technique that first trains a teacher model using physics-driven transformation and scene contrast loss to decouple scene and liveness features. Then, it utilizes the scene branch of this teacher model to filter a subset of data from a massive mixed dataset that highly matches the specific deployment scenario. Finally, it generates a lightweight liveness detection model on this subset through scene attention-guided knowledge distillation. Therefore, this method ensures that the final model is customized for a specific scenario. It effectively solves the performance degradation problem caused by domain drift between training data and actual deployment scenarios in existing general-purpose lightweight models, as well as the lack of scenario specificity and low knowledge transfer efficiency in traditional knowledge distillation processes. This allows for the deployment of a liveness detection model with extremely high detection accuracy and robustness for a specific scenario on resource-constrained edge devices, improving user experience and security levels in practical applications.
[0026] 2. By employing a technique that decomposes the base model into a shared encoder, a scene branch, and a liveness branch, and by introducing a total loss function, the model is explicitly guided during training to learn two sets of independent features: one set for recognizing environmental factors such as lighting and background, and the other set specifically for recognizing physiological cues such as micro-expressions and textures. This effectively solves the problem in existing technologies where models easily learn false associations between scenes and liveness, such as incorrectly associating specific indoor lighting with real people, leading to poor model generalization ability and susceptibility to scene changes. The knowledge passed to the student model is therefore more accurate and reliable, fundamentally improving the robustness and credibility of the final liveness detection model.
[0027] 3. By employing a closed-loop update strategy that continuously calculates the distribution difference between the real-time input attention mask and the pre-stored baseline attention mask after model deployment to obtain a scene drift metric, and triggers adjustments to the weights of the model's scene-related layers when the metric exceeds a threshold, the system possesses the ability to proactively perceive environmental changes and perform self-optimization. This effectively solves the problem in existing technologies where the performance of static models gradually declines over time and with environmental changes (i.e., model aging), eliminating the costly manual retraining and deployment, and ensuring that the system maintains a high level of detection performance and stability throughout its entire lifecycle. Attached Figure Description
[0028] Figure 1 This is a flowchart illustrating a scene-optimized face liveness detection method in an embodiment of this application.
[0029] Figure 2 This is a schematic diagram of the topology of a face liveness detection system in an embodiment of this application;
[0030] Figure 3This is another flowchart illustrating the scene-optimized face liveness detection method in this application embodiment;
[0031] Figure 4 This is a schematic diagram of the physical device structure of a face liveness detection system in the embodiments of this application. Detailed Implementation
[0032] The terminology used in the following embodiments of this application is for the purpose of describing particular embodiments only and is not intended to be limiting of this application. As used in the specification of this application, the singular expressions “a,” “an,” “the,” “the,” and “this” are intended to include the plural expressions as well, unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used in this application refers to any or all possible combinations including one or more of the listed items.
[0033] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as implying or suggesting relative importance or implicitly indicating the number of indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature, and in the description of the embodiments of this application, unless otherwise stated, "multiple" means two or more.
[0034] The core logic of this application's overall technical solution lies in using a powerful teacher model to understand and deconstruct the complex real world, and then using this understanding to refine a small but sophisticated student model for specific tasks and environments. The base model typically refers to a large-scale pre-trained visual model, such as Vision Transformer (ViT) or ConvNeXt, which possesses powerful general feature extraction capabilities and serves as the starting point for the entire process. Physically driven transformations are a series of enhancement operations performed on the image to simulate real-world changes, such as adjusting brightness and contrast to simulate lighting at different times of day, replacing the background to simulate different locations, and performing rotation and scaling to simulate different shooting angles and distances. The aim is to teach the model to recognize the image content itself, rather than the environment. Scene contrast loss is a self-supervised learning method that drives the model to bring features derived from the same image (positive sample pairs) closer together in the feature space after different physical transformations, while pushing features derived from different images (negative sample pairs) further apart, thereby learning stable feature representations that are insensitive to scene changes. The teacher model trained in this stage possesses powerful scene understanding and liveness detection capabilities. Its internal scene branch specifically outputs scene-related features, while the liveness branch is responsible for determining authenticity. When deploying the model for a specific scene (such as a bank's ATM), a small sample set of target scene data is collected. Features are extracted from this sample set through the teacher model's scene branch and aggregated into a scene target vector representing the scene. This vector then acts as a probe, calculating vector similarity (such as cosine similarity) in a large mixed training dataset to identify the image most similar to the target scene, forming a scene matching data subset. The final stage is knowledge distillation. The teacher model transfers knowledge to a lightweight liveness detection model (student model). Specifically, the teacher model's scene branch generates an attention mask, instructing the student model which regions of the image to focus on during learning, thus achieving scene-aware knowledge transfer.
[0035] The following describes the process of the method provided in this implementation. Please refer to [link / reference]. Figure 1 This is a flowchart illustrating a scene-optimized face liveness detection method in an embodiment of this application.
[0036] S101. Extract hybrid image samples from the hybrid training dataset of the base model, apply physical driving transformation to the hybrid image samples to obtain enhanced image samples.
[0037] The hybrid training dataset represents a collection of numerous face images from diverse sources, encompassing different scenes, lighting conditions, ethnicities, and attack types, but typically only containing coarse-grained labels for real or fake faces. Physically driven transformations refer to a series of image processing operations that simulate changes in the real-world physical environment, used for data augmentation. Augmented image samples are images obtained by applying physically driven transformations to the original hybrid image samples.
[0038] Specifically, this is a schematic diagram of the topology of a face liveness detection system in an embodiment of this application. Figure 2 The feature decoupling fine-tuning unit module in the system performs this step. The face liveness detection system first loads the hybrid training dataset from storage. For each hybrid image sample x in the dataset, the system applies multiple physical driving transformations T(x), which in... Figure 2 The transformations are denoted as physics-driven transformations. These transformations are designed to simulate real-world scene variations unrelated to liveness detection, such as lighting perturbations (brightness adjustment ±30%, contrast adjustment ±25%), background replacement (e.g., randomly selecting a background from the COCO dataset and blending it with a face), and geometric distortions (rotation ±15°, scaling ±20%). By applying at least two different transformations to an original image, one or more pairs of enhanced image samples can be generated, such as (T1(x), T2(x)).
[0039] In some embodiments, this step can be implemented in several ways to enhance the realism and diversity of the transformation: Optionally, physically based rendering transformation can be introduced, first by reconstructing the face in 3D, then adjusting the position, angle, and light source parameters of the virtual camera in virtual 3D space, and finally re-rendering it into a 2D image; alternatively, style transfer techniques based on generative adversarial networks (GANs) can be used to transfer the style of the target scene (such as the noise pattern and color style of a specific camera) to the original image. It is understood that other methods can also be used to achieve image enhancement, such as elastic deformation, adding artifacts, etc., which are not limited here.
[0040] One potential problem encountered during this step is the improper setting of the parameter range for the physics-driven transformation. This can lead to overly distorted or significantly different augmented samples compared to the real scene, thus hindering model learning. To address this, a small number of target scene samples can be analyzed before the transformation to statistically analyze the distribution of key environmental parameters (such as average brightness, contrast range, and background complexity). The parameter range for the physics-driven transformation can then be dynamically adjusted based on this distribution to ensure that the statistical characteristics of the generated data augmented samples are consistent with the target scene, thereby improving the effectiveness of data augmentation.
[0041] S102. Using enhanced image samples from the same image sample as positive sample pairs and enhanced image samples from different image samples as negative sample pairs, calculate the scene contrast loss.
[0042] In this context, a positive sample pair refers to two enhanced image samples generated from the same original image through different physical driving transformations. A negative sample pair refers to enhanced image samples generated from two different original images. Scene contrast loss is a loss function whose goal is to make the features of positive sample pairs as similar as possible, while the features of negative sample pairs are as different as possible in the feature vector output by the model.
[0043] For details, please refer to Figure 2 This is a schematic diagram of the topology of the face liveness detection system in an embodiment of this application. Step S102 is... Figure 2 This is accomplished in the feature decoupling fine-tuning unit module, whose core is learning scene invariance. In a training batch, assuming there are N different original images, each image generates two augmented samples, resulting in a total of 2N augmented images. For any augmented sample xi, its homologous samples xj (from the same original image) form a positive sample pair (xi, xj), while the remaining 2(N-1) samples xk from other original images form a negative sample pair (xi, xk). The model (the scene branch of the base model) outputs a scene feature vector for each sample. Scene contrast loss (such as InfoNCEloss) is calculated based on these vectors, optimizing the model parameters by maximizing the mutual information (or similarity) of the features in positive sample pairs and minimizing the mutual information of the features in negative sample pairs.
[0044] A key issue in this step is the problem of pseudo-negative samples. This means that among the randomly sampled negative samples, there may be samples that are extremely similar to the current sample in terms of scene but have different labels. Treating these as negative samples can mislead the model. To address this, a filtering mechanism can be introduced when constructing negative sample pairs. For example, a pre-trained, weak scene classifier can be used to initially classify candidate negative samples. If a candidate negative sample is classified into the same scene category as the current sample, its weight as a negative sample is reduced, or it is directly removed from the negative sample set, thus ensuring the purity of the negative samples.
[0045] S103. The total loss function is composed of the liveness classification loss and scene contrast loss of the mixed image samples to complete the training of the basic model and obtain the teacher model.
[0046] The liveness classification loss refers to the loss used to supervise the liveness branch of the model for true / false binary classification, typically employing cross-entropy loss. The total loss function is a weighted sum of multiple loss components, used to collectively guide the optimization of the entire model. The teacher model is the foundational model, with a large number of parameters but powerful performance, obtained after thorough training in this stage.
[0047] For details, please refer to Figure 2 This is a schematic diagram of the topology of the face liveness detection system in an embodiment of this application. Step S103 is... Figure 2 The ultimate goal of the mid-feature decoupling fine-tuning unit module is, for example... Figure 2 As shown, features from the visual encoder are fed into the liveness branch and the scene branch, and their respective losses and decoupling constraints together constitute the joint optimization objective. In each training step, the model computes not only the aforementioned scene contrast loss L_scene, but also the liveness classification loss L_live. The liveness classification loss is calculated by comparing the classification probability p_live of the model's liveness branch output for augmented image samples with its original true / false label y_true. The total loss function L_total is typically a weighted sum of these two: L_total = L_live + λ * L_scene, where λ is a hyperparameter used to balance the importance of the two tasks. This total loss function is backpropagated to update the weights of the model (including the shared encoder, scene branch, and liveness branch) until the model converges, ultimately yielding the teacher model.
[0048] In some embodiments, the total loss function can be constructed in several ways to achieve a more refined training objective: Optionally, a decoupling regularization term L_decouple can be introduced, which penalizes the sensitivity of the liveness branch output to changes in scene features. This term can be calculated as the dot product of the scene feature gradient and the liveness classification loss gradient, with the goal of making them orthogonal. Optionally, an uncertainty-weighted approach from multi-task learning can be used to dynamically adjust λ, allowing the model to automatically learn the optimal weights for the two tasks. It is understood that other regularization terms or different multi-task optimization strategies can also be introduced, and no limitations are imposed here.
[0049] A key challenge in this step is the potential conflict between the liveness classification task and the scene feature learning task; that is, the model might sacrifice the performance of the other task in order to optimize one task. To address this, gradient pruning or gradient orthogonalization techniques can be employed. For example, during backpropagation, after calculating the gradients of L_live and L_scene, the gradient of L_scene is projected onto the orthogonal space of the gradient of L_live before updating. This ensures that scene feature learning does not negatively impact the liveness classification task, achieving co-optimization of the two tasks.
[0050] S104. Input the scene samples from the predefined target scene sample set into the scene branch of the teacher model, extract and aggregate the features of the scene samples to obtain the scene target vector.
[0051] The predefined target scene sample set refers to a small subset of samples collected in the real-world environment where the model will ultimately be deployed, such as facial images captured by the front-facing camera of a specific mobile phone model or an ATM of a specific bank. The scene target vector is a condensed vector that represents the characteristics of that specific scene environment.
[0052] For details, please refer to Figure 2 This is a schematic diagram of the topology of the face liveness detection system in an embodiment of this application. Step S104 corresponds to... Figure 2 The input stage of the mid-scene data screening module. The face liveness detection system first loads the trained teacher model (i.e., Figure 2 (Mid-fine tuning model). Then, the small number (e.g., tens to hundreds) of target scene samples collected (i.e., Figure 2 The scene dataset (from the dataset) is input one by one into the scene branch ϕ_scene of the teacher model to obtain the scene feature vector v_s for each sample. In order to obtain a single vector that can stably represent the entire scene, the system will perform an aggregation operation on these vectors. The simplest aggregation method is to calculate the mean of all feature vectors: v_target = mean({v_s}). This aggregated v_target is the scene target vector.
[0053] A potential problem during this step is that the collected target scene sample set may be biased, for example, only collecting samples during the day and ignoring nighttime scenes, resulting in an incomplete scene target vector. To address this, an active learning strategy can be introduced. After calculating the initial scene target vector, it is used to filter samples from the mixed dataset, and the filtering results are manually evaluated. If significant scene bias is found in the filtered samples, the operator is prompted to collect samples of missing scene types (such as nighttime samples) and add them to the target scene sample set. The scene target vector is then iteratively updated until it is sufficiently representative.
[0054] S105. Input each mixed image sample in the mixed training dataset into the scene branch of the teacher model one by one, and extract multiple scene feature vectors to form a scene vector set.
[0055] Here, the scene feature vector is a high-dimensional vector output by the scene branch of the teacher model for a single image. The scene vector set is the set of scene feature vectors corresponding to all images in the mixed training dataset.
[0056] For details, please refer to Figure 2This is a schematic diagram of the topology of the face liveness detection system in an embodiment of this application. Step S105 is... Figure 2 This is executed in the scene data screening module, aiming to establish a searchable feature library for subsequent screening. Figure 2 The database icon in the image. The face liveness detection system traverses the entire large-scale hybrid training dataset (i.e., ...). Figure 2 (The dataset contains a mixed dataset). For each image in the dataset, the system performs a forward propagation, but only through the scene branch of the teacher model, extracting its output scene feature vector. This process generates millions or even more feature vectors. To facilitate subsequent fast retrieval, the system stores these vectors along with their corresponding image indices in a specially constructed feature library. This feature library is the set of scene vectors.
[0057] In some embodiments, this massive set of scene vectors can be efficiently constructed and managed in several ways: Optionally, a specialized Approximate Nearest Neighbor (ANN) search library, such as FAISS (Facebook AI SimilaritySearch) or ScaNN (Scalable Nearest Neighbors), can be used to construct a feature index, which can reduce the subsequent similarity search time from linear complexity to logarithmic complexity; alternatively, before storing the feature vectors, dimensionality reduction techniques such as PCA (Principal Component Analysis) can be used to compress the vectors to reduce storage space and accelerate computation while retaining most of the information. It is understood that other databases or indexing techniques can also be used to manage these features, and this is not limited here.
[0058] A practical challenge in implementing this step is handling the computational overhead of such a large-scale dataset. To address this, a distributed computing framework (such as Apache Spark) can be employed. The mixed training dataset is sharded and distributed across multiple computing nodes, with each node extracting features from its own shard in parallel. Finally, the feature vectors extracted from all nodes are aggregated to build a global feature index. This parallel processing can significantly reduce the time required to construct the scene vector set.
[0059] S106. Calculate the vector similarity between the scene target vector and each vector in the scene vector set, and select the corresponding image samples from the mixed training dataset based on the vector similarity to obtain a scene matching data subset.
[0060] Vector similarity is an indicator that measures how close two vectors are in a direction; cosine similarity is commonly used. Scene matching data subsets are small subsets of data selected from a large mixed dataset that are highly consistent with the characteristics of the target deployment scene environment.
[0061] For details, please refer to Figure 2 This is a schematic diagram of the topology of the face liveness detection system in an embodiment of this application. Step S106 is... Figure 2 The core function of the scene data screening module is to perform matching and screening using a feature library. The face liveness detection system utilizes the feature library built in the previous step, using the scene target vector v_target obtained in step S104 as the query vector. The system calculates the cosine similarity between v_target and each scene feature vector v_sample in the feature library:
[0062] Similarity = (v_target * v_sample) / (||v_target|| * ||v_sample||). Then, a similarity threshold is set (e.g., 0.85), and the image indices of all samples with similarity greater than this threshold are recorded. Finally, based on these indices, the corresponding images and their labels are extracted from the original mixed training dataset to form a subset of the scene matching data.
[0063] In some embodiments, the screening process can be optimized in several ways to ensure the quality and diversity of the subset: Optionally, instead of using a fixed threshold, the top K samples with the highest similarity can be selected to ensure a fixed subset size; alternatively, a diversity guarantee step can be added after screening, such as clustering the features of the selected samples again and sampling proportionally from each cluster to avoid the selected samples having overly homogeneous scenarios (e.g., all with the same background). It is understood that other screening criteria, such as the distribution of liveness labels on the samples, can also be combined to construct the final data subset, which is not limited here.
[0064] A key issue in this step is the selection of the similarity threshold. If the threshold is too high, the selected data subset is too small, leading to insufficient model training; if the threshold is too low, the subset contains too much noisy data irrelevant to the scene. To address this, an adaptive threshold strategy can be employed. First, a core subset is selected using a relatively high initial threshold, and a student model is initially trained using this subset. Then, the model's performance is evaluated on the validation set, and the threshold is dynamically adjusted based on performance feedback (such as signs of underfitting or overfitting). Multiple rounds of selection and training are performed until the optimal threshold is found.
[0065] S107. Using the teacher model as supervision, perform knowledge distillation on a subset of scene matching data, modulate the distillation loss with the attention mask output by the scene branch of the teacher model, and generate a liveness detection model.
[0066] Knowledge distillation is a model compression technique that allows a small student model to learn and mimic the behavior of a large teacher model. The attention mask is typically a matrix the same size as the feature map, with values representing the model's level of attention to features at that location. The liveness detection model is the lightweight student model ultimately deployed to edge devices.
[0067] For details, please refer to Figure 2 This is a schematic diagram of the topology of the face liveness detection system in an embodiment of this application. Step S107 is performed by... Figure 2 The customized distillation and compression module is executed in the mid-scenario. For example... Figure 2 As shown, this module utilizes a teacher model (consisting of a visual encoder and a liveness branch) to supervise a mobile model (i.e., a student model) and transfers knowledge by calculating distillation loss. The face liveness detection system selects a lightweight network architecture (such as MobileNetV3) as the student model. During training, for each image x in the scene matching data subset, both the teacher and student models process it. Traditional distillation loss causes the output probability distribution of the student model to approximate the output probability distribution of the teacher model. Building on this, this method introduces modulation: the scene branch ϕ_scene(x) of the teacher model outputs feature maps from one or more intermediate layers, which, after processing, form an attention mask A_teacher. This mask is applied to the distillation loss, causing the student model to focus more on regions deemed important by the teacher model during learning.
[0068] In some embodiments, scene-aware knowledge distillation can be achieved in several ways: optionally, not only the final output is distilled, but also the feature representations of intermediate layers are distilled, and attention masks are used to weight the importance of features at different locations; optionally, the attention mask itself is also used as a distillation target, i.e., a loss term is added to allow the student model to learn to generate attention masks similar to those of the teacher model. Understandably, more complex distillation loss functions can also be designed to combine multiple forms of knowledge for transmission, which is not limited here.
[0069] One challenge in implementing this step is balancing the standard classification loss (student model vs. ground truth label) and the distillation loss (student model vs. teacher model). A strategy of curriculum learning can be employed to address this. Initially, the distillation loss is given a higher weight, allowing the student model to quickly mimic the overall behavior of the teacher model. As training progresses, the weight of the classification loss between the student model and the ground truth label is gradually increased, allowing the student model to fine-tune and refine its performance based on imitation, thus achieving better results than simple imitation.
[0070] S108. Input the face image to be detected into the liveness detection model for forward propagation calculation to obtain the classification result representing the liveness confidence.
[0071] In this context, the face image to be detected refers to a face image that needs to be judged for authenticity in practical applications. Forward propagation computation refers to the complete computation process of data from the input layer to the output layer in a neural network. Liveness confidence is a probability value output by the model, indicating how likely it is that the model believes the face is real.
[0072] For details, please refer to Figure 2 This is a schematic diagram of the topology of the face liveness detection system in an embodiment of this application. Step S108 is... Figure 3 In the final application stage of the entire process, a mobile model generated by a scene-customized distillation and compression module is used. After deploying the trained lightweight liveness detection model on edge devices (such as mobile phones and access control machines), when liveness detection is needed, the camera captures a frame of a face image. This image, after preprocessing (such as cropping and normalization), is input into the liveness detection model. The model performs one forward propagation calculation, and its final output layer (usually a Softmax layer) outputs a two-dimensional vector, for example [0.1, 0.9], representing the probability that the model predicts the image to be a fake or a real person, respectively. Based on a preset decision threshold (such as 0.5), the system uses the category with the higher probability as the final classification result and outputs the liveness confidence score (such as 0.9).
[0073] In some embodiments, the inference process can be optimized in various ways to improve speed and energy efficiency: Optionally, the model can be quantized and trained before deployment, converting the model weights from 32-bit floating-point numbers (FP32) to 8-bit integers (INT8) to utilize the hardware's INT8 acceleration unit; alternatively, channel pruning can be performed on the model to remove redundant channels that do not contribute significantly to the final result, further reducing computational load. It is understood that other model compression and acceleration techniques, such as weight sharing and low-rank decomposition, can also be used, and are not limited here.
[0074] A common challenge in this step is balancing processing speed and accuracy. In scenarios with extremely high real-time requirements, even lightweight models may not be fast enough. To address this, a cascaded detection framework can be designed. First, a very small and fast model is used for initial screening, filtering out only very obvious spoofing attacks. For samples that cannot be determined, a slightly more complex but more accurate liveness detection model, as described in the previous step, is then invoked for a secondary assessment. This hierarchical processing approach can significantly improve average processing speed while maintaining high accuracy.
[0075] The following provides a more detailed description of the process of the method provided in this implementation. Please refer to [link / reference].Figure 4 This is another flowchart illustrating the scene-optimized face liveness detection method in this application embodiment.
[0076] S301. Extract features from a predefined target scene sample set to obtain scene environment parameters, and construct a generative network based on the scene environment parameters.
[0077] The target scene sample set represents a small, representative set of images collected in the actual deployment environment; scene environment parameters refer to quantitative indicators extracted from these images that describe the characteristics of the environment, such as light intensity distribution, color saturation, and noise level; the generative network is usually a deep learning model, such as a generative adversarial network (GAN), used to synthesize new images based on given parameters.
[0078] Specifically, this step is the data augmentation preparation phase, designed to create more high-quality training samples, especially attack samples, that are highly relevant to the target scene. The face liveness detection system first performs detailed image analysis on dozens to hundreds of target scene samples. It calculates a series of statistical features to quantify the scene environment, such as: using histogram analysis to obtain the distribution range of brightness and contrast; analyzing the frequency characteristics of the image through Fourier transform to evaluate noise patterns and intensity; and using colorimetric tools to analyze dominant hue and white balance shift. These extracted scene environment parameters are then used to configure or fine-tune a generative network. For example, a pre-trained StyleGAN model can be fine-tuned so that the face images it generates naturally incorporate the unique lighting and color style of the target scene.
[0079] In some embodiments, this generative network can be constructed in several ways: Optionally, a non-GAN method can be used to construct an image processing pipeline with multiple adjustable parameters (such as gamma correction values, Gaussian noise standard deviation, and lens blur kernel) directly set by extracted scene environment parameters; alternatively, flow-based generative models or variational autoencoders (VAEs) can be used to guide the image generation process by taking scene environment parameters as conditional inputs, which typically provides better generative diversity. It is understood that other advanced generative models or image-to-image translation techniques can also be used to achieve this functionality, and no limitation is made here.
[0080] A key issue that may arise during this step is that a small number of target scene samples may not be sufficient to comprehensively capture all changes in the scene (such as lighting conditions at different times of day), resulting in insufficient diversity of generated samples. To address this, parameter interpolation and extrapolation techniques can be introduced. After extracting scene environment parameters from different samples, the system does not only use these discrete parameter points but also performs smooth interpolation between these points, and even extrapolation within a reasonable range, thereby generating a series of continuously changing parameter sets. For example, interpolating between the parameter points of "daytime" and "dusk" can generate parameters under "afternoon" lighting. Using these interpolated / extrapolated parameters in the generative network can synthesize samples that cover a wider range of scene changes, thus improving the comprehensiveness of data augmentation.
[0081] S302. Input the preset attack image into the generator network for conversion processing to obtain the synthetic attack sample, and supplement the synthetic attack sample into the mixed training dataset.
[0082] Among them, the preset attack image refers to a general image library containing various types of attack methods, such as high-definition printed photos, screenshots of facial videos played on different displays, and photos of 3D masks; the conversion processing refers to the process of stylizing or rendering environmental features of these general attack images through the generative network constructed in the previous step; the synthetic attack sample is a new image that has been converted and processed, retaining the original attack characteristics while superimposing the environmental features of the target scene.
[0083] Specifically, this step aims to inject highly targeted, high-order negative samples into the training dataset. The face liveness detection system selects samples from its pre-defined attack image library and then feeds these samples one by one into the generative network constructed in step S301. The generative network processes the input attack images; for example, it overlays low-light and high-ISO noise specific to the target scene onto a printed photo, or simulates glare and moiré patterns specific to the target scene's camera onto a screen re-enactment attack sample. The resulting synthetic attack samples appear to the model as if they were real attacks occurring in the target deployment environment. Finally, the system adds these high-quality synthetic attack samples, along with their spoof labels, to the mixed training dataset, greatly enriching the dataset and making subsequent training more challenging and targeted.
[0084] In some embodiments, the sample supplementation process can be implemented in several ways: Optionally, proportional supplementation can be performed, generating and supplementing specific types of synthetic attack samples based on predictions of the attack types that the target scenario may face. For example, if screen attacks are determined to be the primary threat, more synthetic screen attack samples can be generated. Optionally, online generation and enhancement can be implemented, integrating the generation network into the trained data loader to dynamically generate synthetic attack samples in each training batch and performing additional conventional data augmentation (such as random pruning and flipping) to further enhance data diversity. It is understood that other strategies can also be used to optimize the composition of the dataset, which are not limited here.
[0085] During this step, a potential problem is that the generative network might unintentionally weaken or destroy some key attack cues in the original attack image (e.g., the texture of a printed photo or pixels on a screen). To address this, an attention-based fusion strategy can be introduced. When the generative network transforms the image, it doesn't directly output the final result, but instead generates a scene style layer and a content preservation layer. Simultaneously, another network branch predicts the key cue regions (attack saliency map) in the original attack image. Finally, based on this saliency map, the scene style layer and the content preservation layer are weighted and fused, ensuring that while adding scene features, the original attack cues are preserved to the greatest extent possible, making the synthesized sample both realistic and effective.
[0086] S303. Extract hybrid image samples from the hybrid training dataset of the base model, apply physical driving transformation to the hybrid image samples to obtain enhanced image samples.
[0087] Refer to step S101, which will not be repeated here.
[0088] S304. Using enhanced image samples from the same image sample as positive sample pairs and enhanced image samples from different image samples as negative sample pairs, calculate the scene contrast loss.
[0089] Refer to step S102, which will not be repeated here.
[0090] S305. The total loss function is composed of the liveness classification loss and scene contrast loss of the mixed image samples. The training of the basic model is completed to obtain the teacher model.
[0091] Among them, the liveness classification loss of mixed image samples usually refers to the cross-entropy loss, which is used to measure the model's performance on the true / false classification task; the scene contrast loss is a self-supervised loss, which is used to drive the model to learn feature representations that are insensitive to scene changes; the total loss function is the weighted sum of these two (or more) loss components, which is used to guide the parameter updates of the entire model; the teacher model is a large model that has been trained at this stage and has powerful feature extraction and discrimination capabilities.
[0092] Specifically, in each training iteration, the face liveness detection system takes a batch of data from the augmented mixed training dataset. For each image in the batch, the model computes two main losses in parallel. First, the image is processed by the shared encoder and the liveness branch to produce a classification prediction, which is compared with the image's ground truth label (real person or fake person) to compute the liveness classification loss L_live. Second, augmented sample pairs generated from the same original image are processed by the shared encoder and the scene branch to compute their scene feature vectors, and scene contrast loss L_scene is computed based on these vectors to bring positive sample pairs closer together and push negative sample pairs further apart. Finally, the total loss function is defined as the weighted sum of these two losses: L_total = α * L_live + β * L_scene. By backpropagating this total loss function, the gradient is computed and the weights of the entire teacher model (shared encoder, liveness branch, scene branch) are updated. This process continues until the model's performance on the validation set no longer improves, at which point training is complete, and the resulting model is the teacher model.
[0093] During this step, there may be conflicts in the optimization objectives between the scene contrastive learning task and the liveness classification task, leading to unstable training or poor performance. For example, some subtle texture features crucial for liveness detection may be treated as scene changes in physically driven transformations and suppressed by the contrastive loss. To address this, a hierarchical feature decoupling strategy can be designed. In terms of network structure, the shallow part of the shared encoder is primarily driven by the liveness classification loss to preserve all details; the deeper part is affected by both losses simultaneously, achieving a higher level of semantic decoupling. In terms of the loss function, a mask modulated by the liveness branch attention map can be applied to the scene contrastive loss to prevent the contrastive learning process from suppressing key liveness-related regions.
[0094] S306. Input the scene samples from the predefined target scene sample set into the scene branch of the teacher model, extract and aggregate the features of the scene samples to obtain the scene target vector.
[0095] Refer to step S104, which will not be repeated here.
[0096] S307. Input each mixed image sample in the mixed training dataset into the scene branch of the teacher model one by one, and extract multiple scene feature vectors to form a scene vector set.
[0097] Refer to step S105, which will not be repeated here.
[0098] S308. Calculate the vector similarity between the scene target vector and each vector in the scene vector set, and select the corresponding image samples from the mixed training dataset based on the vector similarity to obtain a scene matching data subset.
[0099] Refer to step S106, which will not be repeated here.
[0100] S309. Input the predefined target scene sample set into the scene branch of the teacher model to obtain the baseline attention mask.
[0101] Among them, the scene branch of the teacher model is the part of the teacher model specifically used to extract scene-related features; the baseline attention mask is an aggregated spatial weight map that can represent typical visual attention areas of the target scene.
[0102] Specifically, this step is a preparatory step for scene-aware distillation, aiming to establish a scene-focused baseline for subsequent knowledge transfer. The face liveness detection system loads the trained teacher model and inputs images from all target scene sample sets one by one into the model. For each image, the system does not care about its final output, but rather extracts the feature maps generated in one or more intermediate layers within the scene branch. The activation values of these feature maps reflect the model's attention to different spatial locations when understanding the image scene. The system aligns and aggregates these feature maps generated from all target scene samples, typically by performing element-wise averaging. The average feature map obtained after aggregation is then normalized (e.g., scaled to the [0, 1] range) to form the baseline attention mask. This mask can be seen as a summary of the teacher model's visual habits for this specific deployment scene.
[0103] In some embodiments, this baseline mask can be generated in several ways: Optionally, Gradient Weighted Class Activation Mapping (Grad-CAM) is used. For each target scene sample, the gradient of the final output of the scene branch relative to the intermediate feature map is calculated, and this gradient is used to weight the feature map to generate a more semantically oriented attention map. Finally, these attention maps are averaged. Optionally, outlier removal is performed before aggregation. First, the similarity between all pairs of attention maps is calculated, and samples that differ too much from other maps are removed (e.g., someone passes by the background at the moment of shooting). Then, the remaining samples are averaged to obtain a more stable and robust baseline mask. It is understood that other attention extraction and aggregation techniques can also be used, and are not limited here.
[0104] One potential issue during this step is that if the target scene itself contains several significantly different sub-scenes (e.g., a room has two common locations: a window and a corner), forcibly averaging the attention maps of all samples might result in a blurry baseline mask that fails to highlight any key elements. To address this, unsupervised clustering (e.g., K-Means clustering) can be performed on the attention maps of the target scene samples. This automatically categorizes the samples into several sub-scene classes (e.g., window scene, corner scene). Then, an independent and clear baseline attention mask is calculated for each class. In subsequent distillation processes, the corresponding baseline mask can be dynamically selected based on the sub-scene class to which the image to be processed belongs.
[0105] S310. Input the samples from the scene matching data subset into the scene branch of the teacher model to obtain the real-time attention mask.
[0106] Here, the scene matching data subset refers to the set of images that are highly similar to the environmental features of the target scene, selected from the massive mixed dataset in step S308; the scene branch of the teacher model is the part of the teacher model responsible for extracting scene features; and the real-time attention mask refers to the instantaneous visual attention region map generated by the teacher model for the single training image currently being processed.
[0107] Specifically, this step is performed within the knowledge distillation training loop to capture the teacher model's immediate attention to each specific training sample. When the face liveness detection system takes an image from the scene matching data subset for training, this image is fed into the scene branch of the teacher model. Similar to step S309, the system extracts and processes the intermediate layer feature maps within the scene branch to generate a spatial attention mask. However, unlike S309, this mask is generated on-the-fly for the current image and is not aggregated with masks from other images. Therefore, it is called a real-time attention mask. This mask reflects how the teacher model's attention is drawn to specific content in the image (such as facial pose and specific background elements) when analyzing this particular image.
[0108] In some embodiments, the generation of this real-time mask can be achieved in several ways to improve its quality: Optionally, a self-attention mechanism can be employed, directly extracting self-attention maps from the Transformer layers of the teacher model (if the teacher model is Transformer-based). These maps naturally represent the model's attention to the relationships between different parts of the image and can serve as a high-quality real-time attention mask. Optionally, the generated real-time mask can be smoothed, for example, by convolving it with a small Gaussian filter to reduce high-frequency noise, making the mask more spatially continuous and stable. It is understood that multiple methods can also be combined to generate a multi-scale real-time attention mask to capture attention information at different levels, which is not limited here.
[0109] One potential issue encountered during this step is that some images in the scene matching data subset may have subtle but crucial differences from the target scene. This can cause a significant deviation between the real-time attention mask generated by the teacher model and the expected scene focus (i.e., the baseline mask). This deviation could be useful information or noise. To effectively utilize this deviation, the system can calculate a difference map between the real-time mask and the baseline mask (e.g., by subtracting element-wise and taking the absolute value). This difference map can serve as an additional distillation signal, guiding the student model not only to learn the teacher's common focus points but also how the teacher's attention adjusts in real-time when encountering samples that deviate from the norm, thereby improving the student model's adaptability.
[0110] S311. The real-time attention mask and the baseline attention mask are fused to obtain the modulation mask.
[0111] Among them, the real-time attention mask is the teacher model's immediate attention map for the current training sample; the baseline attention mask is the teacher model's average attention map for the entire target scene; fusion refers to combining these two masks through mathematical operations; and the modulation mask is the composite attention map obtained after fusion, which is ultimately used to guide the distillation process.
[0112] Specifically, this step aims to combine commonalities and individual characteristics to generate a more comprehensive and effective guidance signal. The face liveness detection system now possesses a baseline attention mask representing the commonalities of the scene and a real-time attention mask representing the individual characteristics of the current sample. To ensure that the student model's learning focuses on key regions of the target scene while also considering the uniqueness of each sample, the system needs to fuse these two masks. A common fusion method is element-wise multiplication, resulting in a modulation mask that highlights regions deemed important by both the baseline and real-time masks. Another method is weighted summation; adjusting the weights controls whether the guidance leans more towards the commonalities of the scene or the individual characteristics of the sample. This final generated modulation mask will serve as the core of the next step, modulation distillation loss.
[0113] In some embodiments, the fusion of this mask can be achieved in several ways: Optionally, a logical OR operation can be used for fusion, that is, the two masks are binarized and their union is taken. This ensures that regions deemed important by either mask are preserved, suitable for scenarios where the student model is expected to learn a wider range of features; alternatively, a learnable fusion module can be introduced, such as a small convolutional network that takes a baseline mask and a real-time mask as input, adaptively learns how to combine them into the optimal modulation mask, and the parameters of this small network are trained end-to-end with the student model. It is understood that more complex nonlinear fusion functions can also be designed according to specific task requirements, which are not limited here.
[0114] During this step, it's necessary to determine the optimal fusion strategy and parameters (e.g., weighted summation weights). A fixed strategy may not be suitable for all situations. To address this, a meta-learning approach can be introduced. The system can retain a small subset of validation data during training. After each training step, a modulation mask is generated using different fusion parameters, and the distillation loss on the validation data is calculated. This loss is then used as the optimization objective of meta-learning, and backpropagation is used to update the parameters of the fusion strategy. Through this "learning how to learn" approach, the system can automatically find the dynamic fusion strategy best suited to the current training stage and data characteristics, thereby maximizing distillation efficiency.
[0115] S312. Apply the modulation mask to the calculation process of distillation loss to obtain the modulated distillation loss, and perform knowledge distillation based on the modulated distillation loss to generate a liveness detection model.
[0116] Among them, the modulation mask is the composite attention map obtained from the previous fusion step; the distillation loss is a loss function that measures the difference between the student model and the teacher model; knowledge distillation is a model compression method; and the liveness detection model is the finally generated, lightweight student model ready for deployment.
[0117] Specifically, this is the core execution step of scene-aware knowledge distillation. During the training of the student model, the face liveness detection system not only calculates the classification loss (such as cross-entropy loss) between the student model's predictions and the true labels, but also calculates a special distillation loss. This distillation loss aims to allow the student model to mimic the thought process of the teacher model. For example, it can calculate the difference between a certain intermediate layer feature map of the student model and the teacher model. Crucially, this difference calculation is modulated: the system uses the modulation mask generated in step S311 to weight the feature map differences. For example, calculating the weighted mean squared error:
[0118] L_distill_feature=Σ[M*(F_teacher-F_student) 2 ] / ΣM, where M is the modulation mask and F is the feature map. In this way, the student model is forced to prioritize learning features that match the teacher model in the highlighted areas of the modulation mask. The final total training loss is a weighted sum of the classification loss and this modulation distillation loss. By optimizing this total loss, the student model is trained into a lightweight liveness detection model that can distinguish between right and wrong and, like a teacher, grasp key points in specific scenarios.
[0119] In some embodiments, this modulation distillation process can be implemented in several ways: Optionally, modulation distillation can be applied to the logit level, i.e., using a modulation mask to weight the logit differences between different categories, if there is some correspondence between the mask and the category; alternatively, relational knowledge distillation can be employed, calculating the relationships (such as distance or angle) between different locations in the teacher model feature map, and using a modulation mask to weight the loss of these relational differences, allowing students to learn higher-order structured knowledge. It is understood that various forms of attention-guided distillation loss can also be designed to convey knowledge at different levels, and this is not limited here.
[0120] S313. Input the face image to be detected into the liveness detection model for forward propagation calculation to obtain the classification result representing the liveness confidence.
[0121] Refer to step S108, which will not be repeated here.
[0122] In some embodiments, the face liveness detection system performs feature decoupling during the training of the teacher model to ensure effective separation of scene features and liveness features. Specifically, the system decomposes the base model into a shared encoder, a scene branch, and a liveness branch; inputs mixed image samples into the shared encoder to obtain a shared feature representation; inputs the shared feature representation into the scene branch and determines the scene loss component by combining it with scene contrast loss; inputs the shared feature representation into the liveness branch and determines the liveness loss component by combining it with the liveness classification loss of the mixed image samples; calculates the correlation between the scene loss component and the liveness loss component to obtain a decoupling regularization component; and determines the total loss function based on the scene loss component, the liveness loss component, and the decoupling regularization component to adjust the model parameters of the base model, thus obtaining the teacher model.
[0123] Feature decoupling refers to designing a specific model structure and constraining the loss function to ensure that the feature representations learned by the model for different tasks are mathematically independent or uncorrelated, thus avoiding negative interference between tasks. The shared encoder represents the common network portion of the model responsible for extracting general low-level and mid-level features from the input image, such as the first few layers of a ResNet. The shared feature representation is the output of the shared encoder; it is a high-dimensional vector or tensor that theoretically contains all the original information used for scene and liveness detection. The scene loss component and the liveness loss component represent the loss values calculated for the scene recognition task and the liveness classification task, respectively, used to guide the optimization of their respective branches. The decoupling regularization component is an additional penalty term whose value is proportional to the correlation between scene features and liveness features, used to suppress this correlation in the total loss function. The total loss function is the final objective function guiding the update of the entire model parameters, and is composed of a weighted combination of the above loss components.
[0124] Specifically, this feature decoupling operation occurs during the offline training phase of the teacher model. Its core objective is to cultivate an expert-level teacher model with extremely strong judgment capabilities regarding liveness features, and its judgment is completely independent of scene factors such as lighting, background, and camera model. In each training iteration, the face liveness detection system extracts a batch of images from the mixed training dataset and feeds them into the decomposed base model. First, the shared encoder converts each image into a shared feature representation. Subsequently, this representation is simultaneously fed into two parallel branches: the scene branch uses scene contrast loss (such as InfoNCELoss) to learn features that distinguish different scenes and calculates the scene loss component; the liveness branch uses classification loss such as cross-entropy to learn features that distinguish between real and fake objects and calculates the liveness loss component. The crucial decoupling step occurs here: the face liveness detection system designs a method to quantify the statistical correlation between the output (or its internal features) of the liveness branch and the output (or its internal features) of the scene branch. For example, by calculating the sum of the off-diagonal elements of the covariance matrix of the two branch feature vectors, or by training an auxiliary discriminator to attempt to predict scene information using liveness features, and using the discriminator's loss as a relevance metric, this metric constitutes the decoupling regularization component. Ultimately, the total loss function is defined as the weighted sum of the liveness loss, scene loss, and decoupling regularization component. By minimizing this total loss through backpropagation, the face liveness detection system forces the model to actively sever the connection between the feature representations of these two tasks while optimizing liveness classification and scene recognition capabilities, ultimately resulting in a highly decoupled teacher model.
[0125] In some embodiments, this feature decoupling process can be implemented in several ways to enhance the effect: Optionally, an adversarial decoupling method using a gradient reversal layer (GRL) can be employed. The specific steps are as follows: First, an auxiliary scene classifier is added on top of the liveness features extracted from the liveness branch; second, a gradient reversal layer is inserted between the liveness features and the auxiliary classifier. This layer keeps the input unchanged during forward propagation but multiplies the gradient from the auxiliary classifier by a negative constant during backward propagation; finally, during training, the face liveness detection system simultaneously optimizes the liveness branch to minimize the liveness classification loss and optimizes the auxiliary scene classifier to minimize the scene classification loss. Due to the presence of GRL, the gradient of the auxiliary classifier is reversed when propagated back to the liveness branch. This is equivalent to having the liveness branch learn a feature representation that most confuses the auxiliary scene classifier, thus ensuring that the liveness features do not contain any information that can be used to determine the scene. Optionally, decoupling can be achieved using orthogonality constraints. The specific steps are as follows: First, the face liveness detection system flattens the feature maps output by the liveness branch and scene branch at a certain layer into feature vector matrices F_live and F_scene. Second, the product of these two matrices, F_live^T*F_scene, is calculated. Ideally, if the features are orthogonal, the off-diagonal elements of this product matrix should approach zero. Finally, the L1 or L2 norm of the off-diagonal elements of this product matrix is added as a regularization term to the total loss function, directly penalizing the linear correlation between feature vectors mathematically, forcing the model to learn two sets of orthogonal feature bases. It is understandable that other more advanced decoupling techniques, such as mutual information minimization, can be used to achieve the same purpose; this is not limited here. It should be noted that the difficulty of decoupling lies in the fact that liveness cues (such as skin texture) and scene features (such as lighting) are naturally coupled at the pixel level. The above method aims to force the model to abstract independent and more essential semantic features from this coupled appearance.
[0126] In some embodiments, after model deployment, the face liveness detection system will initiate a scene drift detection and adaptive update mechanism to cope with environmental changes. Specifically, the face liveness detection system will calculate the distribution difference measure between the baseline attention mask and the real-time attention mask to obtain a scene drift index. When the scene drift index exceeds a preset drift threshold, key scene feature components are extracted based on preset high-activation regions in the modulation mask. The similarity between the key scene feature components and the pre-stored target scene feature template is calculated to generate a scene consistency evaluation report. Based on the degree of deviation in the scene consistency evaluation report, the weight parameters of the scene-related layers in the liveness detection model are adjusted.
[0127] The scene drift detection and adaptive update mechanism is an automated process deployed on edge devices to maintain the long-term performance stability of the model. The baseline attention mask is a template pre-calculated and stored on the device, representing the attention pattern that the model should have in the ideal target scene. The real-time attention mask is an attention map generated by the model in real time when processing the current real-time video frame. The distribution difference metric is a mathematical tool, such as KL divergence or Wasserstein distance, used to quantify the difference between two attention masks (as probability distributions). The scene drift index is the specific value calculated by this metric. The key scene feature components are the features extracted from the current scene image that best reflect its difference from the original target scene. The target scene feature template is a set of scene descriptors that are more detailed than the attention mask and are stored in the cloud or locally. The scene consistency evaluation report is a structured analysis result that details the type and degree of drift. The scene-related layer refers to the network layer in the model that is mainly responsible for processing information such as environment and background, such as shallow convolutional layers or normalization layers.
[0128] Specifically, this mechanism runs continuously after the liveness detection model is deployed in real-world scenarios (such as access control machines and mobile apps), aiming to address the issue of model performance gradually declining due to environmental changes (such as seasonal changes, interior decoration, and equipment aging). On edge devices, the face liveness detection system utilizes lightweight models or specialized modules to perform periodic (e.g., every minute) or event-triggered (e.g., after multiple consecutive low-confidence judgments) scene analysis on captured video streams. For each image at each analysis moment, the system calculates its real-time attention mask. Then, the system compares this real-time mask with a baseline attention mask embedded in the device, obtaining a scene drift index by calculating a distribution difference metric. The system maintains a time series of this index. When this index consistently exceeds a preset drift threshold (e.g., five consecutive samples exceeding the threshold), the system determines that scene drift has occurred. At this point, an adaptive update process is activated: the system first analyzes the current attention mask, identifies the highly activated regions that differ most from the baseline mask, and extracts more detailed key scene feature components (e.g., color histograms, LBP texture features) from these regions of the original image. The system then matches these feature components with the stored target scene feature templates to generate a scene consistency assessment report. This report might indicate that the current scene brightness is 30% lower than the baseline and the color temperature is bluish. Finally, based on the report's conclusions, the system performs a small, targeted model update, such as slightly increasing the weights of the first few convolutional kernels to enhance sensitivity to dark light details, or adjusting the parameters of the batch normalization layer to compensate for color changes, thus enabling the model to quickly adapt to the new environment.
[0129] In some embodiments, this adaptive update mechanism can be implemented in several ways to improve its efficiency and robustness: Optionally, a statistical process control (SPC) approach can be used for drift detection. The specific steps are as follows: First, instead of simply using a fixed threshold, the face liveness detection system treats the scene drift metric as a quality control parameter in the production process; second, the system uses control charts such as Cumulative Sum (CUSUM) or Exponential Weighted Moving Average (EWMA) to monitor the time series of this metric; finally, these control charts are more sensitive to small but persistent systematic shifts (such as a slow decrease in sharpness due to dust accumulation on the camera lens) than a single threshold method, enabling earlier drift alerts. Optionally, a model committee-based drift detection method can be used. The specific steps are as follows: First, the face liveness detection system deploys a committee on an edge device consisting of multiple (e.g., 3-5) lightweight models with slightly different structures or training data; second, during normal operation, these models should have highly consistent attention masks or predictions for the same input. When a scene shifts, the disagreement between different models increases significantly due to their varying sensitivities to change. The system uses this disagreement level as a scene drift metric, triggering an update mechanism when it exceeds a certain threshold. Understandably, more complex online learning or meta-learning frameworks could also be used to achieve model adaptation; this is not a limitation here. It should be noted that adaptive updates are typically fine-tuned. However, if the evaluation report indicates a radical change in the scene (e.g., from indoors to outdoors), the mechanism may trigger a major version update process, downloading a completely new model from the cloud.
[0130] In some embodiments, to improve the accuracy of scene drift detection, the face liveness detection system employs a more refined adaptive benchmark. Specifically, the system performs cluster analysis on the target scene sample set to obtain multiple typical scene subcategories, and constructs a corresponding reference attention mask template for each typical scene subcategory. It then calculates the matching degree between the attention mask corresponding to each sample in the scene matching data subset and each reference attention mask template to determine the best matching scene category. Based on the best matching scene category and the matching degree, the scene matching data subset is divided into multiple scene subsets. The mean value of the attention mask for each scene subset is calculated and used as the adaptive benchmark mask for the best matching scene category, replacing the benchmark attention mask for scene drift detection.
[0131] Here, the adaptive baseline refers to a baseline used for comparison that is not fixed but dynamically selected or generated based on the current context; clustering analysis is an unsupervised learning method used to automatically group data points based on similarity, such as the K-Means algorithm; typical scene subcategories refer to stable micro-environments with significant differences existing in a macro-deployment scenario, such as a sunny area by a window, an interior lighting area, and a dimly lit area in a corridor within an office; the reference attention mask template is an average mask pre-calculated for each subcategory, representing the ideal attention pattern for that sub-scene; the matching degree is a score that measures the similarity between a real-time mask and a template; the best-matching scene category is the subcategory most similar to the current real-time mask; and the adaptive baseline mask is the final baseline used for drift detection that best matches the current context.
[0132] Specifically, this refined adaptive benchmark strategy is primarily applied to deployment scenarios with complex and ever-changing environments to address the problem that a single global benchmark cannot accurately represent all normal operating states. During the initial deployment or calibration phase, the face liveness detection system first extracts features from the collected target scene sample set and performs cluster analysis on these features (or the attention masks they generate). Assume the clustering results divide the samples into three typical scene subcategories. Next, the face liveness detection system calculates the average of the attention masks for all samples within each subcategory, resulting in three independent reference attention mask templates, which are then stored in the edge device. In subsequent real-time operation, when the face liveness detection system captures a new image frame and calculates its real-time attention mask, it does not immediately compare it with a fixed global benchmark. Instead, it calculates the matching degree (e.g., cosine similarity) between the real-time mask and all three stored reference templates. The subcategory corresponding to the highest matching degree is identified as the best-matching scene category. At this point, the adaptive baseline mask used for scene drift detection is dynamically determined as the reference template for the best matching category. Subsequent drift metric calculations are based on the difference between the real-time mask and this dynamically selected, most relevant baseline template, thereby greatly improving detection accuracy and avoiding false alarms caused by scene switching between several normal subcategories.
[0133] In some embodiments, this adaptive benchmark can be constructed and applied in several ways: Optionally, an online clustering and dynamic template update strategy can be adopted. The specific steps are as follows: First, the face liveness detection system starts with the reference template obtained from the initial clustering; second, the system continuously collects new, correctly identified real-time attention masks and caches them; finally, the system periodically (e.g., every morning) merges the cached new data with the old data and reruns the clustering algorithm. This allows the system to automatically discover new stable scenes in the environment (e.g., a new floor lamp is added to the office), or merge / split existing scene categories, and update the reference attention mask template library accordingly, achieving lifelong learning of the benchmark. Optionally, a hierarchical benchmark matching strategy can be adopted. The specific steps are as follows: First, the face liveness detection system organizes scene templates into a tree-like hierarchical structure. For example, the top layer is "office," with two child nodes: "daytime" and "nighttime." The "daytime" node then has two leaf nodes: "sunny day" and "cloudy day." Second, when matching real-time masks, the system starts from the root node and performs a coarse-to-fine hierarchical matching process. Finally, the system first determines whether it is daytime or nighttime, and then further subdivides under the determined branch. This hierarchical search and matching is more efficient than a flat traversal of all templates and better aligns with human perception of scenes. It is understandable that a more flexible Gaussian Mixture Model (GMM) could be used to model the scene distribution, probabilistically determining the likelihood of the current scene belonging to each subcategory; this is not limited here.
[0134] During this step, it's necessary to determine the scene transition state. When the environment is slowly transitioning from one typical sub-scene to another (e.g., from daytime to dusk), the real-time attention mask may not match any single reference template well, or its match with two templates may be similar. Forcibly selecting one as the baseline would result in artificially high drift metrics due to incomplete matching. To address this, the face liveness detection system can employ a probabilistic baseline fusion strategy. Specifically, after calculating the match between the real-time mask and all reference templates, the system doesn't simply select the highest score. Instead, it uses a Softmax function to convert all match scores into a probability distribution. For example, the probability of the current scene belonging to the daytime template is 0.6, and the probability of it belonging to the nighttime template is 0.4. In this case, the system doesn't select either template but dynamically synthesizes a new adaptive baseline mask based on this probability distribution. The calculation method is: Fusion Baseline = 0.6 * Daytime Template + 0.4 * Nighttime Template. This fused baseline perfectly represents the attention pattern of the current dusk transition state. Using this dynamically synthesized benchmark for drift detection can greatly improve the stability and accuracy of the system during smooth scene transitions.
[0135] In some embodiments, when making the final liveness detection system, a multi-inference verification strategy is adopted to handle samples with high uncertainty. That is, when the liveness confidence is within the uncertainty range, the face image to be detected is re-inputted into the liveness detection model to perform multiple forward propagation calculations to obtain multiple reclassification results; the consistency index of the multiple reclassification results is calculated, and the liveness detection result is determined based on the consistency index.
[0136] Among them, samples with high uncertainty refer to input images that the model has difficulty in clearly distinguishing as real people or fakes. Their characteristic is that the confidence score output by the model is close to the decision boundary (e.g., 0.5). The multiple inference verification strategy is a method to enhance the reliability of the decision by performing multiple independent model inferences on the same sample. The uncertainty interval is a pre-set confidence score range, such as [0.4, 0.6]. Samples falling into this interval will trigger the strategy. The reclassification result refers to the classification score obtained by each independent forward propagation calculation in the multiple inference process. The consistency index is a statistic, such as variance, standard deviation, or information entropy, used to quantify the consistency or dispersion among multiple reclassification results.
[0137] Specifically, this strategy is triggered at the final decision stage of a single liveness detection process, acting as an expert consultation for handling difficult samples. After a user's face image is captured and undergoes its first forward propagation through the liveness detection model, the face liveness detection system obtains an initial liveness confidence score. The system immediately checks whether this confidence score falls within a predefined uncertainty range. If the confidence score is 0.9 (clearly a real person) or 0.1 (clearly a fake), the result is output directly. However, if the confidence score is 0.52, falling within the range [0.4, 0.6], the system pauses the decision-making process and initiates multiple inferences. An effective implementation is to utilize Monte Carlo Dropout: the system keeps the Dropout layer in the model active during inference (it is usually turned off during inference), and then repeatedly inputs the same face image to be detected into the model for, for example, 20 forward propagations. Due to the randomness of Dropout, the computational path for each propagation is slightly different, resulting in 20 not entirely identical reclassification results. Subsequently, the face liveness detection system calculates a consistency index for these 20 results, such as their variance. If the variance is extremely small, it indicates that although the model's initial judgment was uncertain, the conclusions reached after multiple considerations are highly consistent, and the system can adopt the average of these 20 results as the final, more reliable judgment. Conversely, if the variance is large, it indicates that the model's judgment is very unstable and extremely sensitive to small perturbations in the input, which is itself a strong signal of high uncertainty. In this case, the system can output "uncertain" and request the user to perform interactive verification (such as performing a specified action).
[0138] In some embodiments, this multiple inference process can be implemented in several ways to adapt to different hardware and performance requirements: Optionally, a test-time augmentation (TTA) strategy can be employed. The specific steps are as follows: First, when an uncertain sample is detected, the face liveness detection system does not repeatedly input the original image, but instead performs a series of minor, semantically invariant transformations on the original image to generate an image set, such as including slight rotation, cropping, scaling, and horizontal flipping; second, the system inputs each augmented image from this set into the model once (Dropout can be turned off at this time), obtaining a set of reclassification results; finally, the final decision is made by calculating the mean and variance of this set of results. This method simulates observing the same face from different perspectives, helping the model overcome oversensitivity to specific poses or framing. Optionally, a quantized model ensemble strategy can be employed. The specific steps are as follows: First, when deploying the face liveness detection system, it doesn't just deploy a single FP32-precision model, but simultaneously deploys multiple versions of the same model quantized to different precisions (such as INT8, INT4). Second, when encountering uncertain samples, the system simultaneously inputs the sample into all models of different precisions for inference. Finally, because quantization introduces slight computational differences, the outputs of models with different precisions will constitute a set of reclassification results, and the system can make a judgment based on the consistency of this set of results. This method is particularly efficient on hardware that supports mixed-precision computation. Understandably, it's also possible to combine various methods, such as performing MCDropout inference on each image generated by TTA, to obtain richer uncertainty information; this is not limited here.
[0139] In this step, the issue of latency penalty needs to be addressed. While multiple inference strategies can improve the reliability of decisions, the cost is a significant increase in computation time and response latency when handling uncertain samples. For scenarios that prioritize an optimal user experience (such as millisecond-level unlocking), this latency may be unacceptable. To address this, the face liveness detection system can implement a progressive inference and early exit optimization scheme. Specifically, the system does not execute all (e.g., 20) inferences at once, but rather in stages. The system first executes a small number of inferences (e.g., 5), and then immediately calculates a consistency index. The system presets several consistency thresholds: if the variance after 5 inferences is already extremely low or extremely high, it indicates that the conclusion is very clear and no further verification is needed; the system can then exit the loop early and make a decision immediately. Only when the consistency index itself is in an ambiguous intermediate range will the system continue to execute the next batch (e.g., another 5) of inferences and re-evaluate. This process can be repeated until the maximum number of inferences is reached or the consistency index falls into a decisionable range. In this way, most uncertain samples can be resolved in fewer inferences, and only the most difficult samples will suffer the greatest delay penalty, thus achieving a dynamic balance between reliability and response speed.
[0140] In this embodiment, by employing scene feature decoupling and data filtering based on large-model self-supervised learning, combined with a closed-loop technical solution of scene-aware knowledge distillation and dynamic adaptation updates, a highly optimized lightweight liveness detection model can be tailored for specific edge devices and deployment scenarios from massive, coarse-labeled mixed data. This effectively solves the problems of contradiction between model generalization ability and scene specificity, low data utilization efficiency, and performance degradation after deployment in traditional methods. Thus, it achieves high-precision, high-robustness, and continuously adaptive liveness detection capabilities at resource-constrained edge devices, combining innovation with significant practical application value.
[0141] The face liveness detection system in the embodiments of this invention is described below from the perspective of hardware processing. Please refer to [link / reference]. Figure 4 This is a schematic diagram of the physical device structure of a face liveness detection system in an embodiment of this application.
[0142] It should be noted that, Figure 4 The structure of the face liveness detection system shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of the present invention.
[0143] like As shown, the face liveness detection system includes a CPU 401, which can perform various appropriate actions and processes according to a program stored in ROM 402 or a program loaded into RAM 403 from storage section 408, such as executing the methods described in the above embodiments. RAM 403 also stores various programs and data required for system operation. The CPU 401, ROM 402, and RAM 403 are interconnected via bus 404. I / O interface 405 is also connected to bus 404.
[0144] The following components are connected to I / O interface 405: input section 406 including audio input devices, push-button switches, etc.; output section 407 including liquid crystal display (LCD) and audio output devices, indicator lights, etc.; storage section 408 including hard disks, etc.; and communication section 409 including network interface cards such as LAN (Local Area Network) cards, modems, etc. Communication section 409 performs communication processing via a network such as the Internet. Drive 410 is also connected to I / O interface 405 as needed. Removable media 411, such as disks, optical disks, magneto-optical disks, semiconductor memories, etc., are installed on drive 410 as needed so that computer programs read from them can be installed into storage section 408 as needed.
[0145] In particular, according to embodiments of the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of the present invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing computer programs for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 409, and / or installed from removable medium 411. When the computer program is executed by CPU 401, it performs the various functions defined in the present invention.
Claims
1. A method for face liveness detection based on scene optimization, characterized in that, The method is applied to a face living body detection system, and the method comprises the following steps: Extracting a mixed image sample in a mixed training data set of a basic model, and applying a physical driving transformation to the mixed image sample to obtain an enhanced image sample; Taking the enhanced image sample derived from the same image sample as a positive sample pair and taking the enhanced image sample derived from different image samples as a negative sample pair, and calculating a scene contrast loss; A total loss function is composed of a living body classification loss of the mixed image sample and the scene contrast loss, and the training of the basic model is completed to obtain a teacher model; A scene sample in a predefined target scene sample set is input into a scene branch of the teacher model, and a feature of the scene sample is extracted and aggregated to obtain a scene target vector; Each mixed image sample in the mixed training data set is input into the scene branch of the teacher model one by one, and a plurality of scene feature vectors are extracted to form a scene vector set; The vector similarity of the scene target vector and each vector in the scene vector set is calculated, and corresponding image samples are screened from the mixed training data set according to the vector similarity to obtain a scene matching data subset; The teacher model is taken as supervision, and knowledge distillation is performed on the scene matching data subset to generate a living body detection model by using the attention mask modulation distillation loss output by the scene branch of the teacher model; A face image to be detected is input into the living body detection model for forward propagation calculation to obtain a classification result representing the living body confidence.
2. The method of claim 1, wherein, The step of obtaining the teacher model by composing the total loss function from the living body classification loss of the mixed image sample and the scene contrast loss and completing the training of the basic model comprises the following steps: The basic model is decomposed into a shared encoder, a scene branch and a living body branch; The mixed image sample is input into the shared encoder to obtain a shared feature representation; The shared feature representation is input into the scene branch to determine a scene loss component in combination with the scene contrast loss; The shared feature representation is input into the living body branch to determine a living body loss component in combination with the living body classification loss of the mixed image sample; The correlation of the scene loss component and the living body loss component is calculated to obtain a decoupling regularization component; The total loss function is determined according to the scene loss component, the living body loss component and the decoupling regularization component to adjust the model parameters of the basic model to obtain the teacher model.
3. The method of claim 1, wherein, The step of generating the living body detection model by taking the teacher model as supervision, performing knowledge distillation on the scene matching data subset and using the attention mask modulation distillation loss output by the scene branch of the teacher model comprises the following steps: The predefined target scene sample set is input into the scene branch of the teacher model to obtain a reference attention mask; The samples in the scene matching data subset are input into the scene branch of the teacher model to obtain a real-time attention mask; The real-time attention mask and the reference attention mask are fused to obtain a modulation mask; apply the modulation mask to a calculation process of a distillation loss to obtain a modulated distillation loss, and perform knowledge distillation based on the modulated distillation loss to generate a live detection model.
4. The method of claim 3, wherein, After the step of applying the modulation mask to a calculation process of a distillation loss to obtain a modulated distillation loss, and performing knowledge distillation based on the modulated distillation loss to generate a live detection model, the method further comprises: calculating a distribution difference measure between the reference attention mask and the real-time attention mask to obtain a scene drift indicator; when the scene drift indicator exceeds a preset drift threshold, extracting a key scene feature component based on a preset high activation area in the modulation mask; performing similarity calculation on the key scene feature component and a pre-stored target scene feature template to generate a scene consistency evaluation report; adjusting a weight parameter of a scene-related layer in the live detection model according to a deviation degree in the scene consistency evaluation report.
5. The method of claim 4, wherein, Before the step of calculating a distribution difference measure between the reference attention mask and the real-time attention mask to obtain a scene drift indicator, the method further comprises: performing cluster analysis on the target scene sample set to obtain a plurality of typical scene subcategories, and constructing a corresponding reference attention mask template for each typical scene subcategory; calculating a matching degree between an attention mask corresponding to each sample in the scene matching data subset and each reference attention mask template to determine a best matching scene category; dividing the scene matching data subset into a plurality of scene subsets based on the best matching scene category and the matching degree; calculating an attention mask mean value of each scene subset as an adaptive reference mask of the best matching scene category to replace the reference attention mask for scene drift detection.
6. The method of claim 1, wherein, Before the step of extracting a mixed image sample in the mixed training data set of the base model, and applying a physical driving transformation to the mixed image sample to obtain an enhanced image sample, the method further comprises: performing feature extraction on the pre-defined target scene sample set to obtain scene environment parameters, and constructing a generation network based on the scene environment parameters; inputting a preset attack image into the generation network for conversion processing to obtain a synthetic attack sample, and supplementing the synthetic attack sample to the mixed training data set.
7. The method of claim 1, wherein, After the step of inputting the to-be-detected face image into the live detection model for forward propagation calculation to obtain a classification result representing a live body confidence, the method further comprises: when the live body confidence is in an uncertainty interval range, re-inputting the to-be-detected face image into the live detection model to perform multiple forward propagation calculations to obtain a plurality of re-classification results; calculating a consistency indicator of the plurality of re-classification results to determine a live detection result according to the consistency indicator.
8. A face liveness detection system, characterized in that, The face liveness detection system comprises one or more processors and a memory; the memory is coupled with the one or more processors, the memory is configured to store computer program codes, the computer program codes comprise computer instructions, and the one or more processors invoke the computer instructions to enable the face liveness detection system to perform the method according to any one of claims 1-7.
9. A computer-readable storage medium comprising instructions, characterized in that, The instructions enable the face liveness detection system to perform the method according to any one of claims 1-7 when the instructions run on the face liveness detection system.
10. A computer program product, characterised in that, The computer program product enables the face liveness detection system to perform the method according to any one of claims 1-7 when the computer program product runs on the face liveness detection system.
Citation Information
Patent Citations
Living body face detection model training method and device, apparatus and storage medium
CN113052144A
Living body detection method and system
CN116189315A