Text-guided image detection method, system, device, medium and program product

Through the text-guided image detection method, the cross-attention mechanism is used to fuse image and text features, which solves the problem of low accuracy of image forgery detection in the existing technology and achieves more efficient forgery image detection.

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

Patent Information

Application Number
CN202410750876.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-12
Publication Date
2024-10-11
Estimated Expiration
2044-06-12

Smart Images

  • Figure CN118314148B_ABST
    Figure CN118314148B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a text-guided image detection method, system, device, medium and program product, which relates to the field of image detection technology and aims to accurately judge the authenticity of an image. The method comprises: obtaining a trained image description model, wherein the image description model comprises an image encoder and multiple text decoders; inputting an image into the image encoder to obtain semantic image features of the image, and inputting the semantic image features and the output of the previous text decoder into each of the text decoders to obtain text features of the description text of the image; under the guidance of the text features, using the extracted global image features of the image, the authenticity of the image is detected based on a cross-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 a text-guided image detection method, system, device, medium and program product. Background Art

[0002] Image forgery detection is an important technology in computer vision tasks, which is used to detect the authenticity of images and thus protect the reliability of real images. Traditional methods, such as detection methods based on illumination inconsistency, detection methods based on image noise, and detection methods based on scale-invariant feature transformation, have the disadvantages of being cumbersome and requiring assumptions about the type of forgery. Related technologies extract image features through trained visual models and then classify the images into two categories to determine the authenticity of the images, but this method is not very accurate. Summary of the invention

[0003] To overcome the problems existing in the related art, the embodiments of the present disclosure provide a text-guided image detection method, system, device, medium and program product. 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, a text-guided image detection method is provided, comprising:

[0005] Acquire a trained image description model, wherein the image description model includes an image encoder and a plurality of text decoders;

[0006] Inputting an image into the image encoder to obtain semantic image features of the image, and inputting the semantic image features and the output of the previous text decoder into each of the text decoders to obtain text features of the description text of the image;

[0007] Under the guidance of the text features, the authenticity of the image is detected based on the cross-attention mechanism using the extracted global image features of the image.

[0008] Optionally, under the guidance of the text features, using the extracted global image features of the image, detecting the authenticity of the image based on a cross-attention mechanism includes:

[0009] Obtaining self-attention of the text feature;

[0010] Performing a dot product of the self-attention and the text feature to obtain a target text feature;

[0011] Linearly mapping the global image features to obtain image content features;

[0012] Obtaining cross attention between the image content feature and the target text feature;

[0013] Performing a dot multiplication of the cross attention between the image content feature and the target text feature and the image content feature to obtain a fusion feature;

[0014] Based on the fused features, the authenticity of the image is detected.

[0015] Optionally, the text decoder is constructed based on a long short-term memory network; the semantic image features and the output of the previous text decoder are input into each of the text decoders to obtain the text features of the description text of the image, including:

[0016] Inputting the semantic image features and the output of the previous text decoder into each of the text decoders to obtain the activation value of the input gate, the activation value of the forget gate, the activation value of the output gate and the cell state update value in each of the long short-term memory networks;

[0017] Determine a new cell state and an output value according to the activation value of the input gate, the activation value of the forget gate and the cell state update value in each of the long short-term memory networks; the new cell state and the output value are inputs to the next long short-term memory network;

[0018] The adjustable noise is obtained, a description text of the image is determined according to the adjustable noise and an output value of the last long short-term memory network, and a text feature of the description text is obtained.

[0019] Optionally, obtaining the adjustable noise includes:

[0020] Sampling the standard normal distribution, we get multiple noises;

[0021] Acquire a plurality of target noises from the plurality of noises;

[0022] The multiple target noises are mapped to obtain the adjustable noise.

[0023] Optionally, the image encoder is constructed based on a plurality of converters with a self-attention mechanism; and inputting the image into the image encoder to obtain semantic image features of the image comprises:

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

[0025] Inputting the plurality of sub-images into the converter to obtain attention between the sub-images;

[0026] Extracting semantic image features of each of the plurality of sub-images;

[0027] The semantic image features of the image are determined according to the attention between the sub-images and the semantic image features of each of the multiple sub-images.

[0028] Optionally, the training step of the image description model at least includes:

[0029] Acquire an image sample, wherein the image sample carries a description text reference sample;

[0030] Inputting the image sample into the image description model to be trained to obtain a description text prediction sample of the image sample;

[0031] Establishing a contrast loss function and an absolute value loss function according to the description text reference sample and the description text prediction sample of the image sample;

[0032] The image description model to be trained is trained according to the contrast loss function and the absolute value loss function to obtain a trained image description model.

[0033] Optionally, detecting the authenticity of the image based on the fusion feature includes:

[0034] Inputting the fused features into a fusion classification head to obtain a first prediction probability that the image is true and a second prediction probability that the image is false;

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

[0036] Optionally, before detecting the authenticity of the image based on the cross-attention mechanism, the method further includes:

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

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

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

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

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

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

[0043] ;

[0044] 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.

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

[0046] 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;

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

[0048] Optionally, the text-guided image detection method is implemented by an image detection model, wherein the image detection model includes the image description model and a fusion classification head;

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

[0050] Obtain multiple image samples with true and false labels;

[0051] Inputting the image sample into the image description model to obtain a text feature sample of a description text sample of the image sample;

[0052] Obtaining the authenticity prediction result of the image sample output by the fusion classification head based on the cross attention mechanism using the extracted global image feature sample of the image sample under the guidance of the text feature sample;

[0053] Establishing a cross entropy loss function according to the authenticity label of the image sample and the authenticity prediction result;

[0054] The image detection model to be trained is trained according to the cross entropy loss function to obtain the trained image detection model.

[0055] Optionally, the training step of the image detection model further includes:

[0056] Obtaining model parameters of the image detection model in each training round;

[0057] Constructing a parameter loss function according to the model parameters of the image detection model in the current training round and the model parameters in the previous training round;

[0058] The step of training the image detection model to be trained according to the cross entropy loss function to obtain the trained image detection model includes:

[0059] The image detection model to be trained is trained according to the cross entropy loss function and the parameter loss function to obtain the trained image detection model.

[0060] Optionally, it also includes:

[0061] Predicting a first true or false probability of the image according to the global image feature;

[0062] The method of detecting the authenticity of the image based on a cross-attention mechanism by using the extracted global image features of the image under the guidance of the text features includes:

[0063] Under the guidance of the text features, using the extracted global image features of the image, predicting a second true or false probability of the image based on a cross-attention mechanism;

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

[0065] According to a second aspect of an embodiment of the present disclosure, there is provided a text-guided image detection system, comprising: a trained image description model and a fusion classification head; the image description model comprises an image encoder and a plurality of text decoders;

[0066] The image encoder is used to extract semantic image features of an input image;

[0067] The text decoder is used to obtain text features of the description text of the image according to the semantic image features and the output of the previous text decoder;

[0068] The fusion classification head is used to detect the authenticity of the image based on a cross-attention mechanism by utilizing the extracted global image features of the image under the guidance of the text features.

[0069] 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 text-guided image detection method described in the first aspect.

[0070] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided, and when the computer program is executed by a processor, the steps of the text-guided image detection method described in the first aspect are implemented.

[0071] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, comprising a computer program, wherein when the computer program is executed by a processor, the steps of the text-guided image detection method described in the first aspect are implemented.

[0072] In the disclosed embodiment, a pre-trained image description model is used to generate image description text, which has the advantage of being more automated and does not require manual description of image information. At the same time, it avoids forged labels in manually collected image description information, and can ensure that the generated description text more accurately aligns the semantic content between the text and the image, thereby helping the generated description text to be consistent with the image content and ultimately improving the rationality of the detection results of forged images. BRIEF DESCRIPTION OF THE DRAWINGS

[0073] 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.

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

[0075] Figure 2 is a schematic diagram of steps of a text-guided image detection method shown in an embodiment of the present disclosure;

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

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

[0078] Figure 5 is a structural diagram of a visual coding model shown in an embodiment of the present disclosure;

[0079] Figure 6 is a structural schematic diagram of an image description model shown in an embodiment of the present disclosure;

[0080] Figure 7 is a schematic diagram of a feature fusion process shown in an embodiment of the present disclosure;

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

[0082] 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.

[0083] Figure 1 It is a flowchart of the related technology for image forgery detection; Figure 1As 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.

[0084] 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.

[0085] However, 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.

[0086] The role of the image caption model is to combine images with natural language generation to generate natural language descriptions related to the image content. It plays an important role in the fields of computer vision and natural language processing. The image caption model can help understand and analyze the content of the image. By generating descriptive text, the model can extract and express information such as objects, scenes, actions, etc. in the image, enabling the computer to better understand the semantics and context of the image. The image caption model can include the following components: Image Encoder, Sequence Model, Attention Mechanism, and Loss Function. The image encoder uses a convolutional neural network or other visual feature extraction method to encode the input image into a feature vector representation. The sequence model uses a recurrent neural network (such as a long short-term memory network) or a Transformer model to generate descriptive text. The model generates the next word based on the previously generated words and image feature inputs until a complete description is generated. The attention mechanism is introduced to give weighted attention to different image regions when generating the description. The loss function is used to measure the difference between the generated description text and the reference description text and is used to train the model.

[0087] In the related art, only the label is used as a text description, which has low information content and cannot fully utilize the capabilities of the language vision model. The disclosed embodiment constructs an image description model to generate a text description to fully describe the image. The related art simply fuses the features of the image and text (addition or splicing), which cannot efficiently utilize the fused information. The disclosed embodiment proposes an efficient feature fusion method.

[0088] The image forgery detection in the related art has the following problems, one of which is how to improve the accuracy of image forgery detection. The disclosed embodiment combines the visual-language pre-training model, and by comparing the text and image models trained by learning, the features between the matched text and image can be brought closer. After the image is forged, the features are offset, and the fusion of the text features and the forged image features will produce obvious differences, so as to distinguish the forged image.

[0089] Another problem is how to add text information to pure image forgery detection, that is, how to construct text information and utilize the knowledge of multimodal pre-trained models. The disclosed embodiment uses an image description model to generate image description text, which is more automated and does not require manual description of image information. It also avoids forged labels in manually collected image description information, and ensures that the generated description more accurately aligns the semantic content between text and image. This helps the generated description to be consistent with the image content and ultimately improves the rationality of the forgery detection results.

[0090] 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 uses cross attention to fuse image and text information, which allows the model to interact and transfer information between text and image. By performing cross attention calculations on text information and image information, the model can automatically learn the correlation and alignment between text and image, and better fuse the information of the two modalities when generating descriptions.

[0091] The text-guided image detection method proposed in the embodiment of the present disclosure adopts an image description model to obtain the description text of the image, and uses it as the text in the visual language pre-training model to guide the detection of image forgery. The embodiment of the present disclosure proposes an image description model with an adjustable noise gating mechanism, which includes a Transformer-based image encoder, multiple LSTM (Long Short-Term Memory)-based text decoders, and a gating mechanism with noise. Since the forgery detection task is different from other visual tasks and the number of required label categories is small, noise is introduced to alleviate the phenomenon of overfitting of the image-text description model. The text encoder and the visual encoder are pre-trained using a contrastive learning method to learn the potential association between image and text pairs, and the difference in text description between real images and forged images is used to enhance the judgment of image forgery information. The text features are obtained by inputting the text description into the text encoder, the image is input into the image encoder to obtain the image features, and the two features are fused through the fusion module, and the fused features are input into the fusion classification head to output the authenticity of the image. In addition, the image features can be directly output and the authenticity probability of the image can be obtained through the visual classification head, and the results of the two classification heads are added to obtain the final result. By comparing the text and image models trained by learning, the features between the matching text and image can be brought closer. After the image is forged, the features are offset. After the text features are fused with the forged image features, there will be obvious differences, which can be used to distinguish forged images.

[0092] Figure 2 is a schematic diagram of the steps of a text-guided image detection method shown in an embodiment of the present disclosure, such as Figure 2 As shown, the text-guided image detection method includes steps S11 to S13.

[0093] In step S11, a trained image description model is obtained, where the image description model includes an image encoder and a plurality of text decoders;

[0094] In step S12, the image is input into the image encoder to obtain semantic image features of the image, and the semantic image features and the output of the previous text decoder are input into each of the text decoders to obtain text features of the description text of the image;

[0095] In step S13, under the guidance of the text features, the authenticity of the image is detected based on a cross-attention mechanism using the extracted global image features of the image.

[0096] The information flow process of the text-guided image detection method of the present disclosure embodiment can be referred to Figure 3 As shown, Figure 3Only two text decoders are shown as an example. It is understandable that the number of text decoders can be greater than or equal to two. The text-guided image detection method of 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 the image detection model shown in an embodiment of the present disclosure. The image detection model includes an image description model, a text encoder, a multimodal feature fusion module, a fusion classification head, a visual encoder and a visual classification head.

[0097] The image described in the embodiment of the present disclosure can be any image. The image features of the image can be obtained by inputting the image into a pre-trained visual encoder. The visual encoder can take advantage of the visual Swin Transformer (a hierarchical Transformer structure) to model visually inconsistent information at the image level for image forgery detection. SwinTransformer is a hierarchical visual Transformer that uses shifted windows to solve the challenges faced by traditional Transformers in visual tasks, such as multi-scale problems and computational issues for high-resolution images. The input image and the output of the Swin Transformer are connected by a long residual to ensure the gradient vanishing problem of the input information. Figure 5 : 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.

[0098] As an embodiment, the extraction of global image features of an image may include: dividing the image into multiple 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-wise to obtain an embedding vector sequence; and inputting the embedding vector sequence into a pre-trained visual encoder to obtain global image features of the image.

[0099] In order to ensure the consistency of the dimensions of global image features, the image size input to the visual encoder 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.

[0100] As an example, the visual encoder accepts fixed-size input images. Typically, 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.

[0101] 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 .

[0102] 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.

[0103] 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.

[0104] 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:

[0105] ;

[0106] 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.

[0107] 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 vector is input into the visual encoder to obtain the global image features.

[0108] Figure 6 It is a structural schematic diagram of an image description model shown in an embodiment of the present disclosure. The image description model includes an image encoder and multiple text decoders based on long short-term memory networks, and an output layer; the image encoder includes multiple Transformers. On the basis of the above technical solution, the semantic image features and the output of the previous text decoder are input into each text decoder to obtain the text features of the description text of the image, which may include: inputting the semantic image features and the output of the previous text decoder into each text decoder to obtain the activation value of the input gate, the activation value of the forget gate, the activation value of the output gate and the cell state update value in each long short-term memory network; determining the new cell state and output value according to the activation value of the input gate, the activation value of the forget gate and the cell state update value in each long short-term memory network; the new cell state and the output value are the input of the next long short-term memory network; obtaining adjustable noise, and determining the description text of the image according to the adjustable noise and the output value of the last long short-term memory network. Afterwards, the description text is input into the text encoder to obtain the text features of the description text.

[0109] The obtaining of adjustable noise includes: sampling a standard normal distribution to obtain a plurality of noises; obtaining a plurality of target noises from the plurality of noises; and mapping the plurality of target noises to obtain the adjustable noise.

[0110] The image encoder is constructed based on multiple converters with self-attention mechanism; the image is input into the image encoder to obtain the semantic image features of the image, including: dividing the image into multiple sub-images; inputting the multiple sub-images into the converter to obtain the attention between each of the sub-images; extracting the semantic image features of each of the multiple sub-images; and determining the semantic image features of the image based on the attention between each of the sub-images and the semantic image features of each of the multiple sub-images.

[0111] The image encoder is responsible for encoding the input image features. It includes multiple converters, each of which contains a self-attention mechanism and a feedforward neural network. The self-attention mechanism can help the model learn the dependencies and contextual information between image features, while the feedforward neural network can introduce nonlinear transformations. By stacking multiple converters, the image encoder can gradually extract higher-level image features. The LSTM-based text decoder is used to generate image description text. The text decoder consists of multiple LSTM blocks, which need to calculate the activation value of the input gate, the activation value of the forget gate, the input gate activation value, and the cell state update value. LSTM can automatically and selectively remember or forget some information by introducing gating mechanisms such as input gate, forget gate, and output gate, so as to better handle long-term dependencies. By learning the input image features and contextual information, the model can generate natural language descriptions related to the image. Finally, the output layer combines the noisy gating mechanism to map the output of the decoder to the final prediction result. In the image description task, the output layer may use appropriate activation functions and loss functions (such as cross entropy loss function) to generate description text and compare it with the real description text.

[0112] As an example, the image encoder consists of four stages of basic transformers, each of which is mainly composed of a normalization layer, an attention layer, and a feed-forward neural network. The self-attention mechanism allows the model to establish global dependencies within a single sequence or semantic space. The weight of each element in the input sequence is calculated by interacting with other elements. In this way, the model can automatically focus on the most relevant parts of the input sequence.

[0113] When performing text-guided image detection, before feeding the image into the model, the image is cut into multiple small pieces, called sub-images, and then each sub-image is vectorized and embedded. The specific method is to split the image into pieces of size Window, Represent the sub-image size and apply a 2D convolution operation on each window, where the stride and kernel size are set to The dimension of the embedding vector for each sub-image is determined by setting the number of output channels. Finally, the height (H) and width (W) dimensions of each sub-image are expanded and moved to the first dimension of the vector.

[0114] The benefit of this method is that it can perform fine-grained feature extraction on the entire image and encode the information of each sub-image into a vector, which is convenient for subsequent processing and analysis. By using convolution operations, the local structure and texture information in the image can be captured. By expanding the embedding vector of each sub-image to one dimension, the image can be represented as a collection of feature vectors, providing a more flexible input form for subsequent tasks.

[0115] After the input image is divided into sub-images, it is input into the image encoder to obtain semantic image features. The semantic image features can be represented as the collection of features obtained by all sub-images after passing through the four-stage Transformer. ,in, Characterize image features, is the number of sub-images, Indicates The image features of sub-images, ; is the feature vector dimension, is a natural number. Based on the image features, a feature is retained as the global context using the basic network. The global context is expressed as , express The contextual information at the moment, is the word vector dimension; contextual attention obtains more complete semantic information from the global context and uses it as an auxiliary information in the LSTM encoder to guide the generated image semantic description vector, expressed as ,in To describe the text, is the i-th semantic description vector, ; T is the maximum length of the generated description. The vocabulary consists of complete words and subword units. In a specific case, the final description text Can be expressed as a length The string of 12 is "A beautiful blonde is smiling happily".

[0116] In the long short-term memory network encoder that introduces multi-stage image information, a bidirectional long short-term memory network can be used. Since the calculation method of the forward long short-term memory network and the reverse long short-term memory network is the same, only the forward long short-term memory network is introduced here. The forward long short-term memory network encoder is composed of multiple long short-term memory network encoder modules, and the output result of the entire long short-term memory network encoder is a hidden state sequence. In the embodiment of the present disclosure, since the image information will gradually be forgotten in the traditional long short-term memory network after visual encoding, the embodiment of the present disclosure is designed to introduce image information in each long short-term memory network encoding module.

[0117] The activation value of the input gate needs to be calculated in the long short-term memory network encoding module , the activation value of the forget gate , input gate activation value , and the cell state update value . Input gate activation value , the activation value of the forget gate , input gate activation value , and the cell state update value The calculation of can be automatically realized by the long short-term memory network. In the embodiment of the present disclosure, the specific parameters of the long short-term memory network encoder are set to the number of hidden states. Set to 128, which means that the maximum length of text output is 128.

[0118] The output of each LSTM network encoder is subjected to a noisy gating mechanism to introduce noise to alleviate the overfitting of the model. This gating method introduces some adjustable noise, and its main advantage is to increase the robustness and generalization ability of the model. In addition, the previous By sampling the standard normal distribution, multiple noises are obtained, the first k noises among the multiple noises are determined as target noises, and the target noises are mapped to a non-negative range to obtain adjustable noises. The value of k can be set according to actual needs.

[0119] On the basis of the above technical solution, the training steps of the image description model at least include: obtaining an image sample, the image sample carrying a description text reference sample; inputting the image sample into the image description model to be trained to obtain a description text prediction sample of the image sample; establishing a contrast loss function and an absolute value loss function based on the description text reference sample and the description text prediction sample of the image sample; training the image description model to be trained based on the contrast loss function and the absolute value loss function to obtain a trained image description model.

[0120] The loss function of the image description model is calculated, and the image description model is trained to obtain a pre-trained image description model. The image description model includes two parts of loss functions, including a contrast loss function and an L1 (absolute value) loss function.

[0121] The contrast loss function is used to measure the similarity between the description text prediction samples generated by the model and the description text reference samples. The goal of the contrast loss function is to minimize the distance between samples of the same type and maximize the distance between samples of different types. The contrast loss function can encourage the model to generate descriptions as close to the description text reference samples as possible. The contrast loss function can be calculated using the following formula:

[0122] ;

[0123] in, Characterize the contrast loss function, represents the natural exponential function, Representation distance, is a temperature parameter that controls the smoothness of the probability distribution. represents a positive sample, represents negative samples, Characterize the description text prediction sample, Representation summation. By minimizing the distance between samples of the same type and maximizing the distance between samples of different types, the contrast loss function can provide a more representative feature representation and help learn more useful features.

[0124] The absolute value loss function is used to measure the difference between the description text prediction samples generated by the model and the real description text reference samples. It calculates the absolute difference of each corresponding word or feature between the description text prediction samples generated by the model and the real description text reference samples, and takes the average. The absolute value loss function can be calculated using the following formula:

[0125] ;

[0126] in, is the absolute value loss function, Prediction samples of description text generated by the model, For real descriptive text reference samples, Characterization 1 paradigm.

[0127] The total loss function of the image description model can be obtained by weighted summing the absolute value loss function and the contrast loss function. Based on the total loss function of the image description model, the image description model to be trained is trained to obtain a trained image description model.

[0128] Optionally, when extracting global image features and / or semantic image features, the image is input into a one-layer two-dimensional convolution to obtain shallow image features. In order to introduce nonlinear transformations, an activation function is usually applied to the output of the first convolution layer. The activation function used in the embodiment disclosed in the present invention is a hyperbolic tangent function. The purpose of multi-layer convolution operations is that the network can gradually extract abstract features of the image. Shallow convolution layers extract low-level features (such as edges and textures). As the network deepens, convolution layers gradually extract higher-level features (such as shapes and object parts). In addition, through convolution and pooling operations, the network can gradually reduce the size of the feature map and extract more abstract and rich features. This helps to reduce the number of parameters and computational complexity of the model and improve the generalization and expression capabilities of the model.

[0129] In some specific cases, the image description model block includes an image encoder and a text decoder, which inputs shallow image features and outputs text. The text length is limited to 5-128 words, and T means that the maximum text length is set to 128. Frozen parameters mean that the parameters of this module will not be modified during the entire image detection model training.

[0130] On the basis of the above technical solution, under the guidance of the text feature, the authenticity of the image is detected based on the cross-attention mechanism using the extracted global image features of the image, which may include: obtaining the self-attention of the text feature; performing dot multiplication of the self-attention with the text feature to obtain the target text feature; linearly mapping the global image feature to obtain the image content feature; obtaining the cross-attention between the image content feature and the target text feature; performing dot multiplication of the cross-attention between the image content feature and the target text feature with the image content feature to obtain a fused feature; and detecting the authenticity of the image based on the fused feature.

[0131] Figure 7 : This is a flow chart of feature fusion shown in the embodiment of the present disclosure. The text features are linearly mapped and then passed through a multi-layer attention mechanism to obtain the self-attention of the text features. The output of the self-attention layer is then dot-multiplied with the text features and then input into the feedforward neural network to obtain the target text features.

[0132] The obtained target text features are input into the image feature branch. In the image branch, the global image features are linearly mapped to obtain image content features. At the same time, the image content features and the target text features are input into the multi-head attention mechanism module to obtain the attention between the image content features and the target text features. The attention between the image content features and the target text features is dot-multiplied with the image content features to obtain the fused features.

[0133] On the basis of the above technical solution, the authenticity of the image is detected based on the fusion feature, including: inputting the fusion feature into a fusion classification head to obtain a first prediction probability that the image is true and a second prediction probability that the image is false; and determining the authenticity of the image based on the first prediction probability and the second prediction probability.

[0134] The fusion classification head consists of multiple linear layers and a softmax (soft maximization) layer. The input is the fusion feature, and the output is the binary classification probability, which includes the first prediction probability that the image is real and the second prediction probability that the image is fake. The result corresponding to the maximum value of the first prediction probability and the second prediction probability is determined as the authenticity result of the image. In an example, the output result is in the form of [0.4, 0.6], the former represents the probability of being real, and the latter represents the probability of being fake. The maximum probability value is taken as the output, the image is real as 0, and the image is forged as 1.

[0135] On the basis of the above technical solution, the text-guided image detection method can be implemented through an image detection model, wherein the image detection model includes the pre-trained image description model and a fusion classification head; the training steps of the image detection model at least include: obtaining a plurality of image samples carrying authenticity labels; inputting the image samples into the image description model to obtain text feature samples of description text samples of the image samples; obtaining the authenticity prediction results of the image samples output by the fusion classification head based on a cross-attention mechanism using the extracted global image feature samples of the image samples under the guidance of the text feature samples; establishing a cross-entropy loss function according to the authenticity labels of the image samples and the authenticity prediction results; and training the image detection model to be trained according to the cross-entropy loss function to obtain the trained image detection model.

[0136] 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.

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

[0138] The method for obtaining the authenticity prediction result of the image sample can refer to the method for detecting the authenticity of the image in the previous text. According to the authenticity label of the image sample and the authenticity prediction result, a cross entropy loss function is established. Specifically, the cross entropy loss function can be determined by the following formula:

[0139] ;

[0140] in, represents the cross entropy loss function, N represents the number of image samples, Σ represents summation, * represents the multiplication of the corresponding positions of the elements, log represents the natural logarithm, Characterize the authenticity label of the image sample, Characterize the authenticity prediction results of image samples.

[0141] On the basis of the above technical solution, the training step of the image detection model also includes: obtaining the model parameters of the image detection model in each training round; constructing a parameter loss function according to the model parameters of the image detection model in the current training round and the model parameters in the previous training round; training the image detection model to be trained according to the cross entropy loss function to obtain the trained image detection model, including: training the image detection model to be trained according to the cross entropy loss function and the parameter loss function to obtain the trained image detection model.

[0142] Since the model is trained based on the descriptive text of the image, in order to fully utilize the capabilities of the image description model, as well as the model's generalization ability on unseen image samples and reduce the risk of overfitting, the model can pay more attention to the important weights that have been learned during the training process and reduce overfitting on new samples. The disclosed embodiment designs a parameter loss function, the goal of which is to limit the change of model weights, thereby protecting the learned knowledge. By weighted penalizing changes in learned weights, the parameter loss function can prevent the model from over-adjusting the learned weights during training. The parameter loss function can be determined by the following formula:

[0143] ;

[0144] in, Characterize the parameter loss function, Represents the parameters of the model during a training process, Contains all weights and biases, Characterizes the average parameters of the previous iterations of this training process. In each training iteration, the Euclidean distance between the current model parameters and the average parameters in the previous iteration can be calculated. This distance is then used as part of the L2 regularization loss function.

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

[0146] On the basis of the above technical solution, the text-guided image detection method also includes: predicting a first authenticity probability of the image based on the image features; determining the authenticity of the image based on the fusion features, including: predicting a second authenticity probability of the image based on the fusion features; determining the authenticity of the image based on the first authenticity probability and the second authenticity probability of the image.

[0147] The visual classification head and the fusion classification head have the same composition, but the parameters are not shared. They are two independent classification heads. The image features extracted by the visual encoder are input into the visual classification head to obtain the first true or false probability of the image predicted by the visual classification head. The fusion features are input into the fusion classification head to obtain the second true or false probability of the image. The second true or false probability includes the first predicted probability that the image is true and the second predicted probability that the image is false. The first true or false probability and the second true or false probability are weighted and summed to obtain the final probability. According to the final probability, the authenticity of the image is determined.

[0148] In the disclosed embodiment, by comparing the text and image models trained by learning, the features between the matched 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, obvious differences will be produced, thereby distinguishing the forged image.

[0149] In the disclosed embodiment, an image description model is used to generate image description text, which is more automated and does not require manual description of image information. It also avoids forged labels in manually collected image description information, and can ensure that the generated description more accurately aligns the semantic content between text and image. This helps the generated description to be consistent with the image content and ultimately improves the rationality of forgery detection results.

[0150] In the disclosed embodiment, cross attention is used to fuse image and text information, which allows the model to interact and transfer information between text and image. By performing cross attention calculations on text information and image information, the model can automatically learn the correlation and alignment between text and image, and better fuse the information of the two modalities when generating descriptions.

[0151] 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.

[0152] As an embodiment, the present disclosure also provides a text-guided image detection system, the text-guided image detection system comprising: a trained image description model and a fusion classification head; the image description model comprises an image encoder and a plurality of text decoders;

[0153] The image encoder is used to extract semantic image features of an input image;

[0154] The text decoder is used to obtain text features of the description text of the image according to the semantic image features and the output of the previous text decoder;

[0155] The fusion classification head is used to detect the authenticity of the image based on a cross-attention mechanism by utilizing the extracted global image features of the image under the guidance of the text features.

[0156] 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.

[0157] 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 text-guided image detection method disclosed in the embodiment of the present disclosure.

[0158] The embodiment of the present disclosure also 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 text-guided image detection method disclosed in the embodiment of the present disclosure.

[0159] 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 execute the steps in the text-guided image detection method disclosed in the embodiments of the present disclosure.

[0160] 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.

[0161] 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.

[0162] 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.

[0163] 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.

[0164] 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.

[0165] 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.

[0166] 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.

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

Claims

1. A text-guided image detection method, characterized in that: include: Acquire a trained image description model, wherein the image description model includes an image encoder and a plurality of text decoders; Inputting an image into the image encoder to obtain semantic image features of the image, and inputting the semantic image features and the output of the previous text decoder into each of the text decoders to obtain text features of the description text of the image; Under the guidance of the text features, the extracted global image features of the image are used to fuse the image content features corresponding to the global image features and the target text features corresponding to the text features based on a cross-attention mechanism to detect the authenticity of the image.

2. The text-guided image detection method according to claim 1, characterized in that: The method of detecting the authenticity of the image by using the extracted global image features of the image under the guidance of the text features and fusing the image content features corresponding to the global image features and the target text features corresponding to the text features based on a cross attention mechanism comprises: Obtaining self-attention of the text feature; Performing a dot multiplication of the self-attention and the text feature to obtain the target text feature; Linearly mapping the global image features to obtain the image content features; Obtaining cross attention between the image content feature and the target text feature; Performing a dot multiplication of the cross attention between the image content feature and the target text feature and the image content feature to obtain a fusion feature; Based on the fused features, the authenticity of the image is detected.

3. The text-guided image detection method according to claim 1, characterized in that: The text decoder is constructed based on a long short-term memory network; the semantic image features and the output of the previous text decoder are input into each of the text decoders to obtain the text features of the description text of the image, including: Inputting the semantic image features and the output of the previous text decoder into each of the text decoders to obtain the activation value of the input gate, the activation value of the forget gate, the activation value of the output gate and the cell state update value in each of the long short-term memory networks; Determine a new cell state and an output value according to the activation value of the input gate, the activation value of the forget gate and the cell state update value in each of the long short-term memory networks; the new cell state and the output value are inputs to the next long short-term memory network; The adjustable noise is obtained, a description text of the image is determined according to the adjustable noise and an output value of the last long short-term memory network, and a text feature of the description text is obtained.

4. The text-guided image detection method according to claim 3, characterized in that: The step of obtaining the adjustable noise comprises: Sampling the standard normal distribution, we get multiple noises; Acquire a plurality of target noises from the plurality of noises; The multiple target noises are mapped to obtain the adjustable noise.

5. The text-guided image detection method according to claim 1, characterized in that: The image encoder is constructed based on multiple converters with a self-attention mechanism; the image is input into the image encoder to obtain the semantic image features of the image, including: dividing the image into a plurality of sub-images; Inputting the plurality of sub-images into the converter to obtain attention between the sub-images; Extracting semantic image features of each of the plurality of sub-images; The semantic image features of the image are determined according to the attention between the sub-images and the semantic image features of each of the multiple sub-images.

6. The text-guided image detection method according to claim 1, characterized in that: The training steps of the image description model at least include: Acquire an image sample, wherein the image sample carries a description text reference sample; Inputting the image sample into the image description model to be trained to obtain a description text prediction sample of the image sample; Establishing a contrast loss function and an absolute value loss function according to the description text reference sample and the description text prediction sample of the image sample; The image description model to be trained is trained according to the contrast loss function and the absolute value loss function to obtain a trained image description model.

7. The text-guided image detection method according to claim 2, characterized in that: The detecting the authenticity of the image based on the fusion feature includes: Inputting the fused features into a fusion classification head to obtain a first prediction probability that the image is true and a second prediction probability that the image is false; The authenticity of the image is determined according to the first prediction probability and the second prediction probability.

8. The text-guided image detection method according to claim 1, characterized in that: Before detecting the authenticity of the image based on the cross-attention mechanism, the method further includes: 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 the global image features of the image.

9. The text-guided image detection method according to claim 8, 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.

10. The text-guided image detection method according to claim 8, 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.

11. The text-guided image detection method according to claim 1, characterized in that: Implementing the text-guided image detection method through an image detection model, wherein the image detection model includes the image description model and a fusion classification head; The training steps of the image detection model at least include: Obtain multiple image samples with true and false labels; Inputting the image sample into the image description model to obtain a text feature sample of a description text sample of the image sample; Obtaining the authenticity prediction result of the image sample output by the fusion classification head based on the cross attention mechanism using the extracted global image feature sample of the image sample under the guidance of the text feature sample; Establishing a cross entropy loss function according to the authenticity label of the image sample and the authenticity prediction result; The image detection model to be trained is trained according to the cross entropy loss function to obtain the trained image detection model.

12. The text-guided image detection method according to claim 11, characterized in that: The training step of the image detection model also includes: Obtaining model parameters of the image detection model in each training round; Constructing a parameter loss function according to the model parameters of the image detection model in the current training round and the model parameters in the previous training round; The step of training the image detection model to be trained according to the cross entropy loss function to obtain the trained image detection model includes: The image detection model to be trained is trained according to the cross entropy loss function and the parameter loss function to obtain the trained image detection model.

13. The text-guided image detection method according to claim 1, characterized in that: Also includes: Predicting a first true or false probability of the image according to the global image feature; The method of detecting the authenticity of the image by using the extracted global image features of the image under the guidance of the text features and fusing the image content features corresponding to the global image features and the target text features corresponding to the text features based on a cross attention mechanism comprises: Under the guidance of the text features, using the extracted global image features of the image, predicting a second true or false probability of the image based on a cross-attention mechanism; The authenticity of the image is determined according to the first authenticity probability and the second authenticity probability of the image.

14. A text-guided image detection system, characterized in that: include: A trained image description model and a fusion classification head; the image description model includes an image encoder and multiple text decoders; The image encoder is used to extract semantic image features of an input image; The text decoder is used to obtain text features of the description text of the image according to the semantic image features and the output of the previous text decoder; The fusion classification head is used to detect the authenticity of the image by utilizing the extracted global image features of the image under the guidance of the text features, fusing the image content features corresponding to the global image features and the target text features corresponding to the text features based on a cross-attention mechanism.

15. An electronic device, 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 text-guided image detection method described in any one of claims 1-13.

16. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the text-guided image detection method described in any one of claims 1-13 are implemented.

17. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the text-guided image detection method described in any one of claims 1-13 are implemented.