Image detection model training method and device, image detection method and device, equipment and medium
Through the feature extraction and classification network of the image detection model, combined with clustering processing and loss function adjustment, the shortcomings of traditional methods in identifying real and fake images are solved, and more efficient face image detection is achieved.
Patent Information
- Application Number
- CN202410737148.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-07
- Publication Date
- 2024-09-17
AI Technical Summary
With the development of AI technology, traditional face image detection methods are ineffective and difficult to effectively identify real and fake face images.
Use an image detection model, including a feature extraction network and a classification network, to determine the model parameters by clustering non-real images, and adjust the model parameters based on the loss function to improve the accuracy and generalization of image detection.
It improves the accuracy and generalization of image detection, can more effectively identify real and fake face images, and improves the image detection effect.
Smart Images

Figure CN118657987A
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of artificial intelligence technology, specifically computer vision, deep learning and other technical fields, and can be applied to scenarios such as smart cities and smart industries. In particular, it relates to image detection model training and image detection methods, devices, equipment and media. Background Art
[0002] Image detection technology refers to identifying whether an image is real. With the development of artificial intelligence (AI) technology, the images obtained using AI technology are becoming more and more realistic, so it is necessary to improve the image detection effect. Summary of the invention
[0003] The present invention provides an image detection model training and image detection method, device, equipment and medium.
[0004] According to one aspect of the present disclosure, a training method for an image detection model is provided, wherein the image detection model comprises: a feature extraction network and a classification network, wherein the classification network comprises: a first output node corresponding to a non-real category and a second output node corresponding to a real category, wherein the method comprises: using the feature extraction network to perform feature extraction processing on a target image to obtain current image features; the target image is obtained based on a sample image; if the sample image is a non-real image, using the current image features to update existing image features to obtain updated image features, and clustering the updated image features to obtain cluster centers; the number of cluster centers is the same as the number of the first output nodes; based on the cluster centers, determining first model parameters corresponding to the first output nodes; using the classification network to perform classification processing on the current image features to obtain predicted values of the real category, and constructing a loss function based on the predicted values of the real category; using the loss function to adjust model parameters of the feature extraction network, and second model parameters corresponding to the second output nodes.
[0005] According to another aspect of the present disclosure, there is provided an image detection method, comprising: performing feature extraction processing on a target image to obtain image features; the target image is obtained based on a sample image; based on a first model parameter and a second model parameter, performing classification processing on the image features to obtain a category prediction value; and determining a detection result of the image to be detected based on the category prediction value; wherein the first model parameter is determined based on a cluster center, the second model parameter is adjusted based on a loss function, and the cluster center is obtained after clustering the image features of a non-real image.
[0006] According to another aspect of the present disclosure, a training device for an image detection model is provided, the image detection model includes: a feature extraction network and a classification network, the classification network includes: a first output node corresponding to a non-real category and a second output node corresponding to a real category, the device includes: an extraction module, used to use the feature extraction network to perform feature extraction processing on a target image to obtain current image features; the target image is obtained based on a sample image; a clustering module, used to use the current image features to update existing image features to obtain updated image features if the sample image is a non-real image, and cluster the updated image features to obtain cluster centers; the number of cluster centers is the same as the number of the first output nodes; a determination module, used to determine a first model parameter corresponding to the first output node based on the cluster centers; a classification module, used to use the classification network to perform classification processing on the current image features to obtain a predicted value of the real category, and construct a loss function based on the predicted value of the real category; an adjustment module, used to use the loss function to adjust the model parameters of the feature extraction network and the second model parameters corresponding to the second output node.
[0007] According to another aspect of the present disclosure, there is provided an image detection device, comprising: an extraction module, configured to perform feature extraction processing on a target image to obtain image features; the target image is obtained based on a sample image; a classification module, configured to perform classification processing on the image features based on a first model parameter and a second model parameter to obtain a category prediction value; and a determination module, configured to determine a detection result of the image to be detected based on the category prediction value; wherein the first model parameter is determined based on a cluster center, the second model parameter is adjusted based on a loss function, and the cluster center is obtained after clustering the image features of a non-real image.
[0008] According to another aspect of the present disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute any method as described in any of the above aspects.
[0009] According to another aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute any one of the methods according to any one of the above aspects.
[0010] According to another aspect of the present disclosure, a computer program product is provided, including a computer program, wherein when the computer program is executed by a processor, the computer program implements any one of the methods described in any one of the above aspects.
[0011] According to the technical solution disclosed in the present invention, the image detection effect can be improved.
[0012] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0014] Figure 1 is a schematic diagram according to a first embodiment of the present disclosure;
[0015] Figure 2 is a schematic diagram of an application scenario for implementing an embodiment of the present disclosure;
[0016] Figure 3 is a structural schematic diagram of an image detection model provided according to an embodiment of the present disclosure;
[0017] Figure 4 is a schematic diagram according to a second embodiment of the present disclosure;
[0018] Figure 5 is a schematic diagram according to a third embodiment of the present disclosure;
[0019] Figure 6 is a schematic diagram according to a fourth embodiment of the present disclosure;
[0020] Figure 7 is a schematic diagram according to a fifth embodiment of the present disclosure;
[0021] Figure 8 It is a schematic diagram of an electronic device used to implement the training method of the image detection model or the image detection method of the embodiment of the present disclosure. DETAILED DESCRIPTION
[0022] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0023] Taking face image detection as an example, face image detection can identify whether a face image is a real person image or an image obtained by AI (such as synthesis or editing). It is an important part of the face recognition system and ensures the security of the face recognition system.
[0024] In the related technologies, face image detection is usually performed based on traditional machine learning technology or deep learning technology. However, with the development of AI technology, the face images obtained by AI are becoming more and more realistic, and the traditional face image detection methods have the problem of poor effect.
[0025] In order to improve the image detection effect, the present disclosure provides the following embodiments.
[0026] Figure 1 is a schematic diagram according to the first embodiment of the present disclosure. This embodiment provides a training method for an image detection model, the image detection model comprising: a feature extraction network and a classification network, the classification network comprising: a first output node corresponding to a non-real category and a second output node corresponding to a real category, the method comprising:
[0027] 101. Using the feature extraction network, perform feature extraction processing on a target image to obtain current image features; the target image is obtained based on a sample image.
[0028] 102. If the sample image is a non-real image, the existing image features are updated using the current image features to obtain updated image features, and the updated image features are clustered to obtain cluster centers; the number of cluster centers is the same as the number of the first output nodes.
[0029] 103. Based on the cluster center, determine a first model parameter corresponding to the first output node.
[0030] 104. Using the classification network, classify the current image features to obtain a predicted value of the true category, and construct a loss function based on the predicted value of the true category.
[0031] 105. Use the loss function to adjust the model parameters of the feature extraction network and the second model parameters corresponding to the second output node.
[0032] The sample images refer to images used as training samples, which may come from existing data sets.
[0033] The sample image includes a target object, and the target object varies depending on the recognition scenario. For example, in a face recognition scenario, the target object is a face, and the corresponding sample image is a face image; or, in a person recognition scenario, the target object is a person, and the corresponding sample image is a person image; or, in a vehicle recognition scenario, the target object is a vehicle, and the corresponding sample image is a vehicle image.
[0034] Sample images include positive sample images and negative sample images. Positive sample images are real images, i.e., non-forged images. Negative sample images are non-real images, such as forged images obtained by artificial forgery or AI forgery (synthesis or editing). Taking facial images as an example, forged images can be obtained by forgery methods such as head replacement, face replacement, or facial feature editing.
[0035] The target image refers to the image used as the input of the feature extraction network, which is obtained based on the sample image.
[0036] Specifically, the sample image may be used as the target image; or, the sample image may be converted to obtain a converted image in a different domain from the sample image, and the sample image and the converted image may be used as the target image.
[0037] After acquiring the target image, the target image is input into the feature extraction network. The feature extraction network performs feature extraction processing on the target image, and the output image features are called current image features.
[0038] If the target image includes a sample image and a converted image, after the sample image and the converted image are input into the feature extraction network, the current image features that integrate information from different domains will be obtained.
[0039] The existing image feature is an already existing image feature, and its initial state is empty. After obtaining the current image feature, the existing image feature is updated to obtain the updated image feature.
[0040] Existing image features can be stored in a queue. The length of the queue is represented by Q, which is a hyperparameter and can be 65535.
[0041] Specific updating methods may include: when the queue storage space is sufficient, storing the current image features in the queue, and using the existing image features and the current image features as updated image features; or, when the queue storage space is insufficient, deleting at least part of the existing image features, and storing the current image features in the queue, and using the current image features and the existing image features retained after deletion as updated image features.
[0042] For example, the feature extraction network usually processes the target images in batches. Assuming that the number of target images in the first batch is represented by N, N current image features can be obtained. The initial state of the existing image features is empty. After obtaining the N current image features in the first batch, the N current image features are stored in the queue, and the updated image features are the N current image features. Assuming that the number of target images in the second batch is also N, and 2N is less than Q, the N current image features in the second batch are also stored in the queue, thereby obtaining 2N updated image features. When the storage space of the queue is insufficient, it is updated according to the first-in-first-out principle. For example, after obtaining N current image features for a batch, the number of existing image features is represented by M. If M+N is greater than Q, it means that the storage space of the queue is insufficient. At this time, at least part of the existing image features need to be deleted. The number of deleted existing image features can be the number that exceeds the queue length, such as deleting (M+NQ) existing image features, and storing the N current image features in the preset queue after deletion, so that the updated image features include N current image features and (QN) existing image features. The (M+NQ) existing image features deleted from the M existing image features may be selected according to a first-in-first-out principle, ie, the (M+NQ) existing image features first stored in the M existing image features.
[0043] After obtaining the updated image features, clustering processing is performed on them to obtain a preset number of cluster centers. Assuming that the preset number is represented by k, k cluster centers are obtained, and the number of first output nodes of the classification network is also k. The clustering processing is, for example, k-Mean clustering processing.
[0044] The model parameters corresponding to the first output node are called the first model parameters, which are obtained based on the cluster center. The model parameters usually include weight W and bias value b, then W ij (i=1,2,...,I,j=1,2,...,k) and b j (j=1,2,...,k) is determined based on k cluster centers, k is the number of cluster centers, and I is the number of input nodes of the classification network.
[0045] The classification network also includes a second output node, the number of the second output node is 1, and the second output node corresponds to a real category. The classification network can specifically be a fully connected network.
[0046] The input of the classification network is the current image feature, and the output is the category prediction value. The category prediction value is used to characterize the true or false category of the sample image. There are k+1 category prediction values, which are the prediction values of k fake categories and 1 real category. The prediction value can be a prediction probability.
[0047] The loss function is constructed based on the predicted value of the true category, and specifically can be constructed based on the predicted value of the true category and the true value of the true category. The specific function type can be a cross entropy (CE) loss function.
[0048] The true value of the true category comes from the label of the sample image. If the sample image in the existing data set has a label, the label can be obtained directly. If the sample image has no label, it can be annotated manually or by other means to obtain the label.
[0049] The label includes the true value of the true category of the sample image. For example, if the sample image is a positive sample image (true image), the true value of the true category is represented by 1, or if the sample image is a negative sample image (untrue image), the true value of the true category is represented by 0. Among them, there is no need to distinguish the specific forgery method for negative sample images, that is, no matter which forgery method is used, the true value of the true category is represented by 0. In this way, there is no need to distinguish the specific forgery method, which can reduce the amount of annotation and improve processing efficiency.
[0050] Taking the loss function as the cross entropy function as an example, the cross entropy loss function can be expressed as:
[0051] L=CE(p,y k+1 )
[0052] Among them, L is the loss function, CE represents the cross entropy operation, p is the true value of the true category, and y k+1 is the predicted value of the true category.
[0053] After the loss function is obtained, the model parameters are adjusted using the loss function to obtain the final image detection model. In this embodiment, the adjusted model parameters include: model parameters of the feature extraction network, and second model parameters corresponding to the second output node of the classification network.
[0054] The model training process includes multiple iterations, starting from the initial value, and continuously updating the model parameters until the preset end conditions are met (such as reaching a preset number of times or model convergence) to obtain the final image detection model.
[0055] The model is updated based on the total loss function, for example, by using the back propagation (BP) algorithm to adjust the model parameters.
[0056] Assume that the second model parameters include W i(k+1) (i=1,2,...,I) and b (k+1) , I is the number of input nodes of the classification network, then W i(k+1) (i=1,2,...,I) and b (k+1)It is adjusted according to the BP process of the loss function.
[0057] In this way, the model parameters of the feature extraction network are adjusted according to the loss function, the classification network includes a first model parameter and a second model parameter, the first model parameter is determined according to the cluster center, the cluster center is obtained according to the image features of the negative sample image, and the second model parameter is adjusted according to the loss function.
[0058] In this embodiment, clustering processing is performed on the image features of the non-real image to obtain the cluster center, and the first model parameter is determined based on the cluster center. The clustering process of the negative sample features can provide more abundant supervision information for model training, improve the accuracy of image detection, and effectively improve the generalization of the model, thereby improving the image detection effect.
[0059] In order to better understand the embodiments of the present disclosure, application scenarios to which the embodiments of the present disclosure can be applied are described.
[0060] Figure 2 Schematic diagram of an application scenario for implementing the embodiment of the present disclosure. This embodiment takes image detection based on a face image as an example. Figure 2 As shown, the user can upload the face image to be detected by using a user terminal. The user terminal can be a terminal with an image acquisition module (such as a camera), such as a mobile phone, a tablet computer, a laptop computer, a smart wearable device, etc.
[0061] Taking a mobile phone as an example, an application (Application, APP) that needs to perform image detection can be installed on the mobile phone 201. When image detection is required, the APP can use the camera on the mobile phone 201 to collect the user's face image and transmit the face image to the server. The server can be called an image detection system. The server can be deployed on the server 202, which can be a local server or a cloud server. After receiving the face image, the server inputs the face image into the image detection model and outputs the image detection result. The image detection result is a multi-classification result. Taking k forgery categories as an example, the image detection result includes k+1 results, specifically including: real person images, or forged images of the jth (j=1,2,...k) category. The server can return the image detection result to the APP, and the APP can pass or fail face recognition based on the image detection result. For example, if the image detection result is a real person image, face recognition is passed, and if the image detection result is any forged image, face recognition is not passed. The above takes the server performing image detection as an example. It can be understood that if the user terminal has the corresponding capability locally, image detection can also be performed locally on the user terminal based on the image detection model.
[0062] Taking a mobile phone as an example, an application (Application, APP) that needs to perform image detection can be installed on the mobile phone 201. When image detection is required, the APP can use the camera on the mobile phone 201 to collect the user's facial image and transmit the facial image to the server. The server can be called an image detection system. The server can be deployed on the server 202. The server can be a local server or a cloud server. After the server receives the facial image, it inputs the facial image into the image detection model and outputs the detection result. In this embodiment, the detection result is used to indicate whether the image to be detected is a real person image. The server can return the detection result to the APP, and the APP can pass or fail the facial recognition based on the detection result. For example, if the detection result is a real person image, the facial recognition is passed. If the detection result is not a real person image, the facial recognition is not passed. The above takes the server performing image detection based on the image detection model as an example. It can be understood that if the user terminal has the corresponding capability locally, image detection can also be performed based on the image detection model locally on the user terminal.
[0063] The image detection model is obtained through training. Figure 3 Schematic diagram of the structure of the image detection model provided according to the embodiment of the present disclosure. Figure 3 As shown, the image detection model includes: feature extraction network and classification network.
[0064] The image detection model can be specifically used for image authentication, that is, to identify whether an image is a real image or a forged image. Accordingly, the image detection model can be called an image authentication model, and a non-real image is a forged image. Taking face image detection as an example, the detection result is a real image or a forged image. Furthermore, the forged images of this embodiment are divided into multiple categories, such as k (preset positive integer) categories, so it can be identified that the face image is a real image or a forged image of the jth (j=1, 2, ..., k) category.
[0065] Regarding the training process: the input of the image detection model is the target image, which is obtained based on the sample image. In this embodiment, the target image includes: the sample image and its corresponding frequency domain image as an example.
[0066] Specifically, the sample image may be subjected to a frequency domain transformation, such as Fourier transformation, wavelet transformation or discrete cosine transformation, to transform the sample image into a frequency domain image.
[0067] In this embodiment, the feature extraction network includes: an embedding layer and a coding layer. The embedding layer may be a block embedding layer, and the coding layer may be a Transformer encoder.
[0068] After the sample image and the frequency domain image are divided into blocks, the obtained patch images are input into the patch embedding layer. Assuming that the sample image and the frequency domain image are divided into T patch images, the input of the patch embedding layer is 2T patch images; the patch embedding layer embeds the input patch images to obtain embedding vectors, such as converting 2T patch images into 2T embedding vectors; the embedding vectors are input into the encoding layer, and the encoder encodes the embedding vectors and outputs the encoding vectors, which incorporate the frequency domain information. For the specific embedding and encoding process, please refer to the embedding and encoding process of the Visual Transformer (ViT).
[0069] After obtaining the encoded vector, it is normalized to obtain a normalized vector. Vector normalization, also known as unitization, is the process of adjusting a vector to have a modulus (length) of 1 and an unchanged direction, so that each vector value of the normalized vector is in the range of 0 to 1.
[0070] After obtaining the normalized vector, on the one hand, if the sample image is a negative sample image (fake image), the normalized vector corresponding to the negative sample image is stored in the queue, the existing normalized vectors in the queue are updated to obtain the updated normalized vector, and the updated normalized vector is clustered to obtain k cluster centers. Since the clustering object is a normalized vector, each cluster center is also a normalized vector, and its vector value is in the range of 0 to 1. After that, the vector values of these k cluster centers are used as the first model parameters corresponding to the k first output nodes of the classification network. The above clustering process is performed in response to the update operation. In this way, during the model training process, each iteration uses a new batch of negative sample image features for update processing, and the updated image features are clustered as new first model parameters to achieve continuous updating of the first model parameters. In addition, during the clustering process, a pseudo-label can be assigned to each category, so that different categories can be distinguished and the correct update of each cluster center can be achieved. For example, the pseudo-labels are represented by 1 to k. Figure 3 As shown, taking k=3 as an example, three cluster centers can be obtained, the number of first output nodes is also 3, the three first output nodes correspond to three groups of first model parameters, and the vector values of the three cluster centers are respectively used as a group of first model parameters.
[0071] On the other hand, no matter whether the sample image is a positive sample image or a negative sample image, the normalized vector is input into the classification network, and the classification network classifies the normalized vector to obtain a category prediction value, which includes the prediction value of the true category output by the second output node. Figure 3The second output node in is represented by the (k+1)th output node. Afterwards, a loss function L is constructed based on the predicted value of the true category and the true value of the corresponding true category, and the model parameters of the feature extraction network and the second model parameters corresponding to the second output node are adjusted using the loss function.
[0072] For the image detection stage: the model input is the target image, which is consistent with the training stage. If the sample image is used as the target image in the training stage, the image to be detected is used as the target image in the detection stage. Alternatively, if the sample image and its frequency domain image are used as the target image in the training stage, the image to be detected and its frequency domain image are used as the target image in the detection stage. In addition, the acquisition method of the frequency domain image is consistent with that of the training stage. For example, if the frequency domain image is acquired by Fourier transform in the training stage, the frequency domain image is also acquired by Fourier transform in the detection stage.
[0073] After acquiring the target image, the target image is input into a pre-trained feature extraction network, the output of the feature extraction network is a coding vector, and then the coding vector is normalized to obtain a normalized vector; the normalized vector is input into a pre-trained classification network, the classification network includes a first model parameter and a second model parameter, the first model parameter is obtained according to the cluster center, and the second model parameter is obtained according to the loss function, and the output of the classification network is (k+1) category prediction values, which respectively represent the probability that the image to be detected belongs to each category, that is, the probability of k forged categories and the probability of 1 real category, and then the category corresponding to the maximum probability is used as the image detection result, for example, if the probability of the real category is the largest, then the image detection result is: the image to be detected is a real image, if the probability of the jth forged category is the largest, then the image detection result is: the image to be detected is the jth forged image, j is one of 1 to k.
[0074] In combination with the above application scenarios, the present disclosure also provides the following embodiments.
[0075] Figure 4 is a schematic diagram according to the second embodiment of the present disclosure. This embodiment provides a training method for an image detection model, the image detection model comprising: a feature extraction network and a classification network, the classification network comprising: a first output node corresponding to a non-real category and a second output node corresponding to a real category, the method comprising:
[0076] 401. Perform conversion processing on a sample image to obtain a conversion image in a different domain from the sample image, and use the sample image and the conversion image as target images.
[0077] For example, the sample image is converted into a frequency domain image by using a method such as Fourier transform, and the sample image and the frequency domain image are used as the target image.
[0078] In this embodiment, by using the sample image and the converted image as the target image, target images in various forms can be obtained. These target images in various forms contain information from multiple domains. After subsequent feature extraction processing, image features that integrate information from multiple domains can be obtained, thereby improving the image feature's ability to mine forgery clues and further improving the image detection effect.
[0079] 402. Use the feature extraction network to perform feature extraction processing on the target image to obtain current image features.
[0080] These may include:
[0081] Performing block processing on the target image to obtain block images;
[0082] Using the embedding layer, embedding the block image to obtain an embedding vector;
[0083] The encoding layer is used to encode the embedded vector to obtain an encoding vector as the current image feature.
[0084] In this embodiment, through the block division, embedding and encoding processing, the information of different positions of the image can be extracted, the expression ability of the encoding vector can be improved, and the image authentication performance can be improved.
[0085] 403. Normalize the encoding vector to obtain a normalized vector.
[0086] 404. Determine whether the sample image is a real image. If not, execute 405-408. If yes, execute 407-408.
[0087] 405. Use the normalized vector to update the existing image features to obtain an updated normalized vector, and perform clustering on the updated normalized vector to obtain a cluster center.
[0088] 406. Use the vector value of the cluster center as a first model parameter corresponding to the first output node.
[0089] In this embodiment, the encoding vector is normalized to obtain a normalized vector, and subsequent calculations are performed based on the normalized vector, which facilitates calculations and improves processing efficiency.
[0090] In this embodiment, since the cluster center is also a normalized vector after normalization processing, the first model parameter can be obtained simply and efficiently by using the vector value of the cluster center as the first model parameter, thereby improving processing efficiency and accuracy.
[0091] 407. Use the classification network to perform classification processing on the normalized vector to obtain the predicted value of the true category, and construct a loss function based on the predicted value of the true category.
[0092] 408. Use the loss function to adjust the model parameters of the feature extraction network and the second model parameters corresponding to the second output node.
[0093] In this way, the first model parameters of the classification model are continuously updated through the clustering centers, and the second model parameters are continuously updated according to the loss function, so that richer supervision information can be introduced in the model training process, improving the model effect and generalization, thereby improving the image authentication performance.
[0094] Figure 5 is a schematic diagram according to a third embodiment of the present disclosure. This embodiment provides an image detection method, the method comprising:
[0095] 501. Perform feature extraction processing on a target image to obtain image features; the target image is obtained based on a sample image.
[0096] 502. Classify the image features based on the first model parameter and the second model parameter to obtain a category prediction value.
[0097] 503. Determine a detection result of the image to be detected based on the category prediction value.
[0098] The first model parameter is determined based on the cluster center, and the second model parameter is adjusted based on the loss function. The cluster center is obtained by clustering the image features of the non-real image.
[0099] Among them, the image to be detected refers to the image to be detected for authenticity, and the image to be detected contains a target object. The target object varies according to the recognition scenario. For example, in a face recognition scenario, the target object is a face, and the corresponding sample image is a face image; or, in a person recognition scenario, the target object is a person, and the corresponding sample image is a person image; or, in a vehicle recognition scenario, the target object is a vehicle, and the corresponding sample image is a vehicle image.
[0100] The target image refers to the image used as the input of the feature extraction network, which is obtained based on the image to be detected.
[0101] Specifically, the image to be detected may be used as the target image; or, the image to be detected may be converted to obtain a converted image in a different domain from the image to be detected, and the image to be detected and the converted image may be used as the target image.
[0102] After acquiring the target image, feature extraction is performed on the target image to obtain image features.
[0103] If the target image includes an image to be detected and a converted image, after feature extraction processing is performed on the image to be detected and the converted image, image features that fuse information from different domains will be obtained.
[0104] After obtaining the image features, the image features are classified based on the first model parameters and the second model parameters to obtain category prediction values. Assuming that the first model parameters are k groups and the second model parameters are 1 group, (k+1) category prediction values are obtained, and each category prediction value represents the probability that the image to be detected belongs to the corresponding category.
[0105] Afterwards, the category corresponding to the maximum probability is taken as the image detection result. For example, if the probability of the real category is the largest, the image detection result is: the image to be detected is a real image. If the probability of the jth forged category is the largest, the image detection result is: the image to be detected is the jth forged image, and j is one of 1 to k.
[0106] In this embodiment, the first model parameter is obtained based on the clustering result of the image features of the negative sample image, and the first model parameter is obtained based on the loss function, so that the image features can be processed using model parameters containing more supervisory information to improve the image detection effect.
[0107] In some embodiments, it also includes:
[0108] Performing conversion processing on the image to be detected to obtain a conversion image in a different domain from the sample image, and using the image to be detected and the conversion image as the target image; or,
[0109] The image to be detected is used as the target image.
[0110] In this embodiment, by using the sample image and the converted image as the target image, target images in various forms can be obtained. These target images in various forms contain information from multiple domains. After subsequent feature extraction processing, image features that integrate information from multiple domains can be obtained, thereby improving the image feature's ability to mine forgery clues and further improving the image detection effect.
[0111] In some embodiments,
[0112] The step of performing feature extraction processing on the target image to obtain image features includes: using a feature extraction network of an image detection model to perform feature extraction processing on the target image to obtain image features;
[0113] The classifying process of the image features based on the first model parameter and the second model parameter to obtain a category prediction value includes: using the first model parameter and the second model parameter of the classification network of the image detection model to classify the image features to obtain a category prediction value;
[0114] The image detection model is trained using any one of the above embodiments.
[0115] In this embodiment, since the image detection model introduces richer supervision information during training, the model performance is improved, and then image detection is performed based on the image detection model with better performance, which can improve the image detection effect.
[0116] Figure 6 is a schematic diagram according to the fourth embodiment of the present disclosure. This embodiment provides a training device for an image detection model, the image detection model comprising: a feature extraction network and a classification network, the classification network comprising: a first output node corresponding to a non-real category and a second output node corresponding to a real category, such as Figure 6 As shown, the device 600 includes: an extraction module 601, a clustering module 602, a determination module 603, a classification module 604 and an adjustment module 605.
[0117] The extraction module 601 is used to use the feature extraction network to perform feature extraction processing on the target image to obtain the current image features; the target image is obtained based on the sample image; the clustering module 602 is used to use the current image features to update the existing image features if the sample image is a non-real image to obtain updated image features, and cluster the updated image features to obtain cluster centers; the number of cluster centers is the same as the number of the first output nodes; the determination module 603 is used to determine the first model parameters corresponding to the first output node based on the cluster centers; the classification module 604 is used to use the classification network to classify the current image features to obtain the predicted value of the real category, and construct a loss function based on the predicted value of the real category; the adjustment module 605 is used to use the loss function to adjust the model parameters of the feature extraction network and the second model parameters corresponding to the second output node.
[0118] In this embodiment, clustering processing is performed on the image features of the non-real image to obtain the cluster center, and the first model parameter is determined based on the cluster center. The clustering process of the negative sample features can provide more abundant supervision information for model training, improve the accuracy of image detection, and effectively improve the generalization of the model, thereby improving the image detection effect.
[0119] In some embodiments, the apparatus 600 further includes:
[0120] An acquisition module is used to perform conversion processing on the sample image to obtain a conversion image in a different domain from the sample image, and use the sample image and the conversion image as the target image; or use the sample image as the target image.
[0121] In this embodiment, by using the sample image and the converted image as the target image, target images in various forms can be obtained. These target images in various forms contain information from multiple domains. After subsequent feature extraction processing, image features that integrate information from multiple domains can be obtained, thereby improving the image feature's ability to mine forgery clues and further improving the image detection effect.
[0122] In some embodiments, the feature extraction network includes: an embedding layer and a coding layer. Using the feature extraction network, the extraction module 601 is further used to:
[0123] Performing block processing on the target image to obtain block images;
[0124] Using the embedding layer, embedding the block image to obtain an embedding vector;
[0125] The encoding layer is used to encode the embedded vector to obtain an encoding vector as the current image feature.
[0126] In this embodiment, through the block division, embedding and encoding processing, the information of different positions of the image can be extracted, the expression ability of the encoding vector can be improved, and the image authentication performance can be improved.
[0127] In some embodiments, the clustering module 602 is further configured to:
[0128] Normalizing the encoding vector to obtain a normalized vector;
[0129] If the sample image is not a real image, the normalized vector is used to update the existing image features to obtain an updated normalized vector;
[0130] The updated normalized vector is clustered to obtain a cluster center.
[0131] In this embodiment, the encoding vector is normalized to obtain a normalized vector, and subsequent calculations are performed based on the normalized vector, which facilitates calculations and improves processing efficiency.
[0132] In some embodiments, the determining module 603 is further configured to:
[0133] The vector value of the cluster center is used as the first model parameter.
[0134] In this embodiment, since the cluster center is also a normalized vector after normalization processing, the first model parameter can be obtained simply and efficiently by using the vector value of the cluster center as the first model parameter, thereby improving processing efficiency and accuracy.
[0135] Figure 7 is a schematic diagram according to the fifth embodiment of the present disclosure. This embodiment provides an image detection device, such as Figure 7 As shown, the device 700 includes: an extraction module 701, a classification module 702 and a determination module 703.
[0136] The extraction module 701 is used to perform feature extraction processing on the target image to obtain image features; the target image is obtained based on the sample image; the classification module 702 is used to perform classification processing on the image features based on the first model parameter and the second model parameter to obtain a category prediction value; the determination module 703 is used to determine the detection result of the image to be detected based on the category prediction value;
[0137] The first model parameter is determined based on the cluster center, and the second model parameter is adjusted based on the loss function. The cluster center is obtained by clustering the image features of the non-real image.
[0138] In this embodiment, the first model parameter is obtained based on the clustering result of the image features of the negative sample image, and the first model parameter is obtained based on the loss function, so that the image features can be processed using model parameters containing more supervisory information to improve the image detection effect.
[0139] In some embodiments, the apparatus 700 further includes:
[0140] The acquisition module is used to perform conversion processing on the image to be detected to obtain a conversion image in a different domain from the sample image, and use the image to be detected and the conversion image as the target image; or use the image to be detected as the target image.
[0141] In this embodiment, by using the sample image and the converted image as the target image, target images in various forms can be obtained. These target images in various forms contain information from multiple domains. After subsequent feature extraction processing, image features that integrate information from multiple domains can be obtained, thereby improving the image feature's ability to mine forgery clues and further improving the image detection effect.
[0142] In some embodiments, the extraction module 701 is further used to: use the feature extraction network of the image detection model to perform feature extraction processing on the target image to obtain image features. The classification module 702 is further used to: use the first model parameters and the second model parameters of the classification network of the image detection model to perform classification processing on the image features to obtain category prediction values; wherein the image detection model is trained using any of the above embodiments.
[0143] In this embodiment, since the image detection model introduces richer supervision information during training, the model performance is improved, and then image detection is performed based on the image detection model with better performance, which can improve the image detection effect.
[0144] It can be understood that in the embodiments of the present disclosure, the same or similar contents in different embodiments can be referenced to each other.
[0145] It can be understood that the “first”, “second”, etc. in the embodiments of the present disclosure are only used for distinction and do not indicate the degree of importance, time sequence, etc.
[0146] In the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0147] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
[0148] Figure 8 A schematic block diagram of an example electronic device 800 that can be used to implement an embodiment of the present disclosure is shown. The electronic device 800 is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, servers, blade servers, mainframe computers, and other suitable computers. The electronic device 800 can also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0149] like Figure 8As shown, the electronic device 800 includes a computing unit 801, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 802 or a computer program loaded from a storage unit 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the electronic device 800 can also be stored. The computing unit 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0150] Multiple components in the electronic device 800 are connected to the I / O interface 805, including: an input unit 806, such as a keyboard, a mouse, etc.; an output unit 807, such as various types of displays, speakers, etc.; a storage unit 808, such as a disk, an optical disk, etc.; and a communication unit 809, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 809 allows the electronic device 800 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0151] The computing unit 801 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 801 performs the various methods and processes described above, such as the training method or image detection method of the image detection model. For example, in some embodiments, the training method or image detection method of the image detection model may be implemented as a computer software program, which is tangibly included in a machine-readable medium, such as a storage unit 808. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 800 via ROM 802 and / or communication unit 809. When the computer program is loaded into RAM 803 and executed by the computing unit 801, one or more steps of the training method or image detection method of the image detection model described above may be executed. Alternatively, in other embodiments, the computing unit 801 may be configured to execute the image detection model training method or the image detection method in any other appropriate manner (for example, by means of firmware).
[0152] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0153] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0154] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0155] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0156] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0157] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship between the client and the server is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services ("Virtual Private Server", or "VPS" for short). The server may also be a server of a distributed system, or a server combined with a blockchain.
[0158] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0159] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A training method for an image detection model, wherein the image detection model include: A feature extraction network and a classification network, wherein the classification network comprises: a first output node corresponding to a non-real category and a second output node corresponding to a real category, and the method comprises: Using the feature extraction network, a target image is subjected to feature extraction processing to obtain current image features; the target image is obtained based on a sample image; If the sample image is not a real image, the existing image features are updated using the current image features to obtain updated image features, and the updated image features are clustered to obtain cluster centers; the number of cluster centers is the same as the number of the first output nodes; Based on the cluster center, determining a first model parameter corresponding to the first output node; Using the classification network, classify the current image features to obtain the predicted value of the true category, and construct a loss function based on the predicted value of the true category; The loss function is used to adjust the model parameters of the feature extraction network and the second model parameters corresponding to the second output node.
2. The method according to claim 1, further comprising: include: Performing conversion processing on the sample image to obtain a conversion image in a different domain from the sample image, and using the sample image and the conversion image as the target image; or, The sample image is used as the target image.
3. The method according to claim 1, in, The feature extraction network includes: an embedding layer and a coding layer. The feature extraction network is used to perform feature extraction processing on the target image to obtain current image features, including: Performing block processing on the target image to obtain block images; Using the embedding layer, embedding the block image to obtain an embedding vector; The encoding layer is used to encode the embedded vector to obtain an encoding vector as the current image feature.
4. The method according to claim 3, in, If the sample image is a non-real image, the existing image features are updated using the current image features to obtain updated image features, and the updated image features are clustered to obtain cluster centers, including: Normalizing the encoding vector to obtain a normalized vector; If the sample image is not a real image, the normalized vector is used to update the existing image features to obtain an updated normalized vector; The updated normalized vector is clustered to obtain a cluster center.
5. The method according to claim 4, in, The determining, based on the cluster center, a first model parameter corresponding to the first output node includes: The vector value of the cluster center is used as the first model parameter.
6. An image detection method, include: Perform feature extraction processing on the target image to obtain image features; The target image is obtained based on the sample image; Based on the first model parameter and the second model parameter, classify the image feature to obtain a category prediction value; Determining a detection result of the image to be detected based on the category prediction value; The first model parameter is determined based on the cluster center, and the second model parameter is adjusted based on the loss function. The cluster center is obtained by clustering the image features of the non-real image.
7. The method according to claim 6, further comprising: include: Performing conversion processing on the image to be detected to obtain a conversion image in a different domain from the sample image, and using the image to be detected and the conversion image as the target image; or, The image to be detected is used as the target image.
8. The method according to claim 6, in, The step of performing feature extraction processing on the target image to obtain image features includes: Using a feature extraction network of an image detection model, performing feature extraction processing on the target image to obtain image features; The classifying process of the image feature based on the first model parameter and the second model parameter to obtain a category prediction value includes: Using the first model parameter and the second model parameter of the classification network of the image detection model, classify the image features to obtain a category prediction value; Wherein, the image detection model is trained using the method described in any one of claims 1-5.
9. A training device for an image detection model, wherein the image detection model include: A feature extraction network and a classification network, wherein the classification network comprises: a first output node corresponding to a non-real category and a second output node corresponding to a real category, and the device comprises: An extraction module, used to use the feature extraction network to perform feature extraction processing on the target image to obtain current image features; the target image is obtained based on the sample image; A clustering module, configured to, if the sample image is a non-real image, update the existing image features using the current image features to obtain updated image features, and cluster the updated image features to obtain cluster centers; the number of the cluster centers is the same as the number of the first output nodes; A determination module, configured to determine a first model parameter corresponding to the first output node based on the cluster center; A classification module, configured to classify the current image features using the classification network to obtain a predicted value of the true category, and to construct a loss function based on the predicted value of the true category; An adjustment module is used to use the loss function to adjust the model parameters of the feature extraction network and the second model parameters corresponding to the second output node.
10. The device according to claim 9, further comprising: include: An acquisition module is used to perform conversion processing on the sample image to obtain a conversion image in a different domain from the sample image, and use the sample image and the conversion image as the target image; or use the sample image as the target image.
11. The device according to claim 9, in, The feature extraction network includes: an embedding layer and a coding layer. The feature extraction network is used, and the extraction module is further used to: Performing block processing on the target image to obtain block images; Using the embedding layer, embedding the block image to obtain an embedding vector; The encoding layer is used to encode the embedded vector to obtain an encoding vector as the current image feature.
12. The device according to claim 11, in, The clustering module is further used for: Normalizing the encoding vector to obtain a normalized vector; If the sample image is not a real image, the normalized vector is used to update the existing image features to obtain an updated normalized vector; The updated normalized vector is clustered to obtain a cluster center.
13. The device according to claim 11, in, The determination module is further used for: The vector value of the cluster center is used as the first model parameter.
14. An image detection device, include: An extraction module is used to perform feature extraction processing on the target image to obtain image features; The target image is obtained based on the sample image; A classification module, used for classifying the image features based on the first model parameter and the second model parameter to obtain a category prediction value; A determination module, used to determine the detection result of the image to be detected based on the category prediction value; The first model parameter is determined based on the cluster center, and the second model parameter is adjusted based on the loss function. The cluster center is obtained by clustering the image features of the non-real image.
15. The device according to claim 14, further comprising: include: The acquisition module is used to perform conversion processing on the image to be detected to obtain a conversion image in a different domain from the sample image, and use the image to be detected and the conversion image as the target image; or use the image to be detected as the target image.
16. The device according to claim 14, in, The extraction module is further used to: use the feature extraction network of the image detection model to perform feature extraction processing on the target image to obtain image features The classification module is further used to: use the first model parameter and the second model parameter of the classification network of the image detection model to classify the image features to obtain a category prediction value; Wherein, the image detection model is trained using the method described in any one of claims 1-5.
17. An electronic device, include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 8.
18. A non-transitory computer-readable storage medium storing computer instructions, in, The computer instructions are used to cause the computer to execute the method according to any one of claims 1-8.
19. A computer program product, comprising a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 8.
