A method, apparatus, and equipment for live detection based on large-scale model screening and distillation.

By introducing spatial saliency maps and imitation loss to optimize the student model in liveness detection, the computational complexity problem of high-precision liveness detection on resource-constrained devices is solved, improving the accuracy and robustness of liveness detection.

CN121583009BActive Publication Date: 2026-04-21SHENZHEN UNION TIMMY TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SHENZHEN UNION TIMMY TECH CO LTD
Filing Date
2026-01-27
Publication Date
2026-04-21

AI Technical Summary

Technical Problem

When existing liveness detection algorithms are deployed on resource-constrained devices, the computational complexity and memory consumption of high-precision models are too high, making them difficult to apply widely. Furthermore, traditional distillation methods lose key subtle feature information in liveness detection tasks, causing student models to degrade in the face of high-difficulty attacks.

Method used

By acquiring liveness image data, the teacher model generates the first liveness confidence score and intermediate layer feature maps, calculates the spatial saliency map, and performs feature difference weighting with the feature map of the student model. Combining spatial weighted feature imitation loss and confidence imitation loss, the parameters of the student model are optimized to improve its liveness detection accuracy.

Benefits of technology

Without increasing computational complexity, the student model can better mimic the discriminative feature patterns of the teacher model, improving the accuracy and robustness of liveness detection and adapting to deployments on resource-constrained devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121583009B_ABST
    Figure CN121583009B_ABST
Patent Text Reader

Abstract

A method, apparatus, and device for liveness detection based on large model screening and distillation are disclosed, relating to the field of data processing. In this method, liveness image data is input into a preset teacher processing model to generate a first liveness confidence score and a teacher intermediate layer feature map, and a first spatial saliency map is calculated. Liveness image data is then input into a preset student processing model to generate a second liveness confidence score and a student intermediate layer feature map. The feature differences between the teacher and student intermediate layer feature maps are calculated, and these differences are weighted spatially to generate a weighted feature difference. The spatially weighted feature imitation loss and confidence imitation loss are calculated. The internal parameters of the preset student processing model are adjusted and optimized to obtain a target student processing model, and liveness images to be detected are then detected based on this target student processing model. Implementing the technical solution provided in this application improves the accuracy of liveness detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing, specifically to a method, apparatus, and equipment for live detection based on large model screening and distillation. Background Technology

[0002] Liveness detection technology serves as a crucial security barrier in the field of biometric identification. Its core task is to determine whether a collected biological sample (such as a facial image or video) originates from a real individual, rather than being a forgery attack such as a photo, video, or mask. With the widespread adoption of scenarios such as access control and identity authentication, the importance of liveness detection technology is becoming increasingly prominent. To defend against diverse attacks, existing algorithms rely on complex neural networks. Their high accuracy comes with high computational overhead and memory consumption, making them difficult to deploy on resource-constrained devices such as mobile devices, thus limiting their widespread application.

[0003] To address the deployment challenges of high-performance models on resource-constrained devices, existing research has proposed a series of model compression techniques, among which model distillation is a widely adopted method. The core idea of ​​this technique lies in constructing a teacher-student framework: first, a powerful but bloated teacher model is trained, and then its output knowledge is used to guide the training of a lightweight student model. Through knowledge transfer, the student model can simulate the decision-making capabilities of the teacher model with low computational complexity, thus adapting to edge environments.

[0004] However, existing distillation methods have limitations in liveness detection tasks. Traditional distillation only transmits the final class probabilities of the teacher model, which results in the loss of crucial information. This is because liveness detection often relies on local, high-frequency subtle artifacts (such as moiré patterns, printed dots, and differences in material reflection) rather than global features. The high performance of the teacher model stems from its focus on these local discriminative regions. If knowledge is transferred solely through a highly compressed final output, a significant amount of this subtle feature information will be lost, leading to a performance degradation of the student model when facing challenging attacks and insufficient fidelity in knowledge transfer. Summary of the Invention

[0005] This application provides a method, apparatus, and equipment for live organism detection based on large model screening and distillation, which improves the accuracy of live organism detection.

[0006] The first aspect of this application provides a liveness detection method based on large model screening and distillation. The method includes: acquiring liveness image data and inputting the liveness image data into a preset teacher processing model to generate a first liveness confidence score and a teacher intermediate layer feature map associated with a preset first intermediate layer of the preset teacher processing model; calculating and generating a first spatial saliency map based on the first liveness confidence score and the teacher intermediate layer feature map; inputting the liveness image data into a preset student processing model to generate a second liveness confidence score and a student intermediate layer feature map associated with a preset second intermediate layer of the preset student processing model; and calculating the... The feature differences between the teacher's intermediate layer feature map and the student's intermediate layer feature map are analyzed, and the feature differences are weighted spatially using the first spatial saliency map to generate weighted feature differences. Based on the weighted feature differences, a spatially weighted feature imitation loss is calculated. Based on the difference between the first liveness confidence and the second liveness confidence, a confidence imitation loss is calculated. According to the spatially weighted feature imitation loss and the confidence imitation loss, the internal parameters of the preset student processing model are adjusted and optimized to obtain a target student processing model. The liveness image to be detected is then detected based on the target student processing model.

[0007] By employing the aforementioned technical solution, liveness image data is acquired and input into a preset teacher processing model and a preset student processing model, generating a first liveness confidence score, a teacher intermediate layer feature map, a second liveness confidence score, and a student intermediate layer feature map, respectively. Then, based on the first liveness confidence score and the teacher intermediate layer feature map, a first spatial saliency map is calculated to characterize the contribution of feature vectors at each spatial location in the teacher intermediate layer feature map to the first liveness confidence score output by the teacher processing model. Next, the feature differences between the teacher intermediate layer feature map and the student intermediate layer feature map are calculated, and the feature differences are weighted spatially using the first spatial saliency map to generate weighted feature differences. This aims to amplify feature differences at locations with high contribution values ​​in the first spatial saliency map while suppressing feature differences at locations with low contribution values. Subsequently, based on the weighted feature differences and the differences between the first and second liveness confidence scores, spatially weighted feature imitation losses and confidence imitation losses are calculated. Finally, the internal parameters of the preset student processing model are adjusted and optimized based on these two losses to obtain the target student processing model. Then, liveness detection is performed on the images to be detected based on the target student processing model. This method can utilize the discriminative feature knowledge inherent in the teacher model to guide the training process of the student model, improving its liveness detection accuracy without increasing the computational complexity of the student model. By constructing the imitation loss by simultaneously considering feature differences and confidence differences, the degree to which the student model imitates the teacher model can be more comprehensively evaluated, enabling the student model to approach the teacher model in both feature extraction and classification judgment, further improving the accuracy and robustness of liveness detection.

[0008] Optionally, the step of calculating and generating a first spatial saliency map based on the first liveness confidence and the teacher intermediate layer feature map specifically includes: calculating the gradient of the first liveness confidence relative to each feature channel in the teacher intermediate layer feature map to obtain a set of gradient maps with the same number of channels as the teacher intermediate layer feature map; performing a global average pooling operation on each gradient map in the spatial dimension to calculate the channel importance weight of the corresponding feature channel; multiplying each feature channel in the teacher intermediate layer feature map by the corresponding channel importance weight to obtain a weighted feature channel, and linearly combining the weighted feature channels to generate an initial saliency map; and performing non-negative activation processing on the initial saliency map to obtain the first spatial saliency map.

[0009] By adopting the above technical solution and introducing channel importance weights, the differences in the contribution of different feature channels to the confidence level of liveness can be automatically revealed. This makes the generated saliency map focus more on channels and regions with strong discriminative power and ignore channels and regions with weak discriminative power, thereby providing more accurate and efficient spatial guidance for subsequent feature difference weighting.

[0010] Optionally, the step of calculating the feature difference between the teacher intermediate layer feature map and the student intermediate layer feature map, and using the first spatial saliency map to weight the feature difference spatially to generate a weighted feature difference, specifically includes: performing multiple convolution operations on the student intermediate layer feature map to generate an adapted student feature map; extracting teacher channel vectors and student channel vectors based on each shared spatial position of the teacher intermediate layer feature map and the adapted student feature map; and calculating amplitude difference values ​​and structural difference values ​​based on the teacher channel vectors and the student channel vectors, wherein the amplitude difference... The value is the square of the difference between the L2 norm of the teacher channel vector and the L2 norm of the student channel vector. The structural difference value is the difference between a preset value and the cosine similarity between the teacher channel vector and the student channel vector. The magnitude difference value and the structural difference value are weighted and summed to obtain the feature difference value at the corresponding shared spatial position. The feature difference values ​​of all shared spatial positions are used to construct an initial difference map. The first spatial saliency map is linearly transformed to generate a focal weight map. The initial difference map and the focal weight map are multiplied element-wise to obtain the weighted feature difference.

[0011] By employing the aforementioned technical solution, the differences between teacher and student features are accurately compared at the fine-grained spatial location and channel dimensions. This considers not only their numerical differences but also their structural differences, comprehensively characterizing the degree to which student features approximate teacher features. Furthermore, element-wise multiplication of the feature difference map with the focused spatial saliency map allows the feature differences to focus more on the key discriminative regions of the teacher model, reducing attention to non-critical regions. This enables the student model to focus on imitating the most discriminative feature patterns of the teacher model, improving the targeting and effectiveness of feature imitation, and ultimately enhancing the liveness detection performance of the student model.

[0012] Optionally, based on the weighted feature differences, a spatial weighted feature imitation loss is calculated, specifically including: calculating the arithmetic mean of the values ​​of the weighted feature differences at all spatial locations to obtain a first loss component; calculating the standard deviation of the values ​​of the weighted feature differences at all spatial locations to obtain a standard deviation value; adding the first loss component to the standard deviation value to generate a difference threshold; determining all spatial locations in the weighted feature differences where the values ​​are greater than the difference threshold, forming a high difference location set; extracting all values ​​in the weighted feature differences that are located within the high difference location set, and calculating the arithmetic mean of all extracted values ​​to obtain a second loss component; and performing a weighted summation of the first loss component and the second loss component according to a preset first weight coefficient and a preset second weight coefficient to obtain the spatial weighted feature imitation loss.

[0013] By employing the above technical solution, both the overall statistical characteristics and local saliency of feature differences are comprehensively considered. The first loss component is used to measure the overall approximation of student features to teacher features, while the second loss component specifically focuses on the local regions where student and teacher features differ most, causing these regions to contribute additional loss. Introducing the standard deviation as a threshold factor adaptively defines high and low difference locations based on the distribution of feature differences, improving the robustness of the segmentation. Finally, through the weighted summation of the two loss components, the global approximation of student features to teacher features is optimized, while also prompting the student model to focus on improving the local regions with the greatest differences from teacher features. This allows the student model to better mimic the discriminative feature distribution of the teacher model, thereby improving the performance of liveness detection.

[0014] Optionally, the step of calculating the confidence imitation loss based on the difference between the first and second liveness confidence scores specifically includes: calculating the absolute difference between the first and second liveness confidence scores to obtain a preliminary confidence difference; calculating the arithmetic mean of the first and second liveness confidence scores to obtain a confidence mean; and calculating the confidence imitation loss based on a preset formula, the preliminary confidence difference, and the confidence mean.

[0015] By adopting the above technical solutions and introducing preset formulas, the mapping method from confidence difference to loss value can be flexibly designed. For example, the initial confidence difference can be directly used as the loss value to minimize the confidence difference between the student model and the teacher model; alternatively, a normalization formula including the mean confidence level can be used to limit the loss value to a fixed range, making it unaffected by the confidence level; furthermore, nonlinear transformations such as squaring or exponential transformations can be applied to the confidence difference to amplify the contribution of larger differences to the loss function, prompting the student model to focus on optimizing samples with larger differences from the teacher model. By calculating the confidence imitation loss, the degree of imitation of the teacher model by the student model at the liveness confidence output level can be directly measured and optimized, making it not only close to the teacher model in intermediate layer features but also in the final classification and discrimination ability. Combining the confidence imitation loss with the spatially weighted feature imitation loss can simultaneously guide the student model's distillation learning of the teacher model at both the feature and confidence levels, enabling the student model to comprehensively inherit the teacher model's liveness detection capability, improving detection accuracy while maintaining detection efficiency.

[0016] Optionally, adjusting and optimizing the internal parameters of the preset student processing model based on the spatially weighted feature imitation loss and the confidence imitation loss to obtain the target student processing model specifically includes: calculating a first loss weight and a second loss weight, and calculating a total imitation loss based on the first loss weight and the second loss weight; calculating the gradient of the total imitation loss relative to the internal parameters of the preset student processing model using a backpropagation algorithm; and iteratively updating the internal parameters of the preset student processing model using a preset optimizer based on the gradient until the total imitation loss converges or reaches a preset number of training rounds to obtain the target student processing model.

[0017] By adopting the above technical solution, the weights of the two imitation losses are adaptively determined and the total imitation loss is calculated accordingly. This allows for dynamic adjustment of the relative importance of feature imitation and confidence imitation in optimizing the student model during training, enabling the student model to more flexibly adapt to the distillation needs at different stages. Employing a mature optimizer and backpropagation algorithm for gradient descent optimization efficiently and reliably adjusts the internal parameters of the student model, gradually evolving it from its initial state to a target state that effectively imitates the teacher model. By setting convergence conditions or the maximum number of iterations, the termination of the training process can be automatically controlled, obtaining a high-performance student model while preventing overfitting due to over-optimization. The final target student processing model not only makes classification judgments similar to the teacher model on live images but also effectively imitates the key discriminative feature patterns of the teacher model at the feature extraction level, thus achieving a good balance between computational efficiency and detection accuracy.

[0018] Optionally, the step of calculating the first loss weight and the second loss weight, and calculating the total imitation loss based on the first loss weight and the second loss weight, specifically includes: calculating the gradient of the shared parameters in the preset student processing model affected by the spatially weighted feature imitation loss to obtain a first temporary gradient vector; calculating the gradient of the shared parameters in the preset student processing model affected by the confidence imitation loss to obtain a second temporary gradient vector; calculating the L2 norm of the first temporary gradient vector to obtain a first gradient magnitude, and calculating the L2 norm of the second temporary gradient vector to obtain a second gradient magnitude; calculating the first loss weight and the second loss weight based on the first gradient magnitude and the second gradient magnitude; multiplying the spatially weighted feature imitation loss by the first loss weight to obtain a first weighted loss, multiplying the confidence imitation loss by the second loss weight to obtain a second weighted loss, and adding the first weighted loss and the second weighted loss to obtain the total imitation loss.

[0019] By adopting the above technical solution, an adaptive dynamic adjustment mechanism for loss weights is introduced during training. This mechanism automatically determines the proportion of spatially weighted feature imitation loss and confidence imitation loss in the total imitation loss based on their influence on model parameters. First, the gradients of shared parameters affected by spatially weighted feature imitation loss and confidence imitation loss in the preset student processing model are calculated, yielding a first temporary gradient vector and a second temporary gradient vector. These reflect the adjustment strength of the two imitation losses on the model parameters in the current training state. Then, the L2 norm of the first and second temporary gradient vectors is calculated to obtain the corresponding gradient magnitude, which measures the parameter update magnitude caused by each imitation loss. Next, based on the two gradient magnitudes, the weights of the first and second losses are calculated using a preset formula. This calculation method assigns larger weights to loss functions with larger gradient magnitudes and smaller weights to loss functions with smaller gradient magnitudes, thus achieving adaptive weight allocation.

[0020] A second aspect of this application provides a liveness detection device based on large model screening and distillation. The device includes a teacher information generation module, a spatial saliency map generation module, a student information generation module, a loss calculation module, and a model optimization and detection module. The teacher information generation module acquires liveness image data and inputs the liveness image data into a preset teacher processing model to generate a first liveness confidence score and a teacher intermediate layer feature map associated with a preset first intermediate layer of the preset teacher processing model. The spatial saliency map generation module calculates and generates a first spatial saliency map based on the first liveness confidence score and the teacher intermediate layer feature map. The student information generation module inputs the liveness image data into a preset student processing model to generate a second liveness confidence score and a student information generation module associated with a preset first intermediate layer of the preset teacher processing model. A student processing model is associated with a preset second intermediate layer and a student intermediate layer feature map. The loss calculation module calculates the feature differences between the teacher intermediate layer feature map and the student intermediate layer feature map, and uses the first spatial saliency map to weight the feature differences spatially, generating a weighted feature difference. Based on the weighted feature difference, a spatially weighted feature imitation loss is calculated. Based on the difference between the first liveness confidence and the second liveness confidence, a confidence imitation loss is calculated. The model optimization and detection module adjusts and optimizes the internal parameters of the preset student processing model according to the spatially weighted feature imitation loss and the confidence imitation loss to obtain a target student processing model, and detects the liveness image to be detected based on the target student processing model.

[0021] A third aspect of this application provides an electronic device including a processor, a memory, a user interface, and a network interface, wherein the memory is used to store instructions, the user interface and the network interface are both used to communicate with other devices, and the processor is used to execute the instructions stored in the memory to cause the electronic device to perform the method as described in any of the foregoing.

[0022] A fourth aspect of this application provides a computer-readable storage medium storing instructions that, when executed, perform the method described in any of the preceding descriptions.

[0023] In summary, one or more technical solutions provided in this application have at least the following technical effects or advantages:

[0024] This method combines intermediate layer features from the teacher model with spatial saliency maps, and designs spatially weighted feature imitation loss and confidence imitation loss to target key features in liveness detection tasks. This enhances the student model's ability to capture subtle forgery features and improves classification accuracy. Simultaneously, this method significantly reduces the computational complexity and memory footprint of the student model, enabling it to maintain high accuracy while adapting to resource-constrained mobile and edge devices, effectively improving the practicality and robustness of liveness detection technology. Attached Figure Description

[0025] Figure 1 This is a schematic flowchart of a liveness detection method based on large model screening and distillation disclosed in an embodiment of this application;

[0026] Figure 2 This is another schematic diagram of a liveness detection method based on large model screening and distillation disclosed in an embodiment of this application;

[0027] Figure 3 This is a schematic diagram of a liveness detection device based on large-scale model screening and distillation disclosed in an embodiment of this application;

[0028] Figure 4 This is a schematic diagram of the structure of an electronic device disclosed in an embodiment of this application.

[0029] Explanation of reference numerals in the attached diagram: 301, Teacher information generation module; 302, Spatial saliency map generation module; 303, Student information generation module; 304, Loss calculation module; 305, Model optimization and testing module; 400, Electronic device; 401, Processor; 402, Communication bus; 403, User interface; 404, Network interface; 405, Memory. Detailed Implementation

[0030] To enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments.

[0031] In the description of the embodiments of this application, the words "for example" or "for instance" are used to indicate examples, illustrations, or explanations. Any embodiment or design that is described as "for example" or "for instance" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design options. Rather, the use of the words "for example" or "for instance" is intended to present the relevant concepts in a specific manner.

[0032] In the description of the embodiments of this application, the term "multiple" means two or more. For example, multiple systems means two or more systems, and multiple screen terminals means two or more screen terminals. Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the indicated technical features. Thus, a feature defined with "first" or "second" may explicitly or implicitly include one or more of that feature. The terms "comprising," "including," "having," and variations thereof all mean "including but not limited to," unless otherwise specifically emphasized.

[0033] This application provides a liveness detection method based on large model screening and distillation, referring to... Figure 1 , Figure 1 This is a flowchart illustrating a liveness detection method based on large-scale model screening and distillation, provided in an embodiment of this application. The method is applied to a server, which executes the liveness detection program based on large-scale model screening and distillation. The server can be a single server, a server cluster consisting of multiple servers, or a cloud computing service center. The method includes steps S101 to S107, as follows:

[0034] Step S101: Obtain liveness image data and input the liveness image data into the preset teacher processing model to generate a first liveness confidence score and a teacher intermediate layer feature map associated with the preset first intermediate layer of the preset teacher processing model.

[0035] In step S101, the liveness image data refers to digital image files containing real human faces or other biometric features. These files are the raw materials used to train and validate the liveness detection model, such as a real-time frontal photo of a user captured by a camera. The pre-trained teacher processing model refers to a large-scale, high-performance deep learning model that achieves very high accuracy in liveness detection tasks, but typically involves high computational cost and slow inference speed. Examples include a large Vision Transformer model or a deep convolutional neural network such as ResNet-152. The first liveness confidence score is a quantified value output by the pre-trained teacher processing model after analyzing an input liveness image. This value represents the confidence level of the model's judgment that the image is "live," and is usually a probability value between 0 and 1. The closer the value is to 1, the higher the probability that the model considers the image to be live. The pre-selected first intermediate layer refers to a specific layer pre-selected within the complex network structure of the pre-trained teacher processing model. This layer is neither an input layer nor the final output layer; it is generally a deep convolutional layer or attention layer capable of extracting rich semantic information. The teacher intermediate layer feature map refers to the multidimensional data tensor generated in the preset first intermediate layer when the live image data flows through the preset teacher processing model. It contains the feature representation of the image at a specific level of abstraction, such as contour, texture, and component combination information.

[0036] Specifically, the server first receives a batch of liveness image data from a storage device or via a network interface. For each image, the server performs preprocessing, including resizing the image to the input size required by the preset teacher processing model, such as 224x224 pixels, and normalizing it, for example, scaling the pixel values ​​from 0 to 255 to 0 to 1. Then, the server uses this preprocessed image as input and feeds it into the preset teacher processing model already loaded into memory, performing a complete forward propagation computation. During this process, data in the model network is passed and processed layer by layer. The computation ultimately produces two key outputs: first, in the model's final classification layer, a specific numerical value is obtained through an activation function such as Sigmoid or Softmax, namely the first liveness confidence score; second, the server intercepts and saves the activation values ​​generated when the data flows through the preset first intermediate layer; this multidimensional array is the teacher intermediate layer feature map required for subsequent steps.

[0037] Step S102: Calculate and generate the first spatial saliency map based on the first liveness confidence and the teacher intermediate layer feature map.

[0038] In step S102, the first spatial saliency map refers to a two-dimensional map with the same spatial dimension as the teacher's intermediate layer feature map. Each pixel value in this map represents the degree of attention or importance weight that the teacher model pays to the features at the corresponding spatial location in the teacher's intermediate layer feature map when making a "live" judgment. For example, if the teacher processing model is preset to mainly rely on the small details of the eyes and mouth to determine whether someone is alive, then on the saliency map, the pixel values ​​corresponding to the eye and mouth areas will be relatively high, while the pixel values ​​corresponding to the background wall areas will be relatively low.

[0039] Specifically, to calculate and generate the first spatial saliency map, the server performs a gradient-based attribution analysis process. First, starting with the first liveness confidence obtained in step S101, the server initiates a backpropagation process from the model output to a preset first intermediate layer. This process calculates the gradient of the first liveness confidence relative to each element in the teacher intermediate layer feature map. Then, the server performs global average pooling on this gradient tensor along the channel dimension, calculating a single weight value for each channel of the feature map. This weight represents the average contribution of that channel to the final liveness determination. Finally, the server multiplies each channel of the teacher intermediate layer feature map by its corresponding weight value and sums all the weighted channels along the channel dimension. This merges a multi-channel feature map into a single-channel two-dimensional image, which is the first spatial saliency map. For ease of subsequent use, the server also performs a normalization process on this image, ensuring that all pixel values ​​fall within a standard range, such as 0 to 1.

[0040] In one possible implementation, a first spatial saliency map is calculated and generated based on the first liveness confidence score and the teacher intermediate layer feature map, specifically including:

[0041] Step S1021: Calculate the gradient of the first liveness confidence relative to each feature channel in the teacher intermediate layer feature map, and obtain a set of gradient maps with the same number of channels as the teacher intermediate layer feature map.

[0042] In step S1021, the gradient refers to the direction and magnitude of the rate of change of a scalar function relative to all its variables in multivariable calculus. Here, it specifically refers to the rate of change of the single output value of the first liveness confidence score relative to each independent element value in the teacher intermediate layer feature map. Each feature channel refers to a slice of the multidimensional data volume of the teacher intermediate layer feature map in the depth dimension. Each slice is a two-dimensional feature map, representing a specific pattern extracted by the model. The gradient map set refers to a new data volume with the same dimensions as the teacher intermediate layer feature map, which contains gradient maps corresponding one-to-one with each channel of the original feature map. Each gradient map reflects the sensitivity of the final confidence score to each spatial location in that feature channel.

[0043] Specifically, when the server performs this step, it uses the scalar value obtained in step S101, i.e., the first liveness confidence, as the starting point for backpropagation. The server utilizes the automatic differentiation function in the deep learning framework to calculate the partial derivative of this confidence value with respect to each numerical element in the teacher intermediate layer feature map obtained in step S101. This calculation process starts from the model's output layer and propagates the gradient layer by layer until the preset first intermediate layer. After the calculation is complete, the server obtains a tensor with the exact same size as the teacher intermediate layer feature map. For example, if the teacher intermediate layer feature map has a height of 14, a width of 14, and 512 channels, then the calculated gradient tensor will also have a size of 14x14x512. This gradient tensor is the set of gradient maps to be obtained in this step.

[0044] Step S1022: For each gradient map in the gradient map set, perform global average pooling operation in the spatial dimension to calculate the channel importance weight of the corresponding feature channel.

[0045] In step S1022, the gradient map refers to the two-dimensional gradient matrix corresponding to a single feature channel in the gradient map set. Spatial dimension refers to the height and width of the gradient map. Global average pooling is a dimensionality reduction operation that compresses the entire matrix into a single value by calculating the arithmetic mean of all elements in a two-dimensional matrix. The channel importance weight is the scalar value obtained after performing global average pooling on a gradient map. It quantifies the average contribution of the corresponding feature channel to the final "liveness" determination; a positive value indicates positive promotion, and a negative value indicates negative inhibition.

[0046] Specifically, the server retrieves the set of gradient maps generated in step S1021. This set contains gradient maps with the same number of channels as the feature maps in the teacher's intermediate layer. The server iterates through each gradient map in this set. For each gradient map, it sums all its spatial dimensions (height multiplied by width) and divides the sum by the total number of elements in the spatial dimension, which is the product of height and width. This calculation process is called global average pooling. For example, for a 14x14 gradient map, the server calculates the average of these 196 gradient values. After calculating each gradient map, a corresponding channel importance weight is obtained. Once all gradient maps have been processed, the server receives a list or one-dimensional array with a length equal to the number of feature channels, where each element is a channel importance weight.

[0047] Step S1023: Multiply each feature channel in the teacher intermediate layer feature map by the corresponding channel importance weight to obtain the weighted feature channel, and then perform a linear combination of the weighted feature channels to generate the initial saliency map.

[0048] In step S1023, the weighted feature channel refers to the new feature channel obtained by performing a scalar multiplication operation between an original feature channel in the teacher's intermediate layer feature map and the corresponding channel importance weight calculated in step S1022. Linear combination here specifically refers to the operation of summing the values ​​of all corresponding positions of the weighted feature channels in space, thereby merging multiple channels into a single channel. The initial saliency map is the single-channel two-dimensional map generated after linear combination. It initially integrates the information of all feature channels and weights them according to the importance of each channel to the final decision. Regions with larger values ​​in the map represent regions whose features contribute more comprehensively and are more important to the liveness detection.

[0049] Specifically, the server needs to use two sets of data simultaneously: one is the original teacher intermediate layer feature map from step S101, and the other is the channel importance weight list from step S1022. The server first creates a two-dimensional zero matrix with the same spatial size as the feature map but only one channel, which is used as an accumulator to generate the initial saliency map. Then, the server iterates through all feature channels, from the first to the last. In each iteration, the server extracts the k-th feature channel (a two-dimensional matrix) and its k-th channel importance weight (a scalar). The server multiplies each element of this two-dimensional matrix by this scalar weight to obtain the weighted feature channel. Subsequently, the server adds this newly generated weighted feature channel element-wise to the previously created accumulator matrix. After all channels have completed this weighting and accumulation process, the final result in the accumulator matrix is ​​the initial saliency map to be generated.

[0050] Step S1024: Perform non-negative activation processing on the initial saliency map to obtain the first spatial saliency map.

[0051] In step S1024, non-negative activation processing refers to applying an activation function to each pixel value in the initial saliency map. This function retains all values ​​greater than or equal to zero, while forcing all values ​​less than zero to zero. This operation is performed by the Modified Linear Unit (ReLU) function. Its purpose is to filter out feature regions that negatively impact or inhibit the "live" classification result, focusing only on regions that contribute positively. The first spatial saliency map refers to the final two-dimensional map obtained after non-negative activation processing. It clearly indicates which regions in the image, from the teacher model's perspective, represent key positive evidence for determining "liveness."

[0052] Specifically, the server obtains the initial saliency map generated in step S1023. This is a single-channel two-dimensional matrix that may contain positive, negative, and zero values. The server iterates through each element in this matrix. For each value, the server performs a check: if the value is less than zero, it is replaced with zero; if the value is greater than or equal to zero, its original value is left unchanged. After performing this check and possible operations on all elements, the server obtains a new two-dimensional matrix. This new matrix will no longer contain any negative values; it is the final required first-space saliency map. To facilitate subsequent weighted calculations, the server may also choose to perform a normalization operation on this map, such as linearly scaling all its values ​​to the range of 0 to 1, but this is not mandatory for this step.

[0053] Step S103: Input the liveness image data into the preset student processing model to generate the second liveness confidence and the student intermediate layer feature map associated with the preset second intermediate layer of the preset student processing model.

[0054] In step S103, the preset student processing model refers to a lightweight deep learning model with a relatively simple structure and low computational cost, which is intended to be optimized through training. Its goal is to achieve inference speeds significantly faster than the teacher model while maintaining high accuracy, such as a MobileNetV3 or ShuffleNetV2 model. The second liveness confidence score refers to the quantitative value output by the preset student processing model after analyzing the same liveness image data, representing the degree to which it judges the image to be "live." The preset second intermediate layer refers to a specific intermediate layer in the network structure of the preset student processing model that corresponds in function or network depth to the preset first intermediate layer of the teacher model. The student intermediate layer feature map refers to the feature representation generated in the preset second intermediate layer when the same liveness image data flows through the preset student processing model.

[0055] Specifically, the server executes this step in parallel or sequentially. It feeds the same preprocessed liveness image data as in step S101 into the preset student processing model. It's worth noting that this student processing model is the version used in the current training iteration, and its internal parameters will be updated in subsequent steps. Similar to the teacher model's processing flow, the server performs a complete forward propagation computation on the student model. This computation also produces two core outputs: first, in the student model's final classification layer, a second liveness confidence score representing its current judgment ability is obtained; second, the server also extracts the corresponding activation values ​​from the student model's preset second intermediate layer, thereby obtaining the student intermediate layer feature map.

[0056] Step S104: Calculate the feature differences between the teacher intermediate layer feature map and the student intermediate layer feature map, and use the first spatial saliency map to weight the feature differences spatially to generate weighted feature differences.

[0057] In step S104, feature difference refers to the numerical inconsistency between the teacher's intermediate layer feature map and the student's intermediate layer feature map, reflecting the gap between the student model and the teacher model in feature extraction ability. Spatial position-wise weighting is a fine-tuning operation that uses the first spatial saliency map to amplify or reduce the difference values ​​at different spatial positions in the feature difference map. Its core idea is to allow the student model to prioritize learning regions that the teacher model considers important. Weighted feature difference refers to the final result obtained after the above weighting operation, reflecting the focused differences.

[0058] Specifically, the server first ensures that the teacher's intermediate layer feature map and the student's intermediate layer feature map have the same dimensions. If their number of channels, height, or width differs, the server will first adjust the size of the student's intermediate layer feature map to be completely consistent with the teacher's intermediate layer feature map through operations such as convolution, pooling, or interpolation. Then, the server performs element-wise subtraction on these two size-aligned feature maps to obtain an initial feature difference tensor. Next, the server retrieves the first spatial saliency map generated in step S102 and ensures that its spatial dimensions are consistent with the feature difference tensor, adjusting the dimensions if necessary. Finally, the server performs element-wise multiplication of the feature difference tensor with the first spatial saliency map, also known as the Hadamard product. The effect of this operation is that in regions with high values ​​in the saliency map, such as the eye region, the corresponding feature difference values ​​are preserved or even amplified; while in regions with low values ​​in the saliency map, such as the background region, the corresponding feature difference values ​​are significantly weakened. The final importance-modulated difference tensor obtained by the server is the weighted feature difference.

[0059] In one possible implementation, the feature differences between the teacher's intermediate layer feature map and the student's intermediate layer feature map are calculated, and the feature differences are weighted spatially using a first spatial saliency map to generate a weighted feature difference. Specific steps S1041-S1046 are as follows:

[0060] Step S1041: Perform multiple convolution operations on the student intermediate layer feature map to generate a student-adapted feature map.

[0061] In step S1041, the student intermediate layer feature map refers to the feature representation extracted from the student network model to be optimized, located in a certain intermediate layer. Its dimensions, especially the number of channels, may differ from the corresponding layer of the teacher model. Multiple convolution operations refer to the process of applying one or more convolution kernels to the student intermediate layer feature map for feature transformation. Its main purpose is not to extract deeper semantic features, but to adjust the dimensions of the feature map, especially the number of channels. Adapting the student feature map refers to the new feature map obtained after convolution operations that matches the teacher intermediate layer feature map in terms of channel dimension. This allows the feature representation of the student model to be directly compared with the feature representation of the teacher model in the same dimensional space.

[0062] Specifically, the server first obtains the intermediate layer feature maps of the student network. Since student networks are typically more lightweight than teacher networks, their feature maps may have fewer channels. For example, the teacher's intermediate layer feature map might have 512 channels, while the student's might have 256. To enable subsequent channel-by-channel vector comparisons, the server aligns the dimensions of the student's feature maps. The server constructs one or more consecutive convolutional layers, typically using 1x1 kernels, as these kernels can efficiently change the number of channels without altering the feature map's spatial dimensions (height and width). The server inputs the student's intermediate layer feature maps into these convolutional layers, setting the output channel count to be equal to that of the teacher's intermediate layer feature maps. After this convolutional adaptation process, the output feature map is the adapted student feature map, with the same spatial dimensions as the original student feature map, but with the same number of channels as the teacher's intermediate layer feature map. Figure 1 To.

[0063] Step S1042: Based on each shared spatial location of the teacher intermediate layer feature map and the adapted student feature map, extract the teacher channel vector and the student channel vector.

[0064] In step S1042, a shared spatial location refers to a point on both the teacher's intermediate layer feature map and the adapted student feature map that has the same spatial coordinates, i.e., the same height and width index values. The teacher channel vector is a one-dimensional vector composed of all values ​​extracted along the depth or channel dimension of the feature map at a given shared spatial location. The length of this vector is equal to the number of channels in the feature map, and it encodes the activation intensity of all feature patterns extracted by the teacher model at that spatial point. The student channel vector is similar to the teacher channel vector; it is a one-dimensional vector extracted along the channel dimension from the adapted student feature map at the same shared spatial location.

[0065] Specifically, the server now possesses two feature maps with identical dimensions: one is the teacher intermediate layer feature map, and the other is the adapted student feature map generated in step S1041. Assume they both have a height of H, a width of W, and a number of channels C. The server traverses each shared space location in a preset order, such as from left to right and from top to bottom. The coordinates of each location can be represented as (h, w), where h ranges from 0 to H minus 1, and w ranges from 0 to W minus 1. When processing each coordinate point (h, w), the server extracts the values ​​of all C channels at that point from the teacher intermediate layer feature map, forming a teacher channel vector of length C. Simultaneously, the server also extracts the values ​​of all C channels at the identical coordinate point (h, w) from the adapted student feature map, forming a student channel vector of length C. This extraction process is repeated for all H multiplied by W shared space locations.

[0066] Step S1043: Based on the teacher channel vector and the student channel vector, calculate the amplitude difference value and the structural difference value. The amplitude difference value is the square of the difference between the L2 norm of the teacher channel vector and the L2 norm of the student channel vector. The structural difference value is the difference between the preset value and the cosine similarity between the teacher channel vector and the student channel vector.

[0067] In step S1043, the L2 norm, also known as the Euclidean norm, is the square root of the sum of the squares of all elements in a vector. It measures the length or amplitude of a vector, representing the overall strength of the feature response at a certain spatial location. The amplitude difference value is the square of the difference between the L2 norm of the teacher channel vector and the L2 norm of the student channel vector. It quantifies the degree of difference between the overall strength of the student model's feature response and that of the teacher model at a certain spatial location. Cosine similarity is an index that measures the consistency of the directions of two vectors. Its value ranges from -1 to 1, with values ​​closer to 1 indicating greater consistency. The structural difference value is a preset ideal value, usually 1, and the difference between it and the actual calculated cosine similarity between the two channel vectors. It quantifies the degree of deviation between the feature combination pattern learned by the student model at that spatial location and that of the teacher model. The preset value is usually set to 1, representing the ideal state where the teacher and student channel vectors are completely consistent in direction.

[0068] Specifically, for each pair of teacher channel vectors and student channel vectors obtained from step S1042, the server performs the following calculations. First, it calculates the L2 norm of the teacher channel vector, which is the square root of the sum of the squares of all its elements. Similarly, it calculates the L2 norm of the student channel vector. Then, it subtracts the two L2 norm values ​​and squares the result, obtaining the magnitude difference value. Next, the server calculates the dot product of the two vectors, which is the sum of the product of their corresponding elements. Then, it divides the result of the dot product by the product of the L2 norms of the two vectors to obtain their cosine similarity. Finally, it subtracts this cosine similarity value from a preset value, such as 1.0, obtaining the structural difference value. These two difference values, the magnitude difference value and the structural difference value, together describe the difference between the student and the teacher at that spatial point.

[0069] Step S1044: Perform a weighted summation of the amplitude difference value and the structural difference value to obtain the characteristic difference value at the corresponding shared spatial location.

[0070] In step S1044, weighted summation refers to the process of multiplying the magnitude difference value and the structural difference value by their respective weighting coefficients and then summing them to obtain a comprehensive difference index. The weighting coefficients are used to adjust the relative importance of the two differences in the total difference. The feature difference value refers to the final scalar value obtained after weighted summation at a single shared spatial location. It comprehensively represents the combined gap between the student model and the teacher model at that point in terms of feature strength and feature structure.

[0071] Specifically, the server pre-sets or reads two hyperparameters from the configuration: amplitude difference weight and structural difference weight. These two weights determine whether, when evaluating the learning performance of the student model, more attention is paid to the overall strength of its feature responses and their matching degree with the teacher, or to the similarity between its feature combination patterns and the teacher's. For each shared spatial location, the server obtains the amplitude difference value and structural difference value calculated in step S1043. Then, the server multiplies the amplitude difference value by its corresponding weight, multiplies the structural difference value by its corresponding weight, and then adds these two products together. The result of this weighted sum is the single feature difference value at that shared spatial location.

[0072] Step S1045: Combine the feature difference values ​​of all shared spatial locations to form an initial difference map.

[0073] In step S1045, the initial difference map refers to a single-channel two-dimensional image whose spatial dimensions are the same as those of the intermediate feature maps of the teacher and student. The value of each pixel on the image is the feature difference value calculated at the corresponding shared spatial location. This image visually shows the distribution of the difference between the student model and the teacher model in various regions of the image.

[0074] Specifically, before starting the calculation, the server first creates a new two-dimensional matrix with the same spatial dimensions as the teacher's intermediate layer feature map, namely height H and width W, and initializes it with zeros. During the loop traversal in steps S1042 to S1044, whenever the server calculates a feature difference value located at a shared spatial position (h, w), it fills this value into the corresponding position (h, w) of the newly created two-dimensional matrix. When all feature difference values ​​of H multiplied by W shared spatial positions have been calculated and filled into the matrix, this filled two-dimensional matrix is ​​the initial difference map to be generated in this step.

[0075] Step S1046: Perform a linear transformation on the first spatial saliency map to generate a focal weight map, and multiply the initial difference map and the focal weight map element by element to obtain the weighted feature difference.

[0076] In step S1046, the linear transformation refers to applying a simple mathematical operation, in the form of "multiplying by a coefficient and adding a constant," to each pixel value in the first spatial saliency map. The purpose is to adjust the numerical range and distribution of the saliency map so that it can play a more ideal role as a weight. The focal weight map is the new map obtained after linearly transforming the first spatial saliency map. It is designed to highlight or adjust the weights of regions that the teacher model considers important. Element-wise multiplication, also known as the Hadamard product, involves multiplying corresponding elements of two matrices of the same size to generate a new matrix of the same size. The weighted feature difference is the final product of this series of steps. It is the result of weighting the initial difference map with the focal weight map. The values ​​in the map reflect the feature differences between students and teachers within the key regions of focus for the teacher model. These differences will be optimized in subsequent model training.

[0077] Specifically, the server first obtains the first spatial saliency map calculated in the previous step. Simultaneously, the server defines the parameters of a linear transformation: a multiplication coefficient and an addition constant. For example, a simple transformation could be "multiply each pixel value by 1 and add 1." The server applies this transformation to every pixel in the first spatial saliency map, generating a focal weight map. This ensures that even in regions with zero saliency, the difference values ​​retain a basic weight, preventing complete information loss. Then, the server obtains the initial difference map generated in step S1045. Since the focal weight map and the initial difference map have the exact same spatial dimensions, the server can multiply them element-wise. That is, the values ​​at the same coordinates (h, w) of the two maps are multiplied, and the result is used as the new value for the output map at position (h, w). After performing this operation on all positions, the resulting new map is the final weighted feature difference.

[0078] Step S105: Calculate the spatial weighted feature imitation loss based on the weighted feature differences.

[0079] In step S105, the spatially weighted feature imitation loss is a scalar value used to quantify the magnitude of the differences in weighted features. It plays a crucial penalty role throughout the model training process. A larger loss value means the student model performs worse in imitating features in the key regions that the teacher model focuses on, and vice versa. The training objective is to minimize this loss value by adjusting the parameters of the student model.

[0080] Specifically, the server calculates the spatially weighted feature imitation loss based on the weighted feature difference tensor obtained in step S104. A common calculation method is to calculate the mean squared error of all elements in the tensor. The server iterates through each element in the weighted feature difference tensor, calculates its square, sums up the squared values ​​of all elements, and finally divides by the total number of elements to obtain an average value. This final average value is a non-negative scalar, namely the spatially weighted feature imitation loss. This loss value directly reflects the overall performance of the student model in imitating the "focus" of the teacher model.

[0081] In one possible implementation, the spatial weighted feature imitation loss is calculated based on the weighted feature difference, specifically including steps S1051-S1056, as follows:

[0082] Step S1051: Calculate the arithmetic mean of the weighted feature differences at all spatial locations to obtain the first loss component.

[0083] In step S1051, the weighted feature difference refers to the two-dimensional difference map generated in the preceding step S1046 after spatial significance weighting, where each value represents the degree of comprehensive feature difference between the student model and the teacher model at the corresponding spatial location. The arithmetic mean is the result obtained by summing all the values ​​in a set and dividing by the number of values ​​in that set; it reflects the central tendency or average level of the set of values. The first loss component is the result obtained by calculating the arithmetic mean of all the values ​​in the entire weighted feature difference map; it is used to represent the global average imitation difference between the student model and the teacher model on the current input sample.

[0084] Specifically, the server first obtains the weighted feature difference map calculated in step S1046, which is a two-dimensional matrix. The server needs to calculate the arithmetic mean of all elements in this matrix. To do this, the server iterates through every spatial position of the two-dimensional matrix, summing the values ​​at all positions to obtain a total. Simultaneously, the server counts the total number of elements in the matrix, which is equal to the matrix's height multiplied by its width. Finally, the server divides the calculated sum of values ​​by the total number of elements, and the result is the first loss component. This component can be considered a basic loss, measuring the student model's overall imitation performance.

[0085] Step S1052: Calculate the standard deviation of the weighted feature differences across all spatial locations to obtain the standard deviation value.

[0086] In step S1052, standard deviation is a statistic used to measure the dispersion of a set of values. It represents the degree to which data points deviate from their arithmetic mean. The larger the standard deviation, the greater the difference between most values ​​and the mean, and the more uneven the distribution. The standard deviation value refers to the standard deviation calculated for all values ​​in the weighted feature difference plot. It is used to quantify the volatility or inconsistency of feature differences at different spatial locations. A higher standard deviation value means that the differences are small in some areas and very large in others.

[0087] Specifically, when calculating the standard deviation, the server utilizes the first loss component, i.e., the arithmetic mean, calculated in step S1051. The server iterates through each spatial location of the weighted feature difference map again. For each value at a location, the server calculates the difference between it and the first loss component, and then squares this difference. The server sums up the squared differences calculated for all locations to obtain a total sum of squares. Next, this total sum of squares is divided by the total number of elements in the matrix to obtain the variance. Finally, the server takes the arithmetic square root of the calculated variance, and the result is the standard deviation.

[0088] Step S1053: Add the first loss component to the standard deviation to generate the difference threshold.

[0089] In step S1053, the difference threshold is a dynamically generated value used as a criterion to distinguish spatial locations with particularly significant differences. This threshold is not a fixed constant, but is dynamically set based on the statistical properties of the current weighted feature difference map itself, namely the mean and standard deviation. This allows it to adapt to different difference distributions generated by different input samples.

[0090] Specifically, the server obtains the first loss component calculated in step S1051 and the standard deviation calculated in step S1052. Then, the server performs a simple addition operation, adding the first loss component to the standard deviation. This sum is defined as the difference threshold for this calculation. Using the "mean plus standard deviation" as a threshold is a common statistical method used to identify numerical points in a dataset that are significantly above the average level; these points are often considered outliers or key areas requiring special attention.

[0091] Step S1054: Determine all spatial locations in the weighted feature differences where the values ​​are greater than the difference threshold, forming a set of high difference locations.

[0092] In step S1054, the high-discrepancy location set refers to a set that records multiple spatial location coordinates, where the weighted feature difference values ​​corresponding to these recorded locations all exceed the difference threshold calculated in step S1053. This set identifies several "difficult regions" in the image where the student model performs the worst and differs most significantly from the teacher model.

[0093] Specifically, the server initializes an empty list or set to store the coordinates of spatial locations that meet the conditions. Then, the server iterates through each spatial location in the weighted feature difference map, for example, location (h, w), where h is the row index and w is the column index. At each location, the server compares the value at that location with the difference threshold generated in step S1053. If the value at that location is strictly greater than the difference threshold, the server adds the coordinates of that location, i.e., (h, w), to the previously initialized list or set. After iterating through all spatial locations, this list or set constitutes a complete set of high-difference locations.

[0094] Step S1055: Extract all values ​​located in the set of high-discrepancy positions from the weighted feature differences, and calculate the arithmetic mean of all extracted values ​​to obtain the second loss component.

[0095] In step S1055, the second loss component refers to calculating the arithmetic mean of the weighted feature difference values ​​for only those locations identified as having high differences. This component focuses on the regions where the student model performs the worst and can be seen as a kind of "hard example mining" loss, the purpose of which is to drive the model to focus on improving its performance in these difficult regions.

[0096] Specifically, the server first obtains the set of high-discrepancy locations determined in step S1054. The server initializes an accumulator and a counter, both with initial values ​​of zero. Next, the server iterates through each coordinate in the set of high-discrepancy locations. For each coordinate, the server uses it to look up and extract the corresponding value from the weighted feature difference map, then adds this value to the accumulator and increments the counter. After iterating through all high-discrepancy locations, the server checks the counter value. If the counter is not zero, it indicates the existence of high-discrepancy locations, and the server divides the sum of the accumulator values ​​by the counter value; the result is the second loss component. If the counter is zero, it indicates that no location's difference value exceeds the threshold, and the second loss component is typically set to zero.

[0097] Step S1056: Based on the preset first weight coefficient and the preset second weight coefficient, the first loss component and the second loss component are weighted and summed to obtain the spatial weighted feature imitation loss.

[0098] In step S1056, the preset first weight coefficient and the preset second weight coefficient are two pre-defined hyperparameters, which are used to adjust the relative importance of the first and second loss components in the final total loss, respectively. By adjusting these two coefficients, the focus of model optimization can be controlled, whether it is more inclined to improve the overall average performance or to overcome local difficulties. The spatially weighted feature imitation loss is the final result calculated in this series of steps. It is a single scalar value that combines the global average difference and the difference in local difficult regions. It will be used as part of the total loss function to update the parameters of the student network model through the backpropagation algorithm.

[0099] Specifically, the server reads preset first weight coefficients and preset second weight coefficients from the system configuration. Then, the server obtains the first loss component calculated in step S1051 and the second loss component calculated in step S1055. The server performs a weighted summation operation: multiplying the first loss component by the preset first weight coefficient to obtain the weighted first component; multiplying the second loss component by the preset second weight coefficient to obtain the weighted second component. Finally, the two weighted components are added together, and the sum is the final spatial weighted feature imitation loss. This loss value is then used to drive the training process of the student model.

[0100] Step S106: Calculate the confidence imitation loss based on the difference between the first and second liveness confidence scores.

[0101] In step S106, the confidence imitation loss is a scalar value used to quantify the difference between the first and second liveness confidence levels. The goal of this loss term is to make the final output of the student model as close as possible to the output of the teacher model in terms of probability distribution, thereby learning the "decision logic" of the teacher model.

[0102] Specifically, the server obtains the first liveness confidence score obtained in step S101 and the second liveness confidence score obtained in step S103. To allow the student model to learn richer information from the teacher's output, rather than just the final hard label, a "softening" process is applied to these two confidence scores (and their corresponding "non-liveness" confidence scores, which are summed to 1). This process is achieved by introducing a hyperparameter called "temperature," which is calculated by dividing the confidence score by the temperature value and then applying the Softmax function to obtain the softened probability distribution. Then, the server uses a loss function such as the Kohlbek-Leibler divergence to calculate the difference between the softened probability distribution of the teacher model and the softened probability distribution of the student model. This calculated difference is the confidence imitation loss, which measures the similarity between the two models in their final classification decisions.

[0103] In one possible implementation, the confidence imitation loss is calculated based on the difference between the first and second liveness confidence levels, specifically including steps S1061-S1063, as follows:

[0104] Step S1061: Calculate the absolute difference between the first and second liveness confidence levels to obtain the preliminary confidence difference.

[0105] In step S1061, the first liveness confidence score is a scalar value output by the teacher model after performing liveness detection on the input sample. This value is typically between 0 and 1 and represents the confidence level of the teacher model in determining that the sample is a real live subject. The second liveness confidence score is the corresponding scalar value output by the student model after performing liveness detection on the same input sample and represents the confidence level of the student model in determining that the sample is a real live subject. The absolute difference is a mathematical operation used to calculate the difference between two values ​​regardless of their positive or negative direction. The preliminary confidence difference is the result obtained by calculating the absolute difference between the first and second liveness confidence scores, which directly quantifies the magnitude of the prediction difference between the student model and the teacher model in the final liveness judgment.

[0106] Specifically, the server first obtains the first liveness confidence score calculated by the teacher model for the current input sample, and the second liveness confidence score calculated by the student model. Both confidence scores are single values. The server then performs a subtraction operation, subtracting the second liveness confidence score from the first liveness confidence score to obtain a difference. To ensure that the resulting difference is a non-negative number, thus focusing only on the magnitude of the difference rather than its direction, the server takes the absolute value of this difference. For example, if the difference is negative, its sign is reversed to positive; if the difference is positive or zero, it remains unchanged. This non-negative value obtained after the absolute value operation is defined as the initial confidence difference.

[0107] Step S1062: Calculate the arithmetic mean of the first and second live confidence scores to obtain the mean confidence score.

[0108] In step S1062, the arithmetic mean is the result of adding a set of values ​​and dividing by the number of values; it reflects the central position of this set of values. The confidence mean is the result of calculating the arithmetic mean of the first and second liveness confidence scores. This mean can be understood as a combined or average view of the teacher model and the student model regarding the liveness judgment on the current sample; a higher mean indicates that both models tend to believe the sample is a live person, and vice versa.

[0109] Specifically, the server retrieves the first and second liveness confidence scores already used in previous steps. The server performs an addition operation, summing these two confidence scores to obtain a total. Since only two values ​​are involved in the calculation, the server then divides this sum by 2. The result of this division is the mean confidence score. This value will be used in subsequent steps to adjust the final loss calculation so that it takes into account the overall prediction levels of both models.

[0110] Step S1063: Based on the preset formula, the initial confidence difference, and the confidence mean, calculate the confidence imitation loss.

[0111] In step S1063, the preset formula refers to a pre-designed mathematical expression used to calculate the final loss by combining the initial confidence difference and the confidence mean. This formula is designed to achieve a dynamic, adaptive loss calculation mechanism that not only penalizes the difference in predictions but also adjusts the penalty intensity based on the magnitude of the predicted value itself. The confidence imitation loss is the final result calculated in this series of steps. It is a single scalar value used to measure the student model's performance in imitating the teacher model on live confidence predictions and serves as part of the total loss function to guide the optimization of the student model.

[0112] Specifically, the server first obtains the preliminary confidence difference calculated in step S1061 and the mean confidence score calculated in step S1062. The server processes these two input values ​​according to a pre-configured formula. One possible pre-configured formula is to multiply the preliminary confidence difference by a moderating factor determined by the mean confidence score. For example, this moderating factor could be designed to be inversely proportional to the mean confidence score, meaning that when the mean confidence scores of both models are low—that is, when they both consider the sample not to be living—even if their prediction differences are small, this difference will be amplified, thus imposing a greater penalty, and vice versa. Another possible formula is to combine the preliminary confidence difference with a function of the mean confidence score, such as an exponential or logarithmic function. The server substitutes the preliminary confidence difference and the mean confidence score into the calculation according to the selected pre-configured formula, ultimately obtaining a single value, which is the confidence imitation loss.

[0113] Step S107: Adjust and optimize the internal parameters of the preset student processing model according to the spatial weighted feature imitation loss and the confidence imitation loss to obtain the target student processing model, and detect the liveness image to be detected based on the target student processing model.

[0114] In step S107, intrinsic parameters refer to all learnable variables constituting the preset student processing model, mainly including the weights and biases of each convolutional kernel in the neural network. Tuning and optimization refers to the process of using gradient descent algorithm and its variants to perform small but effective iterative updates to the intrinsic parameters of the student model based on the calculated total loss. The target student processing model refers to the lightweight liveness detection model that meets performance standards and can be used for practical deployment after sufficient and multiple rounds of tuning and optimization. The liveness detection image refers to the new image that needs to be used to determine whether a person is alive in a real-world application scenario after training is completed.

[0115] Specifically, the server first combines the spatially weighted feature imitation loss calculated in step S105 and the confidence imitation loss calculated in step S106 into a total loss through a weighted sum. For example, the total loss equals the spatially weighted feature imitation loss plus a weight coefficient multiplied by the confidence imitation loss. Then, based on this total loss, the server uses an automatic differentiation mechanism to calculate the gradient of the total loss relative to each intrinsic parameter of the preset student processing model. This gradient indicates the direction in which the parameters should be adjusted to maximize the decrease in the total loss. Next, the server uses a preset optimizer, such as the Adam optimizer, to update all intrinsic parameters of the student model based on the calculated gradient. The entire process from S101 to S107 constitutes a complete training iteration. The server uses a large amount of liveness image data and non-liveness attack image data to repeatedly execute this iteration process tens of thousands of times. In each iteration, the parameters of the student model are fine-tuned, and its performance gradually improves. The training process terminates when the preset number of epochs is reached or the model's performance no longer improves on the validation set. The student processing model obtained at this point is the final target student processing model. Finally, when actual detection is required, the server or terminal device can directly load this target student processing model, input a liveness detection image into it, and the model will quickly perform a forward propagation and output a liveness confidence score, thereby completing an efficient liveness detection task.

[0116] Please refer to Figure 2 In one possible implementation, the internal parameters of the preset student processing model are adjusted and optimized based on the spatially weighted feature imitation loss and the confidence imitation loss to obtain the target student processing model. Specifically, this includes steps S201-S207, as follows:

[0117] Step S201: Calculate the gradient of the shared parameters affected by the spatially weighted feature imitation loss in the preset student processing model to obtain the first temporary gradient vector.

[0118] In step S201, the preset student processing model refers to the student model version whose internal parameters have not been updated by the gradient of the current iteration before the start of the current training iteration. Spatial weighted feature imitation loss is a loss function used to measure the difference between the feature maps generated by the student model and those generated by the teacher model, and this difference is weighted according to the importance of spatial location. Shared parameters refer to those parameters in the network structure of the preset student processing model whose calculation results simultaneously affect the subsequent calculation of spatial weighted feature imitation loss and confidence imitation loss; these correspond to the front-end or backbone network part of the model. In deep learning, the gradient is the partial derivative of the loss function with respect to the model parameters; it indicates the direction of parameter updates to minimize the loss function value. The first temporary gradient vector is a vector combining the gradient values ​​calculated by the spatial weighted feature imitation loss with respect to all shared parameters; this vector is only used for subsequent weight calculations and not directly for model updates.

[0119] Specifically, the server first obtains the scalar value of the previously calculated spatially weighted feature imitation loss. Next, the server identifies the shared parameters in the predefined student processing model, for example, the parameters of all convolutional and pooling layers in a convolutional neural network model. The server performs a local backpropagation calculation, but the purpose of this calculation is only to obtain the gradient of the spatially weighted feature imitation loss with respect to this specific set of shared parameters. After the calculation is complete, the server arranges the obtained gradient values ​​for each shared parameter in a predefined order, forming a one-dimensional vector with the same dimension as the number of shared parameters; this vector is the first temporary gradient vector.

[0120] Step S202: Calculate the gradient of the shared parameters affected by the confidence imitation loss in the preset student processing model to obtain the second temporary gradient vector.

[0121] In step S202, the confidence imitation loss is a loss function used to measure the difference between the liveness confidence output by the student model and the liveness confidence output by the teacher model. The second temporary gradient vector is a vector formed by combining the gradient values ​​calculated from the confidence imitation loss with the same shared parameters as in step S201. Like the first temporary gradient vector, this vector's main purpose is to serve as the basis for calculating the dynamic loss weights.

[0122] Specifically, the server retrieves the scalar value of the confidence imitation loss calculated previously. The server uses the same set of shared parameters determined in step S201. Then, the server performs another independent local backpropagation calculation, this time determining the gradient of the confidence imitation loss with respect to this set of shared parameters. After the calculation is complete, the server arranges the resulting gradient values ​​for each shared parameter in the exact same order as the first temporary gradient vector, thus forming a second temporary gradient vector. Ensuring that the dimensions and parameter order of the two temporary gradient vectors are consistent is crucial for the accuracy of subsequent calculations.

[0123] Step S203: Calculate the L2 norm of the first temporary gradient vector to obtain the first gradient magnitude, and calculate the L2 norm of the second temporary gradient vector to obtain the second gradient magnitude.

[0124] In step S203, the L2 norm, also known as the Euclidean norm, is a mathematical method for measuring the size or length of a vector. It is calculated as the square root of the sum of the squares of all elements in the vector. The first gradient magnitude refers to the scalar value obtained by calculating the L2 norm on the first temporary gradient vector. It quantifies the overall gradient strength generated by the spatially weighted feature imitation loss on the shared parameters. The second gradient magnitude refers to the scalar value obtained by calculating the L2 norm on the second temporary gradient vector. It quantifies the overall gradient strength generated by the confidence imitation loss on the shared parameters.

[0125] Specifically, the server first obtains the first temporary gradient vector obtained in step S201. The server squares each element of this vector and then sums all the squared results to obtain a total. Finally, the server calculates the square root of this sum, which is the first gradient magnitude. Similarly, the server obtains the second temporary gradient vector obtained in step S202 and uses the exact same calculation process: squaring each element, summing, and then taking the square root to calculate the second gradient magnitude. Both magnitude values ​​are non-negative real numbers, intuitively reflecting the influence of the two losses on the shared parts of the model in the current training state.

[0126] Step S204: Calculate the first loss weight and the second loss weight based on the first gradient magnitude and the second gradient magnitude.

[0127] In step S204, the first loss weight and the second loss weight are two dynamically calculated scalar values, which are used to adjust the proportions of the spatially weighted feature imitation loss and the confidence imitation loss in the total loss, respectively. The preset total weight value is a hyperparameter that defines the target sum of the two loss weights and is used to control the overall scale of the weighted total loss. A very small positive number is used to prevent division by zero and is included in the denominator in the calculation to avoid calculation errors when the sum of the magnitudes of the two gradients is zero.

[0128] Specifically, the server obtains the first and second gradient magnitudes calculated in step S203. The server first calculates the denominator by adding the first and second gradient magnitudes to a preset minimum stable value. Then, the server calculates the first loss weight according to a preset formula: multiplying the preset total weight value by the second gradient magnitude and then dividing by the calculated denominator. Next, the server calculates the second loss weight by multiplying the preset total weight value by the first gradient magnitude and then dividing by the same denominator. This cross-calculation method achieves a balancing mechanism: loss tasks with smaller gradient magnitudes receive relatively larger weights, while loss tasks with larger gradient magnitudes receive relatively smaller weights.

[0129] Step S205: Multiply the spatial weighted feature imitation loss by the first loss weight to obtain the first weighted loss, multiply the confidence imitation loss by the second loss weight to obtain the second weighted loss, and add the first weighted loss and the second weighted loss to obtain the total imitation loss.

[0130] In step S205, the first weighted loss is the result of multiplying the original spatial weighted feature imitation loss by its corresponding first loss weight. The second weighted loss is the result of multiplying the original confidence imitation loss by its corresponding second loss weight. The total imitation loss is the final loss value obtained by adding the first weighted loss and the second weighted loss, and this value will be used as the sole optimization objective for this model parameter update.

[0131] Specifically, the server obtains the original spatially weighted feature imitation loss value and the first loss weight calculated in step S204. The server multiplies these two values ​​to obtain the first weighted loss. Simultaneously, the server obtains the original confidence imitation loss value and the second loss weight calculated in step S204. The server also multiplies these two values ​​to obtain the second weighted loss. Finally, the server adds the first weighted loss and the second weighted loss to obtain a single scalar value, which is the total imitation loss.

[0132] Step S206: Calculate the gradient of the total imitation loss relative to the preset internal parameters of the student processing model using the backpropagation algorithm.

[0133] In step S206, the backpropagation algorithm is a widely used algorithm in neural network training. It uses a chain rule to calculate the gradient of the loss function with respect to all trainable parameters in the network, starting from the final loss function and working backward layer by layer. The preset student processing model's internal parameters refer to all trainable weights and biases that constitute the model, including not only shared parameters but also non-shared parameters that are only relevant to a specific task.

[0134] Specifically, the server uses the total imitation loss calculated in step S205 as a starting point. The server triggers a complete backpropagation process. This process calculates the partial derivatives of the total imitation loss with respect to each intrinsic parameter in the preset student processing model. Unlike the local calculations in steps S201 and S202, this backpropagation traverses the entire student model computation graph, calculating gradient values ​​for all parameters of the model, whether shared or not. After the calculations are complete, the server obtains a complete set of gradients, which contains all the information needed to update the entire model.

[0135] Step S207: Using a preset optimizer, iteratively update the internal parameters of the preset student processing model according to the gradient until the total imitation loss converges or the preset number of training rounds is reached, and obtain the target student processing model.

[0136] In step S207, the preset optimizer is an algorithm, such as stochastic gradient descent (SGD), Adam, or RMSprop, which updates the model's internal parameters based on the gradients calculated through backpropagation. Iterative update refers to repeatedly executing the cycle of "forward propagation - loss calculation - backpropagation - parameter update" during training. Convergence means that the model's performance or loss value no longer shows significant improvement after multiple iterations, reaching a stable state. The preset training epochs refer to a fixed total number of training cycles set before training begins, serving as one of the conditions for stopping training. The target student processing model is the optimized model produced after sufficient iterative updates, achieving the expected performance requirements.

[0137] Specifically, the server passes the complete set of gradients calculated in step S206 to the preset optimizer. The optimizer calculates the update amount for each parameter based on its own update rules; for example, for the Adam optimizer, it combines the first and second moment estimates of the gradient. Then, the optimizer subtracts this calculated update amount from the current parameter values, thus completing one update of all internal parameters of the preset student processing model. This complete process from input data to parameter update constitutes a training step. The server continuously repeats this process, processing batches of data and performing thousands of iterative updates until the total imitation loss decreases to a stable plateau, or all preset training rounds are completed. At this point, the training process ends, and the finally updated model is the desired target student processing model.

[0138] Reference Figure 3This application also provides a liveness detection device based on large model screening and distillation. This device is a server, which includes a teacher information generation module 301, a spatial saliency map generation module 302, a student information generation module 303, a loss calculation module 304, and a model optimization and detection module 305. Specifically: the teacher information generation module 301 acquires liveness image data and inputs it into a preset teacher processing model to generate a first liveness confidence score and a teacher intermediate layer feature map associated with a preset first intermediate layer of the preset teacher processing model; the spatial saliency map generation module 302 calculates and generates a first spatial saliency map based on the first liveness confidence score and the teacher intermediate layer feature map; the student information generation module 303 inputs liveness image data into a preset student processing model... The system generates a second liveness confidence score and a student intermediate layer feature map associated with a preset second intermediate layer of the preset student processing model. A loss calculation module 304 calculates the feature differences between the teacher intermediate layer feature map and the student intermediate layer feature map, and uses a first spatial saliency map to weight the feature differences spatially, generating a weighted feature difference. Based on the weighted feature difference, a spatially weighted feature imitation loss is calculated. Based on the difference between the first and second liveness confidence scores, a confidence imitation loss is calculated. A model optimization and detection module 305 adjusts and optimizes the internal parameters of the preset student processing model according to the spatially weighted feature imitation loss and the confidence imitation loss to obtain a target student processing model, and detects the liveness image to be detected based on the target student processing model.

[0139] In one possible implementation, the spatial saliency map generation module 302 calculates and generates a first spatial saliency map based on a first liveness confidence score and a teacher intermediate layer feature map. Specifically, the spatial saliency map generation module 302 calculates the gradient of the first liveness confidence score relative to each feature channel in the teacher intermediate layer feature map, obtaining a set of gradient maps with the same number of channels as the teacher intermediate layer feature map; the spatial saliency map generation module 302 performs a global average pooling operation on each gradient map in the gradient map set in the spatial dimension to calculate the channel importance weight of the corresponding feature channel; the spatial saliency map generation module 302 multiplies each feature channel in the teacher intermediate layer feature map with the corresponding channel importance weight to obtain a weighted feature channel, and performs a linear combination of the weighted feature channels to generate an initial saliency map; the spatial saliency map generation module 302 performs non-negative activation processing on the initial saliency map to obtain the first spatial saliency map.

[0140] In one possible implementation, the loss calculation module 304 calculates the feature differences between the teacher's intermediate layer feature map and the student's intermediate layer feature map, and uses a first spatial saliency map to weight the feature differences spatially to generate weighted feature differences. Specifically, this includes: the loss calculation module 304 performing multiple convolution operations on the student's intermediate layer feature map to generate an adapted student feature map; the loss calculation module 304 extracting teacher channel vectors and student channel vectors based on each shared spatial position of the teacher's intermediate layer feature map and the adapted student feature map; and the loss calculation module 304 calculating the magnitude difference value and structural difference based on the teacher channel vector and the student channel vector. The value is calculated as follows: the amplitude difference is the square of the difference between the L2 norm of the teacher channel vector and the L2 norm of the student channel vector; the structural difference is the difference between the preset value and the cosine similarity between the teacher channel vector and the student channel vector. The loss calculation module 304 performs a weighted summation of the amplitude difference value and the structural difference value to obtain the feature difference value at the corresponding shared spatial location. The loss calculation module 304 constructs an initial difference map by combining the feature difference values ​​of all shared spatial locations. The loss calculation module 304 performs a linear transformation on the first spatial saliency map to generate a focus weight map, and multiplies the initial difference map and the focus weight map element-wise to obtain the weighted feature difference.

[0141] In one possible implementation, the loss calculation module 304 calculates a spatially weighted feature imitation loss based on weighted feature differences. Specifically, this includes: the loss calculation module 304 calculating the arithmetic mean of the values ​​of the weighted feature differences at all spatial locations to obtain a first loss component; the loss calculation module 304 calculating the standard deviation of the values ​​of the weighted feature differences at all spatial locations to obtain a standard deviation value; the loss calculation module 304 adding the first loss component to the standard deviation value to generate a difference threshold; the loss calculation module 304 determining all spatial locations where the values ​​of the weighted feature differences are greater than the difference threshold, forming a high difference location set; the loss calculation module 304 extracting all values ​​located within the high difference location set of the weighted feature differences and calculating the arithmetic mean of all extracted values ​​to obtain a second loss component; and the loss calculation module 304 performing a weighted summation of the first loss component and the second loss component according to a preset first weighting coefficient and a preset second weighting coefficient to obtain the spatially weighted feature imitation loss.

[0142] In one possible implementation, the loss calculation module 304 calculates the confidence imitation loss based on the difference between the first and second liveness confidence levels. Specifically, the loss calculation module 304 calculates the absolute difference between the first and second liveness confidence levels to obtain a preliminary confidence difference; the loss calculation module 304 calculates the arithmetic mean of the first and second liveness confidence levels to obtain a confidence mean; and the loss calculation module 304 calculates the confidence imitation loss based on a preset formula, the preliminary confidence difference, and the confidence mean.

[0143] In one possible implementation, the model optimization and detection module 305 adjusts and optimizes the internal parameters of the preset student processing model based on the spatially weighted feature imitation loss and the confidence imitation loss to obtain the target student processing model. Specifically, the model optimization and detection module 305 calculates the first loss weight and the second loss weight, and calculates the total imitation loss based on the first loss weight and the second loss weight; the model optimization and detection module 305 uses the backpropagation algorithm to calculate the gradient of the total imitation loss relative to the internal parameters of the preset student processing model; the model optimization and detection module 305 uses a preset optimizer to iteratively update the internal parameters of the preset student processing model according to the gradient until the total imitation loss converges or reaches a preset number of training rounds to obtain the target student processing model.

[0144] In one possible implementation, the model optimization and detection module 305 calculates a first loss weight and a second loss weight, and calculates the total imitation loss based on the first loss weight and the second loss weight. Specifically, the model optimization and detection module 305 calculates the gradient of the shared parameters in the preset student processing model affected by the spatially weighted feature imitation loss to obtain a first temporary gradient vector; the model optimization and detection module 305 calculates the gradient of the shared parameters in the preset student processing model affected by the confidence imitation loss to obtain a second temporary gradient vector; the model optimization and detection module 305 calculates the L2 norm of the first temporary gradient vector to obtain a first gradient magnitude, and calculates the L2 norm of the second temporary gradient vector to obtain a second gradient magnitude; based on the first gradient magnitude and the second gradient magnitude, the first loss weight and the second loss weight are calculated; the model optimization and detection module 305 multiplies the spatially weighted feature imitation loss by the first loss weight to obtain a first weighted loss, multiplies the confidence imitation loss by the second loss weight to obtain a second weighted loss, and adds the first weighted loss and the second weighted loss to obtain the total imitation loss.

[0145] It should be noted that the device provided in the above embodiments is only illustrated by the division of the above functional modules when implementing its functions. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0146] This application also provides an electronic device. (See reference...) Figure 4 , Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. The electronic device 400 may include: at least one processor 401, at least one network interface 404, a user interface 403, a memory 405, and at least one communication bus 402. The communication bus 402 is used to enable communication between these components. The user interface 403 may include a display screen or a camera; optionally, the user interface 403 may also include a standard wired interface or a wireless interface. The network interface 404 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface). The processor 401 may include one or more processing cores. The processor 401 connects to various parts of the server using various interfaces and lines, and performs various functions of the server and processes data by running or executing instructions, programs, code sets, or instruction sets stored in the memory 405, and by calling data stored in the memory 405. The memory 405 may include random access memory (RAM) or read-only memory.

[0147] Reference Figure 4 The memory 405, as a computer storage medium, may include an operating system, a network communication module, a user interface module, and an application program based on a large-model screening and distillation method for liveness detection. Figure 4 In the illustrated electronic device 400, the user interface 403 is primarily used to provide an input interface for the user and acquire user input data; while the processor 401 can be used to call an application program stored in the memory 405 for a liveness detection method based on large model screening and distillation. When executed by one or more processors 401, the electronic device 400 performs one or more of the methods described in the above embodiments. This application also provides a computer-readable storage medium storing instructions. When executed by one or more processors 401, the electronic device 400 performs one or more of the methods described in the above embodiments.

[0148] This application is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not described in this disclosure. The specification and embodiments are to be considered exemplary only, and the scope and spirit of this disclosure are defined by the claims.

Claims

1. A live cell detection method based on large-scale model screening and distillation, characterized in that, The method includes: Acquire liveness image data and input the liveness image data into a preset teacher processing model to generate a first liveness confidence score and a teacher intermediate layer feature map associated with a preset first intermediate layer of the preset teacher processing model; Based on the first liveness confidence score and the teacher intermediate layer feature map, a first spatial saliency map is calculated and generated; The liveness image data is input into a preset student processing model to generate a second liveness confidence score and a student intermediate layer feature map associated with a preset second intermediate layer of the preset student processing model. Calculate the feature differences between the teacher intermediate layer feature map and the student intermediate layer feature map, and use the first spatial saliency map to weight the feature differences spatially to generate weighted feature differences; Based on the weighted feature differences, the spatial weighted feature imitation loss is calculated; The confidence imitation loss is calculated based on the difference between the first and second liveness confidence scores. Based on the spatial weighted feature imitation loss and the confidence imitation loss, the internal parameters of the preset student processing model are adjusted and optimized to obtain the target student processing model, and the liveness image to be detected is detected based on the target student processing model. The step of calculating and generating a first spatial saliency map based on the first liveness confidence score and the teacher intermediate layer feature map specifically includes: Calculate the gradient of the first liveness confidence with respect to each feature channel in the teacher intermediate layer feature map to obtain a set of gradient maps with the same number of channels as the teacher intermediate layer feature map; For each gradient map in the gradient map set, a global average pooling operation is performed in the spatial dimension to calculate the channel importance weight of the corresponding feature channel. Each feature channel in the teacher intermediate layer feature map is multiplied by its corresponding channel importance weight to obtain a weighted feature channel. The weighted feature channels are then linearly combined to generate an initial saliency map. The initial saliency map is subjected to non-negative activation processing to obtain the first spatial saliency map; The step of calculating the feature differences between the teacher's intermediate layer feature map and the student's intermediate layer feature map, and then using the first spatial saliency map to weight the feature differences spatially to generate weighted feature differences, specifically includes: Perform multiple convolution operations on the student intermediate layer feature map to generate an adapted student feature map; Based on each shared spatial location of the teacher intermediate layer feature map and the adapted student feature map, extract the teacher channel vector and the student channel vector; Based on the teacher channel vector and the student channel vector, the amplitude difference value and the structural difference value are calculated, wherein the amplitude difference value is the square of the difference between the L2 norm of the teacher channel vector and the L2 norm of the student channel vector, and the structural difference value is the difference between a preset value and the cosine similarity between the teacher channel vector and the student channel vector. The amplitude difference value and the structural difference value are weighted and summed to obtain the feature difference value at the corresponding shared spatial location; The feature difference values ​​of all shared spatial locations are used to construct an initial difference map; A linear transformation is performed on the first spatial saliency map to generate a focal weight map, and the initial difference map is multiplied element-wise with the focal weight map to obtain the weighted feature difference; The calculation of the spatial weighted feature imitation loss based on the weighted feature differences specifically includes: Calculate the arithmetic mean of the weighted feature differences across all spatial locations to obtain the first loss component; Calculate the standard deviation of the weighted feature differences across all spatial locations to obtain the standard deviation value; The first loss component is added to the standard deviation to generate a difference threshold; Determine all spatial locations in the weighted feature differences whose values ​​are greater than the difference threshold, and form a set of high difference locations. Extract all values ​​located within the set of high-difference positions from the weighted feature differences, and calculate the arithmetic mean of all extracted values ​​to obtain the second loss component; Based on the preset first weight coefficient and the preset second weight coefficient, the first loss component and the second loss component are weighted and summed to obtain the spatial weighted feature imitation loss.

2. The method according to claim 1, characterized in that, The confidence imitation loss is calculated based on the difference between the first and second liveness confidence scores, specifically including: Calculate the absolute difference between the first and second liveness confidence scores to obtain the preliminary confidence score difference; Calculate the arithmetic mean of the first and second liveness confidence scores to obtain the mean confidence score; The confidence imitation loss is calculated based on the preset formula, the initial confidence difference, and the confidence mean.

3. The method according to claim 1, characterized in that, The step of adjusting and optimizing the internal parameters of the preset student processing model based on the spatially weighted feature imitation loss and the confidence imitation loss to obtain the target student processing model specifically includes: Calculate the first loss weight and the second loss weight, and calculate the total imitation loss based on the first loss weight and the second loss weight; The gradient of the total imitation loss relative to the internal parameters of the preset student processing model is calculated using the backpropagation algorithm; Using a preset optimizer, the internal parameters of the preset student processing model are iteratively updated according to the gradient until the total imitation loss converges or reaches a preset number of training rounds, thereby obtaining the target student processing model.

4. The method according to claim 3, characterized in that, The calculation of the first loss weight and the second loss weight, and the calculation of the total imitation loss based on the first loss weight and the second loss weight, specifically includes: Calculate the gradient of the shared parameters in the preset student processing model that are affected by the spatial weighted feature imitation loss to obtain the first temporary gradient vector; Calculate the gradient of the shared parameters in the preset student processing model that are affected by the confidence imitation loss to obtain the second temporary gradient vector; Calculate the L2 norm of the first temporary gradient vector to obtain the first gradient magnitude, and calculate the L2 norm of the second temporary gradient vector to obtain the second gradient magnitude; Based on the first gradient magnitude and the second gradient magnitude, the first loss weight and the second loss weight are calculated. The spatial weighted feature imitation loss is multiplied by the first loss weight to obtain the first weighted loss, the confidence imitation loss is multiplied by the second loss weight to obtain the second weighted loss, and the first weighted loss and the second weighted loss are added together to obtain the total imitation loss.

5. A live organism detection device based on large-scale model screening and distillation, characterized in that, The apparatus is used to perform the method as described in any one of claims 1-4, the apparatus comprising a teacher information generation module (301), a spatial saliency map generation module (302), a student information generation module (303), a loss calculation module (304), and a model optimization and detection module (305), wherein: The teacher information generation module (301) is used to acquire live image data and input the live image data into a preset teacher processing model to generate a first live confidence score and a teacher intermediate layer feature map associated with a preset first intermediate layer of the preset teacher processing model. The spatial saliency map generation module (302) is used to calculate and generate a first spatial saliency map based on the first liveness confidence and the teacher intermediate layer feature map; The student information generation module (303) is used to input the liveness image data into a preset student processing model to generate a second liveness confidence and a student intermediate layer feature map associated with a preset second intermediate layer of the preset student processing model. The loss calculation module (304) is used to calculate the feature difference between the teacher intermediate layer feature map and the student intermediate layer feature map, and to use the first spatial saliency map to weight the feature difference spatially to generate a weighted feature difference; based on the weighted feature difference, the spatial weighted feature imitation loss is calculated; based on the difference between the first liveness confidence and the second liveness confidence, the confidence imitation loss is calculated. The model optimization and detection module (305) is used to adjust and optimize the internal parameters of the preset student processing model according to the spatial weighted feature imitation loss and the confidence imitation loss to obtain the target student processing model, and to detect the liveness image to be detected based on the target student processing model.

6. An electronic device, characterized in that, The device includes a processor (401), a memory (405), a user interface (403), and a network interface (404). The memory (405) is used to store instructions. The user interface (403) and the network interface (404) are used to communicate with other devices. The processor (401) is used to execute the instructions stored in the memory (405) to cause the electronic device (400) to perform the method as described in any one of claims 1-4.

7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores instructions that, when executed, perform the method as described in any one of claims 1-4.

Citation Information

Patent Citations

  • Living body detection model training method and living body detection method and system

    CN116665315A