Image processing method and device of multi-modal large model, electronic equipment and storage medium
By generating and screening feature vectors of image feature sequences, the problem of low efficiency of multi-modal large models in image processing is solved and more efficient image processing is achieved.
Patent Information
- Application Number
- CN202410932267.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-12
- Publication Date
- 2024-10-08
AI Technical Summary
Existing multi-modal large models are less efficient in image processing and are limited by video memory and computing power, resulting in low processing efficiency.
By generating an image feature sequence from the image to be processed, and performing screening and attention calculation based on the feature vector, a target feature vector is generated, which reduces the number of calculated features and improves processing efficiency.
It improves the efficiency of machine learning models in image processing and reduces the complexity and resource consumption of feature calculations.
Smart Images

Figure CN118747822A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of machine learning models, and in particular to an image processing method, device, electronic device and storage medium for a multimodal large model. Background Art
[0002] With the rapid development of artificial intelligence technology based on machine learning, machine learning models have been applied in more and more fields. Multimodal large models are a type of machine learning model. Multimodal large models refer to large deep learning models that can handle multiple input modalities (such as text, images, voice, etc.). These models combine different types of data, enabling them to understand and process complex information more comprehensively. The emergence of multimodal large models has promoted the development of cross-modal learning, helped to process more complex and diverse data, and brought more possibilities for artificial intelligence applications.
[0003] At present, the general way for multimodal large models to process images is to scale the image size before processing, or to divide the image into blocks before processing. However, both processing methods are limited by the video memory and computing power of the multimodal large model, resulting in low image processing efficiency. Summary of the invention
[0004] The embodiments of the present application provide a method, device, electronic device and storage medium for processing images of a multimodal large model, which solves the problem of low efficiency of image processing by machine learning models in the prior art.
[0005] In a first aspect, an embodiment of the present application provides an image processing method of a multimodal large model, which is applied to an electronic device, on which a first machine learning model is deployed, and the method includes:
[0006] Step S1: generating an image feature sequence according to an image to be processed, wherein the image feature sequence includes at least two slice images obtained after image encoding of the image to be processed;
[0007] Step S2: generating a first feature vector and a second feature vector based on the image feature sequence, and generating a third feature vector based on a preset variable vector, wherein the first feature vector and the second feature vector are feature vectors of the image feature sequence respectively, and the first feature vector and the second feature vector include different parameter values;
[0008] Step S3: screening the feature length included in the first feature vector and the feature length included in the second feature vector according to the feature length included in the third feature vector, and determining a first target feature vector and a second target feature vector, wherein the feature lengths of the first target feature vector and the second target feature vector are the same;
[0009] Step S4: Performing attention calculation based on the first target feature vector, the second target feature vector and the third feature vector to generate a target feature vector, wherein the target feature vector is used to characterize the image features of the image to be processed.
[0010] Optionally, in step S3: screening the feature length included in the first feature vector and the feature length included in the second feature vector according to the feature length included in the third feature vector, and before determining the first target feature vector and the second target feature vector, the method further includes:
[0011] Step S01: obtaining a sample image;
[0012] Step S02: inputting the sample image into the first machine learning model for feature extraction and outputting a first feature length, and inputting the sample image into the second machine learning model for feature extraction and outputting a second feature length, wherein a target model parameter of the second machine learning model is greater than a target model parameter of the first machine learning model, wherein the target model parameter is a feature length obtained after feature extraction of the received image, and the first feature length is less than the second feature length;
[0013] Step S03: calculating the similarity between the features included in the first feature length and the features included in the second feature length, and generating a plurality of first similarity results;
[0014] Step S04: screening the plurality of first similarity results according to a similarity threshold to determine a plurality of second similarity results;
[0015] Step S05: determining a target feature length as the feature length of the preset variable vector, wherein the target feature length is determined according to the plurality of second similarity results.
[0016] Optionally, the first machine learning model includes a first linear layer, a second linear layer, and a third linear layer, and the step S2: generating a first feature vector and a second feature vector based on the image feature sequence, and generating a third feature vector based on a preset variable vector, includes:
[0017] Step S21: inputting the image feature sequence into the first linear layer for linearization processing to generate the first feature vector;
[0018] Step S22: inputting the image feature sequence into the second linear layer for linearization processing to generate the second feature vector;
[0019] Step S23: performing linearization processing on the preset variable vector based on the third linear layer to obtain the third eigenvector.
[0020] Optionally, the step S3: screening the feature length included in the first feature vector and the feature length included in the second feature vector according to the feature length included in the third feature vector to determine the first target feature vector and the second target feature vector, comprises:
[0021] Step S31: determining a third characteristic length corresponding to the first characteristic vector and a fourth characteristic length corresponding to the second characteristic vector;
[0022] Step S32: determining a fifth characteristic length from the third characteristic lengths according to the characteristic lengths included in the third characteristic vector;
[0023] Step S33: determining a sixth characteristic length that is the same as the fifth characteristic length in the fourth characteristic length;
[0024] Step S34: determining the first target feature vector according to the fifth feature length, and determining the second target feature vector according to the sixth feature length.
[0025] Optionally, the step S32: determining a fifth characteristic length from the third characteristic length according to the characteristic length included in the third characteristic vector, comprises:
[0026] Step S321: determining the target feature length included in the third feature vector;
[0027] Step S322: respectively calculating the similarity between the features included in the third feature length and the features included in the target feature length, and generating a calculation result, wherein the calculation result includes the plurality of features sorted from high to low in similarity;
[0028] Step S323: determining a plurality of target features from the plurality of features based on the features included in the target feature length;
[0029] Step S324: Generate the fifth characteristic length based on the multiple target features.
[0030] Optionally, the step S4: performing attention calculation based on the first target feature vector, the second target feature vector and the third feature vector to generate a target feature vector includes:
[0031] Step S41: multiplying the first target feature vector and the third feature vector to generate a fourth vector;
[0032] Step S42: multiplying the fourth vector by the second target feature vector to generate the target feature vector.
[0033] Optionally, the step S42: multiplying the fourth vector by the second target feature vector to generate the target feature vector includes:
[0034] Step S421: normalizing the fourth vector according to the classification problem activation function to generate a fifth vector;
[0035] Step S422: performing regularization processing on the fifth vector to generate a sixth vector;
[0036] Step S423: multiply the sixth vector and the second target feature vector to generate the target feature vector.
[0037] In a second aspect, the present application further provides an image processing device of a multimodal large model, which is applied to an electronic device, on which a first machine learning model is deployed, and the device includes:
[0038] A processing module, for generating an image feature sequence according to the image to be processed, wherein the image feature sequence includes at least two slice images obtained after image encoding of the image to be processed;
[0039] A generating module, configured to generate a first feature vector and a second feature vector based on the image feature sequence, and to generate a third feature vector based on a preset variable vector, wherein the first feature vector and the second feature vector are feature vectors of the image feature sequence respectively, and the first feature vector and the second feature vector include different parameter values;
[0040] A screening module, used for screening the feature length included in the first feature vector and the feature length included in the second feature vector according to the feature length included in the third feature vector, to determine a first target feature vector and a second target feature vector, wherein the feature lengths of the first target feature vector and the second target feature vector are the same;
[0041] A calculation module is used to perform attention calculation based on the first target feature vector, the second target feature vector and the third feature vector to generate a target feature vector, wherein the target feature vector is used to characterize the image features of the image to be processed.
[0042] In a third aspect, an embodiment of the present application further provides an electronic device, comprising: a memory, a processor, and a program stored in the memory and executable on the processor; the processor is used to read the program in the memory to implement the steps in the method described in the first aspect above.
[0043] In a fourth aspect, an embodiment of the present application further provides a readable storage medium for storing a program, which, when executed by a processor, implements the steps in the method described in the first aspect above.
[0044] In a fifth aspect, an embodiment of the present application further provides a computer program product, which is stored in a storage medium and is executed by at least one processor to implement the steps in the method described in the first aspect.
[0045] The present application provides an image processing method, device, electronic device and storage medium of a multimodal large model, which are applied to an electronic device, wherein a first machine learning model is deployed on the electronic device, and the method comprises: step S1: generating an image feature sequence according to an image to be processed, segmenting the image to be processed to obtain an image sequence, wherein the image sequence image feature sequence comprises at least two slice images obtained after segmenting the image to be processed and encoding the image; step S2: generating a first feature vector and a second feature vector based on the image sequence image feature sequence, and generating a third feature vector based on a preset variable vector, wherein the first feature vector and the second feature vector are feature vectors of the image sequence image feature sequence, respectively. , and the first feature vector and the second feature vector represent different feature dimensions and include different parameter values; Step S3: Screen the feature length included in the first feature vector and the feature length included in the second feature vector according to the feature quantity and feature length included in the third feature vector, and determine the first target feature vector and the second target feature vector, wherein the feature length and feature quantity of the third feature vector, the first target feature vector and the second target feature vector are the same; Step S4: Perform attention calculation based on the first target feature vector, the second target feature vector and the third feature vector to generate a target feature vector, wherein the target feature vector is used to characterize the image features of the image to be processed. The present application reduces the features of the first feature vector and the second feature vector for attention calculation by screening the first feature vector and the second feature vector generated by the image to be processed through the feature length of a preset variable vector, thereby improving the efficiency of the machine learning model in processing images. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 A schematic diagram of a flow chart of an image processing method for a multimodal large model provided in an embodiment of the present application;
[0047] Figure 2 This is a flow chart of the second machine learning model in the embodiment of the present application;
[0048] Figure 3This is a flow chart of the first machine learning model in the embodiment of the present application;
[0049] Figure 4 Schematic diagram of the process of attention calculation stage in the embodiment of the present application;
[0050] Figure 5 A schematic diagram of the structure of an image processing device for a multimodal large model provided in an embodiment of the present application;
[0051] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0052] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0053] The terms "first", "second" etc. in the embodiments of the present application are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. In addition, the terms "include" and "have" and any variation thereof are intended to cover non-exclusive inclusions, for example, the process, method, system, product or equipment comprising a series of steps or units need not be limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or equipment. In addition, "and / or" is used in the present application to represent at least one of connected objects, such as A and / or B and / or C, representing the inclusion of separate A, separate B, separate C, and A and B all exist, B and C all exist, A and C all exist, and 7 situations that A, B and C all exist.
[0054] The "Multimodal Large Models" mentioned in the present invention refer to models that combine multimodal information such as text, images, videos, audio, etc. for training, including but not limited to multimodal large language models.
[0055] The “large language model” mentioned in the present invention refers to a large language model (LLM), which is a language model with a large parameter scale. It is designed to understand and generate human language. It is trained with a large amount of text data and can perform a wide range of tasks including text summarization, translation, sentiment analysis, etc.
[0056] The "step S01" described in the present invention is before the "step S1", the "step S02" described in the present invention is before the "step S2", the "step S03" described in the present invention is before the "step S3", the "step S04" described in the present invention is before the "step S4", and the "step S05" described in the present invention is before the "step S5".
[0057] See also Figure 1 , Figure 1 : is a flow chart of an image processing method of a multimodal large model provided in an embodiment of the present application. The present application is applied to an electronic device, on which a first machine learning model is deployed. The method includes:
[0058] Step S1: generating an image feature sequence according to an image to be processed, wherein the image feature sequence includes at least two slice images obtained after image encoding is performed on the image to be processed.
[0059] In this embodiment, the method provided in this application is applied to a machine learning platform, which can deploy multiple machine learning models and deep learning models, wherein deep learning is a subset of machine learning, and machine learning models include deep learning models. Generative AI models or large language models (LLM) belong to deep learning models, and new content can be generated using deep learning and other technologies. The machine learning model in the embodiment of this application is not limited to characterizing machine learning models, but is also used to characterize deep learning models, large language models, etc. In this application, the first machine learning model can be a multimodal large model, which refers to a large artificial intelligence model that can process and understand a variety of different types of input data (such as text, images, audio, etc.). The multimodal large model uses deep learning technology, especially neural networks, to integrate information from different modalities to perform complex tasks, such as object recognition in images and descriptions, video content analysis, cross-modal information retrieval, and automatic content generation.
[0060] The image to be processed is a picture that needs to be processed, wherein the image to be processed may be an image with a larger size or more pixels, and the image processing is performed by inputting the image to be processed into the first machine learning model. Preferably, the first machine learning model is an improved blip2 Qformer structure.
[0061] In this embodiment, the image to be processed is first processed by the encoder (eva-vit-img-encode) of the first machine learning model and divided into multiple image feature sequences, wherein the image can be segmented by image encoding, and the image feature sequence includes multiple slice images. The result of image processing is img-sequence (the dimension of the image feature sequence is [bs, seq_len, hidden_size], wherein bs is batch_size, seq_len is 257, and hidden_size is 768), which is used as the input of the blip2 Qformer structure.
[0062] Step S2: Generate a first feature vector and a second feature vector based on the image feature sequence, and generate a third feature vector based on a preset variable vector, wherein the first feature vector and the second feature vector are feature vectors of the image feature sequence, respectively, and the first feature vector and the second feature vector include different parameter values.
[0063] In this embodiment, the image feature sequence is processed by different linear layers of the first machine learning model to generate a first feature vector and a second feature vector, wherein the first feature vector and the second feature vector can be represented by k_vector (dimension [batch_size, seq_len, hidden_size]) and v_vector (dimension [batch_size, seq_len, hidden_size]). In addition, the preset variable vector is mapped through another linear layer based on the image feature sequence to obtain a third feature vector, wherein the third feature vector can be represented as q_vector ([batch_size, seq_len, hidden_size]).
[0064] It should be noted that the first eigenvector and the second eigenvector have different training parameters, and thus the parameter values included in the first eigenvector and the second eigenvector are different.
[0065] Step S3: Screening the feature length included in the first feature vector and the feature length included in the second feature vector according to the feature length included in the third feature vector to determine a first target feature vector and a second target feature vector, wherein the feature lengths of the first target feature vector and the second target feature vector are the same.
[0066] In this embodiment, the feature length included in the third feature vector is determined. The feature length is determined according to a preset variable vector and is a preset value. It should be noted that the preset value can be adaptively adjusted according to the actual large model or data situation, and is not specifically limited in this embodiment. It should be noted that the third feature vector contains at least three feature dimensions [batch_size, seq_len, hidden_size], where the feature length refers to seq_len, and the screening in this application is performed on the dimension of seq_len.
[0067] The first feature vector and the second feature vector are screened respectively by the feature length included in the third feature vector, thereby determining a plurality of features in the first feature vector that are most similar to the feature length included in the third feature vector, and determining a plurality of features in the second feature vector that are most similar to the feature length included in the third feature vector, thereby generating a first target feature vector and a second target feature vector respectively. Thus, the generated first target feature vector and the second target feature vector have the same feature length.
[0068] It should be noted that the screening of the first eigenvector and the second eigenvector can be to screen out the vectors in the first eigenvector and the second eigenvector that have the highest similarity to the third eigenvector, and discard the vectors with lower similarity. The result of the calculation is the same as the result of calculating the features of all the first eigenvectors and the features of the second eigenvector, but this can reduce the number of features that need to be calculated, thereby improving the calculation efficiency.
[0069] Step S4: Performing attention calculation based on the first target feature vector, the second target feature vector and the third feature vector to generate a target feature vector, wherein the target feature vector is used to characterize the image features of the image to be processed.
[0070] In this embodiment, attention calculation is performed based on the first target feature vector, the second target feature vector and the third feature vector to generate a calculated target feature vector, wherein attention calculation is a technology that enables the model to focus on specific parts of the input data to improve performance, which can focus on certain parts when processing information and ignore other less important information, thereby improving the image processing accuracy of multimodal large models.
[0071] It should be noted that the target feature vector needs to be calculated through multiple convolution modules and other attention calculation mechanisms to finally generate a processed image. In this embodiment, the subsequent steps are not specifically limited.
[0072] The present application provides an image processing method for a multimodal large model, which is applied to an electronic device, on which a first machine learning model is deployed, and the method comprises: step S1: generating an image feature sequence according to an image to be processed, wherein the image feature sequence comprises at least two slice images obtained after image encoding of the image to be processed; step S2: generating a first feature vector and a second feature vector based on the image feature sequence, and generating a third feature vector based on a preset variable vector, wherein the first feature vector and the second feature vector are feature vectors of the image feature sequence, respectively, and the first feature vector and the second feature vector include different parameter values; step S3: screening the feature length included in the first feature vector and the feature length included in the second feature vector according to the feature length included in the third feature vector, and determining a first target feature vector and a second target feature vector, wherein the feature lengths of the first target feature vector and the second target feature vector are the same; step S4: performing attention calculation based on the first target feature vector, the second target feature vector and the third feature vector, and generating a target feature vector, wherein the target feature vector is used to characterize the image features of the image to be processed. The present application reduces the features of the first eigenvector and the second eigenvector for attention calculation by filtering the first eigenvector and the second eigenvector generated by the image to be processed through the feature length of a preset variable vector, thereby improving the efficiency of the machine learning model in processing the image.
[0073] In some feasible implementations, the step S3: before screening the feature length included in the first feature vector and the feature length included in the second feature vector according to the feature length included in the third feature vector, and determining the first target feature vector and the second target feature vector, the method further includes:
[0074] Step S01: obtaining a sample image;
[0075] Step S02: inputting the sample image into the first machine learning model for feature extraction and outputting a first feature length, and inputting the sample image into the second machine learning model for feature extraction and outputting a second feature length, wherein a target model parameter of the second machine learning model is greater than a target model parameter of the first machine learning model, wherein the target model parameter is a feature length obtained after feature extraction of the received image, and the first feature length is less than the second feature length;
[0076] Step S03: calculating the similarity between the features included in the first feature length and the features included in the second feature length, and generating a plurality of first similarity results;
[0077] Step S04: screening the plurality of first similarity results according to a similarity threshold to determine a plurality of second similarity results;
[0078] Step S05: determining a target feature length as the feature length of the preset variable vector, wherein the target feature length is determined according to the plurality of second similarity results.
[0079] In this embodiment, the characteristic length of the preset variable vector can be determined by the recognition result of the sample image in the machine learning model. Specifically, the second machine learning model is a model that improves the first machine learning model, such as Figure 2 and Figure 3 As shown, Figure 2 This is a flow chart of the second machine learning model. Figure 3 is a flow chart of the first machine learning model. Specifically, the cross-attention structure in the blip2 Qformer-encoder in the second machine learning model is replaced with the knn-xattention structure, thereby improving the second machine learning model to generate the first machine learning model. Specifically, img_sequence is the image to be processed, where k_layer, v_layer and q_layer are different linear layers. Different feature vectors can be output through different linear layers. Figure 2 The difference is that in Figure 3 In the example, the vector k_vector output by k_layer and the vector v_vector output by v_layer are screened by the knn algorithm to obtain k_neighbor and v_neighbor, thereby reducing the feature length that needs to be calculated and improving the processing efficiency of the model. It should be noted that the second machine learning model reuses the pre-trained parameters of the cross-attention in the blip2 Qformer-encoder as the attention parameters in the knn-xattention.
[0080] In this embodiment, the sample image is first input into the first machine learning model and the second machine learning model for feature extraction, respectively, to obtain the first feature length and the second feature length, respectively, wherein the first feature length is less than the second feature length, that is, the feature length extracted by the second machine learning model is greater than the first machine learning model. The similarity between the features included in the first feature length and the features included in the second feature length is calculated to generate a plurality of first similarity results, wherein each similarity result is used to indicate the semantic similarity between the features, and the plurality of first similarity results are screened by a similarity threshold to determine a plurality of second similarity results. The similarity threshold can be adaptively adjusted according to actual conditions. In this embodiment, 0.9 is taken as an example for explanation, and the first similarity result obtained when the similarity exceeds 0.9 is determined as the second similarity result. Thus, the feature length corresponding to the calculated second similarity result is determined as the target feature length, that is, the feature length of the preset variable vector.
[0081] By comparing the similarity of the outputs of the first machine learning model and the second machine learning model, the characteristic length of the preset variable vector can be determined within a certain standard, and the impact on the model output is within a preset range, thereby relatively reducing the characteristic length that needs to be processed.
[0082] Optionally, the first machine learning model includes a first linear layer, a second linear layer, and a third linear layer, and the step S2: generating a first feature vector and a second feature vector based on the image feature sequence, and generating a third feature vector based on a preset variable vector, includes:
[0083] Step S21: inputting the image feature sequence into the first linear layer for linearization processing to generate the first feature vector;
[0084] Step S22: inputting the image feature sequence into the second linear layer for linearization processing to generate the second feature vector;
[0085] Step S23: performing linearization processing on the preset variable vector based on the third linear layer to obtain the third eigenvector.
[0086] In this embodiment, if Figure 3As shown, the first linear layer, the second linear layer and the third linear layer are k_layer, v_layer and q_layer respectively. The first feature vector k_vector and the second feature vector v_vector are generated by inputting the image feature sequence into k_layer and v_layer respectively for linearization processing, and the third feature vector q_vector is generated by inputting the preset variable vector, namely learning-query, into q_layer for linearization processing.
[0087] It should be noted that the characteristic length of the third characteristic vector q_vector is the characteristic length of the preset variable vector determined in the above embodiment.
[0088] Optionally, the step S3: screening the feature length included in the first feature vector and the feature length included in the second feature vector according to the feature length included in the third feature vector to determine the first target feature vector and the second target feature vector, comprises:
[0089] Step S31: determining a third characteristic length corresponding to the first characteristic vector and a fourth characteristic length corresponding to the second characteristic vector;
[0090] Step S32: determining a fifth characteristic length from the third characteristic lengths according to the characteristic lengths included in the third characteristic vector;
[0091] Step S33: determining a sixth characteristic length that is the same as the fifth characteristic length in the fourth characteristic length;
[0092] Step S34: determining the first target feature vector according to the fifth feature length, and determining the second target feature vector according to the sixth feature length.
[0093] In this embodiment, the first feature vector and the second feature vector are screened by the third feature vector, wherein the first feature vector k_vector (dimension [batch_size, seq_len, hidden_size]) includes the third feature length, and the second feature vector v_vector (dimension [batch_size, seq_len, hidden_size]) includes the fourth feature length. The third feature vector q_vector ([batch_size, seq_len, hidden_size]) includes a feature length of X.
[0094] Thus, the fifth characteristic length is determined by screening multiple third characteristic lengths through X. The screening process may be similarity calculation, which is not specifically limited in this embodiment.
[0095] After the fifth characteristic length is determined, a sixth characteristic length that is the same as the fifth characteristic length is determined in the fourth characteristic length, that is, the fifth characteristic length is the same as the sixth characteristic length, thereby ensuring that each characteristic length remains aligned when the first target characteristic vector and the second target characteristic vector are multiplied. Thus, the first target characteristic vector and the second target characteristic vector can be determined.
[0096] Optionally, step S32: determining a fifth characteristic length from the third characteristic length according to the characteristic length included in the third characteristic vector, comprises:
[0097] Step S321: determining the target feature length included in the third feature vector;
[0098] Step S322: respectively calculating the similarity between the features included in the third feature length and the features included in the target feature length, and generating a calculation result, wherein the calculation result includes the plurality of features sorted from high to low in similarity;
[0099] Step S323: determining a plurality of target features from the plurality of features based on the features included in the target feature length;
[0100] Step S324: Generate the fifth characteristic length based on the multiple target features.
[0101] In this embodiment, the fifth feature length is determined from the third feature length by the knn algorithm, wherein the knn algorithm is a basic classification and regression algorithm. In the classification task, the knn algorithm predicts the label of the test sample by finding the k nearest neighbors of the test sample in the feature space, and then predicts the label of the test sample based on the labels of these neighbors. In the regression task, it predicts the result by the average or median of the numerical output of the neighbors.
[0102] Specifically, the multiple features included in the third feature vector are determined, that is, the corresponding features are taken from each position of q_vector (on the dimension of seq_len), and the similarity is calculated with the features included in the target feature length, that is, the features at all positions of k_vector (on the dimension of seq_len), and the calculation results are generated, wherein the calculation results are arranged from large to small according to the similarity. In this way, after knn, the first target feature of the X k_vector features at each position of q_vector, that is, neighbor_k_vector (the dimension is [batch_size, seq_len, topk]), is output.
[0103] It should be noted that the filtering is for the features at each position of q_vector. If there is no filtering, the features at each position of q_vector will correspond to the full amount of k_vector and v_vector. After filtering, the features at each position of q_vector will correspond to the most similar top_k k_vectors and v_vectors.
[0104] Optionally, the step S4: performing attention calculation based on the first target feature vector, the second target feature vector and the third feature vector to generate a target feature vector includes:
[0105] Step S41: multiplying the first target feature vector and the third feature vector to generate a fourth vector;
[0106] Step S42: multiplying the fourth vector by the second target feature vector to generate the target feature vector.
[0107] In this embodiment, if Figure 4 As shown, Figure 4 These are specific implementation steps for attention calculation in the first machine learning model, wherein the first target feature vector neighbor_k_vector and the second target feature vector neighbor_v_vector are determined according to the screening steps in the above embodiment, and a fourth vector is generated by multiplying the first target feature vector and the third feature vector (matmul), and the fourth vector and the second target feature vector neighbor_v_vector are multiplied to finally generate the target feature vector, i.e., the result of attention calculation, attention-score.
[0108] Optionally, the step S42: multiplying the fourth vector by the second target feature vector to generate the target feature vector includes:
[0109] Step S421: normalizing the fourth vector according to the classification problem activation function to generate a fifth vector;
[0110] Step S422: performing regularization processing on the fifth vector to generate a sixth vector;
[0111] Step S423: multiply the sixth vector and the second target feature vector to generate the target feature vector.
[0112] In this embodiment, the fourth vector is also normalized by a classification problem activation function (softmax) to generate a fifth vector, wherein the classification problem activation function Softmax can convert the output of the neural network into a probability distribution. All output values are between 0 and 1, and their sum is 1. This allows the probability vector output by Softmax to be understood as the relative probability of each category, rather than a specific numerical value. Regularization is used to prevent overfitting of the neural network. The sixth vector is generated by regularizing the fifth vector; specifically, a portion of the neurons in the network are randomly "discarded" (i.e., temporarily removed) during the training process. This can reduce the complex co-adaptation relationship between neurons, forcing the network to learn more robust features, thereby improving the generalization ability of the model. Finally, the sixth vector is multiplied by the second target feature vector to generate a target feature vector.
[0113] The present application reduces the features of the first eigenvector and the second eigenvector for attention calculation by filtering the first eigenvector and the second eigenvector generated by the image to be processed through the feature length of a preset variable vector, thereby improving the efficiency of the machine learning model in processing the image.
[0114] See also Figure 5 , Figure 5 is a structural diagram of an image processing device 500 of a multimodal large model provided in an embodiment of the present application. Figure 5 As shown, the image processing device 500 of the multimodal large model includes:
[0115] A processing module 510 is used to generate an image feature sequence according to the image to be processed, wherein the image feature sequence includes at least two slice images obtained after image encoding is performed on the image to be processed;
[0116] A generating module 520, configured to generate a first feature vector and a second feature vector based on the image feature sequence, and to generate a third feature vector based on a preset variable vector, wherein the first feature vector and the second feature vector are feature vectors of the image feature sequence, respectively, and the first feature vector and the second feature vector include different parameter values;
[0117] A screening module 530 is used to screen the feature length included in the first feature vector and the feature length included in the second feature vector according to the feature length included in the third feature vector, and determine a first target feature vector and a second target feature vector, wherein the feature lengths of the first target feature vector and the second target feature vector are the same;
[0118] The calculation module 540 is used to perform attention calculation based on the first target feature vector, the second target feature vector and the third feature vector to generate a target feature vector, wherein the target feature vector is used to characterize the image features of the image to be processed.
[0119] Optionally, also include:
[0120] A sample acquisition module, used for acquiring a sample image;
[0121] a feature extraction module, used for inputting the sample image into the first machine learning model for feature extraction and outputting a first feature length, and inputting the sample image into the second machine learning model for feature extraction and outputting a second feature length, wherein a target model parameter of the second machine learning model is greater than a target model parameter of the first machine learning model, wherein the target model parameter is a feature length obtained after feature extraction is performed on the received image, and the first feature length is less than the second feature length;
[0122] A similarity calculation module, used for calculating the similarity between the features included in the first feature length and the features included in the second feature length, and generating a plurality of first similarity results;
[0123] A similarity screening module, used for screening the plurality of first similarity results according to a similarity threshold value to determine a plurality of second similarity results;
[0124] A determination module is used to determine a target feature length as a feature length of the preset variable vector, wherein the target feature length is determined according to the multiple second similarity results.
[0125] Optionally, the generating module 520 includes:
[0126] A first generating submodule, used for inputting the image feature sequence into the first linear layer for linearization processing to generate the first feature vector;
[0127] Inputting the image feature sequence into the second linear layer for linearization processing to generate the second feature vector;
[0128] The preset variable vector is linearized based on the third linear layer to obtain the third eigenvector.
[0129] Optionally, the screening module 530 includes:
[0130] A first determining submodule, used to determine a third characteristic length corresponding to the first characteristic vector and a fourth characteristic length corresponding to the second characteristic vector;
[0131] A second determining submodule, configured to determine a fifth characteristic length from the third characteristic lengths according to the characteristic lengths included in the third characteristic vector;
[0132] A third determining submodule is used to determine, from the fourth characteristic length, a sixth characteristic length that is the same as the fifth characteristic length;
[0133] The fourth determination submodule is used to determine the first target feature vector according to the fifth feature length, and to determine the second target feature vector according to the sixth feature length.
[0134] Optionally, the second determining submodule includes:
[0135] A first determining unit, used to determine a target feature length included in the third feature vector;
[0136] a calculation unit, configured to respectively calculate similarities between features included in the third feature length and features included in the target feature length, and generate a calculation result, wherein the calculation result includes the plurality of features sorted from high to low in similarity;
[0137] a second determining unit, configured to determine a plurality of target features from among the plurality of features based on features included in the target feature length;
[0138] The first generating unit is used to generate the fifth characteristic length based on the multiple target features.
[0139] Optionally, the calculation module 540 includes:
[0140] A second generating submodule, configured to multiply the first target feature vector and the third feature vector to generate a fourth vector;
[0141] The third generating submodule is used to multiply the fourth vector and the second target feature vector to generate the target feature vector.
[0142] Optionally, the third generation submodule includes:
[0143] A first processing unit, configured to perform normalization processing on the fourth vector according to a classification problem activation function to generate a fifth vector;
[0144] a second processing unit, configured to perform regularization processing on the fifth vector to generate a sixth vector;
[0145] The second generating unit is used to multiply the sixth vector and the second target feature vector to generate the target feature vector.
[0146] The present application reduces the features of the first eigenvector and the second eigenvector for attention calculation by filtering the first eigenvector and the second eigenvector generated by the image to be processed through the feature length of a preset variable vector, thereby improving the efficiency of the machine learning model in processing the image.
[0147] The present application also provides an electronic device. Figure 6 , the electronic device may include a processor 601, a memory 602, and a program 6021 stored in the memory 602 and executable on the processor 601.
[0148] When the program 6021 is executed by the processor 601, it can achieve Figure 1 Any step in the corresponding method embodiment:
[0149] Step S1: generating an image feature sequence according to an image to be processed, wherein the image feature sequence includes at least two slice images obtained after image encoding of the image to be processed;
[0150] Step S2: generating a first feature vector and a second feature vector based on the image feature sequence, and generating a third feature vector based on a preset variable vector, wherein the first feature vector and the second feature vector are feature vectors of the image feature sequence respectively, and the first feature vector and the second feature vector include different parameter values;
[0151] Step S3: screening the feature length included in the first feature vector and the feature length included in the second feature vector according to the feature length included in the third feature vector, and determining a first target feature vector and a second target feature vector, wherein the feature lengths of the first target feature vector and the second target feature vector are the same;
[0152] Step S4: Performing attention calculation based on the first target feature vector, the second target feature vector and the third feature vector to generate a target feature vector, wherein the target feature vector is used to characterize the image features of the image to be processed.
[0153] Optionally, in step S3: screening the feature length included in the first feature vector and the feature length included in the second feature vector according to the feature length included in the third feature vector, and before determining the first target feature vector and the second target feature vector, the method further includes:
[0154] Step S01: obtaining a sample image;
[0155] Step S02: inputting the sample image into the first machine learning model for feature extraction and outputting a first feature length, and inputting the sample image into the second machine learning model for feature extraction and outputting a second feature length, wherein a target model parameter of the second machine learning model is greater than a target model parameter of the first machine learning model, wherein the target model parameter is a feature length obtained after feature extraction of the received image, and the first feature length is less than the second feature length;
[0156] Step S03: calculating the similarity between the features included in the first feature length and the features included in the second feature length, and generating a plurality of first similarity results;
[0157] Step S04: screening the plurality of first similarity results according to a similarity threshold to determine a plurality of second similarity results;
[0158] Step S05: determining a target feature length as the feature length of the preset variable vector, wherein the target feature length is determined according to the plurality of second similarity results.
[0159] Optionally, the first machine learning model includes a first linear layer, a second linear layer, and a third linear layer, and the step S2: generating a first feature vector and a second feature vector based on the image feature sequence, and generating a third feature vector based on a preset variable vector, includes:
[0160] Step S21: inputting the image feature sequence into the first linear layer for linearization processing to generate the first feature vector;
[0161] Step S22: inputting the image feature sequence into the second linear layer for linearization processing to generate the second feature vector;
[0162] Step S23: performing linearization processing on the preset variable vector based on the third linear layer to obtain the third eigenvector.
[0163] Optionally, the step S3: screening the feature length included in the first feature vector and the feature length included in the second feature vector according to the feature length included in the third feature vector to determine the first target feature vector and the second target feature vector, comprises:
[0164] Step S31: determining a third characteristic length corresponding to the first characteristic vector and a fourth characteristic length corresponding to the second characteristic vector;
[0165] Step S32: determining a fifth characteristic length from the third characteristic lengths according to the characteristic lengths included in the third characteristic vector;
[0166] Step S33: determining a sixth characteristic length that is the same as the fifth characteristic length in the fourth characteristic length;
[0167] Step S34: determining the first target feature vector according to the fifth feature length, and determining the second target feature vector according to the sixth feature length.
[0168] Optionally, the step S32: determining a fifth characteristic length from the third characteristic length according to the characteristic length included in the third characteristic vector, comprises:
[0169] Step S321: determining the target feature length included in the third feature vector;
[0170] Step S322: respectively calculating the similarity between the features included in the third feature length and the features included in the target feature length, and generating a calculation result, wherein the calculation result includes the plurality of features sorted from high to low in similarity;
[0171] Step S323: determining a plurality of target features from the plurality of features based on the features included in the target feature length;
[0172] Step S324: Generate the fifth characteristic length based on the multiple target features.
[0173] Optionally, the step S4: performing attention calculation based on the first target feature vector, the second target feature vector and the third feature vector to generate a target feature vector includes:
[0174] Step S41: multiplying the first target feature vector and the third feature vector to generate a fourth vector;
[0175] Step S42: multiplying the fourth vector by the second target feature vector to generate the target feature vector.
[0176] Optionally, the step S42: multiplying the fourth vector by the second target feature vector to generate the target feature vector includes:
[0177] Step S421: normalizing the fourth vector according to the classification problem activation function to generate a fifth vector;
[0178] Step S422: performing regularization processing on the fifth vector to generate a sixth vector;
[0179] Step S423: multiplying the sixth vector and the second target feature vector to generate the target feature vector.
[0180] The present application reduces the features of the first eigenvector and the second eigenvector for attention calculation by screening the first eigenvector and the second eigenvector generated by the image to be processed through a preset variable vector feature number, thereby improving the efficiency of the machine learning model in processing the image.
[0181] The embodiment of the present application also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, each process of the above-mentioned multimodal large model image processing method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it is not repeated here. The computer-readable storage medium is, for example, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0182] An embodiment of the present application further provides a computer program product, which is stored in a storage medium. The computer program product is executed by at least one processor to implement the various processes of the above-mentioned multimodal large model image processing method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0183] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or 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 device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0184] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0185] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
Claims
1. A multi-modal large model image processing method, It is characterized in that Applied to an electronic device, wherein a first machine learning model is deployed on the electronic device, the method comprising: Step S1: generating an image feature sequence according to an image to be processed, wherein the image feature sequence includes at least two slice images obtained after image encoding of the image to be processed; Step S2: generating a first feature vector and a second feature vector based on the image feature sequence, and generating a third feature vector based on a preset variable vector, wherein the first feature vector and the second feature vector are feature vectors of the image feature sequence respectively, and the first feature vector and the second feature vector include different parameter values; Step S3: screening the feature length included in the first feature vector and the feature length included in the second feature vector according to the feature length included in the third feature vector, and determining a first target feature vector and a second target feature vector, wherein the feature lengths of the first target feature vector and the second target feature vector are the same; Step S4: Performing attention calculation based on the first target feature vector, the second target feature vector and the third feature vector to generate a target feature vector, wherein the target feature vector is used to characterize the image features of the image to be processed.
2. The method according to claim 1, It is characterized in that Before the step S3 of screening the feature lengths included in the first feature vector and the feature lengths included in the second feature vector according to the feature lengths included in the third feature vector to determine the first target feature vector and the second target feature vector, the method further includes: Step S01: obtaining a sample image; Step S02: inputting the sample image into the first machine learning model for feature extraction and outputting a first feature length, and inputting the sample image into the second machine learning model for feature extraction and outputting a second feature length, wherein a target model parameter of the second machine learning model is greater than a target model parameter of the first machine learning model, wherein the target model parameter is a feature length obtained after feature extraction of the received image, and the first feature length is less than the second feature length; Step S03: calculating the similarity between the features included in the first feature length and the features included in the second feature length, and generating a plurality of first similarity results; Step S04: screening the plurality of first similarity results according to a similarity threshold to determine a plurality of second similarity results; Step S05: determining a target feature length as the feature length of the preset variable vector, wherein the target feature length is determined according to the plurality of second similarity results.
3. The method according to claim 1, It is characterized in that The first machine learning model includes a first linear layer, a second linear layer and a third linear layer, and the step S2: generating a first feature vector and a second feature vector based on the image feature sequence, and generating a third feature vector based on a preset variable vector, includes: Step S21: inputting the image feature sequence into the first linear layer for linearization processing to generate the first feature vector; Step S22: inputting the image feature sequence into the second linear layer for linearization processing to generate the second feature vector; Step S23: performing linearization processing on the preset variable vector based on the third linear layer to obtain the third eigenvector.
4. The method according to claim 1, It is characterized in that The step S3: screening the feature length included in the first feature vector and the feature length included in the second feature vector according to the feature length included in the third feature vector to determine the first target feature vector and the second target feature vector, comprises: Step S31: determining a third characteristic length corresponding to the first characteristic vector and a fourth characteristic length corresponding to the second characteristic vector; Step S32: determining a fifth characteristic length from the third characteristic lengths according to the characteristic lengths included in the third characteristic vector; Step S33: determining a sixth characteristic length that is the same as the fifth characteristic length in the fourth characteristic length; Step S34: determining the first target feature vector according to the fifth feature length, and determining the second target feature vector according to the sixth feature length.
5. The method according to claim 4, It is characterized in that The step S32: determining a fifth characteristic length from the third characteristic length according to the characteristic length included in the third characteristic vector, comprises: Step S321: determining the target feature length included in the third feature vector; Step S322: respectively calculating the similarity between the features included in the third feature length and the features included in the target feature length, and generating a calculation result, wherein the calculation result includes the plurality of features sorted from high to low in similarity; Step S323: determining a plurality of target features from the plurality of features based on the features included in the target feature length; Step S324: Generate the fifth characteristic length based on the multiple target features.
6. The method according to claim 1, It is characterized in that The step S4: performing attention calculation based on the first target feature vector, the second target feature vector and the third feature vector to generate a target feature vector, comprises: Step S41: multiplying the first target feature vector and the third feature vector to generate a fourth vector; Step S42: multiplying the fourth vector and the second target feature vector to generate the target feature vector.
7. The method according to claim 6, It is characterized in that The step S42: multiplying the fourth vector by the second target feature vector to generate the target feature vector, comprises: Step S421: normalizing the fourth vector according to the classification problem activation function to generate a fifth vector; Step S422: performing regularization processing on the fifth vector to generate a sixth vector; Step S423: multiplying the sixth vector and the second target feature vector to generate the target feature vector.
8. An image processing device, It is characterized in that Applied to an electronic device, wherein a first machine learning model is deployed on the electronic device, the device comprises: A processing module, configured to generate an image feature sequence according to the image to be processed, wherein the image feature sequence includes at least two slice images obtained after image encoding is performed on the image to be processed; A generating module, configured to generate a first feature vector and a second feature vector based on the image feature sequence, and to generate a third feature vector based on a preset variable vector, wherein the first feature vector and the second feature vector are feature vectors of the image feature sequence respectively, and the first feature vector and the second feature vector include different parameter values; A screening module, used for screening the feature length included in the first feature vector and the feature length included in the second feature vector according to the feature length included in the third feature vector, to determine a first target feature vector and a second target feature vector, wherein the feature lengths of the first target feature vector and the second target feature vector are the same; A calculation module is used to perform attention calculation based on the first target feature vector, the second target feature vector and the third feature vector to generate a target feature vector, wherein the target feature vector is used to characterize the image features of the image to be processed.
9. An electronic device, include: A memory, a processor, and a program stored in the memory and executable on the processor; wherein the processor is used to read the program in the memory to implement the steps in the image processing method of a multimodal large model as described in any one of claims 1 to 7.
10. A readable storage medium for storing a program, It is characterized in that When the program is executed by a processor, the steps in the image processing method of a multimodal large model as described in any one of claims 1 to 7 are implemented.
11. A computer program product, It is characterized in that The computer program product is stored in a storage medium, and the computer program product is executed by at least one processor to implement the steps in the image processing method of a multimodal large model according to any one of claims 1 to 7.
Citation Information
Patent Citations
Image feature dimension reduction method and device, electronic equipment and storage medium
CN113298049A
Image classification method and device, computer equipment and storage medium
CN114373098A
Method, device and equipment for annotating image and obtaining image annotation model
CN114782514A
Integrating spatial locality into image transformers with masked attention
US20230103997A1
