Knowledge distillation method, image processing method and device for graphic and text multimodal model

Through the knowledge distillation method of multi-modal image and text models, the image and image and text alignment losses are used to adjust model parameters, which solves the problem of insufficient performance of deep learning models in the existing technology on devices with limited computing power, and realizes an image processing model. Efficient operation and performance improvement on hardware devices.

CN118587562BActive Publication Date: 2024-10-22ZHEJIANG DAHUA TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411073162.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-06
Publication Date
2024-10-22
Estimated Expiration
2044-08-06

AI Technical Summary

Technical Problem

When existing knowledge distillation methods compress deep learning models, the performance of the compressed models is not ideal, and it is difficult to achieve real-time operation on hardware devices with limited computing power.

Method used

Using the knowledge distillation method of the image and text multi-modal model, by obtaining the trained multi-modal model and the pre-trained image processing model, the image alignment loss and the image and text alignment loss are used to adjust the model parameters and improve the performance of the image processing model. Feature extraction accuracy and convergence speed of two image encoders.

Benefits of technology

It realizes the efficient operation of the image processing model on hardware devices with limited computing power, improves the image processing effect of the model, and ensures the performance of the image processing model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118587562B_ABST
    Figure CN118587562B_ABST
Patent Text Reader

Abstract

The present application discloses a knowledge distillation method, an image processing method and a device for a multimodal model of images and texts, the method comprising: inputting a sample image into a first image encoder of the multimodal model to obtain a first image feature, inputting a prompt text into a text encoder of the multimodal model to obtain a text feature; inputting a sample image into a second image encoder of the image processing model to obtain a second image feature; calculating an image alignment loss between the first image feature and the second image feature; and calculating a picture-text alignment loss between the text feature and the second image feature; training the image processing model based on the image alignment loss and the picture-text alignment loss, and performing distillation training on the second image encoder of the image processing model from two different modal dimensions, respectively, so that the second image encoder of the image processing model can understand complex text semantic information, improve the convergence speed of the second image encoder, and ensure the image processing effect of the image processing model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of deep learning technology, and in particular to a knowledge distillation method, image processing method and device for a graphic and text multimodal model. Background Art

[0002] The development of deep learning has enabled neural network models to be widely used in the field of artificial intelligence. For example, the performance of target detection algorithms has been greatly improved after using deep network models, and can be applied to multiple fields such as industry and autonomous driving. At present, one of the main factors restricting the execution effect of algorithms such as target detection is the computing power of the hardware devices on which the algorithms are deployed. Whether the computing speed of the hardware devices can support the real-time operation of the algorithms determines whether the algorithms can truly solve problems and create value.

[0003] In order to make large-scale deep network models suitable for hardware devices with limited computing power, researchers have proposed knowledge distillation technology. In order to compress the computational overhead of complex models, large models are used as teacher models and small models are used as student models. The student model is optimized and trained by the teacher model, so that the student model can reach or exceed the reasoning effect of the teacher model.

[0004] At present, knowledge distillation of models is still a key research topic in the field of deep learning. The existing knowledge distillation methods have the problem that the compressed models do not have ideal performance. Summary of the invention

[0005] In order to solve the above technical problems, the present application at least provides a knowledge distillation method, image processing method and device for a graphic and text multimodal model.

[0006] In a first aspect, the present application provides a knowledge distillation method for a text-image multimodal model, the method comprising: obtaining a trained multimodal model, a pre-trained image processing model and a sample image; wherein the multimodal model contains a text encoder and a first image encoder, the image processing model contains a second image encoder, and the sample image is marked with a prompt text; inputting the sample image into the first image encoder to obtain a first image feature output by the first image encoder, inputting the prompt text into the text encoder to obtain a text feature output by the text encoder; inputting the sample image into the second image encoder to obtain a second image feature output by the second image encoder; calculating the image alignment loss between the first image feature and the second image feature using a preset image loss function; and calculating the text-image alignment loss between the text feature and the second image feature using a preset text-image loss function; calculating the total model distillation loss based on the image alignment loss and the text-image alignment loss; and adjusting the parameters of the second image encoder in the pre-trained image processing model based on the total model distillation loss to obtain a trained image processing model.

[0007] In one embodiment, the second image encoder is composed of a plurality of image coding network layers cascaded in sequence; a sample image is input into the second image encoder to obtain second image features output by the second image encoder, including: inputting the sample image into the second image encoder, and performing image encoding on the sample image using a plurality of image coding network layers cascaded in sequence in the second image encoder; obtaining image coding features output by each image coding network layer to obtain a plurality of image coding features; and using the plurality of image coding features as the second image features output by the second image encoder.

[0008] In one embodiment, an image alignment loss between a first image feature and a second image feature is calculated using a preset image loss function, including: using the image coding feature output by the last level image coding network layer as the second image feature; and calculating the image alignment loss between the first image feature and the second image feature using a preset image loss function.

[0009] In one embodiment, a preset image-text loss function is used to calculate the image-text alignment loss between the text feature and the second image feature, including: splicing multiple image coding features to obtain a spliced ​​image feature; and using a preset image-text loss function to calculate the image-text alignment loss between the text feature and the spliced ​​image feature.

[0010] In one embodiment, a preset image-text loss function is used to calculate the image-text alignment loss between a text feature and a second image feature, including: using the preset image-text loss function to respectively calculate the initial image-text alignment loss between each image coding feature and the text feature; performing a weighted sum calculation on each initial image-text alignment loss to obtain the image-text alignment loss.

[0011] In one embodiment, a preset image-text loss function is used to calculate the image-text alignment loss between the text feature and the second image feature, including: calculating the feature similarity between the text feature and the second image feature; calculating the image-text alignment loss based on the feature similarity; wherein the image-text alignment loss is inversely proportional to the feature similarity.

[0012] In one embodiment, the image alignment loss between the first image feature and the second image feature is calculated using a preset image loss function, including: calculating the image alignment loss between the first image feature and the second image feature using an information divergence loss function or a cross entropy loss function.

[0013] In one embodiment, based on the image alignment loss and the image-text alignment loss, the total model distillation loss is calculated, including: obtaining weight parameters corresponding to the image alignment loss and the image-text alignment loss; using the weight parameters, performing weighted summation of the image alignment loss and the image-text alignment loss to obtain the total model distillation loss.

[0014] The second aspect of the present application provides an image processing method, which includes: obtaining an image to be processed; inputting the image to be processed into an image processing model trained by the knowledge distillation method of the above-mentioned image-text multimodal model, and obtaining an image processing result output by the image processing model.

[0015] In a third aspect, the present application provides a knowledge distillation device for a text-image multimodal model, the device comprising: a data acquisition module, used to acquire a trained multimodal model, a pre-trained image processing model and a sample image; wherein the multimodal model contains a text encoder and a first image encoder, the image processing model contains a second image encoder, and the sample image is marked with a prompt text; a feature extraction module, used to input the sample image into the first image encoder to obtain a first image feature output by the first image encoder, input the prompt text into the text encoder to obtain a text feature output by the text encoder; input the sample image into the second image encoder to obtain a second image feature output by the second image encoder; an alignment loss calculation module, used to calculate the image alignment loss between the first image feature and the second image feature using a preset image loss function; and, using a preset text-image loss function to calculate the text-image alignment loss between the text feature and the second image feature; a total loss calculation module, used to calculate the total loss of model distillation based on the image alignment loss and the text-image alignment loss; and a parameter adjustment module, used to adjust the parameters of the second image encoder in the pre-trained image processing model based on the total loss of model distillation to obtain a trained image processing model.

[0016] The fourth aspect of the present application provides an image processing device, which includes: an image acquisition module for acquiring an image to be processed; an image processing module for inputting the image to be processed into an image processing model trained by the knowledge distillation method of the above-mentioned image-text multimodal model to obtain an image processing result output by the image processing model.

[0017] The fifth aspect of the present application provides an electronic device, including a memory and a processor, the processor being used to execute program instructions stored in the memory to implement the knowledge distillation method and image processing method of the above-mentioned graphic and text multimodal model.

[0018] In a sixth aspect, the present application provides a computer-readable storage medium having program instructions stored thereon, which, when executed by a processor, implement the knowledge distillation method and image processing method of the above-mentioned graphic and text multimodal model.

[0019] The above scheme obtains a trained multimodal model, a pre-trained image processing model and a sample image; wherein the multimodal model contains a text encoder and a first image encoder, the image processing model contains a second image encoder, and the sample image is marked with a prompt text; the sample image is input into the first image encoder to obtain the first image feature output by the first image encoder, the prompt text is input into the text encoder to obtain the text feature output by the text encoder; the sample image is input into the second image encoder to obtain the second image feature output by the second image encoder; the image alignment loss between the first image feature and the second image feature is calculated; and the image-text alignment loss between the text feature and the second image feature is calculated; based on the image alignment loss and the image-text alignment loss, the parameters of the second image encoder in the pre-trained image processing model are adjusted to obtain the trained image processing model, and the second image encoder of the image processing model can be distilled and trained from two different modal dimensions respectively, which not only focuses on the single-modal distillation of images and images, but also focuses on the cross-modal distillation of text and images, so that the second image encoder of the image processing model can understand complex text semantic information, improve the accuracy of the image features extracted by the second image encoder, and improve the convergence speed of the second image encoder, thereby ensuring the image processing effect of the image processing model.

[0020] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present application and are used together with the specification to illustrate the technical solution of the present application.

[0022] Figure 1 It is a schematic diagram of an implementation environment of a solution provided by an embodiment of the present application;

[0023] Figure 2 is a flowchart of a knowledge distillation method for a graphic-text multimodal model shown in an exemplary embodiment of the present application;

[0024] Figure 3 is a schematic diagram of graphic encoding shown in an exemplary embodiment of the present application;

[0025] Figure 4 is a schematic diagram showing an exemplary embodiment of the present application of encoding an input sample image by using a second image encoder;

[0026] Figure 5 is a schematic diagram of loss calculation shown in an exemplary embodiment of the present application;

[0027] Figure 6is a flowchart of an image processing method shown in an exemplary embodiment of the present application;

[0028] Figure 7 is a block diagram of a knowledge distillation device for a graphic-text multimodal model shown in an exemplary embodiment of the present application;

[0029] Figure 8 is a block diagram of an image processing device shown in an exemplary embodiment of the present application;

[0030] Fig. 9 is a schematic structural diagram of an electronic device shown in an exemplary embodiment of the present application;

[0031] Fig.10 It is a schematic diagram of the structure of a computer-readable storage medium shown in an exemplary embodiment of the present application. DETAILED DESCRIPTION

[0032] The scheme of the embodiment of the present application is described in detail below in conjunction with the drawings of the specification.

[0033] In the following description, for the purpose of explanation rather than limitation, specific details such as specific system structures, interfaces, and technologies are provided to facilitate a thorough understanding of the present application.

[0034] The term "and / or" in this article is only an association information describing the associated objects, indicating that there may be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the previous and next associated objects are in an "or" relationship. In addition, "many" in this article means two or more than two. In addition, the term "at least one" in this article means any combination of at least two of any one or more of a plurality of, for example, including at least one of A, B, and C, can mean including any one or more elements selected from the set consisting of A, B, and C.

[0035] The following is a description of the knowledge distillation method of the graphic and text multimodal model provided in the embodiment of the present application.

[0036] Please refer to Figure 1 , which shows a schematic diagram of a solution implementation environment provided by an embodiment of the present application. The solution implementation environment may include a terminal 110 and a server 120, and the terminal 110 and the server 120 are connected to each other in communication.

[0037] The number of the terminal 110 may be one or more. The terminal 110 may be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited thereto.

[0038] Server 120 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), as well as big data and artificial intelligence platforms.

[0039] In one example, the server 120 may perform model training to obtain a trained image processing model, and deploy the image processing model to the terminal 110 .

[0040] Of course, in the knowledge distillation method of the graphic and text multimodal model provided in the embodiment of the present application, the execution subject of each step can be the terminal 110, or the server 120, or the terminal 110 and the server 120 can interact and cooperate to execute, that is, part of the steps of the method are executed by the terminal 110 and the other part of the steps are executed by the server 120. This application does not limit this.

[0041] See also Figure 2 , Figure 2 is a flowchart of a method for knowledge distillation of a text-image multimodal model shown in an exemplary embodiment of the present application. The method for knowledge distillation of a text-image multimodal model can be applied to Figure 1 It should be understood that the method can also be applied to other exemplary implementation environments and be specifically executed by devices in other implementation environments, and this embodiment does not limit the implementation environment to which the method is applicable.

[0042] like Figure 2 As shown, the knowledge distillation method of the graphic-text multimodal model includes at least steps S210 to S250, which are described in detail as follows:

[0043] Step S210: Acquire a trained multimodal model, a pre-trained image processing model and a sample image; wherein the multimodal model contains a text encoder and a first image encoder, the image processing model contains a second image encoder, and the sample image is marked with a prompt text.

[0044] The sample image is marked with a prompt text. It should be noted that the prompt text is different for different image processing tasks, including but not limited to target detection tasks, event recognition tasks, etc. For example, if the image processing task is a target detection task, the prompt text is used to indicate the target object contained in the sample image, such as the prompt text is "motor vehicle, traffic light, zebra crossing..."

[0045] The multimodal model is used to process image data and text data. The model parameters of the pre-trained image processing model are smaller than those of the multimodal model, that is, the multimodal model serves as a teacher model and the pre-trained image processing model serves as a student model.

[0046] Specifically, the multimodal model contains at least a text encoder and a first image encoder, and the image processing model contains at least a second image encoder. The text encoder is used to perform text feature extraction processing on the input text content, and the first image encoder and the second image encoder are used to perform image feature extraction processing on the input image content.

[0047] Of course, the specific network structures of the text encoder, the first image encoder and the second image encoder can be flexibly selected according to actual conditions, and the multimodal model and the image processing model can also contain more network structures, which is not limited in this application.

[0048] Step S220: input the sample image into the first image encoder to obtain the first image features output by the first image encoder, input the prompt text into the text encoder to obtain the text features output by the text encoder; input the sample image into the second image encoder to obtain the second image features output by the second image encoder.

[0049] The prompt text of the sample image is encoded using the text encoder of the multimodal model to obtain text features; the sample image is encoded using the first encoder of the multimodal model to obtain first image features; and at the same time, the sample image is encoded using the second encoder of the pre-trained image processing model to obtain second image features.

[0050] Step S230: using a preset image loss function to calculate the image alignment loss between the first image feature and the second image feature; and using a preset image-text loss function to calculate the image-text alignment loss between the text feature and the second image feature.

[0051] An image alignment loss between the first image feature and the second image feature is calculated, and an image-text alignment loss between the text feature and the second image feature is calculated.

[0052] For example, see Figure 3 , Figure 3 A schematic diagram of graphic encoding is shown for an exemplary embodiment of the present application, such as Figure 3As shown, the marked prompt text corresponding to the current sample image is input into the text encoder of the multimodal model for text feature extraction, and the text feature output by the text encoder is obtained, which is recorded as Text-vector; the current sample image is input into the first image encoder of the multimodal model for image feature extraction, and the first image feature output by the first image encoder is obtained, which is recorded as Img-vector1; the current sample image is input into the second image encoder of the image processing model for image feature extraction, and the second image feature output by the second image encoder is obtained, which is recorded as Img-vector2.

[0053] Then, the preset image loss function is used to calculate the image alignment loss between Img-vector1 and Img-vector2, and the preset image-text loss function is used to calculate the image-text alignment loss between Text-vector and Img-vector2.

[0054] In some implementations, before calculating the image alignment loss and the image-text alignment loss, it is also necessary to perform channel and dimension correction on the text features, the first image features, and the second image features to make their channels and dimensions consistent, which facilitates loss calculation.

[0055] Step S240: Based on the image alignment loss and the image-text alignment loss, the total loss of the model distillation is calculated.

[0056] For example, a weighted sum is calculated for the image alignment loss and the image-text alignment loss, and the weighted sum calculation result is used as the total loss of the model distillation.

[0057] For another example, the image alignment loss and the image-text alignment loss are averaged, and the average calculation result is used as the total loss of the model distillation.

[0058] For example, the maximum value of the image alignment loss and the image-text alignment loss is selected, and the maximum value is taken as the total loss of the model distillation.

[0059] In some embodiments, the specific implementation method of calculating the total loss of model distillation can be determined according to the actual training situation. For example, the specific implementation method of calculating the total loss of model distillation can be determined according to the number of iterations of the current knowledge distillation training of the image processing model, the difference between the image alignment loss and the image-text alignment loss, etc.

[0060] For example, if the number of iterations is less than the preset number threshold, the image alignment loss and the image-text alignment loss are weighted and summed, and the weighted sum calculation result is used as the total loss of model distillation; if the number of iterations is not less than the preset number threshold, the maximum value of the image alignment loss and the image-text alignment loss is selected, and the maximum value is used as the total loss of model distillation. This application does not limit the specific implementation method for determining the total loss of model distillation.

[0061] Step S250: Adjust the parameters of the second image encoder in the pre-trained image processing model based on the total loss of model distillation to obtain a trained image processing model.

[0062] Based on the model distillation total loss, backpropagation is performed to adjust the parameters of the second image encoder in the pre-trained image processing model.

[0063] Iterate the above steps S210 to S250 until the image processing model meets the training end condition, thereby obtaining a trained image processing model. The training end condition may be that the number of iterations reaches a preset number threshold, the image processing model loss converges, etc.

[0064] In the process of performing knowledge distillation training on the image processing model using the text-image multimodal model, the text encoder and the first image encoder in the multimodal model perform feature distillation on the second image encoder of the image processing model from two different modal dimensions respectively. It not only focuses on the unimodal distillation between images, but also focuses on the cross-modal distillation between text and images, so that the second image encoder of the image processing model can understand complex text semantic information, improve the accuracy of the image features extracted by the second image encoder, and improve the convergence speed of the second image encoder, thereby ensuring the image processing effect of the image processing model.

[0065] Next, some embodiments of the present application are described in detail.

[0066] In some embodiments, the second image encoder is composed of a plurality of image coding network layers cascaded in sequence; in step S220, the sample image is input into the second image encoder to obtain a second image feature output by the second image encoder, including: inputting the sample image into the second image encoder, and performing image encoding on the sample image using a plurality of image coding network layers cascaded in sequence in the second image encoder; obtaining the image coding feature output by each image coding network layer to obtain a plurality of image coding features; and using the plurality of image coding features as the second image features output by the second image encoder.

[0067] For example, see Figure 4 , Figure 4 FIG. 1 is a schematic diagram showing an exemplary embodiment of the present application, showing how to use a second image encoder to encode an input sample image. Figure 4As shown, it is assumed that the second image encoder consists of three image encoding network layers cascaded in sequence, namely network layer 1, network layer 2 and network layer 3, and the output of the previous network layer is also used as the input of the next network layer. The sample image is input into the second image encoder, and the image encoding features output by each image encoding network layer are obtained to obtain the first image encoding feature L1-Feature, the second image encoding feature L2-Feature, and the third image encoding feature L3-Feature. L1-Feature, L2-Feature and L3-Feature are all used as the second image features output by the second image encoder.

[0068] Optionally, the second image encoder is implemented based on a residual network (Residual Network, ResNet) or other network structures, which is not limited in the present application.

[0069] In some embodiments, after obtaining the image coding features output by each image coding network layer, the image coding features are subjected to channel and dimension preprocessing. Figure 4 The image processing network is also provided with a pooling layer (Pooling) to input L1-Feature, L2-Feature and L3-Feature into the pooling layer for channel and dimension preprocessing to obtain preprocessed image coding features L1-Vec, L2-Vec and L3-Vec, and L1-Vec, L2-Vec and L3-Vec are all used as the second image features output by the second image encoder.

[0070] For example: the pooling layer uses maximum pooling to preprocess the input features in terms of channels and dimensions. Assume that the dimensions of the input image encoding feature F are (B, C, H, W), where B refers to the batch dimension; C refers to the channel dimension; H refers to the height of the feature map; and W refers to the width of the feature map. The pooling layer uses maximum pooling to calculate the maximum value on the dim=1 dimension as the output, and the corresponding preprocessed image encoding feature is obtained, and its corresponding dimensions are (B, C, 1, 1).

[0071] Combination Figure 4 The corresponding embodiments describe in detail the calculation steps of the image alignment loss and the image-text alignment loss.

[0072] In some embodiments, the image alignment loss between the first image feature and the second image feature is calculated using a preset image loss function in step S230, including: using the image coding feature output by the last level image coding network layer as the second image feature; and calculating the image alignment loss between the first image feature and the second image feature using a preset image loss function.

[0073] For example, see Figure 5 , Figure 5 A schematic diagram of loss calculation is shown for an exemplary embodiment of the present application, such as Figure 5 As shown, the image coding feature output by the last level image coding network layer is obtained as L3-Vec, L3-Vec is used as the second image feature, and the loss value between L3-Vec and the first image feature Img-vector1 is calculated using the preset image loss function to obtain the image alignment loss.

[0074] In some embodiments, the image coding features output by each image coding network layer can be spliced ​​to obtain spliced ​​image features, and the spliced ​​image features can be used as second image features. The loss value between the second image features and the first image features can be calculated using a preset image loss function to obtain the image alignment loss.

[0075] In some implementations, a preset image loss function may be used to calculate the loss value between the image coding feature output by each image coding network layer and the first image feature, respectively, to obtain the initial image alignment loss, and a weighted sum calculation is performed on each initial image alignment loss to obtain the image alignment loss. The weight parameter used in the weighted sum calculation may be preset.

[0076] In some embodiments, a preset image loss function can also be used to calculate the loss value between the image coding feature output by each image coding network layer and the first image feature, respectively, to obtain multiple initial image alignment losses, and the maximum value of the initial image alignment losses is selected as the image alignment loss.

[0077] Among them, the preset image loss function includes but is not limited to information divergence loss (Kullback-LeiblerDivergence Loss, KL Divergence Loss) function or cross entropy loss (Cross-Entropy Loss) function, etc., and this application does not limit this.

[0078] For example, the preset image loss function is expressed as the following formula 1:

[0079] KL(P || Q) = ∑(P(i) * log(P(i) / Q(i))) (Formula 1)

[0080] In Formula 1, KL(P || Q) represents the image alignment loss; P and Q represent the first image feature and the second image feature, respectively, and i represents the feature dimension.

[0081] The image alignment loss is calculated using the above formula 1 to achieve unimodal distillation of images and images during subsequent model parameter adjustment, and to transfer the image feature extraction capability of the first image encoder in the multimodal model to the second image encoder.

[0082] In some embodiments, in step S230, a preset image-text loss function is used to calculate the image-text alignment loss between the text feature and the second image feature, including: splicing multiple image coding features to obtain a spliced ​​image feature; and calculating the image-text alignment loss between the text feature and the spliced ​​image feature using a preset image-text loss function.

[0083] For example, see Figure 5 , obtain the image coding features output by each image coding network layer, including L1-Vec, L2-Vec, and L3-Vec, and concatenate L1-Vec, L2-Vec, and L3-Vec in the channel dimension to obtain the concatenated image features.

[0084] For example, assuming that the channel dimensions of L1-Vec, L2-Vec, and L3-Vec before splicing are c1, c2, and c3 respectively, and the channel dimensions after splicing are c1+c2+c3, further, the channel dimensions of the splicing result are corrected to obtain the final spliced ​​image features. The purpose of the correction is to make the dimensions of the spliced ​​image features and the text features consistent. For example, a 1x1 convolution kernel can be used to process the splicing result. The input and output channel dimensions of the 1x1 convolution kernel are the length of the vector in Text-vector to obtain the spliced ​​image features.

[0085] Then, the spliced ​​image feature is used as the second image feature, recorded as Img-vector2, and the text feature is recorded as Text-vector. The preset image-text loss function is used to calculate the loss value between Img-vector2 and Text-vector to obtain the image-text alignment loss.

[0086] In some implementations, the image coding feature output by any image coding network layer may be used as the second image feature, and the loss value between the second image feature and the text feature may be calculated using a preset image-text loss function to obtain the image-text alignment loss.

[0087] In some implementations, a preset image-text loss function may be used to calculate the loss value between the image coding features and the text features output by each image coding network layer, respectively, to obtain the initial image-text alignment loss, and a weighted sum calculation is performed on each initial image-text alignment loss to obtain the image-text alignment loss. The weight parameter used in the weighted sum calculation may be preset.

[0088] In some embodiments, a preset image-text loss function can also be used to calculate the loss value between the image coding features and text features output by each image coding network layer, respectively, to obtain multiple initial image-text alignment losses, and select the maximum value of the initial image-text alignment losses as the image-text alignment loss.

[0089] In some embodiments, since the second image feature comes from the image processing model, which is calculated based on the pure image, and the text feature is calculated using the text encoder of the multimodal model, there is a strong latent space correlation between the two. Therefore, the KL divergence loss function or the cross entropy loss function cannot be directly used for calculation. In particular, the present application uses the feature similarity between the second image feature and the text feature as a loss metric, and the feature similarity can be calculated using the following formula 2:

[0090] cosine_similarity(A, B) = (A B) / (||A|| * ||B||) (Formula 2)

[0091] In Formula 2, cosine_similarity(A, B) represents feature similarity; A and B represent text features and second image features, respectively.

[0092] The image-text alignment loss is calculated based on the feature similarity. The image-text alignment loss is inversely proportional to the feature similarity. That is, the larger the feature similarity value is, the more similar the second image feature is to the text feature is, and therefore, the image-text alignment loss is smaller. Conversely, the smaller the feature similarity value is, the less similar the second image feature is to the text feature is, and therefore, the image-text alignment loss is larger.

[0093] Of course, in addition to the above embodiments, other methods may be used to calculate the image-text alignment loss, which is not limited in the present application.

[0094] In some embodiments, the image coding feature output by the last level image coding network layer in the second image encoder is calculated, and the image alignment loss between the first image feature is calculated; the image-text alignment loss between the spliced ​​image feature of the image coding feature output by each level image coding network layer in the second image encoder and the text feature is calculated; the image alignment loss and the image-text alignment loss are combined to train the second image encoder. This allows the image distillation to focus on the last network layer of the second image encoder, while the text distillation focuses on all network positions of the second image encoder, thereby improving the training efficiency of the second image encoder and accelerating the convergence speed of the second image encoder.

[0095] After obtaining the image alignment loss and the image-text alignment loss, the total loss of the model distillation is determined based on the image alignment loss and the image-text alignment loss.

[0096] In some embodiments, in step S240, the total loss of model distillation is calculated based on the image alignment loss and the image-text alignment loss, including: obtaining weight parameters corresponding to the image alignment loss and the image-text alignment loss; using the weight parameters, performing weighted summation of the image alignment loss and the image-text alignment loss to obtain the total loss of model distillation.

[0097] Specifically, the total loss of model distillation is calculated using the following formula 3:

[0098] (Formula 3)

[0099] In formula 3, Loss represents the total loss of model distillation; cosine_similarity(A, B) represents the image-text alignment loss, which can be the feature similarity calculated by formula 2. is the weight parameter corresponding to the image-text alignment loss, The value can be less than 0, so that the feature similarity and the final model distillation total loss are inversely proportional; KL(P || Q) represents the image alignment loss, is the weight parameter corresponding to the image alignment loss.

[0100] In some embodiments, in step S240, the total loss of model distillation is calculated based on the image alignment loss and the image-text alignment loss, including: obtaining the predicted output of the multimodal model and the predicted output of the image processing model, and calculating the output loss based on the predicted output of the multimodal model and the predicted output of the image processing model; obtaining weight parameters corresponding to the image alignment loss, the image-text alignment loss, and the output loss; using the weight parameters, weightedly summing the image alignment loss, the image-text alignment loss, and the output loss to obtain the total loss of model distillation.

[0101] Among them, the greater the difference between the predicted output of the multimodal model and the predicted output of the image processing model, the greater the output loss; conversely, the smaller the difference between the predicted output of the multimodal model and the predicted output of the image processing model, the smaller the output loss.

[0102] See also Figure 6 , Figure 6 is a flowchart of an image processing method shown in an exemplary embodiment of the present application. The image processing method can be applied to Figure 1 The implementation environment shown is specifically executed by a terminal in the implementation environment, and the terminal is deployed with a trained image processing model. It should be understood that the method can also be applied to other exemplary implementation environments and specifically executed by devices in other implementation environments, and this embodiment does not limit the implementation environment to which the method is applicable.

[0103] like Figure 6 As shown, the image processing method at least includes steps S610 to S620, which are described in detail as follows:

[0104] Step S610: Acquire the image to be processed.

[0105] Step S620: input the image to be processed into the image processing model trained by the knowledge distillation method of the image-text multimodal model to obtain the image processing result output by the image processing model.

[0106] The functions of the trained image processing model will be different depending on the image processing task.

[0107] For example, if the image processing task is a target detection task, the image to be processed is input into the image processing model for target detection, and the image processing result obtained is information such as the position of the target object in the image to be processed and the type of the target object.

[0108] Figure 7 FIG. 1 is a block diagram of a knowledge distillation device for a multimodal model of graphics and texts, as shown in an exemplary embodiment of the present application. Figure 7 As shown, the exemplary knowledge distillation device 700 of the image-text multimodal model includes: a data acquisition module 710, a feature extraction module 720, an alignment loss calculation module 730, a total loss calculation module 740 and a parameter adjustment module 750. Specifically:

[0109] The data acquisition module 710 is used to acquire the trained multimodal model, the pre-trained image processing model and the sample image; wherein the multimodal model includes a text encoder and a first image encoder, the image processing model includes a second image encoder, and the sample image is marked with a prompt text;

[0110] The feature extraction module 720 is used to input the sample image into the first image encoder to obtain the first image feature output by the first image encoder, input the prompt text into the text encoder to obtain the text feature output by the text encoder; input the sample image into the second image encoder to obtain the second image feature output by the second image encoder;

[0111] An alignment loss calculation module 730 is used to calculate the image alignment loss between the first image feature and the second image feature using a preset image loss function; and to calculate the image-text alignment loss between the text feature and the second image feature using a preset image-text loss function;

[0112] A total loss calculation module 740 is used to calculate the total loss of model distillation based on the image alignment loss and the image-text alignment loss;

[0113] The parameter adjustment module 750 is used to adjust the parameters of the second image encoder in the pre-trained image processing model based on the total loss of model distillation to obtain a trained image processing model.

[0114] Figure 8 FIG. 1 is a block diagram of an image processing device shown in an exemplary embodiment of the present application. Figure 8 As shown, the exemplary image processing device 800 includes: an image acquisition module 810 and an image processing module 820. Specifically:

[0115] An image acquisition module 810 is used to acquire an image to be processed;

[0116] The image processing module 820 is used to input the image to be processed into the image processing model trained by the knowledge distillation method of the above-mentioned image-text multimodal model to obtain the image processing result output by the image processing model.

[0117] It should be noted that the knowledge distillation device and image processing device of the graphic-text multimodal model provided in the above-mentioned embodiments belong to the same concept as the knowledge distillation method and image processing method of the graphic-text multimodal model provided in the above-mentioned embodiments, wherein the specific manner in which each module and unit performs the operation has been described in detail in the method embodiment and will not be repeated here. In practical applications, the knowledge distillation device and image processing device of the graphic-text multimodal model provided in the above-mentioned embodiments can distribute the above-mentioned functions to different functional modules as needed, that is, divide the internal structure of the device into different functional modules to complete all or part of the functions described above, and this is not limited here.

[0118] See also Fig. 9 , Fig. 9It is a structural diagram of an embodiment of an electronic device of the present application. The electronic device 900 includes a memory 901 and a processor 902, and the processor 902 is used to execute program instructions stored in the memory 901 to implement the steps in the embodiments of the knowledge distillation method and image processing method of any of the above-mentioned graphic multimodal models. In a specific implementation scenario, the electronic device 900 may include but is not limited to: a microcomputer, a server, and in addition, the electronic device 900 may also include mobile devices such as laptops and tablet computers, which are not limited here.

[0119] Specifically, the processor 902 is used to control itself and the memory 901 to implement the steps in the above-mentioned knowledge distillation method and image processing method embodiment of any of the above-mentioned graphic multimodal models. The processor 902 can also be called a central processing unit (CPU). The processor 902 may be an integrated circuit chip with signal processing capabilities. The processor 902 can also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. In addition, the processor 902 can be implemented by an integrated circuit chip.

[0120] See also Fig.10 , Fig.10 The computer-readable storage medium 1000 stores program instructions 1010 that can be executed by a processor, and the program instructions 1010 are used to implement the steps in any of the above-mentioned knowledge distillation methods and image processing methods of the multimodal model of graphics and text.

[0121] In some embodiments, the functions or modules included in the device provided by the embodiments of the present disclosure can be used to execute the method described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.

[0122] The above description of various embodiments tends to emphasize the differences between the various embodiments. The same or similar aspects can be referenced to each other, and for the sake of brevity, they will not be repeated herein.

[0123] In the several embodiments provided in the present application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the device implementation described above is only schematic. For example, the division of modules or units is only a logical function division. There may be other division methods in actual implementation, such as units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.

[0124] In addition, each functional unit in each embodiment of the present application can be integrated into a processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional unit. If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or part of the contribution to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor (processor) to perform all or part of the steps of each implementation method of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), disk or optical disk and other media that can store program code.

Claims

1. A knowledge distillation method for a multimodal model of images and texts, characterized in that: include: Acquire a trained multimodal model, a pre-trained image processing model and a sample image; wherein the multimodal model includes a text encoder and a first image encoder, the image processing model includes a second image encoder, and the sample image is marked with a prompt text; Input the sample image to the first image encoder to obtain a first image feature output by the first image encoder, input the prompt text to the text encoder to obtain a text feature output by the text encoder; input the sample image to the second image encoder to obtain a second image feature output by the second image encoder; The image alignment loss between the first image feature and the second image feature is calculated using a preset image loss function; and the image-text alignment loss between the text feature and the second image feature is calculated using a preset image-text loss function; wherein the preset image loss function includes an information divergence loss function or a cross entropy loss function, and the preset image-text loss function calculates the feature similarity between the text feature and the second image feature, and obtains the image-text alignment loss based on the feature similarity, and the image-text alignment loss is inversely proportional to the feature similarity; Based on the image alignment loss and the image-text alignment loss, a total loss of the model distillation is calculated; Based on the total loss of the model distillation, parameters of the second image encoder in the pre-trained image processing model are adjusted to obtain a trained image processing model.

2. The method according to claim 1, characterized in that The second image encoder is composed of a plurality of image encoding network layers cascaded in sequence; the step of inputting the sample image into the second image encoder to obtain a second image feature output by the second image encoder includes: Inputting the sample image into the second image encoder, and performing image encoding on the sample image by using the plurality of sequentially cascaded image encoding network layers in the second image encoder; Obtain the image coding features output by each image coding network layer to obtain multiple image coding features; The multiple image encoding features are all used as second image features output by the second image encoder.

3. The method according to claim 2, characterized in that The calculating the image alignment loss between the first image feature and the second image feature by using a preset image loss function includes: The image coding feature output by the last level image coding network layer is used as the second image feature; An image alignment loss between the first image feature and the second image feature is calculated using a preset image loss function.

4. The method according to claim 2, characterized in that: The calculating the image-text alignment loss between the text feature and the second image feature by using a preset image-text loss function includes: splicing the multiple image coding features to obtain a spliced ​​image feature; The image-text alignment loss between the text feature and the spliced ​​image feature is calculated using a preset image-text loss function.

5. The method according to claim 2, characterized in that: The calculating the image-text alignment loss between the text feature and the second image feature by using a preset image-text loss function includes: Using a preset image-text loss function, respectively calculate the initial image-text alignment loss between each image encoding feature and the text feature; The weighted sum of each initial image-text alignment loss is calculated to obtain the image-text alignment loss.

6. The method according to claim 1, characterized in that The total loss of model distillation is calculated based on the image alignment loss and the image-text alignment loss, including: Obtain weight parameters corresponding to the image alignment loss and the image-text alignment loss; The image alignment loss and the image-text alignment loss are weightedly summed using the weight parameter to obtain the total model distillation loss.

7. An image processing method, characterized in that: include: Get the image to be processed; The image to be processed is input into the image processing model trained by the knowledge distillation method of the image-text multimodal model according to any one of claims 1 to 6 to obtain the image processing result output by the image processing model.

8. An electronic device, characterized in that: The electronic device includes a memory and a processor, and the processor is used to execute program instructions stored in the memory to implement the steps in the knowledge distillation method of the graphic and text multimodal model as described in any one of claims 1 to 6, or to implement the steps in the image processing method as described in claim 7.