A method, device and storage medium for training an anomaly detection model
By training an anomaly detection model and optimizing it using the feature differences between real and synthetic face images, the problem of user privacy leakage in image generation technology is solved, and accurate detection of synthetic face images is achieved, ensuring the accuracy and security of detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ALIPAY (HANGZHOU) INFORMATION TECH CO LTD
- Filing Date
- 2022-12-12
- Publication Date
- 2026-05-29
AI Technical Summary
In existing technologies, network attacks based on image generation methods lead to the leakage of user privacy, especially the risk of using face spoofing technology to generate fake face images to impersonate information and obtain user data has not been effectively resolved.
By acquiring real face images as positive samples and synthetic face images as negative samples, an anomaly detection model is trained. Sample features are extracted using feature extraction and classification layers, and the model is optimized based on the differences between representative features and sample features to ensure that the model can accurately distinguish between real and synthetic face images.
It achieves accurate detection of synthetic face images, ensures the accuracy of anomaly detection, and reduces the risk of user privacy leakage.
Smart Images

Figure CN116152933B_ABST
Abstract
Description
Technical Field
[0001] This specification relates to the field of computer technology, and in particular to a training method, apparatus, device, and storage medium for an anomaly detection model. Background Technology
[0002] Currently, with the rapid development of the internet, image generation methods are being used more and more widely in people's lives. This has led to a surge in cyberattacks based on these image generation methods, posing a risk of user privacy breaches. For example, facial spoofing technology can be used to generate fake faces and then used to impersonate others and obtain user data.
[0003] Based on this, this specification provides an anomaly detection method for recognizing non-real human face images. Summary of the Invention
[0004] This specification provides a training method, apparatus, device, and storage medium for an anomaly detection model, in order to partially solve the aforementioned problems existing in the prior art.
[0005] The following technical solution is adopted in this specification:
[0006] This specification provides a training method for an anomaly detection model, including:
[0007] Obtain real human face images as positive samples and synthetic human face images as negative samples, and use the positive samples and the negative samples as training samples.
[0008] Determine the sample set consisting of several training samples;
[0009] For each training sample in the sample set, the training sample is input into the feature extraction layer of the anomaly detection model to be trained, and the sample features of the training sample are output by the feature extraction layer.
[0010] The sample features are input into the classification layer of the anomaly detection model to obtain the detection result of the training sample output by the classification layer;
[0011] Based on the sample characteristics of each positive sample in the sample set, representative features for characterizing the commonalities of positive samples are determined;
[0012] The anomaly detection model is trained with the optimization objectives of minimizing the difference between the sample features of each positive sample in the sample set and the representative features, maximizing the difference between the sample features of each negative sample in the sample set and the representative features, and minimizing the difference between the detection results and their annotations of each training sample in the sample set. The trained anomaly detection model is then used to detect synthetic face images.
[0013] This specification provides a training device for an anomaly detection model, comprising:
[0014] The acquisition module is used to acquire real face images as positive samples and synthetic face images as negative samples, and to use the positive samples and the negative samples as training samples.
[0015] The first determining module is used to determine the sample set consisting of several training samples;
[0016] The extraction module is used to input each training sample in the sample set into the feature extraction layer of the anomaly detection model to be trained, and obtain the sample features of the training sample output by the feature extraction layer.
[0017] The classification module is used to input the features of the sample into the classification layer of the anomaly detection model to obtain the detection result of the training sample output by the classification layer.
[0018] The second determining module is used to determine representative features for characterizing the commonalities of positive samples based on the sample features of each positive sample in the sample set.
[0019] The training module is used to train the anomaly detection model with the optimization objectives of minimizing the difference between the sample features of each positive sample in the sample set and the representative features, maximizing the difference between the sample features of each negative sample in the sample set and the representative features, and minimizing the difference between the detection results and their annotations of each training sample in the sample set. The trained anomaly detection model is used to detect synthetic face images.
[0020] This specification provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the training method for the above-described anomaly detection model.
[0021] This specification provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the training method of the above-described anomaly detection model.
[0022] The above-mentioned technical solutions adopted in this specification can achieve the following beneficial effects:
[0023] Real face images are acquired as positive samples, and synthetic face images are acquired as negative samples. These positive and negative samples are used as training samples. The feature extraction layer of the anomaly detection model extracts the sample features of each training sample. A classification layer obtains the detection results for each training sample. Based on the sample features of each positive sample, representative features are determined to characterize the commonalities of the positive samples. The loss is determined based on the differences between the sample features and representative features of each positive sample, the differences between the sample features and representative features of each negative sample, and the differences between the detection results and their annotations of each training sample. The anomaly detection model is trained with the goal of minimizing this loss.
[0024] This method can learn an accurate feature extraction method based on representative features, so as to accurately extract facial features from face images for accurate anomaly detection, thus ensuring the accuracy of anomaly detection. Attached Figure Description
[0025] The accompanying drawings, which are included to provide a further understanding of this specification and form part of this specification, illustrate exemplary embodiments and their descriptions, serving to explain this specification and do not constitute an undue limitation thereof.
[0026] In the picture:
[0027] Figure 1 This is a flowchart illustrating the training method for the anomaly detection model provided in this manual.
[0028] Figure 2 This is a schematic diagram of the training device for the anomaly detection model provided in this specification;
[0029] Figure 3 The corresponding information provided in this specification Figure 1 A schematic diagram of an electronic device. Detailed Implementation
[0030] To make the objectives, technical solutions, and advantages of this specification clearer, the technical solutions of this specification will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this specification, and not all of them. Based on the embodiments in this specification, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this specification.
[0031] Currently, with the development of internet technology, image generation technology has also advanced. However, methods of attack using image generation technology are also emerging in endless streams, posing a threat to users' personal privacy. Taking face synthesis technology as an example, faces synthesized using this technology are often used for illegal activities such as fake registrations.
[0032] Based on this, this specification provides a new method for anomaly detection.
[0033] The technical solutions provided in the various embodiments of this specification are described in detail below with reference to the accompanying drawings.
[0034] Figure 1 This is a schematic diagram illustrating the execution flow of a training method for an anomaly detection model described in this specification, specifically including the following steps:
[0035] S100: Obtain real face images as positive samples and synthetic face images as negative samples, and use the positive samples and the negative samples as training samples.
[0036] In one or more embodiments provided in this specification, the training method for the anomaly detection model may be executed by a server.
[0037] To address the issue of high computational resource requirements when using similarity between the target face image and a pre-stored set of specified face images for anomaly detection, especially when the number of specified face images is large, this specification provides a training method for an anomaly detection model. By training a model capable of accurately distinguishing between real and synthetic face images based on extracted features, when a target face image is obtained, it can be input directly into the anomaly detection model to determine the corresponding anomaly detection result. Therefore, the server can train this anomaly detection model. Typically, model training can be divided into a sample determination phase, a sample processing phase, and a training phase.
[0038] Based on this, the server can obtain training samples.
[0039] Specifically, since the anomaly detection model provided in this specification is used to detect non-real face images, i.e., synthetic face images, the training objective of this anomaly detection model should be to distinguish between real face images and synthetic face images.
[0040] Therefore, the server can acquire several real face images as positive samples and several synthetic face images as negative samples. Both the identified positive and negative samples can then be used as training samples.
[0041] The synthesized face image can be automatically generated by a face generation model, or generated by other models capable of manipulating face images by replacing a region or part of a real face image. The specific method for determining the abnormal face image can be set as needed; this manual does not impose any restrictions on this.
[0042] It should be noted that all actions involving the acquisition of facial images in this manual are carried out in compliance with the relevant data protection laws and regulations of the country where the user is located, and with authorization from the owner of the relevant device.
[0043] S102: Determine the sample set consisting of several training samples.
[0044] In one or more embodiments provided in this specification, after determining the training samples, the server may further select several training samples from the training samples to form a sample set. The anomaly detection model can then be trained based on the training samples contained in this sample set. The specific method for determining the sample set and the number of samples contained in the sample set can be set as needed, and this specification does not impose any limitations on this.
[0045] S104: For each training sample in the sample set, input the training sample into the feature extraction layer of the anomaly detection model to be trained, and obtain the sample features of the training sample output by the feature extraction layer.
[0046] In one or more embodiments provided in this specification, the anomaly detection model provided herein is trained to accurately classify real and synthetic face images based on the features of face images, thereby detecting synthetic face images. Typically, for a given class of data, features corresponding to that class of data can be learned to represent that class of data. Based on this, the server can first determine the sample features corresponding to each training sample.
[0047] Specifically, for each training sample in the sample set, the server can use the training sample as input to the feature extraction layer of the anomaly detection model to be trained, and obtain the sample features corresponding to the training sample output by the feature extraction layer.
[0048] The feature extraction layer is used to determine the features corresponding to the face image, so that the extracted features can be classified based on the classification layer to accurately determine the classification result of the face image to be detected.
[0049] S106: Input the training sample into the classification layer of the anomaly detection model to obtain the detection result of the training sample output by the classification layer.
[0050] The training method for the anomaly detection model provided in this specification includes a feature extraction layer and a classification layer. The feature extraction layer extracts the sample features corresponding to each training sample, and the classification layer classifies each training sample based on the extracted sample features. The purpose of the anomaly detection model provided in this specification is to learn feature representations that can accurately characterize whether a face image is abnormal, so that the classification layer can accurately determine the classification corresponding to the sample features based on the sample features determined by the aforementioned feature extraction layer.
[0051] Specifically, for each training sample, the server can take the sample features corresponding to that training sample as input and input them into the classification layer of the anomaly detection model to obtain the detection result of the training sample output by the classification layer.
[0052] The classification layer can be a convolutional neural network, a recurrent neural network, a multilayer perceptron, or other network structures. The detection result output by this classification layer can indicate whether the training sample is normal or abnormal, or it can provide the probability of the training sample being normal or abnormal. The specific network structure of this classification layer and the corresponding type of detection result can be set as needed; this specification does not impose any restrictions on this.
[0053] S108: Based on the sample characteristics of each positive sample in the sample set, determine the representative features used to characterize the commonalities of the positive samples.
[0054] In one or more embodiments provided in this specification, a synthesized face image is typically created by replacing a portion of a real face image with the same portion from another face image. This portion can be facial features, the entire face, etc. However, due to differences in skin color, facial features, and other characteristics among different face images, the pixel value difference between the original face image region and the replaced image region in the synthesized face image may be significant. In other words, compared to a real face image, the features used to represent differences in facial skin color, the proportions between facial features and facial contours, etc., in the synthesized face image will be more inconsistent. Therefore, if feature extraction is performed based on the above features, the extracted features can distinguish between real face images and synthesized face images.
[0055] However, since the replaced parts in each synthesized face image are not exactly the same, and features such as skin tone differences before replacement are also different, there can be significant differences in the features corresponding to each synthesized face image. In other words, it is difficult to obtain common features of synthesized face images based on their features alone. Conversely, with real face images, the aforementioned features are more consistent across different real face images. Therefore, common features of real faces can be obtained based on their features. These commonalities could include differences in facial skin tone and the proportions between facial features and contours across different face images.
[0056] As mentioned earlier, the training objective of this anomaly detection model is to accurately distinguish between positive and negative samples based on the sample features of each training sample. This specification provides a classification approach: given representative features that characterize the commonalities of positive samples, and constrained by the proximity of the sample features of positive samples to the representative features and the greater distance of the sample features of negative samples to the representative features, synthetic face images can be detected based on the determined sample features. Based on this, the server can determine representative features that characterize the commonalities of positive samples based on the sample features of each positive sample, so that the anomaly detection model can be trained subsequently based on these representative features.
[0057] Specifically, the server can identify positive samples from the sample set based on the annotations of each training sample.
[0058] Then, the server can determine the mean value of the feature of each positive sample based on the feature of each positive sample in the sample set.
[0059] Finally, the server can directly use the determined feature mean as a representative feature to characterize the commonalities of positive samples. These commonalities of positive samples are properties that make them relatively easy to distinguish from the features of negative samples. For example, the pixel differences in face images in positive samples are smaller, while the pixel differences in face images in negative samples are larger. Based on the aforementioned representative features, positive and negative samples can be quickly distinguished by the distance between positive samples and the representative features, and the distance between negative samples and the representative features.
[0060] Furthermore, generally speaking, if some data can be clustered into one class, the cluster centers of the resulting clusters can be used to characterize the commonalities of these data. Similarly, if positive samples are clustered, the cluster centers of the clusters corresponding to the positive samples can be used to characterize the commonalities of those positive samples.
[0061] Based on this, the server can cluster each positive sample according to the sample characteristics of each positive sample in the determined sample set, and determine the cluster center corresponding to the cluster as a representative feature that characterizes the commonality of the positive samples.
[0062] Furthermore, the methods used to generate each synthetic face image are not entirely the same as those used to generate other synthetic face images. For example, synthetic face image A is generated using Gaussian blur, while synthetic face image B is generated using liquefaction. These different generation techniques introduce variations in the features of each synthetic face image, further preventing the acquisition of features that guarantee commonalities among the synthetic face images.
[0063] It should be noted that this commonality may have a specific physical meaning or it may have no actual physical meaning and may only be used to characterize the commonality that distinguishes positive samples from negative samples.
[0064] S110: The anomaly detection model is trained with the optimization objectives of minimizing the difference between the sample features of each positive sample in the sample set and the representative features, maximizing the difference between the sample features of each negative sample in the sample set and the representative features, and minimizing the difference between the detection results and their annotations of each training sample in the sample set. The trained anomaly detection model is then used to detect synthetic face images.
[0065] In one or more embodiments provided in this specification, a training phase can be performed after the sample determination phase and the sample processing phase are completed. That is, after processing the training samples accordingly, the model can be trained. As mentioned above, the anomaly detection model in this specification aims to accurately learn the feature representations of each training sample. Therefore, this specification may use a loss metric for learning to train the anomaly detection model.
[0066] Specifically, the server can determine each positive and negative sample contained in the sample set, and for each positive sample, determine the sample features of that positive sample, and for each negative sample, determine the sample features of that negative sample.
[0067] Secondly, the server can determine the differences between the sample features of each positive sample and the representative feature based on the sample features of each positive sample and the representative feature. Similarly, it can determine the differences between the sample features of each negative sample and the representative feature based on the sample features of each negative sample and the representative feature.
[0068] Then, for each training sample in the sample set, the server can determine the difference between the detection result and its annotation for that training sample.
[0069] Finally, the server can optimize the anomaly detection model by taking the minimum difference between the sample features of each positive sample and the representative feature, the maximum difference between the sample features of each negative sample and the representative feature, and the minimum difference between the detection results and their labels of each training sample as the optimization objectives. The model parameters are then adjusted to complete the training process of the anomaly detection model.
[0070] Furthermore, in general, the training objective during model training is to minimize the loss. Therefore, the server can determine the loss based on the above differences and train the model with minimizing the loss as the optimization objective.
[0071] Specifically, the server can calculate the first difference based on the difference between the sample characteristics of each positive sample and the representative characteristic. This first difference can be the TP index, i.e., the Top Percentage. Taking TP99 as an example, the server can determine the difference between the sample characteristics of each positive sample and the representative characteristic. Then, from the differences between the sample characteristics of all positive samples and the representative characteristic, it can determine the smallest difference where the difference between 99% of the positive samples and the representative characteristic is less than a certain value. The server can then use this smallest difference as the first difference. Of course, this first difference can also be an indicator such as the mean.
[0072] Similarly, the server can calculate a second difference based on the difference between the sample characteristics of each negative sample and the representative characteristic. The determination method and type of the second difference are similar to those of the first difference, and the second difference can also be a variety of indicators such as the mean and the TP index.
[0073] After determining the first difference and the second difference, the server can determine the first loss based on the difference between the first difference and the second difference, and determine the second loss based on the detection results and annotations of each training sample.
[0074] Finally, the server can use minimizing the sum of the first loss and the second loss as the optimization objective to adjust the model parameters of the anomaly detection model, thereby completing the training process of the anomaly detection model.
[0075] The representative feature can be used to help characterize the commonalities of positive samples. The first loss quantifies the difference between the representative feature of positive samples and the sample features of each positive sample, as well as the difference between the sample features of each negative sample and the representative feature used to characterize the commonalities of positive samples. The second loss quantifies the difference between the annotations of each training sample and the detection results. Based on the anomaly detection model determined by the above total loss, the extracted feature labels of positive samples are relatively compact in the vector space, while the feature labels of negative samples are relatively far from those of positive samples in the vector space.
[0076] In one or more embodiments provided in this specification, after the anomaly detection model has been trained, the trained anomaly detection model can be applied to the field of face recognition in order to identify whether a face image is a real face image.
[0077] Specifically, the server deploying the anomaly detection model can receive a detection request carrying a face image to be detected and determine the face image to be detected from the detection request. Then, the server can input the face image into the anomaly detection model to obtain the detection result of the face image output by the anomaly detection model. Finally, the server can determine whether the face image to be detected is a real face image based on the detection result. If it is, the server can continue to receive other detection requests; if not, the server can send a prompt message to indicate that the face image corresponding to the detection result is a synthetic face image.
[0078] based on Figure 1 The training method for the anomaly detection model involves acquiring real face images as positive samples and synthetic face images as negative samples. These positive and negative samples are used as training samples. The feature extraction layer of the anomaly detection model extracts the sample features of each training sample. A classification layer obtains the detection results for each training sample. Representative features representing the commonalities of positive samples are determined based on the sample features of each positive sample. The loss is determined based on the differences between the sample features and representative features of each positive sample, the differences between the sample features and representative features of each negative sample, and the differences between the detection results and their annotations of each training sample. The anomaly detection model is trained with the goal of minimizing the loss. This allows the trained anomaly detection model to detect synthetic face images. This method can learn an accurate feature extraction method based on representative features, facilitating accurate extraction of facial features from face images for accurate anomaly detection, thus ensuring the accuracy of anomaly detection.
[0079] Furthermore, since the training phase demands significant computational resources, and given the limited available server resources, the anomaly detection model can be trained iteratively multiple times using a small number of samples. However, for each iteration, the number of positive samples used in training the anomaly detection model is not fixed. Therefore, when the number of positive samples is small, relying solely on the sample features of the positive samples used in the current training session is insufficient to accurately represent the "normal" category. Thus, this specification also employs the momentum method to update the representative features.
[0080] Specifically, the server can determine the mean value of the sample features of each positive sample in the sample set during the current iteration, and use the mean value as a reference feature, as well as determine the representative features of the positive samples identified in the previous iteration.
[0081] Then, the server can determine the representative features used to characterize the commonalities of positive samples in the current iteration based on the reference feature and its weight, as well as the representative features and their weights of the positive samples determined in the previous iteration.
[0082] With Nr f represents the number of positive samples r Taking the sample features representing positive samples as an example, the above reference features can be represented by the following formula:
[0083] Taking the current iteration as the nth iteration as an example, if the weight of the reference feature is a, and the weight of the representative feature determined in the previous iteration is 1-a, then the representative feature obtained in this iteration can be: P n =aP e +(1-a)P n-1 .
[0084] Furthermore, in step S108, when determining the first loss, the server may also determine a comparison difference based on the difference between the first difference and the second difference, and then use the sum of the first difference and the comparison difference as the first loss. This is to enable the anomaly detection model adjusted based on the first loss to make the sample features of positive samples closer to the representative features.
[0085] With D r Characterized by the first difference, D f Taking the second difference as an example, the first loss can be L1 = D r +(D r -D f ).
[0086] Furthermore, to further distinguish between positive and negative samples, ensuring that the difference between the features of positive and negative samples exceeds a preset threshold, the server can also employ a max function to further quantify the difference between positive and negative samples. Then, using D... r Characterized by the first difference, D f Taking the second difference as an example, the first loss can be L1 = D r +max(D r -D f +m,0). Then, the first loss can be used as the first difference when the difference between positive and negative samples is large enough, and when the difference between positive and negative samples is not large enough, the first loss is determined based on the first difference, the second difference, and the difference threshold, so as to characterize the anomaly detection model to optimize in the direction of a sufficiently large difference between positive and negative samples.
[0087] Furthermore, when calculating the first difference and the second difference, the server can also use a method of determining the mean to determine the first difference and the second difference.
[0088] Specifically, for each positive sample in the sample set, the server can determine the difference between the sample feature of that positive sample and the representative feature, as the initial positive difference value. Then, based on the mean of all initial positive difference values, a first difference value is determined.
[0089] Meanwhile, for each negative sample in the sample set, the server can determine the difference between the sample feature and the representative feature of the negative sample as the initial negative difference value, and determine the second difference value based on the mean of each initial negative difference value.
[0090] With D r Characterized by the first difference, D f Taking the second difference as an example, the first and second differences can be determined by the following formula:
[0091] It should be noted that the use of the second norm to represent the difference between the sample feature and the representative feature in the above formula is only an example of quantifying the difference between the sample feature and the representative feature. Furthermore, the above representation of the first loss based on the max function is only an example of the first loss. The specific representation of the difference between the sample feature and the representative feature, as well as the specific representation methods of each sample feature, the representative feature, and each loss, can all be set as needed. This manual does not impose any restrictions on this.
[0092] Furthermore, if the number of positive samples in the sample set is large, accurate representative features can be determined solely based on the number of positive samples. Therefore, the server can also determine the number of positive samples in the sample set. If the number of positive samples in the sample set is greater than a preset threshold, the server can determine the mean value of the sample features of each positive sample in the sample set, using this mean value as a representative feature to characterize the commonalities of the positive samples. That is, the aforementioned reference feature is directly used as the representative feature.
[0093] Of course, the server can also determine the number of positive samples in the sample set for each iteration. When the number is greater than a preset threshold, representative features are determined based on the sample characteristics of each positive sample in the sample set.
[0094] The above describes a training method for an anomaly detection model provided by one or more embodiments of this specification. Based on the same idea, this specification also provides a corresponding training device for anomaly detection models, such as... Figure 2 As shown.
[0095] Figure 2 This is a schematic diagram of the training device for the anomaly detection model provided in this specification. The data processing device is used as a processing node in a distributed database. Wherein:
[0096] The acquisition module 200 is used to acquire real face images as positive samples and to acquire synthetic face images as negative samples, and to use the positive samples and the negative samples as training samples.
[0097] The first determining module 202 is used to determine a sample set consisting of several training samples.
[0098] The extraction module 204 is used to input each training sample in the sample set into the feature extraction layer of the anomaly detection model to be trained, and obtain the sample features of the training sample output by the feature extraction layer.
[0099] The classification module 206 is used to input the features of the sample into the classification layer of the anomaly detection model to obtain the detection result of the training sample output by the classification layer.
[0100] The second determining module 208 is used to determine representative features for characterizing the commonalities of positive samples based on the sample characteristics of each positive sample in the sample set.
[0101] The training module 210 is used to train the anomaly detection model with the optimization objectives of minimizing the difference between the sample features and the representative features of each positive sample in the sample set, maximizing the difference between the sample features and the representative features of each negative sample in the sample set, and minimizing the difference between the detection results and their annotations of each training sample in the sample set. The trained anomaly detection model is used to detect synthetic face images.
[0102] Optionally, the anomaly detection model is trained through multiple iterations. The second determining module 208 is used to determine reference features based on the mean feature value of the sample features of each positive sample in the sample set during the current iteration, and to determine the representative features for characterizing the commonalities of positive samples determined in the previous iteration; based on the reference features and their weights, and the representative features for characterizing the commonalities of positive samples determined in the previous iteration and their weights, to determine the representative features for characterizing the commonalities of positive samples obtained in the current iteration.
[0103] Optionally, the training module 210 is configured to: calculate a first difference based on the difference between the sample features of each positive sample in the sample set and the representative feature; calculate a second difference based on the difference between the sample features of each negative sample in the sample set and the representative feature; determine a first loss based on the difference between the first difference and the second difference; determine a second loss based on the detection results and annotations of each training sample in the sample set; and train the anomaly detection model with the minimum sum of the first loss and the second loss as the optimization objective.
[0104] Optionally, the training module 210 is configured to determine a comparison difference based on the difference between the first difference and the second difference; and to use the sum of the first difference and the comparison difference as the first loss.
[0105] Optionally, the training module 210 is configured to determine a comparison difference based on the difference between the first difference and the second difference; if the comparison difference is less than a preset difference threshold, the first difference is used as a first loss; if the comparison difference is not less than the difference threshold, the sum of the first difference, the comparison difference, and the difference threshold is used as the first loss.
[0106] Optionally, the training module 210 is configured to, for each positive sample in the sample set, determine the difference between the sample feature and the representative feature of the positive sample as an initial positive difference value; determine a first difference value based on the mean of each initial positive difference value; for each negative sample in the sample set, determine the difference between the sample feature and the representative feature of the negative sample as an initial negative difference value; and determine a second difference value based on the mean of each initial negative difference value.
[0107] Optionally, the second determining module 208 is used to determine the mean value of the sample features of each positive sample in the sample set as a representative feature for characterizing the commonality of positive samples if the number of positive samples in the sample set is greater than a preset number threshold.
[0108] This specification also provides a computer-readable storage medium storing a computer program that can be used to execute the above-described... Figure 1 The training method for the provided anomaly detection model.
[0109] This instruction manual also provides Figure 3 The diagram shows a schematic structural representation of the electronic device. Figure 3 At the hardware level, the electronic device includes a processor, internal bus, network interface, memory, and non-volatile memory, and may also include other hardware required for the business operations. The processor reads the corresponding computer program from the non-volatile memory into memory and then runs it to achieve the above-mentioned functions. Figure 1 The training method for the anomaly detection model is described. Of course, besides software implementation, this specification does not exclude other implementation methods, such as logic devices or a combination of hardware and software, etc. That is to say, the execution entity of the following processing flow is not limited to individual logic units, but can also be hardware or logic devices.
[0110] In the 1990s, improvements to a technology could be clearly distinguished as either hardware improvements (e.g., improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the methodology). However, with technological advancements, many methodological improvements today can be considered direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved methodology into the hardware circuit. Therefore, it cannot be said that a methodological improvement cannot be implemented using hardware physical modules. For example, a Programmable Logic Device (PLD) (such as a Field Programmable Gate Array (FPGA)) is such an integrated circuit whose logic function is determined by the user programming the device. Designers can program and "integrate" a digital system onto a PLD themselves, without needing chip manufacturers to design and manufacture dedicated integrated circuit chips. Furthermore, nowadays, instead of manually manufacturing integrated circuit chips, this programming is mostly implemented using "logic compiler" software. Similar to the software compiler used in program development, the original code before compilation must be written in a specific programming language, called a Hardware Description Language (HDL). There are many HDLs, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, and RHDL (Ruby Hardware Description Language). Currently, the most commonly used are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should understand that by simply performing some logic programming on the method flow using one of these hardware description languages and programming it into an integrated circuit, the hardware circuit implementing the logical method flow can be easily obtained.
[0111] The controller can be implemented in any suitable manner. For example, it can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicon Labs C8051F320. A memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also recognize that, in addition to implementing the controller in purely computer-readable program code form, the same functionality can be achieved by logically programming the method steps to make the controller take the form of logic gates, switches, ASICs, programmable logic controllers, and embedded microcontrollers. Therefore, such a controller can be considered a hardware component, and the means included therein for implementing various functions can also be considered as structures within the hardware component. Alternatively, the means for implementing various functions can be considered as both software modules implementing the method and structures within the hardware component.
[0112] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, a computer can be, for example, a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email device, game console, tablet computer, wearable device, or any combination of these devices.
[0113] For ease of description, the above devices are described in terms of function, divided into various units. Of course, in implementing this specification, the functions of each unit can be implemented in one or more software and / or hardware.
[0114] Those skilled in the art will understand that embodiments of this specification can be provided as methods, systems, or computer program products. Therefore, this specification may take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this specification may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0115] This specification is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this specification. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create a machine for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0116] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0117] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0118] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0119] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0120] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0121] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0122] Those skilled in the art will understand that the embodiments of this specification can be provided as methods, systems, or computer program products. Therefore, this specification may take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this specification may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0123] This specification can be described in the general context of computer-executable instructions that are executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform a specific task or implement a specific abstract data type. This specification can also be practiced in distributed computing environments, where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0124] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.
[0125] The above description is merely an embodiment of this specification and is not intended to limit this specification. Various modifications and variations can be made to this specification by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this specification should be included within the scope of the claims of this specification.
Claims
1. A training method for an anomaly detection model, comprising: A real face image is obtained as a positive sample, and a synthetic face image is obtained as a negative sample. The positive sample and the negative sample are used as training samples. The synthetic face image is formed by replacing a part of a real face image with the same part of another face image. The replaced parts in each synthetic face image are not exactly the same, and / or the methods used to generate each synthetic face are not exactly the same. Determine the sample set consisting of several training samples; For each training sample in the sample set, the training sample is input into the feature extraction layer of the anomaly detection model to be trained, and the sample features of the training sample are output by the feature extraction layer. The sample features are input into the classification layer of the anomaly detection model to obtain the detection result of the training sample output by the classification layer; Based on the sample features of each positive sample in the sample set, representative features are determined to characterize the commonalities of the positive samples. The commonalities of the positive samples are properties that all positive samples share that can distinguish them from the features of negative samples. The anomaly detection model is trained with the optimization objectives of minimizing the difference between the sample features of each positive sample in the sample set and the representative features, maximizing the difference between the sample features of each negative sample in the sample set and the representative features, and minimizing the difference between the detection results and their annotations of each training sample in the sample set. The trained anomaly detection model is then used to detect synthetic face images.
2. The method as described in claim 1, wherein the anomaly detection model is trained through a multi-iteration process; Based on the sample characteristics of each positive sample in the sample set, representative features for characterizing the commonalities of positive samples are determined, specifically including: Based on the mean value of the features of each positive sample in the sample set during this iteration, reference features are determined, as well as representative features used to characterize the commonalities of positive samples determined in the previous iteration. Based on the reference features and their weights, as well as the representative features and their weights of the positive samples determined in the previous iteration, the representative features used to characterize the commonalities of the positive samples obtained in this iteration are determined.
3. The method as described in claim 1, wherein the anomaly detection model is trained with the optimization objectives of minimizing the difference between the sample features of each positive sample in the sample set and the representative feature, maximizing the difference between the sample features of each negative sample in the sample set and the representative feature, and minimizing the difference between the detection results and their annotations of each training sample in the sample set, specifically including: The first difference is calculated based on the difference between the sample characteristics of each positive sample in the sample set and the representative characteristics. Furthermore, a second difference is calculated based on the difference between the sample features of each negative sample in the sample set and the representative features; The first loss is determined based on the difference between the first difference and the second difference; The second loss is determined based on the detection results and annotations of each training sample in the sample set; The anomaly detection model is trained with the goal of minimizing the sum of the first loss and the second loss.
4. The method as described in claim 3, wherein determining the first loss based on the difference between the first difference and the second difference specifically includes: The comparison difference is determined based on the difference between the first difference and the second difference; The sum of the first difference and the comparison difference is taken as the first loss.
5. The method as described in claim 3, wherein determining the first loss based on the difference between the first difference and the second difference specifically includes: The comparison difference is determined based on the difference between the first difference and the second difference; If the comparison difference is less than a preset difference threshold, the first difference is taken as the first loss; If the comparison difference is not less than the difference threshold, the sum of the first difference, the comparison difference, and the difference threshold is taken as the first loss.
6. The method as described in claim 3, wherein a first difference is calculated based on the difference between the sample characteristics of each positive sample in the sample set and the representative characteristics; Furthermore, based on the difference between the sample features of each negative sample in the sample set and the representative features, a second difference is calculated, specifically including: For each positive sample in the sample set, the difference between the sample feature and the representative feature of the positive sample is determined as the initial positive difference value; The first difference is determined based on the mean of the initial positive differences; For each negative sample in the sample set, the difference between the sample feature and the representative feature of the negative sample is determined as the initial negative difference value; The second difference is determined based on the mean of the initial negative differences.
7. The method as described in claim 1, wherein representative features for characterizing the commonalities of positive samples are determined based on the sample characteristics of each positive sample in the sample set, specifically including: If the number of positive samples in the sample set is greater than a preset threshold, the mean value of the sample features of each positive sample in the sample set is determined based on the sample features of each positive sample in the sample set, and is used as a representative feature to characterize the commonality of positive samples.
8. A training device for an anomaly detection model, comprising: The acquisition module is used to acquire real face images as positive samples and synthetic face images as negative samples, and to use the positive samples and the negative samples as training samples; wherein, the synthetic face image is obtained by replacing a certain part of a real face image with an image of the same part in another face image; the replaced parts in each synthetic face image are not exactly the same, and / or the methods used to generate each synthetic face are not exactly the same; The first determining module is used to determine the sample set consisting of several training samples; The extraction module is used to input each training sample in the sample set into the feature extraction layer of the anomaly detection model to be trained, and obtain the sample features of the training sample output by the feature extraction layer. The classification module is used to input the features of the sample into the classification layer of the anomaly detection model to obtain the detection result of the training sample output by the classification layer. The second determining module is used to determine representative features for characterizing the commonalities of positive samples based on the sample characteristics of each positive sample in the sample set; the commonalities of positive samples are properties that all positive samples share that can be distinguished from the features of negative samples. The training module is used to train the anomaly detection model with the optimization objectives of minimizing the difference between the sample features of each positive sample in the sample set and the representative features, maximizing the difference between the sample features of each negative sample in the sample set and the representative features, and minimizing the difference between the detection results and their annotations of each training sample in the sample set. The trained anomaly detection model is used to detect synthetic face images.
9. A computer-readable storage medium storing a computer program that, when executed by a processor, implements the method described in any one of claims 1 to 7.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described in any one of claims 1 to 7.