Image detection method, system, device, medium and product guided by prompt information

Through a multi-stage prompt information guided image detection method, the encoder network and attention mechanism are used to fuse image and text features, which solves the problem of insufficient image forgery detection accuracy in the existing technology and achieves more efficient feature fusion and detection performance. promote.

CN118334022BActive Publication Date: 2024-10-01INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410756583.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-13
Publication Date
2024-10-01
Estimated Expiration
2044-06-13

AI Technical Summary

Technical Problem

Existing image forgery detection methods extract image features based on neural network models, but the accuracy has not yet reached a satisfactory level, and it is difficult to effectively use text information for feature fusion.

Method used

An image detection method guided by multi-stage prompt information is adopted to extract features layer by layer through the encoder network, and the attention mechanism and prompt information generator are used to fuse image and text features for multi-stage guidance to improve detection accuracy.

Benefits of technology

It improves the accuracy and consistency of image forgery detection, can more effectively utilize image and text information for feature fusion, and enhances the model's performance on image forgery tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118334022B_ABST
    Figure CN118334022B_ABST
Patent Text Reader

Abstract

The present disclosure relates to an image detection method, system, device, medium and product guided by prompt information, which relates to the field of image detection technology and aims to accurately judge the authenticity of an image. The method comprises: obtaining image features of an image; inputting the image features into an encoder network to obtain prompt information generated by each encoder; the output of each encoder is the input of the next encoder, and the depth of feature extraction of multiple encoders is progressive layer by layer; under the multi-stage guidance of the prompt information, the image features are used to detect the authenticity of the image based on the attention mechanism.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of image detection technology, and in particular to an image detection method, system, device, medium and product guided by prompt information. Background Art

[0002] Image forgery detection aims to detect and identify whether an image has been forged or tampered with, which is crucial to protecting the authenticity and credibility of images. Traditional methods are based on statistical features of images, digital signal processing technology, and physical models to detect image forgery, which has the disadvantage of requiring manual definition and extraction of features. Related technologies extract image features through neural network models and predict the authenticity of images based on image features, but the accuracy of prediction based on neural network models needs to be improved. Summary of the invention

[0003] In order to overcome the problems existing in the related art, the embodiments of the present disclosure provide an image detection method, system, device, medium and product guided by prompt information. The technical solution of the embodiments of the present disclosure is as follows:

[0004] According to a first aspect of an embodiment of the present disclosure, there is provided an image detection method guided by prompt information, comprising:

[0005] Obtain image features of the image;

[0006] Input the image features into an encoder network to obtain prompt information generated by each encoder; the output of each encoder is the input of the next encoder, and the depth of feature extraction by multiple encoders is progressive layer by layer;

[0007] Under the multi-stage guidance of the prompt information, the image features are utilized to detect the authenticity of the image based on an attention mechanism.

[0008] Optionally, the encoder includes an attention mechanism module; and under the multi-stage guidance of the prompt information, using the image features, detecting the authenticity of the image based on the attention mechanism includes:

[0009] Linearly mapping the image features to obtain a key vector, a value vector and a query vector;

[0010] Inputting the key vector, the value vector and the query vector into the attention mechanism module to obtain image features carrying attention information;

[0011] Connecting the prompt information and the image features carrying the attention information to obtain a fusion feature output by the encoder;

[0012] Based on the fused features, the authenticity of the image is determined.

[0013] Optionally, the encoder includes a prompt information generator;

[0014] The step of inputting the image features into an encoder network to obtain prompt information generated by each encoder includes:

[0015] Inputting the image features into the encoder network;

[0016] Linearly mapping the input of the encoder to obtain a query vector; the query vector is used to characterize the characteristics of the input of the encoder;

[0017] The query vector is input into a prompt information generator of the encoder to obtain learnable prompt information.

[0018] Optionally, the step of connecting the prompt information and the image features carrying the attention information to obtain a fusion feature output by the encoder includes:

[0019] Inputting the prompt information into a lexical analyzer to obtain a text sequence; the text sequence includes at least one text tag;

[0020] Obtaining an embedding vector for each of the text tokens;

[0021] Processing the embedding vectors of each of the text tags to obtain a text sequence feature vector;

[0022] The text sequence feature vector and the input feature carrying the attention information are concatenated to obtain the fused feature output by the encoder.

[0023] Optionally, the step of concatenating the text sequence feature vector and the input feature carrying the attention information to obtain a fusion feature output by the encoder includes:

[0024] Calculating the mean vector and variance vector of the text sequence feature vector;

[0025] Normalizing the text sequence feature vector according to the mean vector and the variance vector to obtain a first text sequence feature vector;

[0026] Scaling and offsetting the first text sequence feature vector to obtain a second text sequence feature vector; the second text sequence feature vector is adapted to the input feature carrying the attention information;

[0027] The second text sequence feature vector and the input feature carrying the attention information are concatenated to obtain a fused feature output by the encoder.

[0028] Optionally, the step of concatenating the second text sequence feature vector and the input feature carrying the attention information to obtain a fusion feature output by the encoder includes:

[0029] The second text sequence feature vector is multiplied by residual connection with the input feature carrying the attention information to obtain the fused feature output by the encoder.

[0030] Optionally, performing a multiplication residual connection on the second text sequence feature vector and the input feature carrying the attention information to obtain a fusion feature output by the encoder includes:

[0031] Performing a dot multiplication on the second text sequence feature vector and the input feature carrying the attention information to obtain a first fusion feature;

[0032] Regularizing the first fusion feature to obtain a second fusion feature;

[0033] Feeding the second fused feature forward to a neural network, obtaining a third fused feature;

[0034] The third fusion feature is dot-multiplied by the second fusion feature to obtain the fusion feature output by the encoder.

[0035] Optionally, determining the authenticity of the image based on the fusion feature includes:

[0036] Inputting the fused features output by the last encoder in the encoder network into a classification head to obtain a first prediction probability that the image is real and a second prediction probability that the image is fake;

[0037] The authenticity of the image is determined according to the first prediction probability and the second prediction probability.

[0038] Optionally, the acquiring image features of the image includes:

[0039] dividing the image into a plurality of sub-images;

[0040] Obtaining an embedding vector of each of the sub-images, and obtaining a position code of each of the sub-images;

[0041] Adding the embedding vector and the position code of each sub-image element by element to obtain an embedding vector sequence;

[0042] The embedding vector sequence is input into a pre-trained visual encoder to obtain image features of the image.

[0043] Optionally, obtaining the position code of each sub-image includes:

[0044] The position code of each sub-image is obtained according to the following formula:

[0045] ;

[0046] in, Characterization Line The position encoding of the sub-images of the columns, Characterization Line The column position encoding index of the sub-image, represents the dimension of the embedding vector of the sub-image, represents the dimension of the position encoding, is a sine function, is the cosine function.

[0047] Optionally, dividing the image into a plurality of sub-images includes:

[0048] Normalizing the pixel values ​​of the image and converting the data type of the image into a fixed type to obtain a first image of a fixed size;

[0049] The first image with a fixed size is divided into the multiple sub-images.

[0050] Optionally, the training step of the prompt information generator at least includes:

[0051] Acquire multiple first image samples and a prompt information sample of each of the first image samples;

[0052] Inputting the plurality of first image samples into an initial prompt information generator to obtain predicted prompt information of each of the first image samples;

[0053] With the goal of reducing the difference between the predicted prompt information and the prompt information sample of each first image sample, the initial prompt information generator is trained to obtain the trained prompt information generator.

[0054] Optionally, the prompt information guided image detection method is implemented by an image detection model, wherein the image detection model includes the encoder network and the classification head;

[0055] The training steps of the image detection model at least include:

[0056] Acquire multiple image sample pairs; the image sample pairs include real image sample pairs and forged image sample pairs, and each second image sample in the image sample pairs carries a true or false label;

[0057] Acquire an image feature sample of the second image sample;

[0058] Input the image feature sample into the encoder network to obtain a prompt information sample generated by each encoder; the output of each encoder is the input of the next encoder, and the depth of feature extraction of multiple encoders is progressive layer by layer;

[0059] Under the multi-stage guidance of the prompt information sample, using the image feature sample, based on the attention mechanism, obtain the authenticity prediction result of the second image sample;

[0060] Establishing a category loss function according to the authenticity prediction result of the second image sample and the authenticity label;

[0061] Establishing a sample differentiation loss function according to the similarity between the real image sample pairs and the similarity between the forged image sample pairs;

[0062] The initial image detection model is trained according to the category loss function and the sample differentiation loss function to obtain the trained image detection model.

[0063] Optionally, establishing a category loss function according to the authenticity prediction result of the second image sample and the authenticity label includes:

[0064] The category loss function is established according to the following formula:

[0065] ;

[0066] in, is the category loss function, Characterizing the Second Image Sample The real label, Characterizing the Second Image Sample Fake labels, Characterizing the Second Image Sample is the predicted probability of a forged image, Characterizing the Second Image Sample is the predicted probability of the real image, is the number of samples of the second image.

[0067] Optionally, establishing a sample differentiation loss function according to the similarity between the real image sample pairs and the similarity between the forged image sample pairs includes:

[0068] The sample differentiation loss function is established according to the following formula:

[0069] ;

[0070] in, Characterize the sample differentiation loss function, represents the natural exponential function, Characterize the similarity of the real image sample pair, Characterize the similarity of the forged image sample pair, represents the number of forged image sample pairs, is the temperature parameter.

[0071] Optionally, acquiring a plurality of image sample pairs includes:

[0072] Obtain multiple real image samples;

[0073] Processing the multiple real image samples to generate multiple forged image samples;

[0074] The plurality of image sample pairs are generated according to the plurality of real image samples and the plurality of forged image samples.

[0075] Optionally, the encoder is a multimodal encoder.

[0076] According to a second aspect of an embodiment of the present disclosure, there is provided an image detection system guided by prompt information, comprising: a visual encoder, an encoder network and a classification head, wherein the output of each encoder in the encoder network is the input of the next encoder, and the depth of feature extraction of the multiple encoders is progressive layer by layer;

[0077] The visual encoder is used to obtain image features of the image;

[0078] The encoder is used to generate prompt information according to the image features;

[0079] The classification head is used to detect the authenticity of the image based on the attention mechanism by utilizing the image features under the multi-stage guidance of the prompt information.

[0080] According to a third aspect of an embodiment of the present disclosure, an electronic device is provided, comprising: a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the prompt information guided image detection method described in the first aspect.

[0081] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the prompt information-guided image detection method described in the first aspect are implemented.

[0082] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the steps of the prompt information-guided image detection method described in the first aspect.

[0083] In the disclosed embodiment, the first encoder generates prompt information based on image features, and fuses the prompt information and image features to obtain the fused features output by the first encoder, and uses the fused features output by the first encoder as the input of the second encoder, thereby obtaining the prompt information generated by the second encoder based on the fused features output by the first encoder, and fuses the prompt information generated by the second encoder with the input of the second encoder to obtain the fused features output by the second encoder, and the receptive field of the fused features output by the second encoder is greater than the receptive field of the fused features output by the first encoder, so the depth of the features extracted in the second encoder is deeper; and so on, the depth of the features prompted by each encoder is progressive layer by layer. In addition, by fusing the generated prompt information with the input of the encoder at each stage, multi-stage guidance of the prompt information is achieved. On the one hand, because deep features and shallow features have obvious differences, the prompt information and the input of the encoder are fused in each encoder, and the prompt information can provide context information for the model at different stages; on the other hand, the prompt information is used for multi-stage guidance, which can gradually guide the model to pay attention to important context information and semantic information. Therefore, the authenticity of the image is predicted based on the fused features output by the last encoder in the encoder network, which has the advantage of being more accurate. BRIEF DESCRIPTION OF THE DRAWINGS

[0084] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings required for use in the description of the embodiments of the present disclosure will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0085] Figure 1 It is a flowchart of related technologies for image forgery detection;

[0086] Figure 2 It is a schematic diagram of the steps of an image detection method guided by prompt information in an embodiment of the present disclosure;

[0087] Figure 3 is a schematic diagram of information flow of a text-guided image detection method shown in an embodiment of the present disclosure;

[0088] Figure 4 is a schematic diagram of the architecture of an image detection model shown in an embodiment of the present disclosure;

[0089] Figure 5 is a working schematic diagram of an image detection model shown in an embodiment of the present disclosure;

[0090] Figure 6is a schematic diagram of the structure of a visual encoder shown in an embodiment of the present disclosure;

[0091] Figure 7 is a schematic diagram of the architecture of an encoder shown in an embodiment of the present disclosure;

[0092] Figure 8 is a schematic diagram of an electronic device shown in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0093] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.

[0094] Figure 1 It is a flowchart of the related technology for image forgery detection; Figure 1 As described above, the related technology extracts image features of an image based on a pre-trained image encoder, and then inputs the image features into a linear layer to obtain a binary classification result of whether the image is true or false.

[0095] Although the methods in related technologies are relatively simple, this classification-based paradigm often only utilizes image information and does not fully utilize cross-modal information, such as the association between visual and language information. The visual-language pre-training model can be used to learn generalized visual representations with semantic concepts. Multimodal learning can improve visual representation capabilities and perform very well in visual tasks. The main idea of ​​the visual-language pre-training model is to align images and texts through contrastive learning, that is, to bring the image and matching text description closer in the joint feature space, while separating mismatched image-text pairs. These visual-language pre-training models use the massive training data of these images and texts to build powerful text and image feature extraction capabilities, and can associate text and images.

[0096] However, existing forged images do not provide corresponding texts and often only have image modalities. Therefore, it is difficult to directly apply the visual-language pre-training model to the image forgery detection task. Therefore, a more effective text construction method and feature fusion method are needed.

[0097] Prompt learning is a learning method that uses text prompts in natural language processing tasks, which guides the model to generate the required output by providing a short text prompt or question to the model. In prompt learning, the model receives a task description or question, and then generates a corresponding answer, summary, translation, etc. based on this prompt. This task description can be a complete sentence or a short keyword or phrase. The advantage of using prompt learning is that it can provide a clear context and task goal for the model, helping the model to better understand the requirements of the task and generate relevant outputs. By designing appropriate prompts, the model can be guided to focus on specific information and semantics, improving the accuracy and consistency of the model. The CLIP (Contrastive Language-Image Pre-Training) model directly uses the template "a photo of a certain category" as the prompt information in the text branch, but such a description is too broad. Therefore, the embodiment of the present disclosure proposes a multi-stage fused learnable prompt information to adapt to the image forgery detection task at different stages.

[0098] The purpose of the disclosed embodiments is to build an image detection model specifically for forgery detection tasks based on the vision-language pre-training model, and to improve the accuracy of image forgery detection by utilizing the powerful feature extraction capability of the vision-language pre-training model.

[0099] The vision-language model consists of a vision part and a language part. The CLIP model in the vision-language model includes a parallel image branch and a text branch, which train two matching image feature extractors and text feature extractors. The text branch is mainly responsible for taking the name corresponding to each category, such as "airplane", "cat", and "dog", and combining it with the template "a photo of a certain category" as prompt information to the text encoder to obtain text features when performing classification tasks of multiple categories; the core of the image branch is to extract image features from the input image.

[0100] The related art performs image forgery detection based on prompt information, but does not care about the image context information and image information at multiple stages. The disclosed embodiment makes full use of the role of prompt information, and fuses the prompt information with the image information in multiple stages. Multi-stage fusion requires consideration of the association between the modality and the image features at the time. Therefore, the disclosed embodiment proposes an encoder that performs association calculations on the prompt information and the image information to obtain the most appropriate prompt information at the current stage. And then fuse the prompt information generated based on the current stage features of the image and the image features. Among them, the two fusion processes are one based on the prompt information to generate high-quality prompt information, and the other based on the image features to generate high-quality image features.

[0101] In image forgery detection, prompt learning methods can provide an effective way for complex multimodal prediction tasks. By efficiently injecting text prompts, knowledge can be transferred from a frozen language model to the image forgery detection task, and hopefully promising results can be achieved. However, for tasks such as image forgery detection, directly using existing prompt learning methods may not be applicable because it requires more effective feature fusion and adaptation. The image forgery detection task involves comprehensive analysis and judgment of image content, context, and details, and requires the comprehensive use of image and text information for accurate forgery detection. By reasonably designing the model architecture and training strategy, the accuracy and effectiveness of the image forgery detection task can be improved.

[0102] The image forgery detection in the related art has the following problems, one of which is how to add text information to pure image forgery detection, that is, how to construct text information and utilize the knowledge of the multimodal pre-trained model. The disclosed embodiment uses learnable prompt information as the text information of the image, which is more automated and does not require manual provision of text information. The benefit of using Prompt learning is that it can provide the model with a clear context and task objectives, helping the model to better understand the requirements of the task and generate relevant outputs. By designing appropriate prompts, the model can be guided to focus on specific information and semantics, thereby improving the accuracy and consistency of the model.

[0103] Another problem is how to connect visual information and text information, that is, how to fuse the two types of feature information. The disclosed embodiment proposes a PMPG (Prompt Modality-Preserving Guidance) method, which has the advantage of retaining the uniqueness of different modal features, while at the same time, through multi-stage guidance, the modal features can be gradually integrated and affect the generation of deep features. This compact feature fusion and multi-stage prompt injection method helps to improve the performance and accuracy of image description tasks.

[0104] The image detection method guided by prompt information proposed in the embodiment of the present disclosure is an image forgery detection method based on multi-stage prompt information, which adopts a learnable prompt information construction method and assists image forgery detection. Specifically, the embodiment of the present disclosure proposes a PMPG method guided by prompt information in multiple stages, which has the advantage of retaining the uniqueness of different modal features, and at the same time, through multi-stage guidance, the features of multiple modalities can be gradually integrated and affect the generation of deep features. This compact feature fusion and multi-stage prompt injection method helps to improve the performance and accuracy of image description tasks. On this basis, an encoder is constructed, which is essentially an attention-based multimodal prompt word encoder, which can fuse the text information and image information of PMPG. At the same time, a multi-stage encoder module is constructed through multiple encoders, and the multi-stage encoder can gradually learn and extract feature representations at different levels of data. The encoder at the bottom stage can capture lower image or text features, while the encoder at the high-level stage can capture more abstract and semantic features. Through multiple stages of learning, the encoder can establish a richer and more complex feature representation, and then input the fused features into the classification head to output the authenticity of the image. The encoder in the embodiment of the present disclosure may be a multimodal encoder that can process information in different modalities such as images and texts.

[0105] The principle of the disclosed embodiment is that, through contrast learning training, the features between the matching text and image can be brought closer, while after the image is forged, the features are offset, and after the text features are fused with the forged image features, there will be obvious differences, thereby distinguishing the authenticity of the image.

[0106] Figure 2 FIG. 1 is a schematic diagram of steps of an image detection method guided by prompt information shown in an embodiment of the present disclosure. Figure 2 As shown, the image detection method guided by prompt information includes steps S11 to S13.

[0107] In step S11, image features of the image are obtained;

[0108] In step S12, the image features are input into the encoder network to obtain prompt information generated by each encoder; the output of each encoder is the input of the next encoder, and the depth of feature extraction by multiple encoders is progressive layer by layer;

[0109] In step S13, under the multi-stage guidance of the prompt information, the image features are used to detect the authenticity of the image based on the attention mechanism.

[0110] The information flow process of the image detection method guided by prompt information in the embodiment of the present disclosure can be referred to Figure 3 As shown, Figure 3Only two encoders are shown for illustration, and it can be understood that the number of encoders can be greater than or equal to two.

[0111] The image detection method guided by prompt information in the embodiment of the present disclosure can be implemented by an image detection model. Figure 4 It is a schematic diagram of the architecture of an image detection model shown in an embodiment of the present disclosure. The image detection model includes an encoder network, a classification head, and a pre-trained visual encoder. The encoder network includes multiple cascaded encoders. Figure 5 It is a working schematic diagram of the image detection model shown in an embodiment of the present disclosure.

[0112] The image described in the embodiments of the present disclosure may be any image. The image features of the image may be obtained by inputting the image into a pre-trained visual encoder. As an embodiment, the method of obtaining the image features of the image may include: dividing the image into a plurality of sub-images; obtaining an embedding vector for each of the sub-images, and obtaining a position code for each of the sub-images; adding the embedding vector and the position code of each of the sub-images element by element to obtain an embedding vector sequence; and inputting the embedding vector sequence into a pre-trained visual encoder to obtain the image features of the image.

[0113] The visual encoder can take advantage of the visual Swin Transformer (a hierarchical Transformer structure) to model image-level visual inconsistencies for image forgery detection. Swin Transformer is a hierarchical visual Transformer that uses shifted windows to address challenges faced by traditional Transformers in visual tasks, such as multi-scale problems and computational issues for high-resolution images. It also connects the input image and the output of the Swin Transformer through a long residual to ensure that the gradient of the input information disappears. Figure 6 : is a schematic diagram of the structure of the visual encoder shown in the embodiment of the present disclosure. The visual encoder includes a shallow feature extraction module and a deep feature extraction module, which are used to extract image features of different depths and finally output the global image features of the image. The shallow feature extraction module can be composed of a layer of convolutional neural network, and the deep feature extraction module can be composed of multiple layers of Swin Transformer. The global image features of the image contain the detailed information of the image.

[0114] In order to ensure that the dimensions of the image features input by the encoder are consistent, the image size input by the image detection model must be fixed. Therefore, when dividing an image into multiple sub-images, the pixel values ​​of the image can be normalized first, and the data type of the image can be converted to a fixed type to obtain a first image with a fixed size; the first image with a fixed size can be divided into the multiple sub-images.

[0115] As an example, the image detection model accepts fixed-size input images. Usually, the input images are resized to the same size, such as 256x256 pixels, and the images are preprocessed, the pixel values ​​are normalized, the image data type is converted to float32 (single-precision floating point number) and then divided by 255.0, and the size is ,in is the feature dimension, Characterize the image size. In the disclosed embodiment, the feature dimension is 3 and the image size is 256×256.

[0116] Divide the image into multiple sub-images. Assume that the size of the sub-image is ,in is the height and width of the sub-image. Based on the height and width of the image, the number of rows and columns of the sub-image can be calculated: ,in, represents the number of rows of the sub-image, The number of columns representing the sub-image. Each sub-image is converted into an embedding vector. Assume that the dimension of the embedding vector is . For the input image ,in Representing natural numbers, the embedding vector of each sub-image can be calculated as .

[0117] In one embodiment, the image is divided into 16x16 sub-images, and each image is split into 256 sub-images, that is, the output sequence length is 256, and the dimension of each sub-image is 16x16x3=768. Then each sub-image is projected into a two-dimensional convolutional layer, and the sub-image embedding vector is output, and the dimension is still 768, that is, there are 256 sub-image embedding vectors in total, and the dimension of each sub-image embedding vector is 768, and a sequence of sub-image embedding vectors is obtained. Usually, a terminator is added, and a terminator occupies 1, so the final dimension of the sub-image embedding vector sequence is 256x769.

[0118] Add position encoding to the sequence of sub-image embedding vectors. The position encoding is used to provide position information for each sub-image. The position encoding is consistent with the size of the sequence of sub-image embedding vectors. The position encoding can be encoded using sine and cosine functions and added to the sequence of sub-image embedding vectors through a summation operation. The sequence dimension of the sub-image embedding vector is still 257x768.

[0119] The dimension of the position encoding matrix PE is (N, d), where each row represents the encoding of a position. The position encoding formula is as follows:

[0120] ;

[0121] in, Characterization Line The position encoding of the sub-images of the columns, Characterization Line The column position encoding index of the sub-image, represents the dimension of the embedding vector of the sub-image, represents the dimension of the position encoding, is a sine function, is the cosine function.

[0122] The embedding vector of each sub-image and the corresponding position code are added element by element, so the embedding vector of each sub-image is obtained, which contains the spatial information and position information of the image. The obtained embedding vector is input into the visual encoder to obtain the image features, which are used as the input of the encoder network and passed to the encoder of the subsequent stage for feature extraction and modeling.

[0123] The image features are input into an encoder network to obtain prompt information generated by each encoder in the encoder network; wherein the encoder network includes a plurality of encoders, and the output of each encoder is the input of the next encoder.

[0124] The first encoder generates prompt information based on image features, and fuses the prompt information and image features to obtain fused features output by the first encoder, and uses the fused features output by the first encoder as the input of the second encoder, thereby obtaining prompt information generated by the second encoder based on the fused features output by the first encoder, and fuses the prompt information generated by the second encoder with the input of the second encoder to obtain the fused features output by the second encoder, and the receptive field of the fused features output by the second encoder is larger than the receptive field of the fused features output by the first encoder, therefore, the level of features extracted in the second encoder is deeper; and so on, the level of features prompted by each encoder gradually deepens.

[0125] The entire encoder network contains three stages of encoders, each stage contains n encoders, each stage will reduce the resolution of the input feature map and expand the receptive field layer by layer. Optionally, in some specific cases, only three stages are needed to meet the needs of the model, one of which contains only one encoder, encoding the input into a fixed-length feature vector , size is ,in is the feature dimension, represents stage 1. The second stage contains two encoders, and the input feature size is , the third stage contains an encoder with an input feature size of . It can be expressed as , here Characterization encoders, Characterization The input of the encoder, Characterization The input of the encoder, Characterization The role of an encoder. Among them, the image feature is the input of the first encoder. After the image passes through the three-stage encoder, the fused features output by the last encoder are obtained, and the fused features are input to the classification head for classification to obtain the final discrimination result. The classification head is composed of multiple linear layers and a softmax (soft maximization) layer. The output of the classification head is the first predicted probability that the image is true and the second predicted probability that the image is false; according to the first predicted probability and the second predicted probability, the authenticity of the image is determined. The result corresponding to the maximum value of the first predicted probability and the second predicted probability is determined as the authenticity result of the image. In one embodiment, the output result is in the form of [0.4, 0.6], the former represents the probability of being true, and the latter represents the probability of being false. The maximum probability value is taken for output, the image is true for 0, and the image is forged for 1.

[0126] According to the technical solution of the embodiment of the present disclosure, the first encoder generates prompt information based on image features, and fuses the prompt information and image features to obtain the fused features output by the first encoder, and uses the fused features output by the first encoder as the input of the second encoder, thereby obtaining the prompt information generated by the second encoder based on the fused features output by the first encoder, and fuses the prompt information generated by the second encoder with the input of the second encoder to obtain the fused features output by the second encoder, and the receptive field of the fused features output by the second encoder is greater than the receptive field of the fused features output by the first encoder, so the level of the features extracted in the second encoder is deeper; and so on, the level of the features prompted by each encoder gradually deepens. In addition, by fusing the generated prompt information with the input of the encoder at each stage, multi-stage guidance of the prompt information is achieved. On the one hand, because deep features and shallow features have obvious differences, the prompt information and the input of the encoder are fused in each encoder, and the prompt information can provide context information for the model at different stages; on the other hand, the prompt information is used for multi-stage guidance, which can gradually guide the model to pay attention to important context information and semantic information. Therefore, the authenticity of the image is predicted based on the fused features output by the last encoder in the encoder network, which has the advantage of being more accurate.

[0127] On the basis of the above technical solution, each of the encoders includes a prompt information generator, which generates prompt information, and then the encoder fuses the prompt information generated by the prompt information generator with the input of the encoder to obtain a fused feature. Figure 7 It is a schematic diagram of the architecture of the encoder shown in an embodiment of the present disclosure.

[0128] As an embodiment, the inputting of the image features into the encoder network to obtain the prompt information generated by each encoder includes: inputting the image features into the encoder network; obtaining each encoder to linearly map the input of the encoder to obtain a query vector; the query vector is used to characterize the features of the input of the encoder; and inputting the query vector into the prompt information generator of the encoder to obtain the prompt information generated by the encoder.

[0129] The encoder includes an attention mechanism module, which uses the image features under the multi-stage guidance of the prompt information to detect the authenticity of the image based on the attention mechanism, including: linearly mapping the image features to obtain a key vector, a numerical vector and a query vector; inputting the key vector, the numerical vector and the query vector into the attention mechanism module to obtain image features carrying attention information; connecting the prompt information and the image features carrying attention information to obtain fused features output by the encoder; and determining the authenticity of the image based on the fused features.

[0130] The method of connecting the prompt information and the input features carrying the attention information to obtain the fused features output by the encoder includes: inputting the prompt information into a lexical analyzer to obtain a text sequence; the text sequence includes at least one text tag; obtaining an embedding vector for each of the text tags; processing the embedding vectors of each of the text tags to obtain a text sequence feature vector; and concatenating the text sequence feature vector and the input features carrying the attention information to obtain the fused features output by the encoder.

[0131] The step of concatenating the text sequence feature vector and the input feature carrying the attention information to obtain the fused feature output by the encoder includes: calculating the mean vector and variance vector of the text sequence feature vector; normalizing the text sequence feature vector according to the mean vector and the variance vector to obtain a first text sequence feature vector; scaling and offsetting the first text sequence feature vector to obtain a second text sequence feature vector; matching the second text sequence feature vector with the input feature carrying the attention information; and concatenating the second text sequence feature vector with the input feature carrying the attention information to obtain the fused feature output by the encoder. The step of concatenating the second text sequence feature vector and the input feature carrying the attention information to obtain the fused feature output by the encoder includes: performing a multiplication residual connection between the second text sequence feature vector and the input feature carrying the attention information to obtain the fused feature output by the encoder. The method performs a multiplication residual connection on the second text sequence feature vector and the input feature carrying the attention information to obtain the fused feature output by the encoder, including: performing a dot product on the second text sequence feature vector and the input feature carrying the attention information to obtain a first fused feature; regularizing the first fused feature to obtain a second fused feature; feeding the second fused feature forward to a neural network to obtain a third fused feature; and performing a dot product on the third fused feature and the second fused feature to obtain the fused feature output by the encoder.

[0132] As an example, an encoder network is constructed to guide the model to focus on information about image forgery by using learnable hint information in PMPG. By fusing features, the model can establish a connection between vision and semantics, combining image features with hint information to provide more accurate and consistent predictions.

[0133] First, assume that the input features of the input encoder are , the input feature The key vectors are obtained by linear mapping respectively , numeric vector and query vector ,in, , The key vector, value vector and query vector are input into the attention mechanism module respectively to obtain the input features carrying attention information. , input features that carry attention information It can be obtained by the following formula:

[0134] ;

[0135] in, Represents input features that carry attention information, Characterizing the attention mechanism, is the key vector, is a numeric vector, is the query vector, Characterizing soft maximization, is the number of attention heads, Transform the rank of the matrix.

[0136] At the same time, the copied Mark as , input into the prompt information generator, and the output is ,in, Characterization prompt information, Characterization prompt information generator, A vector representing the input to the hint generator.

[0137] A special feature of the embodiment of the present disclosure is that the input features carrying attention information and the prompt information are dot-multiplied. Through this process, the prompt information guides the image features, and then the regularized information is input into the feedforward neural network to obtain the final fusion features.

[0138] In the attention calculation process, a special feature is that the embodiment of the present disclosure uses multiplication residual connection instead of addition connection after the multi-layer attention mechanism, because the multiplication residual connection provides better accuracy performance, and uses residual connection and regularization to alleviate the problems of overfitting and instability in the training process. Compared with the previous self-attention mechanism for image features to obtain the intrinsic connection between images, the embodiment of the present disclosure guides the image features through prompt information. The benefit of attention mechanism calculation is that it can provide clearer guidance when fusing prompt information, help the model understand the image more accurately, and avoid misunderstanding the fuzzy or ambiguous information in the image. In addition, more importantly, since PMPG uses learnable prompt information, it can help the model better generalize to new and similar data. Due to the diversity of image forgery information, different image forgery tasks often cannot use information from each other, but by fusing image features through prompt information, the model can transfer the learned knowledge from one data set to another, improving the generalization ability of the model on new data. For example, it can be replaced from facial expression forgery to face replacement, and even because of the universality of the text description ability of prompt information, the image detection model is also effective on non-face forgery.

[0139] Because the shallow and deep features of image features are significantly different, prompt information can provide contextual information to the model at different stages. By introducing prompt information at different stages, the model can be gradually guided to focus on important context and semantic information. This helps the model better understand the background and context of the task and improves the performance of the model in complex tasks.

[0140] The prompt information setting that can be learned, the prompt information setting parameters that can be learned are , which means the maximum length of the prompt message is In the disclosed embodiment, different categories are set according to the different annotations of the data set. There are two basic categories, one for marking the image as a real image and the other for marking the image as a forged image. In the disclosed embodiment, the end symbol is used to indicate the start and end position of the text and help the model understand the boundaries of the text. The learnable length of this parameter is set to , then the dimension of the prompt information is .

[0141] Specifically, the prompt information is input into a tokenizer, and a lexical analyzer is used to convert a text string into one or more text sequences, including at least one text token (texttokens). The function of the lexical analyzer is to split the input text into discrete text tokens. The specific lexical analyzer implementation may use spaces, punctuation marks, or other methods for segmentation, and encode each text token as an integer. After passing through the lexical analyzer, a text sequence represented by integers is obtained. These integer tokens are passed as input to an Embedding layer, and each text token is converted into an embedding vector of the text token by looking up the embedding matrix. Finally, the text sequence feature vector is obtained by combining or averaging the embedding vectors of all text tokens.

[0142] Then, the learnable prompt information needs to be input into a scaled prompt information featurization module to adapt to the image features at different stages. First, the mean vector of the text sequence feature vector in the feature dimension is calculated, and then the variance vector of the text sequence feature vector in the feature dimension is calculated. Thereafter, the text sequence feature vector is normalized using the mean vector and the variance vector to obtain the first text sequence feature vector. Using learnable parameters and offset parameters For the first text sequence feature vector Scaling and offset processing are performed to obtain a second text sequence feature vector. The second text sequence feature vector is concatenated with the input feature carrying attention information to obtain a fusion feature output by the encoder. ,in, Indicates element-by-element multiplication. At this time, the fusion feature The feature dimension is .

[0143] To obtain Two different linear layers are used for downsampling to reduce the feature dimension and obtain two downsampled fused features. The downsampling is implemented by the MLP (Multilayer Perceptron) layer. Then the query vector is downsampled to obtain another downsampled feature. The three downsampled features are input into the attention layer to obtain a fused feature with attention information. The fused feature with attention information is then upsampled and transmitted back to the prompt information generator.

[0144] On the basis of the above technical solution, a prompt information generator can be pre-trained, and the training steps of the prompt information generator at least include: obtaining multiple first image samples and a prompt information sample for each of the first image samples; inputting the multiple first image samples into an initial prompt information generator to obtain predicted prompt information for each of the first image samples; with the goal of reducing the difference between the predicted prompt information and the prompt information sample for each of the first image samples, training the initial prompt information generator to obtain the trained prompt information generator.

[0145] The first image sample can be any image sample, and the prompt information sample of the first image sample is marked in advance. The initial prompt information generator is the prompt information generator to be trained. The first image sample is input into the initial prompt information generator to obtain the predicted prompt information of each of the first image samples. According to the predicted prompt information and the prompt information sample of the first image sample, a loss function is established, and the initial prompt information generator is supervisedly trained based on the loss function to obtain the trained prompt information generator.

[0146] On the basis of the above technical scheme, the training step of the image detection model at least includes: obtaining multiple image sample pairs; the image sample pairs include real image sample pairs and forged image sample pairs, and each second image sample in the image sample pairs carries a true or false label; obtaining image feature samples of the second image samples; inputting the image feature samples into the encoder network to obtain prompt information samples generated by each encoder; the output of each encoder is the input of the next encoder, and the depth of feature extraction of multiple encoders is progressive layer by layer; under the multi-stage guidance of the prompt information samples, using the image feature samples, based on the attention mechanism, obtain the authenticity prediction result of the second image sample; according to the authenticity prediction result of the second image sample and the authenticity label, establish a category loss function; according to the similarity between the real image sample pairs and the similarity between the forged image sample pairs, establish a sample differentiation loss function; according to the category loss function and the sample differentiation loss function, train the initial image detection model to obtain the trained image detection model.

[0147] The obtaining of multiple image sample pairs includes: obtaining multiple real image samples; processing the multiple real image samples to generate multiple forged image samples; and generating the multiple image sample pairs according to the multiple real image samples and the multiple forged image samples.

[0148] You can collect real image data from different sources as real image samples, select a forgery method to process the real image samples, and generate forged image samples. Ensure that the generated forged image samples are visually realistic with the real image samples. In some specific scenarios, such as the task of face forgery detection, you can use face forgery methods such as faceswap. Real image samples carry real labels, and forged image samples carry forged labels.

[0149] In the disclosed example, 20,000 annotated face image data are prepared, including 14,000 forged face image samples and 6,000 real face image samples. These images are uniformly processed into a size of 256x256. In order to ensure the diversity of detection capabilities, the forged image samples are forged by mixing multiple forging methods to avoid overfitting the detection method to one of the forging methods. Among them, 16,000 training data are randomly selected from the 20,000 data, 2,000 are randomly selected from the verification set, and 2,000 are selected from the test set. Optionally, non-face images can also be used as image samples. The real image samples are composed of real image sample pairs, and the forged image samples are composed of forged image sample pairs.

[0150] The initial image detection model is an image detection model to be trained. The model structure of the initial image detection model is similar to the model structure of the trained image detection model. The initial image detection model includes an initial encoder network, an initial classification head, and a pre-trained visual encoder. The second image sample is input into the initial image detection model, and the visual encoder in the initial image detection model extracts the image features of the second image sample. The method of outputting the image features to the initial encoder network and finally obtaining the authenticity prediction result can refer to the method of determining the authenticity of an image based on image features in the previous text.

[0151] A category loss function is established based on the authenticity prediction result of the second image sample and the authenticity label; a sample differentiation loss function is established based on the similarity between the real image sample pairs and the similarity between the forged image sample pairs; and the initial image detection model is trained based on the category loss function and the sample differentiation loss function to obtain the trained image detection model.

[0152] In order to enhance the model's ability to distinguish the differences between real image samples and forged image samples, thereby improving the detection ability of forged images, a sample differentiation loss function is designed. The model measures the similarity of a pair of samples, including the real image sample pair. , and the forged image sample pair The sample differentiation loss function can be expressed as follows:

[0153] ;

[0154] in, Characterize the sample differentiation loss function, represents the natural exponential function, Characterize the similarity of the real image sample pair, Characterize the similarity of the forged image sample pair, represents the number of forged image sample pairs, is the temperature parameter. The temperature parameter can control the relative difference between real image samples and forged image samples. A smaller temperature parameter will increase the difference between samples, making the model more sensitive to small differences. A smaller temperature parameter can be achieved by reducing the value of the exponential term in the denominator, thereby increasing the importance of positive sample pairs. Optionally, the Euclidean distance can be used to calculate the similarity of image sample pairs.

[0155] In addition, the category loss function can be used to measure the difference between the true and false prediction results output by the model and the true and false labels of the image samples. Assume that there are N samples in the training set, and each sample has two category labels: real image (category 0) and forged image (category 1). The category loss function can be expressed as follows:

[0156] ;

[0157] in, is the category loss function, Characterizing the Second Image Sample The real label, Characterizing the Second Image Sample Fake labels, Characterizing the Second Image Sample is the predicted probability of a forged image, Characterizing the Second Image Sample is the predicted probability of the real image, is the number of samples of the second image.

[0158] The total loss function of the image detection model is ,in, and The initial image detection model is trained based on the total loss function to obtain the trained image detection model.

[0159] In the disclosed embodiment, the encoder is a multimodal encoder that can process information in image modality and information in text modality.

[0160] The technical solution of the disclosed embodiment uses learnable prompt information as the text information of the image, which has the advantage of being more automated and does not require manual provision of text information. The benefit of using Prompt learning is that it can provide a clear context and task goal for the model, helping the model to better understand the requirements of the task and generate relevant outputs. By designing appropriate prompts, the model can be guided to focus on specific information and semantics, improving the accuracy and consistency of the model.

[0161] Through multi-stage guidance of prompt information, the uniqueness of different modal features is preserved, while the modal features can be gradually integrated and influence the generation of deep features. This compact feature fusion and multi-stage prompt injection method helps improve the performance and accuracy of image description tasks.

[0162] It should be noted that, for the method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present disclosure are not limited by the order of the actions described, because according to the embodiments of the present disclosure, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present disclosure.

[0163] The disclosed embodiment also provides an image detection system guided by prompt information, comprising: a visual encoder, an encoder network and a classification head, wherein the output of each encoder in the encoder network is the input of the next encoder, and the depth of feature extraction of the multiple encoders is progressive layer by layer;

[0164] The visual encoder is used to obtain image features of the image;

[0165] The encoder is used to generate prompt information according to the image features;

[0166] The classification head is used to detect the authenticity of the image based on the attention mechanism by utilizing the image features under the multi-stage guidance of the prompt information.

[0167] Obtain image features of the image;

[0168] Input the image features into an encoder network to obtain prompt information generated by each encoder; the output of each encoder is the input of the next encoder, and the depth of feature extraction by multiple encoders is progressive layer by layer;

[0169] Under the multi-stage guidance of the prompt information, the image features are utilized to detect the authenticity of the image based on an attention mechanism.

[0170] Optionally, the encoder includes an attention mechanism module; and the classification head is specifically used for:

[0171] Linearly mapping the image features to obtain a key vector, a value vector and a query vector;

[0172] Inputting the key vector, the value vector and the query vector into the attention mechanism module to obtain image features carrying attention information;

[0173] Connecting the prompt information and the image features carrying the attention information to obtain a fusion feature output by the encoder;

[0174] Based on the fused features, the authenticity of the image is determined.

[0175] Optionally, the encoder includes a prompt information generator;

[0176] The encoder is specifically used for:

[0177] Inputting the image features into the encoder network;

[0178] Linearly mapping the input of the encoder to obtain a query vector; the query vector is used to characterize the characteristics of the input of the encoder;

[0179] The query vector is input into a prompt information generator of the encoder to obtain learnable prompt information.

[0180] Optionally, the step of connecting the prompt information and the image features carrying the attention information to obtain a fusion feature output by the encoder includes:

[0181] Inputting the prompt information into a lexical analyzer to obtain a text sequence; the text sequence includes at least one text tag;

[0182] Obtaining an embedding vector for each of the text tokens;

[0183] Processing the embedding vectors of each of the text tags to obtain a text sequence feature vector;

[0184] The text sequence feature vector and the input feature carrying the attention information are concatenated to obtain the fused feature output by the encoder.

[0185] Optionally, the step of concatenating the text sequence feature vector and the input feature carrying the attention information to obtain a fusion feature output by the encoder includes:

[0186] Calculating the mean vector and variance vector of the text sequence feature vector;

[0187] Normalizing the text sequence feature vector according to the mean vector and the variance vector to obtain a first text sequence feature vector;

[0188] Scaling and offsetting the first text sequence feature vector to obtain a second text sequence feature vector; the second text sequence feature vector is adapted to the input feature carrying the attention information;

[0189] The second text sequence feature vector and the input feature carrying the attention information are concatenated to obtain a fused feature output by the encoder.

[0190] Optionally, the step of concatenating the second text sequence feature vector and the input feature carrying the attention information to obtain a fusion feature output by the encoder includes:

[0191] The second text sequence feature vector is multiplied by residual connection with the input feature carrying the attention information to obtain the fused feature output by the encoder.

[0192] Optionally, performing a multiplication residual connection on the second text sequence feature vector and the input feature carrying the attention information to obtain a fusion feature output by the encoder includes:

[0193] Performing a dot multiplication on the second text sequence feature vector and the input feature carrying the attention information to obtain a first fusion feature;

[0194] Regularizing the first fusion feature to obtain a second fusion feature;

[0195] Feeding the second fused feature forward to a neural network, obtaining a third fused feature;

[0196] The third fusion feature is dot-multiplied by the second fusion feature to obtain the fusion feature output by the encoder.

[0197] Optionally, determining the authenticity of the image based on the fusion feature includes:

[0198] Inputting the fused features output by the last encoder in the encoder network into a classification head to obtain a first prediction probability that the image is real and a second prediction probability that the image is fake;

[0199] The authenticity of the image is determined according to the first prediction probability and the second prediction probability.

[0200] Optionally, the visual encoder is specifically used for:

[0201] dividing the image into a plurality of sub-images;

[0202] Obtaining an embedding vector of each of the sub-images, and obtaining a position code of each of the sub-images;

[0203] Adding the embedding vector and the position code of each sub-image element by element to obtain an embedding vector sequence;

[0204] The embedding vector sequence is input into a pre-trained visual encoder to obtain image features of the image.

[0205] Optionally, obtaining the position code of each sub-image includes:

[0206] The position code of each sub-image is obtained according to the following formula:

[0207] ;

[0208] in, Characterization Line The position encoding of the sub-images of the columns, Characterization Line The column position encoding index of the sub-image, represents the dimension of the embedding vector of the sub-image, represents the dimension of the position encoding, is a sine function, is the cosine function.

[0209] Optionally, dividing the image into a plurality of sub-images includes:

[0210] Normalizing the pixel values ​​of the image and converting the data type of the image into a fixed type to obtain a first image of a fixed size;

[0211] The first image with a fixed size is divided into the multiple sub-images.

[0212] Optionally, the training step of the prompt information generator at least includes:

[0213] Acquire multiple first image samples and a prompt information sample of each of the first image samples;

[0214] Inputting the plurality of first image samples into an initial prompt information generator to obtain predicted prompt information of each of the first image samples;

[0215] With the goal of reducing the difference between the predicted prompt information and the prompt information sample of each first image sample, the initial prompt information generator is trained to obtain the trained prompt information generator.

[0216] Optionally, the prompt information guided image detection method is implemented by an image detection model, wherein the image detection model includes the encoder network and the classification head;

[0217] The training steps of the image detection model at least include:

[0218] Acquire multiple image sample pairs; the image sample pairs include real image sample pairs and forged image sample pairs, and each second image sample in the image sample pairs carries a true or false label;

[0219] Acquire an image feature sample of the second image sample;

[0220] Input the image feature sample into the encoder network to obtain a prompt information sample generated by each encoder; the output of each encoder is the input of the next encoder, and the depth of feature extraction of multiple encoders is progressive layer by layer;

[0221] Under the multi-stage guidance of the prompt information sample, using the image feature sample, based on the attention mechanism, obtain the authenticity prediction result of the second image sample;

[0222] Establishing a category loss function according to the authenticity prediction result of the second image sample and the authenticity label;

[0223] Establishing a sample differentiation loss function according to the similarity between the real image sample pairs and the similarity between the forged image sample pairs;

[0224] The initial image detection model is trained according to the category loss function and the sample differentiation loss function to obtain the trained image detection model.

[0225] Optionally, establishing a category loss function according to the authenticity prediction result of the second image sample and the authenticity label includes:

[0226] The category loss function is established according to the following formula:

[0227] ;

[0228] in, is the category loss function, Characterizing the Second Image Sample The real label, Characterizing the Second Image Sample Fake labels, Characterizing the Second Image Sample is the predicted probability of a forged image, Characterizing the Second Image Sample is the predicted probability of the real image, is the number of samples of the second image.

[0229] Optionally, establishing a sample differentiation loss function according to the similarity between the real image sample pairs and the similarity between the forged image sample pairs includes:

[0230] The sample differentiation loss function is established according to the following formula:

[0231] ;

[0232] in, Characterize the sample differentiation loss function, represents the natural exponential function, Characterize the similarity of the real image sample pair, Characterize the similarity of the forged image sample pair, represents the number of forged image sample pairs, is the temperature parameter.

[0233] Optionally, acquiring a plurality of image sample pairs includes:

[0234] Obtain multiple real image samples;

[0235] Processing the multiple real image samples to generate multiple forged image samples;

[0236] The plurality of image sample pairs are generated according to the plurality of real image samples and the plurality of forged image samples.

[0237] Optionally, the encoder is a multimodal encoder.

[0238] It should be noted that the system embodiment is similar to the method embodiment, so the description is relatively simple, and the relevant parts can be referred to the method embodiment.

[0239] The present disclosure also provides an electronic device, referring to Figure 8 , Figure 8 Schematic diagram of an electronic device shown in an embodiment of the present disclosure. Figure 8 As shown, the electronic device 100 includes: a memory 110 and a processor 120. The memory 110 and the processor 120 are connected via a bus communication. A computer program is stored in the memory 110. The computer program can be run on the processor 120 to implement the steps in the prompt information guided image detection disclosed in the embodiment of the present disclosure.

[0240] The embodiment of the present disclosure further provides a computer-readable storage medium. When the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device can perform the steps in the prompt information-guided image detection disclosed in the embodiment of the present disclosure.

[0241] The embodiments of the present disclosure also provide a computer program product, including a computer program. When the computer program is executed by a processor of an electronic device, the computer program can perform the steps in the prompt information-guided image detection disclosed in the embodiments of the present disclosure.

[0242] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0243] It should be understood by those skilled in the art that the embodiments of the present disclosure may be provided as methods, devices or computer program products. Therefore, the embodiments of the present disclosure may take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, the embodiments of the present disclosure may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0244] The embodiments of the present disclosure are described with reference to the flowcharts and / or block diagrams of the methods, apparatuses, electronic devices, and computer program products according to the embodiments of the present disclosure. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0245] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0246] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0247] Although some embodiments of the present disclosure have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiment and all changes and modifications that fall within the scope of the present disclosure.

[0248] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.

[0249] The above is a detailed introduction to the image detection method, system, device, medium and product guided by prompt information provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for general technical personnel in this field, according to the idea of ​​the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. A prompt information guided image detection method, It is characterized in that include: Obtain image features of the image; Inputting the image features into an encoder network to obtain prompt information generated by each encoder; The output of each encoder is the input of the next encoder, and the depth of feature extraction by the multiple encoders is progressive layer by layer; The encoder includes a prompt information generator and an attention mechanism module; Inputting the image features into the encoder network to obtain prompt information generated by each encoder includes: inputting the image features into the encoder network; linearly mapping the input of the encoder to obtain a query vector; the query vector is used to characterize the features of the input of the encoder; inputting the query vector into the prompt information generator of the encoder to obtain learnable prompt information; Under the multi-stage guidance of the prompt information, the image features are used to detect the authenticity of the image based on the attention mechanism, including: linearly mapping the image features to obtain a key vector, a numerical vector and a query vector; inputting the key vector, the numerical vector and the query vector into the attention mechanism module to obtain image features carrying attention information; connecting the prompt information and the image features carrying attention information to obtain fused features output by the encoder; and determining the authenticity of the image based on the fused features.

2. The image detection method guided by prompt information according to claim 1, It is characterized in that The step of connecting the prompt information and the image features carrying the attention information to obtain the fusion features output by the encoder includes: Inputting the prompt information into a lexical analyzer to obtain a text sequence; the text sequence includes at least one text tag; Obtaining an embedding vector for each of the text tokens; Processing the embedding vectors of each of the text tags to obtain a text sequence feature vector; The text sequence feature vector and the input feature carrying the attention information are concatenated to obtain the fused feature output by the encoder.

3. The image detection method guided by prompt information according to claim 2, It is characterized in that The step of concatenating the text sequence feature vector and the input feature carrying the attention information to obtain the fusion feature output by the encoder includes: Calculating the mean vector and variance vector of the text sequence feature vector; Normalizing the text sequence feature vector according to the mean vector and the variance vector to obtain a first text sequence feature vector; Scaling and offsetting the first text sequence feature vector to obtain a second text sequence feature vector; the second text sequence feature vector is adapted to the input feature carrying the attention information; The second text sequence feature vector and the input feature carrying the attention information are concatenated to obtain a fused feature output by the encoder.

4. The image detection method guided by prompt information according to claim 3, It is characterized in that The step of concatenating the second text sequence feature vector and the input feature carrying the attention information to obtain the fused feature output by the encoder includes: The second text sequence feature vector is multiplied by residual connection with the input feature carrying the attention information to obtain the fused feature output by the encoder.

5. The image detection method guided by prompt information according to claim 4, It is characterized in that The step of performing a multiplication residual connection on the second text sequence feature vector and the input feature carrying the attention information to obtain a fusion feature output by the encoder includes: Performing a dot multiplication on the second text sequence feature vector and the input feature carrying the attention information to obtain a first fusion feature; Regularizing the first fusion feature to obtain a second fusion feature; Feeding the second fused feature forward to a neural network, obtaining a third fused feature; The third fusion feature is dot-multiplied by the second fusion feature to obtain the fusion feature output by the encoder.

6. The image detection method guided by prompt information according to claim 1, It is characterized in that The determining the authenticity of the image based on the fusion feature includes: Inputting the fused features output by the last encoder in the encoder network into a classification head to obtain a first prediction probability that the image is real and a second prediction probability that the image is fake; The authenticity of the image is determined according to the first prediction probability and the second prediction probability.

7. The image detection method guided by prompt information according to claim 1, It is characterized in that The acquiring of image features of an image comprises: dividing the image into a plurality of sub-images; Obtaining an embedding vector of each of the sub-images, and obtaining a position code of each of the sub-images; Adding the embedding vector and the position code of each sub-image element by element to obtain an embedding vector sequence; The embedding vector sequence is input into a pre-trained visual encoder to obtain image features of the image.

8. The image detection method guided by prompt information according to claim 7, It is characterized in that The step of obtaining the position code of each sub-image comprises: The position code of each sub-image is obtained according to the following formula: ; in, Characterization Line The position encoding of the sub-images of the columns, Characterization Line The column position encoding index of the sub-image, represents the dimension of the embedding vector of the sub-image, represents the dimension of the position encoding, is a sine function, is the cosine function.

9. The image detection method guided by prompt information according to claim 7, It is characterized in that The step of dividing the image into a plurality of sub-images comprises: Normalizing the pixel values ​​of the image and converting the data type of the image into a fixed type to obtain a first image of a fixed size; The first image with a fixed size is divided into the multiple sub-images.

10. The image detection method guided by prompt information according to claim 1, It is characterized in that The training step of the prompt information generator at least includes: Acquire multiple first image samples and a prompt information sample of each of the first image samples; Inputting the plurality of first image samples into an initial prompt information generator to obtain predicted prompt information of each of the first image samples; With the goal of reducing the difference between the predicted prompt information and the prompt information sample of each first image sample, the initial prompt information generator is trained to obtain the trained prompt information generator.

11. The image detection method guided by prompt information according to claim 1, It is characterized in that Implementing the prompt information guided image detection method by an image detection model, wherein the image detection model includes the encoder network and the classification head; The training steps of the image detection model at least include: Acquire multiple image sample pairs; the image sample pairs include real image sample pairs and forged image sample pairs, and each second image sample in the image sample pairs carries a true or false label; Acquire an image feature sample of the second image sample; Input the image feature sample into the encoder network to obtain a prompt information sample generated by each encoder; the output of each encoder is the input of the next encoder, and the depth of feature extraction of multiple encoders is progressive layer by layer; Under the multi-stage guidance of the prompt information sample, using the image feature sample, based on the attention mechanism, obtain the authenticity prediction result of the second image sample; Establishing a category loss function according to the authenticity prediction result of the second image sample and the authenticity label; Establishing a sample differentiation loss function according to the similarity between the real image sample pairs and the similarity between the forged image sample pairs; The initial image detection model is trained according to the category loss function and the sample differentiation loss function to obtain the trained image detection model.

12. The image detection method guided by prompt information according to claim 11, It is characterized in that The establishing of a category loss function according to the authenticity prediction result of the second image sample and the authenticity label includes: The category loss function is established according to the following formula: ; in, is the category loss function, Characterizing the Second Image Sample The real label, Characterizing the Second Image Sample Fake labels, Characterizing the Second Image Sample is the predicted probability of a forged image, Characterizing the Second Image Sample is the predicted probability of the real image, is the number of samples of the second image.

13. The image detection method guided by prompt information according to claim 11, It is characterized in that The establishing of a sample differentiation loss function according to the similarity between the real image sample pairs and the similarity between the forged image sample pairs includes: The sample differentiation loss function is established according to the following formula: ; in, Characterize the sample differentiation loss function, represents the natural exponential function, Characterize the similarity of the real image sample pair, Characterize the similarity of the forged image sample pair, represents the number of forged image sample pairs, is the temperature parameter.

14. The image detection method guided by prompt information according to claim 11, It is characterized in that The obtaining of multiple image sample pairs comprises: Obtain multiple real image samples; Processing the multiple real image samples to generate multiple forged image samples; The plurality of image sample pairs are generated according to the plurality of real image samples and the plurality of forged image samples.

15. The image detection method guided by prompt information according to claim 1, It is characterized in that The encoder is a multimodal encoder.

16. An image detection system guided by prompt information, It is characterized in that include: A visual encoder, an encoder network and a classification head, wherein the output of each encoder in the encoder network is the input of the next encoder, and the depth of feature extraction by multiple encoders is progressive layer by layer; the encoder includes a prompt information generator and an attention mechanism module; The visual encoder is used to obtain image features of the image; The encoder is used to generate prompt information according to the image feature, including: inputting the image feature into the encoder; performing linear mapping on the input of the encoder to obtain a query vector; the query vector is used to represent the feature of the input of the encoder; and inputting the query vector into a prompt information generator of the encoder to obtain learnable prompt information; The classification head is used to detect the authenticity of the image based on the attention mechanism by utilizing the image features under the multi-stage guidance of the prompt information, including: linearly mapping the image features to obtain a key vector, a numerical vector and a query vector; inputting the key vector, the numerical vector and the query vector into the attention mechanism module to obtain image features carrying attention information; connecting the prompt information and the image features carrying attention information to obtain fused features output by the encoder; and determining the authenticity of the image based on the fused features.

17. An electronic device, It is characterized in that include: A memory, a processor and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the prompt information guided image detection method described in any one of claims 1-15.

18. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the steps of the prompt information guided image detection method described in any one of claims 1-15 are implemented.

19. A computer program product comprising a computer program, It is characterized in that When the computer program is executed by a processor, the steps of the prompt information guided image detection method described in any one of claims 1-15 are implemented.