Living body detection method, product and storage medium
By adopting the image-text matching retrieval method in the field of living body detection and retrieving the judgment basis from the pre-built living body detection explanation text library, the problem of long time-consuming living detection reasoning and judgment accuracy is solved, and faster and more accurate living body detection is achieved. Test results.
Patent Information
- Application Number
- CN202410592258.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-13
- Publication Date
- 2024-08-30
AI Technical Summary
In the current field of liveness detection, the reasoning to generate judgment basis takes too long, affecting the user experience, and the visual language model suffers from hallucinations and counter-common sense judgment problems.
Using the image-text matching retrieval method, the living body detection explanation model retrieves the corresponding explanation text from the pre-built living body detection explanation text library as the basis for judgment, replacing the traditional visual language model autoregressive output, shortening the time-consuming reasoning of the judgment basis. , and improve the accuracy of judgment.
It greatly shortens the time-consuming reasoning of living judgment basis, avoids hallucinations and counter-common sense reasoning, and improves the accuracy of judgment basis and user experience.
Smart Images

Figure CN118570882A
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of liveness detection, and in particular to a liveness detection method, product and storage medium. Background Art
[0002] Generative models are widely used in the field of artificial intelligence. Taking the multimodal liveness detection task as an example, the user hopes that the liveness detection model can output the basis for its liveness judgment in the form of text while making a liveness judgment. Currently, the generative model used to generate explanatory text for liveness detection usually adopts the Visual Language Model (VLM).
[0003] However, in the current field of liveness detection, the visual language model is usually trained in advance with liveness data, and then the trained visual language model is used to generate liveness judgment basis (liveness interpretation text). This method of generating judgment basis takes too long to infer, affecting the user experience. Summary of the invention
[0004] In view of this, the present application aims to propose a liveness detection method, product and storage medium to solve the problem that it takes too long to generate judgment basis in liveness detection tasks.
[0005] To achieve the above objectives, the technical solution of this application is as follows:
[0006] The present application provides a method for detecting a living body, the method comprising:
[0007] Acquire an image to be detected of the object to be detected; wherein the image to be detected includes a facial area of the object to be detected;
[0008] The image to be detected is input into a liveness detection model and a liveness detection interpretation model respectively, and a liveness detection result of the object to be detected output by the liveness detection model is obtained, and a first interpretation text corresponding to the liveness detection result output by the liveness detection interpretation model is obtained; wherein the first interpretation text is used to characterize the reason for detecting the liveness detection result, and the first interpretation text is retrieved from a liveness detection interpretation text library based on the image to be detected by the liveness detection interpretation model, and the liveness detection interpretation text library stores liveness interpretation texts corresponding to multiple liveness attack types.
[0009] Optionally, the process of retrieving a first explanation text corresponding to the liveness detection result from a liveness detection explanation text library based on the image to be detected by using a liveness detection explanation model includes:
[0010] Extracting a first image feature of the image to be detected by using the living body detection interpretation model;
[0011] Acquire text features corresponding to each living body interpretation text in the living body detection interpretation text library;
[0012] The first image feature is matched with each acquired text feature in terms of similarity to obtain a first interpretation text corresponding to the living body detection result.
[0013] Optionally, if the living body detection explanation model outputs a plurality of first explanation texts, the method further includes:
[0014] The image to be detected and the multiple first interpretation texts are input into a reordering model, the multiple first interpretation texts are sorted by the reordering model, and a text sorting result of the multiple first interpretation texts is output, and the first interpretation text ranked first in the text sorting result is determined as the final interpretation text corresponding to the living body detection result.
[0015] Optionally, the reordering model includes a text encoder, an image encoder, and a cross attention module connected between the text encoder and the image encoder; sorting the multiple first interpretation texts by the reordering model to obtain the text sorting result includes:
[0016] Encoding the plurality of first interpreted texts by the text encoder to obtain text encoding results of the plurality of first interpreted texts;
[0017] Encoding the image to be detected by the image encoder to obtain an image encoding result;
[0018] The text encoding results of the multiple first interpretation texts and the image encoding results are processed through the cross-attention module to obtain the text sorting result.
[0019] Optionally, the living body detection method further includes:
[0020] The first explanation text corresponding to the image to be detected and the liveness detection result is input into a visual language model, and the first explanation text is updated based on the image to be detected by the visual language model to obtain a second explanation text corresponding to the liveness detection result.
[0021] Optionally, updating the first interpretation text based on the image to be detected by the visual language model to obtain a second interpretation text corresponding to the living body detection result includes:
[0022] Analyzing the image to be detected by using the visual language model to obtain an image description text of the image to be detected;
[0023] The image description text of the image to be detected and the first explanation text are fused through the visual language model to obtain a second explanation text corresponding to the living body detection result.
[0024] Optionally, the liveness detection model obtains the liveness detection result of the object to be detected through the following process:
[0025] Extracting a second image feature of the image to be detected through a living body detection model, and acquiring a first image feature of the image to be detected from the living body detection interpretation model;
[0026] Fusing the first image feature with the second image feature to generate a fused image feature;
[0027] The fused image features are processed to obtain the living body detection result.
[0028] Optionally, fusing the first image feature with the second image feature to generate a fused image feature includes any of the following methods:
[0029] Mapping the first image feature into a key vector k and a value vector v, mapping the second image feature into a query vector q, and fusing the first image feature and the second image feature using a cross attention mechanism to obtain a fused image feature;
[0030] Mapping the second image feature into a key vector k and a value vector v, mapping the first image feature into a query vector q, and fusing the first image feature and the second image feature using a cross attention mechanism to obtain a fused image feature;
[0031] The dimension of the first feature vector corresponding to the first image feature and the dimension of the second feature vector corresponding to the second image feature are adjusted to the same dimension, and the dimension-adjusted first feature vector and the dimension-adjusted second feature vector are concatenated to obtain a fused image feature;
[0032] The dimension of a first feature vector corresponding to the first image feature and the dimension of a second feature vector corresponding to the second image feature are adjusted to the same dimension, and weighted summation is performed according to the weights of the first feature vector after the dimension adjustment and the second feature vector after the dimension adjustment to obtain a fused image feature.
[0033] Optionally, the living body detection interpretation text library is constructed through the following process:
[0034] Get the text describing each type of live attack;
[0035] Classify the acquired text according to the attack type;
[0036] The classified texts and corresponding attack types are stored to obtain a liveness detection explanation text library.
[0037] According to a second aspect of an embodiment of the present application, there is provided an electronic device, including:
[0038] processor;
[0039] a memory for storing instructions executable by the processor;
[0040] The processor is configured to execute the instructions to implement the steps of the living body detection method provided in the first aspect of the embodiment of the present application.
[0041] According to a third aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the liveness detection method as described in the first aspect of the embodiment of the present application are implemented.
[0042] According to a fourth aspect of an embodiment of the present application, a computer program product is provided, including a computer program. When the computer program is executed by a processor, the steps of the liveness detection method as described in the first aspect of the embodiment of the present application are implemented.
[0043] The liveness detection method provided in the present application inputs the image to be detected into the liveness detection model and the liveness detection interpretation model respectively. The liveness detection model outputs the liveness detection result based on the image to be detected. The liveness detection interpretation model retrieves the first interpretation text corresponding to the image to be detected from the liveness detection interpretation text library based on the image to be detected, which is used to characterize the reason for obtaining the liveness detection result. The present application adopts a retrieval method of image-text matching to replace the traditional autoregressive output of the visual language model for liveness detection. The liveness detection interpretation model retrieves the corresponding liveness interpretation text from the liveness detection interpretation text library according to the image to be detected as the basis for judging the liveness detection result. Since the liveness detection interpretation text library already stores the liveness interpretation texts corresponding to different types of liveness attacks, it is not necessary to regenerate word units to obtain the basis for judging the liveness detection result, which greatly shortens the time-consuming reasoning of the basis for liveness judgment. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0045] Figure 1 is a flow chart of a liveness detection method proposed in one embodiment of the present application;
[0046] Figure 2 is a flowchart of obtaining a first interpretation text in an embodiment of the present application;
[0047] Figure 3 is a flow chart of obtaining a liveness detection result in one embodiment of the present application;
[0048] Figure 4 is a flowchart of reordering the first interpretation text in one embodiment of the present application;
[0049] Figure 5 is a flow chart of performing liveness detection in one embodiment of the present application;
[0050] Figure 6 Schematic diagram of a living body detection device proposed in an embodiment of the present application. DETAILED DESCRIPTION
[0051] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0052] It should be understood that the references to "one embodiment" or "an embodiment" throughout the specification mean that the specific features, structures, or characteristics associated with the embodiment are included in at least one embodiment of the present application. Therefore, the references to "in one embodiment" or "in an embodiment" appearing throughout the specification do not necessarily refer to the same embodiment. In addition, these specific features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.
[0053] In the various embodiments of the present application, it should be understood that the size of the serial numbers of the following processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0054] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects as detailed in the present application.
[0055] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application may be combined with each other.
[0056] The current method of generating the basis for liveness judgment through visual language models is to train the visual language models with liveness data in advance, and then use the trained visual language models to generate liveness explanation text. This method has the following defects:
[0057] First, the visual language model uses an autoregressive method to make predictions, and its reasoning process takes a long time and cannot meet the needs of immediacy. Taking the API (Application Programming Interface) call scenario as an example, users expect the liveness judgment result and the corresponding explanation text to be output within 1 second, but due to the time-consuming engineering, the algorithm-side model reasoning time is generally kept within 500 milliseconds, and the smallest open source visual language model (6B) can only output two or three tokens within 500 milliseconds on a common commercial GPU (Graphics Processing Unit), which obviously cannot fully explain the liveness judgment within 1 second.
[0058] Second, visual language models often have hallucinations, which leads to inaccurate judgments. For example, when generating explanatory text, the color of the person’s clothes in the image may be misjudged.
[0059] Third, due to the lack of knowledge in the relevant field, the model often makes counterintuitive judgments, resulting in inaccurate judgments. For example, when generating explanatory text, the visual language model may say, "Because this man is wearing black clothes, he looks like a bad guy, so this image is an attack in the living field."
[0060] This embodiment adopts a graphic-text retrieval method to replace the autoregressive output of the traditional visual language model, and matches the existing liveness explanation text in the existing liveness detection explanation text library, which saves the word generation process and greatly shortens the reasoning time of the liveness judgment basis.
[0061] The present application will be described in detail below with reference to the accompanying drawings and in combination with embodiments.
[0062] Figure 1 FIG. 1 is a flow chart of a liveness detection method proposed in an embodiment of the present application. Figure 1 As shown, the living body detection method includes:
[0063] S1: Acquire an image to be detected of an object to be detected; wherein the image to be detected includes a face area of the object to be detected;
[0064] S2: inputting the image to be detected into a liveness detection model and a liveness detection interpretation model respectively, obtaining the liveness detection result of the object to be detected output by the liveness detection model, and obtaining a first interpretation text corresponding to the liveness detection result output by the liveness detection interpretation model; wherein the first interpretation text is used to characterize the reason for detecting the liveness detection result, and the first interpretation text is retrieved from a liveness detection interpretation text library based on the image to be detected by the liveness detection interpretation model, and the liveness detection interpretation text library stores liveness interpretation texts corresponding to multiple liveness attack types.
[0065] In this embodiment, firstly, an image to be detected of the object to be detected (person) is obtained. Liveness detection is usually used for identity verification of personnel. When obtaining an image to be detected of the object to be detected, the image to be detected can be obtained by shooting an image containing the object to be detected, or by shooting a video containing the object to be detected, and further obtaining the image to be detected from the video frame.
[0066] Then, the image to be detected is input into the liveness detection model and the liveness detection interpretation model respectively. The liveness detection model performs liveness detection on the image to be detected to obtain a liveness detection result, and the liveness detection interpretation model outputs a first interpretation text matching the liveness detection result.
[0067] As an implementation manner of the present application, the living body detection interpretation text library is constructed through the following process:
[0068] Get the text describing each type of live attack;
[0069] Classify the acquired text according to the attack type;
[0070] The classified texts and corresponding attack types are stored to obtain a liveness detection explanation text library.
[0071] Since there are a lot of knowledge texts in the liveness detection task, it is necessary to build an external knowledge base. In one embodiment, in order to improve the accuracy of the liveness detection judgment basis and avoid hallucinations and counter-common sense reasoning, a dedicated liveness detection explanation text library is built before performing retrieval.
[0072] A certain amount of descriptive texts that can be used as the basis for reasoning about liveness detection results are obtained, and the obtained texts are classified and stored according to different attack types. In this embodiment, according to the types of attacks in liveness detection tasks, liveness attack types are roughly divided into ten categories, and their specific causes are roughly divided into thirty or forty categories, and a liveness detection explanation text library is established based on the descriptive texts of the specific causes of all liveness attack types (i.e., liveness explanation texts).
[0073] In this embodiment, when constructing a liveness detection interpretation text library, the classified and stored liveness interpretation texts are all descriptive texts with universality (i.e., no sentences such as clothing color will appear), such as "the border of the electronic device is exposed, so it is judged to be a screen copy", or "the picture is not clear and there seems to be moiré patterns, so it is judged to be a screen copy", etc.
[0074] By pre-building an external liveness detection interpretation text library, non-universal liveness interpretation texts can be avoided from being put into it during the construction process, thereby avoiding the occurrence of hallucinations or counter-common sense inferences in the first interpretation text matched and output by the liveness detection interpretation model for the image to be detected, thereby improving the accuracy of the judgment basis of the final output.
[0075] As an implementation manner of the present application, the process of retrieving a first explanation text corresponding to the liveness detection result from a liveness detection explanation text library based on the image to be detected by using a liveness detection explanation model includes:
[0076] Extracting a first image feature of the image to be detected by using the living body detection interpretation model;
[0077] Acquire text features corresponding to each living body interpretation text in the living body detection interpretation text library;
[0078] The first image feature is matched with each acquired text feature in terms of similarity to obtain a first interpretation text corresponding to the living body detection result.
[0079] Figure 2 This is a flow chart of obtaining the first explanation text in one embodiment of the present application. In the present application, the living body detection explanation model includes a text encoder and an image encoder, and processes the image to be detected by a multi-modal image-text retrieval method.
[0080] like Figure 2 As shown, in one embodiment, the text features of all living body explanation texts in the living body detection explanation text library are extracted in advance by the first text encoder in the living body detection explanation model to obtain multiple text features. When performing a living body detection task, the image to be detected is input into the living body detection explanation model, and the first image encoder of the living body detection explanation model extracts the image features in the image to be detected to obtain a first image feature, and further uses the first image feature to perform similarity matching with multiple text features extracted in advance to obtain a first explanation text corresponding to the living body detection result.
[0081] Optionally, after obtaining the liveness detection result through the liveness detection model, the first interpretation text is used as a judgment basis for the liveness detection result, and the two are combined as the final result output.
[0082] In one embodiment, a similarity calculation is performed on the first image feature and multiple text features to obtain a similarity calculation result between all text features and the first image feature. Based on the similarity calculation result, one or more text features matching the first image feature are screened out, and the corresponding living explanation text is determined based on the screened text features as the first explanation text. The first explanation text can be one or more. In the case where there are multiple first explanation texts, each first explanation text has a corresponding similarity value. All first explanation texts output by the living body detection explanation model are sorted from high to low according to the similarity value. Optionally, the first explanation text of TOP1 (with the highest similarity value) is used as the basis for judging the living body detection result, and the two are combined as the final result of the output.
[0083] In one embodiment, the number of first interpretation texts output by the living body detection interpretation model can be limited. The number of first interpretation texts is limited by setting a first threshold. Starting from the text features with the highest similarity in the similarity calculation results, the text features with the first threshold number are screened out, and then the living body interpretation texts with the first threshold number are determined as the first interpretation texts. Or, the similarity value corresponding to the first interpretation text is limited by setting a second threshold. According to the second threshold, text features with similarity values higher than the second threshold are screened out from the similarity calculation results, and then the corresponding first interpretation text is determined based on the screened text features.
[0084] In one embodiment, a lightweight TinyCLIP (Contrastive Language-Image Pre-Training) model is used as a liveness detection interpretation model. This model is a general model for image-text matching. Considering that the model is pre-trained on a general image-text pair (e.g., laion2B), it is inevitable that the model's ability to extract features on face data and the accuracy of image-text matching will suffer. In order to improve the model's ability to extract features and the accuracy of matching face data in liveness detection tasks, this embodiment uses additional face data pair training samples to fine-tune the TinyCLIP model. Specifically, a face detection model (e.g., RetinaFace) is used to detect open source image-text pair data (e.g., laion400M), and the part containing the face (approximately 40M) is selected as the target training image. The liveness interpretation text in the liveness detection interpretation text library is used to manually annotate the target training image to generate a target training set in the form of image-text pairs. Before performing the liveness detection task, the TinyCLIP model is pre-trained using the target training set.
[0085] In this embodiment, the image-text processing model (TinyCLIP) is fine-tuned using facial data to obtain the final liveness detection interpretation model, so that the image encoder of the liveness detection interpretation model has the visual compression capability of facial images, making the matched first interpretation text more accurate.
[0086] It is worth noting that the present embodiment uses target training data in the form of face image-text pairs to perform comparative learning on the image-text processing model, which has the following advantages compared to the method of directly using the liveness detection classification model to train according to all liveness interpretation texts in the liveness detection interpretation text library:
[0087] (1) The amount of pre-training data for image and text processing models (such as laion) is much larger than that for liveness detection and classification models (such as ImageNet), so image and text processing models have better generalization capabilities;
[0088] (2) The pre-training data of the image-text processing model already includes image-text pair data of human faces. On this basis, it is convenient to use some of the human face images to generate a target training set and further train the image-text processing model to enhance the representation capability of the first image encoder for human face images.
[0089] (3) In the process of processing liveness detection tasks, there is a need to add new liveness explanation texts to the liveness detection explanation text library. On this basis, if the liveness detection classification model is directly trained, a large amount of data needs to be used to retrain the model, and the training cost is too high. However, by using the image-text processing model for comparative learning, it is only necessary to extract the text features of the newly added liveness explanation texts and embed them;
[0090] (4) Since contrastive learning involves the concept of distance, the liveness detection interpretation model trained by contrastive learning calculates the first interpretation text determined by similarity. Even if the first interpretation text with the highest similarity score does not match the image to be detected, the probability that the first interpretation texts with the second and third similarity scores match the image to be detected is much greater than the probability that the liveness interpretation texts with the second and third similarity scores in the output results of the liveness detection classification model match the image to be detected.
[0091] As an implementation manner of the present application, the liveness detection model obtains the liveness detection result of the object to be detected through the following process:
[0092] Extracting a second image feature of the image to be detected through a living body detection model, and acquiring a first image feature of the image to be detected from the living body detection interpretation model;
[0093] Fusing the first image feature with the second image feature to generate a fused image feature;
[0094] The fused image features are processed to obtain the living body detection result.
[0095] In one embodiment, the liveness detection interpretation model obtained after fine-tuning based on face data has the visual compression capability of face images. Therefore, it is integrated with the image features extracted by the original liveness detection classification model to obtain more accurate image features, thereby improving the accuracy of liveness detection and the generalization ability of the model.
[0096] Figure 3 FIG. 1 is a flow chart of obtaining a liveness detection result in an embodiment of the present application. Figure 3 As shown in the figure, the liveness detection model extracts image features from the image to be detected to obtain a second image feature. The first image feature generated by the first image encoder in the liveness detection interpretation model is fused with the second image feature to generate a fused image feature. Then, the fused image feature is passed through a fully connected layer and a Softmax layer to obtain a liveness detection result.
[0097] Optionally, the first interpretation text output by the liveness detection interpretation model is used as a judgment basis for obtaining the liveness detection result, and the two are combined as the final result output.
[0098] In this embodiment, by fusing the image features extracted by the liveness detection model and the liveness detection interpretation model respectively, the liveness detection model can perform detection and classification based on the fused image features with richer information, thereby obtaining a more accurate liveness detection result.
[0099] As an implementation manner of the present application, fusing the first image feature with the second image feature to generate a fused image feature includes any of the following methods:
[0100] Mapping the first image feature into a key vector k and a value vector v, mapping the second image feature into a query vector q, and fusing the first image feature and the second image feature using a cross attention mechanism to obtain a fused image feature;
[0101] Mapping the second image feature into a key vector k and a value vector v, mapping the first image feature into a query vector q, and fusing the first image feature and the second image feature using a cross attention mechanism to obtain a fused image feature;
[0102] The dimension of the first feature vector corresponding to the first image feature and the dimension of the second feature vector corresponding to the second image feature are adjusted to the same dimension, and the dimension-adjusted first feature vector and the dimension-adjusted second feature vector are concatenated to obtain a fused image feature;
[0103] The dimension of a first feature vector corresponding to the first image feature and the dimension of a second feature vector corresponding to the second image feature are adjusted to the same dimension, and weighted summation is performed according to the weights of the first feature vector after the dimension adjustment and the second feature vector after the dimension adjustment to obtain a fused image feature.
[0104] In one embodiment, a suitable fusion method may be used to fuse the first image feature and the second image feature, including but not limited to the four methods provided in this embodiment. In practical applications, the method may be selected as needed. In this embodiment, the above four fusion methods are tested. After testing, the fused image features generated by splicing using the third method can enable the liveness detection model to output liveness detection results with higher classification accuracy.
[0105] As an implementation manner of the present application, if the living body detection interpretation model outputs multiple first interpretation texts, the method further includes:
[0106] The image to be detected and the multiple first interpretation texts are input into a reordering model, the multiple first interpretation texts are sorted by the reordering model, and a text sorting result of the multiple first interpretation texts is output, and the first interpretation text ranked first in the text sorting result is determined as the final interpretation text corresponding to the living body detection result.
[0107] In one embodiment, considering that the encoding (understanding) of the text by the first text encoder may not be accurate enough, the first interpretation text with the highest similarity value among the multiple first interpretation texts output by the liveness detection interpretation model may not be the most consistent with the image to be detected, that is, the liveness detection interpretation model still has the problem of hallucination. Therefore, in order to alleviate the model hallucination, all the first interpretation texts are further sorted and adjusted through the re-ranking model.
[0108] Figure 4 FIG. 1 is a flowchart of reordering the first interpretation text in one embodiment of the present application. Figure 4 As shown, after the liveness detection interpretation model outputs multiple first interpretation texts, the image to be detected and all the first interpretation texts are input into the reordering model, and the reordering model adjusts the order of the first interpretation texts to generate a text sorting result. After reordering, the first interpretation text with a higher order is more consistent with the image to be detected, that is, the probability that the first interpretation text is the basis for judging the liveness detection result is greater. The TOP1 text in the text sorting result is used as the basis for judging the liveness detection result, and the two are combined as the final output result.
[0109] In this embodiment, all the first interpretation texts are sorted based on the image to be detected by the re-ranking model, so as to further alleviate the hallucination problem of the living body detection interpretation model, so that the final output judgment basis is more consistent with the image to be detected.
[0110] As an implementation manner of the present application, the reordering model includes a text encoder, an image encoder, and a cross attention module connected between the text encoder and the image encoder; the multiple first interpretation texts are sorted by the reordering model to obtain the text sorting result, including:
[0111] Encoding the plurality of first interpreted texts by the text encoder to obtain text encoding results of the plurality of first interpreted texts;
[0112] Encoding the image to be detected by the image encoder to obtain an image encoding result;
[0113] The text encoding results of the multiple first interpretation texts and the image encoding results are processed through the cross-attention module to obtain the text sorting result.
[0114] In this embodiment, the reordering model includes a text encoder and an image encoder, which are connected by a cross attention module. Different from the general reordering model in the field of pure text, the reordering model in this embodiment can process the first interpretation text according to the information of the image to be detected, so that the first interpretation text that is more consistent with the image to be detected is ranked higher, thereby improving the accuracy of the output judgment basis.
[0115] Optionally, the image encoder in the re-ranking model uses the image encoder in the TinyCLIP model, and the text encoder uses BERT (Bidirectional Encoder Representations from Transformers). The image encoder extracts features from the image to be detected, and the text encoder extracts text features from multiple first interpretation texts. The image features and text features are processed through a cross-attention module, and finally the multiple first interpretation texts after adjustment and sorting are output. Relying on the powerful text compression capability of BERT, when the TOP1 text in the text sorting result replaces the TOP1 text before re-ranking as the basis for liveness judgment, the accuracy of the output result is greatly improved.
[0116] A large number of image-text pair samples are used in advance to train the re-ranking model. During the training process, each image-text pair sample includes: an image, a positive sample of the text ranking result corresponding to the image, and multiple negative samples of the text ranking results corresponding to the image. For example, in an image-text pair sample, including image 1 and 3 texts A, B, C, the positive sample of the text ranking result is: ABC; the negative samples of the text ranking result include: ACB, BAC, BCA, CAB, CBA.
[0117] As an implementation manner of the present application, the liveness detection method further includes:
[0118] The first explanation text corresponding to the image to be detected and the liveness detection result is input into a visual language model, and the first explanation text is updated based on the image to be detected by the visual language model to obtain a second explanation text corresponding to the liveness detection result.
[0119] In one embodiment, the image to be detected and the TOP1 text are further input into a visual language model, and the visual language model is updated based on the first interpretation text to obtain a second interpretation text that is more consistent with the image to be detected.
[0120] It is worth noting that the TOP1 text input into the visual language model is the TOP1 text in the multiple first interpretation texts output by the living body detection interpretation model sorted by similarity value, or the TOP1 text in the text sorting result output by the re-ranking model.
[0121] As an implementation manner of the present application, updating the first interpretation text based on the image to be detected by the visual language model to obtain a second interpretation text corresponding to the liveness detection result includes:
[0122] Analyzing the image to be detected by using the visual language model to obtain an image description text of the image to be detected;
[0123] The image description text of the image to be detected and the first explanation text are fused through the visual language model to obtain a second explanation text corresponding to the living body detection result.
[0124] Figure 5 FIG. 1 is a flowchart of performing liveness detection in one embodiment of the present application. Figure 5As shown, after the reordering module outputs the text sorting result, the TOP1 text is input into the visual language model together with the image to be detected. The visual language model analyzes the image to be detected and generates a more customized image description text about the image to be detected. The image description text is not universal, for example, it involves personalized descriptions such as clothing and accessories of the characters in the image. The visual language model merges the image description text with the input first explanation text (TOP1 text) to update the second explanation text that is more suitable for the image to be detected. For example, the second explanation text will mention the gender of the person in the image, the color of the clothes, whether he wears glasses and other descriptive information. Further, the second explanation text is used as the basis for judging the liveness detection result, and the two are combined as the final output result.
[0125] The visual language model is used to add a non-universal personalized description to the first interpretation text, so that the judgment basis is more closely related to the image to be detected. The output judgment basis contains richer information, thereby optimizing the user experience.
[0126] In this embodiment, the visual language model is obtained after fine-tuning the traditional visual language model. In view of the hallucination problem of the traditional visual language model, in order to alleviate the hallucination problem, the model is trained and fine-tuned using sample images and corresponding image description texts. In the process of training the visual language model, an interleaved training method is used to improve the hallucination problem. Specifically, customized description information at the image description level is randomly added according to a preset ratio (for example, asking whether the person in the model image wears glasses and giving a yes / no answer), so as to alleviate the hallucination problem of the visual language model.
[0127] In one embodiment, it is also necessary to determine whether the application scenario of the above-mentioned liveness detection method is online liveness detection or offline liveness detection, and whether to use the visual language model is determined according to the application scenario. Usually, liveness detection tasks in online scenarios have timeliness requirements, such as requiring the model running online to return results within 1 second. In this case, since the delay of the visual language model is relatively high and cannot meet the specified response time, the TOP1 text output by the reordering model is directly used as the basis for judging the final output in the online scenario. Liveness detection in offline scenarios usually does not have very strict requirements on the response speed, that is, it is not required to return results within 1 second. Therefore, in offline scenarios, the image to be detected and the TOP1 text output by the reordering model can be further input into the visual language model to obtain a second interpretation text, and the second interpretation text is used as the basis for judging the final output.
[0128] In one embodiment, in a scenario with a real-time response requirement (i.e., returning a result within 1 second), it is also necessary to determine whether to use the reordering model based on the type of hardware device that performs the liveness detection task. Image processing involves a large number of pixel operations and matrix operations, many of which can be performed in parallel and involve a large number of floating-point operations.
[0129] If the device performing the liveness detection task is a CPU (Central Processing Unit), it has no advantage in parallel processing. Therefore, when using the CPU for reasoning in an online scenario, in order to meet the response latency requirements, the reordering model is not used, that is, the TOP1 text output by the liveness detection interpretation model is directly used as the basis for judging the final output.
[0130] If the device performing the liveness detection task is a GPU, since the GPU is dedicated to processing graphics rendering and has stronger parallel processing capabilities, floating-point computing capabilities, and higher memory bandwidth than the CPU, when using the CPU for reasoning, all the first interpretation texts output by the liveness detection interpretation model can be further input into the reordering module.
[0131] Based on the same inventive concept, an embodiment of the present application provides a living body detection device. Figure 6 FIG. 2 is a schematic diagram of a living body detection device 200 proposed in an embodiment of the present application. Figure 6 As shown, the device comprises:
[0132] The first processing module 201 is configured to obtain an image to be detected of the object to be detected; wherein the image to be detected includes a face area of the object to be detected;
[0133] The second processing module 202 is configured to input the image to be detected into a liveness detection model and a liveness detection interpretation model respectively, obtain the liveness detection result of the object to be detected output by the liveness detection model, and obtain a first interpretation text corresponding to the liveness detection result output by the liveness detection interpretation model; wherein the first interpretation text is used to characterize the reason for detecting the liveness detection result, and the first interpretation text is retrieved from a liveness detection interpretation text library based on the image to be detected by the liveness detection interpretation model, and the liveness detection interpretation text library stores liveness interpretation texts corresponding to multiple liveness attack types.
[0134] As an implementation manner of the present application, the second processing module 202 is configured to retrieve the first explanation text corresponding to the liveness detection result from the liveness detection explanation text library based on the image to be detected through the liveness detection explanation model, and the process specifically includes:
[0135] Extracting a first image feature of the image to be detected by using the living body detection interpretation model;
[0136] Acquire text features corresponding to each living body interpretation text in the living body detection interpretation text library;
[0137] The first image feature is matched with each acquired text feature in terms of similarity to obtain a first interpretation text corresponding to the living body detection result.
[0138] As an implementation manner of the present application, if the living body detection interpretation model outputs multiple first interpretation texts, the second processing module 202 is further configured to perform the following steps:
[0139] The image to be detected and the multiple first interpretation texts are input into a reordering model, the multiple first interpretation texts are sorted by the reordering model, and a text sorting result of the multiple first interpretation texts is output, and the first interpretation text ranked first in the text sorting result is determined as the final interpretation text corresponding to the living body detection result.
[0140] As an implementation of the present application, the reordering model includes a text encoder, an image encoder, and a cross attention module connected between the text encoder and the image encoder;
[0141] The second processing module 202 is configured to sort the plurality of first interpretation texts by using the re-sorting model to obtain the text sorting result, which specifically includes:
[0142] Encoding the plurality of first interpreted texts by the text encoder to obtain text encoding results of the plurality of first interpreted texts;
[0143] Encoding the image to be detected by the image encoder to obtain an image encoding result;
[0144] The text encoding results of the multiple first interpretation texts and the image encoding results are processed through the cross-attention module to obtain the text sorting result.
[0145] As an embodiment of the present application, the second processing module 202 is also configured to input the first interpretation text corresponding to the image to be detected and the liveness detection result into a visual language model, and update the first interpretation text based on the image to be detected through the visual language model to obtain a second interpretation text corresponding to the liveness detection result.
[0146] As an implementation manner of the present application, the second processing module 202 is configured to update the first interpretation text based on the image to be detected through the visual language model to obtain a second interpretation text corresponding to the liveness detection result, specifically including:
[0147] Analyzing the image to be detected by using the visual language model to obtain an image description text of the image to be detected;
[0148] The image description text of the image to be detected and the first explanation text are fused through the visual language model to obtain a second explanation text corresponding to the living body detection result.
[0149] As an implementation manner of the present application, the second processing module 202 includes:
[0150] an extraction submodule, configured to extract the second image feature of the image to be detected through the living body detection model, and to obtain the first image feature of the image to be detected from the living body detection interpretation model;
[0151] a fusion submodule, configured to fuse the first image feature with the second image feature to generate a fused image feature;
[0152] The second processing module 202 is further configured to process the fused image features through the liveness detection model to obtain the liveness detection result.
[0153] As an implementation manner of the present application, the fusion submodule is configured to fuse the first image feature with the second image feature to generate a fused image feature, including any of the following methods:
[0154] Mapping the first image feature into a key vector k and a value vector v, mapping the second image feature into a query vector q, and fusing the first image feature and the second image feature using a cross attention mechanism to obtain a fused image feature;
[0155] Mapping the second image feature into a key vector k and a value vector v, mapping the first image feature into a query vector q, and fusing the first image feature and the second image feature using a cross attention mechanism to obtain a fused image feature;
[0156] The dimension of the first feature vector corresponding to the first image feature and the dimension of the second feature vector corresponding to the second image feature are adjusted to the same dimension, and the dimension-adjusted first feature vector and the dimension-adjusted second feature vector are concatenated to obtain a fused image feature;
[0157] The dimension of a first feature vector corresponding to the first image feature and the dimension of a second feature vector corresponding to the second image feature are adjusted to the same dimension, and weighted summation is performed according to the weights of the first feature vector after the dimension adjustment and the second feature vector after the dimension adjustment to obtain a fused image feature.
[0158] Based on the same inventive concept, an embodiment of the present application provides an electronic device, including:
[0159] processor;
[0160] a memory for storing instructions executable by the processor;
[0161] The processor is configured to execute the instructions to implement the steps of the living body detection method provided in the above embodiment.
[0162] Based on the same inventive concept, an embodiment of the present application provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the liveness detection method provided in the above embodiment are implemented.
[0163] Based on the same inventive concept, an embodiment of the present application provides a computer program product, including a computer program. When the computer program is executed by a processor, the steps of the living body detection method provided in the above embodiment are implemented.
[0164] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0165] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application.
[0166] For the method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the order of the actions described, because according to the present application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and components involved are not necessarily required by the present application.
[0167] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the embodiments of the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0168] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0169] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0170] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0171] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they are aware of the basic creative concepts. Therefore, the present application is intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present application.
[0172] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0173] The liveness detection method, product and storage medium provided by the present application are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for general technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A method for detecting a living body, characterized in that: include: Acquire an image to be detected of the object to be detected; wherein the image to be detected includes a facial area of the object to be detected; The image to be detected is input into a liveness detection model and a liveness detection interpretation model respectively, and a liveness detection result of the object to be detected output by the liveness detection model is obtained, and a first interpretation text corresponding to the liveness detection result output by the liveness detection interpretation model is obtained; wherein the first interpretation text is used to characterize the reason for detecting the liveness detection result, and the first interpretation text is retrieved from a liveness detection interpretation text library based on the image to be detected by the liveness detection interpretation model, and the liveness detection interpretation text library stores liveness interpretation texts corresponding to multiple liveness attack types.
2. The method for detecting living body according to claim 1, characterized in that: The process of retrieving a first explanation text corresponding to the liveness detection result from a liveness detection explanation text library based on the image to be detected by using a liveness detection explanation model includes: Extracting a first image feature of the image to be detected by using the living body detection interpretation model; Acquire text features corresponding to each living body interpretation text in the living body detection interpretation text library; The first image feature is matched with each acquired text feature in terms of similarity to obtain a first interpretation text corresponding to the living body detection result.
3. The method for detecting living body according to claim 1, characterized in that: If the living body detection explanation model outputs a plurality of first explanation texts, the method further includes: The image to be detected and the multiple first interpretation texts are input into a reordering model, the multiple first interpretation texts are sorted by the reordering model, and a text sorting result of the multiple first interpretation texts is output, and the first interpretation text ranked first in the text sorting result is determined as the final interpretation text corresponding to the living body detection result.
4. The method for liveness detection according to claim 3, characterized in that: The re-ranking model includes a text encoder, an image encoder, and a cross-attention module connected between the text encoder and the image encoder; Sorting the plurality of first interpretation texts by using the reordering model to obtain the text sorting result includes: Encoding the plurality of first interpreted texts by the text encoder to obtain text encoding results of the plurality of first interpreted texts; Encoding the image to be detected by the image encoder to obtain an image encoding result; The text encoding results of the multiple first interpretation texts and the image encoding results are processed through the cross-attention module to obtain the text sorting result.
5. The method for liveness detection according to claim 1, characterized in that: Also includes: The first explanation text corresponding to the image to be detected and the liveness detection result is input into a visual language model, and the first explanation text is updated based on the image to be detected by the visual language model to obtain a second explanation text corresponding to the liveness detection result.
6. The method for liveness detection according to claim 5, characterized in that: The first explanation text is updated based on the image to be detected by the visual language model to obtain a second explanation text corresponding to the living body detection result, including: Analyzing the image to be detected by using the visual language model to obtain an image description text of the image to be detected; The image description text of the image to be detected and the first explanation text are fused through the visual language model to obtain a second explanation text corresponding to the living body detection result.
7. The method for detecting a living body according to any one of claims 1 to 6, characterized in that: The liveness detection model obtains the liveness detection result of the object to be detected through the following process: Extracting a second image feature of the image to be detected through a living body detection model, and acquiring a first image feature of the image to be detected from the living body detection interpretation model; Fusing the first image feature with the second image feature to generate a fused image feature; The fused image features are processed to obtain the living body detection result.
8. The method for liveness detection according to claim 7, characterized in that: The first image feature and the second image feature are fused to generate a fused image feature, including any of the following methods: Mapping the first image feature into a key vector k and a value vector v, mapping the second image feature into a query vector q, and fusing the first image feature and the second image feature using a cross attention mechanism to obtain a fused image feature; Mapping the second image feature into a key vector k and a value vector v, mapping the first image feature into a query vector q, and fusing the first image feature and the second image feature using a cross attention mechanism to obtain a fused image feature; The dimension of the first feature vector corresponding to the first image feature and the dimension of the second feature vector corresponding to the second image feature are adjusted to the same dimension, and the dimension-adjusted first feature vector and the dimension-adjusted second feature vector are concatenated to obtain a fused image feature; The dimension of a first feature vector corresponding to the first image feature and the dimension of a second feature vector corresponding to the second image feature are adjusted to the same dimension, and weighted summation is performed according to the weights of the first feature vector after the dimension adjustment and the second feature vector after the dimension adjustment to obtain a fused image feature.
9. The method for detecting a living body according to any one of claims 1 to 6, characterized in that: The living body detection explanation text library is constructed through the following process: Get the text describing each type of live attack; Classify the acquired text according to the attack type; The classified texts and corresponding attack types are stored to obtain a liveness detection explanation text library.
10. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the steps of the liveness detection method described in any one of claims 1-9.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the living body detection method described in any one of claims 1 to 9 are implemented.
12. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the living body detection method according to any one of claims 1 to 9 are implemented.
