Image processing acceleration method, device and product

The tensor decomposition strategy decomposes the data into smaller and sparser matrices and stores them in registers or caches, which solves the problem of large data reading delays in ViT technology and improves image data processing efficiency and calculation speed.

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

Patent Information

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

AI Technical Summary

Technical Problem

During the inference process of ViT technology, the data reading delay is large, resulting in a reduction in the efficiency of the data deduction process. This is mainly because some data need to be stored in shared memory or video memory, which causes a large reading consumption when reading.

Method used

The tensor decomposition strategy is adopted to decompose the input data and residual calculation results into smaller and sparser matrices, which are stored in registers or caches to reduce storage complexity and read through high-bandwidth methods.

Benefits of technology

It reduces the time-consuming data reading process, improves the efficiency of the image data processing process, reduces the computational complexity, and improves the data reasoning speed in ViT technology.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118379372B_ABST
    Figure CN118379372B_ABST
Patent Text Reader

Abstract

The embodiment of the present application provides an image processing acceleration method, device and product, which belongs to the technical field of data processing. The method includes obtaining input data of the encoder after preprocessing the original image, and the encoder performs a tensor decomposition strategy on the input data to obtain a tensor decomposition result and stores it in a register or cache; after the multi-head attention mechanism obtains a first calculation result based on the input data, the tensor decomposition result corresponding to the obtained input data is calculated, and the tensor decomposition strategy is executed on the residual calculation result and the corresponding tensor decomposition result is stored in a register or cache; after the multi-layer perceptron generates a second calculation result based on the residual calculation result, the tensor decomposition result corresponding to the read residual calculation result is calculated to obtain output data. The embodiment of the present application aims to improve the efficiency of the image data processing process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the technical field of data processing, and specifically, to an image processing acceleration method, device, and product. Background Art

[0002] Computer vision is an important branch of artificial intelligence, dedicated to enabling computer systems to understand and interpret image or video data. With the development of computer hardware and algorithms, computer vision has made significant progress in many fields and has been widely used in various fields. Among them, ViT (Visual Transformer) has gradually developed into an important technology in this field since its proposal. It has now become one of the mainstream methods for tasks such as image classification, target detection, and image generation.

[0003] However, during the inference process of ViT technology, part of the data needs to be stored in shared memory or video memory when the encoder performs data inference operations. When needed in subsequent inference processes, this part of the data is taken out from the shared memory or video memory for calculation. The reading consumption and delay caused by reading this part of the data are large, which reduces the efficiency of the data inference process of ViT technology. Summary of the invention

[0004] The embodiments of the present application provide an image processing acceleration method, device and product, aiming to improve the efficiency of the image data processing process.

[0005] In a first aspect, an embodiment of the present application provides an image processing acceleration method, the method comprising:

[0006] Acquire preprocessed data obtained after preprocessing the original image, use the preprocessed data as input data of the encoder, execute the processing process of the encoder, and generate a classification result of the original image according to the final output data of the encoder;

[0007] The processing of the encoder includes:

[0008] Execute a tensor decomposition strategy on the input data, generate a tensor decomposition result corresponding to the input data and store it in a register or a cache, and obtain a first calculation result based on the input data, where the first calculation result is a result generated by a multi-head attention mechanism in the encoder;

[0009] Obtaining a tensor decomposition result corresponding to the input data and performing residual calculation on the first calculation result, executing a tensor decomposition strategy on the obtained residual calculation result, generating a tensor decomposition result corresponding to the residual calculation result and storing the result in the register or the cache;

[0010] The multilayer perceptron in the encoder generates a second calculation result according to the residual calculation result, obtains a tensor decomposition result corresponding to the residual calculation result in the register or the cache, and calculates the second calculation result to obtain output data;

[0011] The tensor decomposition strategy is used to reduce the number of matrix elements corresponding to the input data or the residual calculation results, so as to reduce the storage complexity of the input data or the residual calculation results.

[0012] Optionally, before obtaining the preprocessed data obtained after preprocessing the original image, the method further includes:

[0013] Acquire the original image, generate multiple image blocks of the original image, and add a classification mark to each of the multiple image blocks;

[0014] The preprocessed data is obtained according to the multiple image blocks and the position encoding data after adding the classification marks.

[0015] Optionally, obtaining a first calculation result according to the input data includes:

[0016] After normalizing the input data, a three-dimensional tensor is generated, wherein the three-dimensional tensor includes a first tensor Q, a second tensor K, and a third tensor V;

[0017] The three-dimensional tensor is input into the multi-head attention mechanism to obtain the first calculation result.

[0018] Optionally, inputting the three-dimensional tensor into the multi-head attention mechanism to obtain the first calculation result includes:

[0019] Execute a tensor decomposition strategy on the third tensor V, generate a tensor decomposition result corresponding to the third tensor V and store it in a register or a cache;

[0020] Obtain a third calculation result according to the first tensor Q and the second tensor K;

[0021] The first calculation result is calculated based on the tensor decomposition result corresponding to the third tensor V read from the register or cache and the third calculation result.

[0022] Optionally, the second calculation result generated by the multilayer perceptron in the encoder according to the residual calculation result includes:

[0023] Normalizing the residual calculation result;

[0024] The normalized residual calculation result is input into the multi-layer perceptron to obtain the second calculation result.

[0025] Optionally, perform a tensor decomposition strategy, including:

[0026] Obtain any data to be decomposed, and determine the dimension of the data to be decomposed, wherein the data to be decomposed includes the input data, the residual calculation result, and the third tensor V;

[0027] When the data to be decomposed is two-dimensional data, a shape transformation operation is performed to obtain three-dimensional data to be decomposed;

[0028] A tensor decomposition process is performed on the three-dimensional data to be decomposed to obtain a tensor decomposition result corresponding to the data to be decomposed.

[0029] Optionally, the formula for performing the shape transformation operation is:

[0030]

[0031] In the formula, is two-dimensional data to be decomposed; is three-dimensional data to be decomposed; ; .

[0032] Optionally, performing a tensor decomposition process on the three-dimensional data to be decomposed to obtain a tensor decomposition result corresponding to the data to be decomposed includes:

[0033] A quantized tensor column decomposition process is performed on the three-dimensional data to be decomposed to obtain a tensor decomposition result corresponding to the data to be decomposed.

[0034] Optionally, performing a quantized tensor column decomposition process on the three-dimensional data to be decomposed to obtain a tensor decomposition result corresponding to the data to be decomposed includes:

[0035] Performing an element supplement operation on the three-dimensional data to be decomposed to obtain a target three-dimensional tensor;

[0036] Quantizing the target three-dimensional tensor to obtain a target tensor;

[0037] The target tensor is decomposed into a tensor column to obtain a tensor decomposition result corresponding to the data to be decomposed.

[0038] Optionally, performing an element supplement operation on the three-dimensional data to be decomposed to obtain a target three-dimensional tensor includes:

[0039] The three-dimensional data to be decomposed The added 0 element in the target three-dimensional tensor is obtained. The number of elements in the three dimensions is 256, 16, and 64, respectively.

[0040] Optionally, the target three-dimensional tensor is quantized to obtain a target tensor by:

[0041]

[0042] in:

[0043]

[0044] Among them, the target tensor is .

[0045] Optionally, the target tensor is decomposed into tensor columns to obtain a tensor decomposition result corresponding to the data to be decomposed:

[0046]

[0047] In the formula, The scale is The three-dimensional tensor ; is the rank of the quantized tensor column decomposition; Kernel for the decomposition of the quantized tensor array.

[0048] Optionally, performing a tensor decomposition process on the three-dimensional data to be decomposed to obtain a tensor decomposition result corresponding to the data to be decomposed includes:

[0049] A Tucker tensor decomposition process is performed on the three-dimensional data to be decomposed to obtain a tensor decomposition result corresponding to the data to be decomposed.

[0050] Optionally, performing a tensor decomposition process on the three-dimensional data to be decomposed to obtain a tensor decomposition result corresponding to the data to be decomposed includes:

[0051] A tensor column decomposition process is performed on the three-dimensional data to be decomposed to obtain a tensor decomposition result corresponding to the data to be decomposed.

[0052] Optionally, the method further comprises:

[0053] The output data of the encoder is used as the input data of the encoder, and after the processing process of the encoder is iterated a target number of times, the final output data of the encoder is obtained.

[0054] Optionally, generating a classification result of the original image according to the final output data of the encoder includes:

[0055] After the final output data of the encoder is input into the multi-layer perception head for processing, the classification result of the original image is output.

[0056] In a second aspect, an embodiment of the present application provides an image processing acceleration device, the device comprising:

[0057] An image classification module is used to obtain preprocessed data obtained after preprocessing the original image, use the preprocessed data as input data of the encoder, execute the processing process of the encoder, and generate a classification result of the original image according to the final output data of the encoder;

[0058] The image classification module includes an encoder processing module, and the encoder processing module is used to:

[0059] Execute a tensor decomposition strategy on the input data, generate a tensor decomposition result corresponding to the input data and store it in a register or a cache, and obtain a first calculation result based on the input data, where the first calculation result is a result generated by a multi-head attention mechanism in the encoder;

[0060] Obtaining a tensor decomposition result corresponding to the input data and performing residual calculation on the first calculation result, executing a tensor decomposition strategy on the obtained residual calculation result, generating a tensor decomposition result corresponding to the residual calculation result and storing the result in the register or the cache;

[0061] The multilayer perceptron in the encoder generates a second calculation result according to the residual calculation result, obtains a tensor decomposition result corresponding to the residual calculation result in the register or the cache, and calculates the second calculation result to obtain output data;

[0062] The tensor decomposition strategy is used to reduce the input data or the residual calculation result corresponding to each

[0063] In a third aspect, an embodiment of the present application provides a computer device, comprising: at least one processor, and a memory, wherein the memory stores a computer program that can be run on the processor, wherein when the processor executes the computer program, the image processing acceleration method described in the first aspect of the embodiment is performed.

[0064] In a fourth aspect, an embodiment of the present application provides a non-volatile readable storage medium, wherein the non-volatile readable storage medium stores a computer program, wherein when the computer program is executed by a processor, the image processing acceleration method described in the first aspect of the embodiment is executed.

[0065] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the image processing acceleration method described in the first aspect of the embodiment.

[0066] Beneficial effects:

[0067] In this method, preprocessed data obtained after preprocessing the original image is obtained, the preprocessed data is used as input data of the encoder, the processing process of the encoder is executed, and the classification result of the original image is generated according to the final output data of the encoder.

[0068] During the processing of the encoder, a tensor decomposition strategy is executed on the input data, a tensor decomposition result corresponding to the input data is generated and stored in a register or a cache, and then the tensor decomposition result corresponding to the input data is obtained, and residual calculation is performed with the first calculation result generated according to the multi-head attention mechanism to obtain a residual calculation result; a tensor decomposition strategy is executed on the obtained residual calculation result, and a tensor decomposition result corresponding to the residual calculation result is generated and stored in the register or the cache, and then after obtaining a second calculation result generated by the multi-layer perceptron in the encoder according to the residual calculation result, the tensor decomposition result of the residual calculation result is read from the register or the cache and the second calculation result is calculated to obtain output data.

[0069] That is, during the image classification process, this method executes a tensor decomposition strategy for the data that needs to be temporarily stored. The tensor decomposition strategy can reduce the number of matrix elements corresponding to the input data or the residual calculation results, so as to reduce the storage complexity of the input data or the residual calculation results. The storage space occupied by the result after tensor decomposition is smaller and can be stored in a register or a cache and read in a high-bandwidth manner, thereby reducing the time consumption of the reading process and improving the efficiency of the image data processing process in the ViT technology. BRIEF DESCRIPTION OF THE DRAWINGS

[0070] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art.

[0071] Figure 1 A schematic diagram showing a data processing process of a related encoder provided in an embodiment of the present application is shown;

[0072] Figure 2 A schematic diagram of executing the image processing acceleration method provided in an embodiment of the present application is shown;

[0073] Figure 3 A flowchart showing the steps of the image processing acceleration method provided by an embodiment of the present application is shown;

[0074] Figure 4 A flowchart showing the steps of the processing process of the encoder provided in an embodiment of the present application is shown;

[0075] Figure 5 A flowchart of the steps of executing a tensor decomposition strategy provided by an embodiment of the present application is shown;

[0076] Figure 6 A schematic diagram of executing the image processing acceleration method provided by an embodiment of the present application is shown;

[0077] Figure 7 A functional module diagram of an image processing acceleration device provided in an embodiment of the present application is shown;

[0078] Figure 8 A schematic diagram of a computer device provided in an embodiment of the present application is shown;

[0079] Fig. 9 A schematic diagram of a non-volatile readable storage medium provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0080] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.

[0081] To make the purpose, technical scheme and advantages of the embodiments of the present application clearer, each embodiment of the present application will be described in detail below in conjunction with the accompanying drawings. However, it will be appreciated by those skilled in the art that in each embodiment of the present application, many technical details are proposed in order to enable the reader to better understand the present application. However, even without these technical details and various changes and modifications based on the following embodiments, the technical scheme claimed in the present application can also be implemented. The division of the following embodiments is for the convenience of description, and the specific implementation of the present application should not constitute any limitation, and the various embodiments can be combined with each other and referenced to each other without contradiction.

[0082] Computer vision is an important branch of artificial intelligence, dedicated to enabling computer systems to understand and interpret image or video data. With the development of computer hardware and algorithms, computer vision has made significant progress in many fields and has been widely used in industry, medical care, security monitoring, autonomous driving, virtual reality and other fields.

[0083] Since its proposal, ViT technology has gradually developed into an important technology in this field. It has become one of the mainstream methods for tasks such as image classification, target detection, and image generation. ViT technology processes images into sequence data, captures spatial and temporal information in images through the self-attention mechanism of the Transformer encoder, and captures the position information of images through position encoding, thereby continuously learning and updating the corresponding parameter model in subsequent processing units.

[0084] Reference Figure 1, showing a schematic diagram of the data processing process of the relevant encoder. The data input to the encoder must first be normalized and processed by the multi-head attention mechanism, and then the processed data and the original data are subjected to residual processing. In the actual application process, when the original data is normalized and processed by the multi-head attention mechanism, the original data will be stored in the shared memory or even the video memory. After the operation of the multi-head attention mechanism is completed, the original data is read from the storage location in the shared memory or the video memory and added to it for residual processing.

[0085] Similarly, when the residual result obtained for the first time enters the normalization and multi-layer perceptron MLP processing, the residual result obtained for the first time will also be stored in the shared memory or even the video memory. After the operation of the multi-layer perceptron MLP is completed, the residual result obtained for the first time is read from the storage location in the shared memory or the video memory and added to obtain the second residual result.

[0086] In the multi-head attention mechanism, the original data is divided into three matrix data Q, K, and V. First, the transpose of Q and K is multiplied, and then the result is divided by a constant , followed by softmax processing. During this series of operations, the data of V is temporarily stored in the shared memory or even the video memory, and is retrieved from the storage location for subsequent operations after the operations are completed.

[0087] Therefore, in the current ViT technology, during the inference process, when the encoder performs data inference operations, part of the data needs to be stored in shared memory or video memory, and then taken out from the shared memory or video memory for calculation when needed in the subsequent inference process. However, the reading consumption and delay caused by reading this part of the data are large, which reduces the efficiency of the data inference process of ViT technology.

[0088] Therefore, in order to improve the efficiency of the image data processing process, an embodiment of the present application provides an image processing acceleration method.

[0089] Reference Figure 2 , shows a schematic diagram of the execution of the image processing acceleration method provided in an embodiment of the present application, after the original image is preprocessed, the preprocessed data is used as the input data of the encoder; in the encoder, after the tensor decomposition strategy is executed on the input data, the tensor decomposition result corresponding to the input data is stored in a register or a cache.

[0090] After the multi-head attention mechanism in the encoder obtains a first calculation result based on the input data processing, it reads a tensor decomposition result corresponding to the input data in a register or a cache, performs residual calculation on the first calculation result and the tensor decomposition result corresponding to the input data, and generates a residual calculation result.

[0091] The tensor decomposition strategy is executed again on the residual calculation result, and the tensor decomposition result corresponding to the residual calculation result is stored in a register or a cache.

[0092] After the multilayer perceptron in the encoder generates a second calculation result based on the residual calculation result, it obtains the tensor decomposition result corresponding to the residual calculation result in the register or cache, and performs residual calculation on the second result and the tensor decomposition result corresponding to the residual calculation result to generate the output data of the encoder this time.

[0093] The tensor decomposition strategy can reduce the number of matrix elements corresponding to the input data or the residual calculation results, so as to reduce the storage complexity of the input data or the residual calculation results. The result after tensor decomposition occupies a smaller storage space and can be stored in a register or cache and read in a high-bandwidth manner, thereby reducing the time consumption of the reading process; and because the number of matrix elements after tensor decomposition is reduced, the calculation complexity can also be reduced when performing operations based on the tensor decomposition results of any data, thereby speeding up the data processing process.

[0094] In the actual implementation process, the encoder can be iterated multiple times to obtain the final output data of the encoder, and the final output data of the encoder is input into the multi-layer perception head, that is, after being processed by the MLP Head, the classification result of the original image is output.

[0095] Reference Figure 3 , shows a flowchart of a method for accelerating image processing provided by an embodiment of the present application, the method may include the following steps:

[0096] S101: Obtain preprocessed data obtained after preprocessing the original image.

[0097] After acquiring the original image, the original image is first preprocessed, and the preprocessing process includes: after acquiring the original image, generating multiple image blocks of the original image, and adding a classification mark to each of the multiple image blocks; and obtaining the preprocessed data according to the multiple image blocks and the position coding data after adding the classification mark.

[0098] For example, the original image is a 224*224 image. First, the flattenpatches process is performed on the 224*224 original image, that is, the 224*224 original image is processed into 14*14=196 image blocks through a 16*16 convolution kernel, thereby converting the original image into sequence data; then a classification tag classtoken for classification is added to each image block. The class token is a classification record added to the original image. The class token is used as a parameter to obtain the optimal parameter data through learning, and is used to predict the final classification result of the image.

[0099] After adding classification tokens to the 196 image blocks respectively, the preprocessed data is obtained by adding them to the positional encoding data. The preprocessed data is used as input data and input into the encoder, that is, into the Transformer encoder.

[0100] S102: Using the preprocessed data as input data of an encoder, and executing a processing process of the encoder.

[0101] Reference Figure 4 , shows a flowchart of the steps of the processing process of the encoder provided in an embodiment of the present application. In a feasible implementation manner, the processing process of the encoder includes the following steps:

[0102] S1: Execute a tensor decomposition strategy on the input data, generate a tensor decomposition result corresponding to the input data and store it in a register or cache, and obtain a first calculation result based on the input data, where the first calculation result is a result generated by a multi-head attention mechanism in the encoder.

[0103] When the input data is input into the encoder, the tensor decomposition strategy is first executed on the input data. The tensor decomposition strategy can decompose the data into smaller and sparser representation methods, and the data after tensor decomposition occupies less space. The tensor decomposition result can be stored in a register or cache. When the tensor decomposition result needs to be read, it can be read in a high-bandwidth manner, reducing the time consumption of the reading process and improving the efficiency of the data processing process.

[0104] Then, the input data is normalized, and then a three-dimensional tensor is generated according to the normalized input data, where the three-dimensional tensor includes a first tensor Q, a second tensor K, and a third tensor V.

[0105] For example, the preprocessed input data is a 197*768 matrix A. After normalization, it is multiplied with a weight matrix of 768*2304 to obtain a 197*2304 matrix. After adding the bias vector and then undergoing shape transformation, the first tensor Q, the second tensor K, and the third tensor V, all of which are 12*197*64 in size, are obtained.

[0106] Then, the three-dimensional tensor is input into the multi-head attention mechanism to obtain the first calculation result. Specifically, the tensor decomposition strategy is first executed on the third tensor V to generate a tensor decomposition result corresponding to the third tensor V and store it in a register or cache; based on the first tensor Q and the second tensor K, the third calculation result is obtained.

[0107] For example, in the multi-head attention mechanism, the first tensor Q and the transpose of the second tensor K are first multiplied, the product is divided by a constant, and then processed by softmax to obtain the third calculation result.

[0108] Next, the first calculation result is calculated based on the tensor decomposition result corresponding to the third tensor V read from the register or cache and the third calculation result.

[0109] S2: Obtain a tensor decomposition result corresponding to the input data and perform residual calculation on the first calculation result, execute a tensor decomposition strategy on the obtained residual calculation result, generate a tensor decomposition result corresponding to the residual calculation result and store it in the register or the cache.

[0110] After obtaining the first calculation result output by the multi-head attention mechanism, first read the tensor decomposition result corresponding to the input data in the register or cache, perform residual calculation on the tensor decomposition result corresponding to the input data and the first calculation result to obtain the residual calculation result.

[0111] Then, a tensor decomposition strategy is executed on the residual calculation result, and a tensor decomposition result corresponding to the residual calculation result is stored in a register or a cache.

[0112] S3: The multilayer perceptron in the encoder generates a second calculation result according to the residual calculation result, obtains a tensor decomposition result corresponding to the residual calculation result in the register or the cache, and calculates output data with the second calculation result.

[0113] According to the residual calculation result, a second calculation result is output through a multi-layer perceptron in the encoder. Specifically, the residual calculation result is normalized and then input into the multi-layer perceptron MLP to obtain the second calculation result output by the MLP.

[0114] After obtaining the second calculation result output by the MLP, the tensor decomposition result corresponding to the residual calculation result is read from the register or cache, and the tensor decomposition result corresponding to the residual calculation result and the second calculation result are subjected to residual calculation to obtain the output data of the encoder.

[0115] In the actual implementation process, the output data of the encoder can be used as the input data of the encoder. After iterating the processing process of the encoder for a target number of times, the final output data of the encoder can be obtained, that is, the parameters in the encoder are updated through multiple iterations to obtain the optimal parameters of the encoder, thereby improving the accuracy of the encoder; for example, the target number of times can be set to 12 times.

[0116] Reference Figure 5 , shows a flowchart of the steps of executing the tensor decomposition strategy provided by an embodiment of the present application. In a feasible implementation, the following steps may be included when executing the tensor decomposition strategy:

[0117] A1: Get any data to be decomposed and determine the dimension of the data to be decomposed.

[0118] During the processing of the encoder, any data that needs to be stored temporarily so as to participate in the subsequent inference processing process can be used as data to be decomposed. For example, the data to be decomposed includes the input data, the residual calculation result and the third tensor V.

[0119] When performing tensor decomposition on any data to be decomposed, it is first necessary to determine the dimension of the data to be decomposed. If the data to be decomposed is two-dimensional data, the two-dimensional data to be decomposed needs to be converted into three-dimensional data to be decomposed first; if the data to be decomposed is three-dimensional data, the tensor decomposition process can be directly executed.

[0120] A2: When the data to be decomposed is two-dimensional data, a shape transformation operation is performed to obtain three-dimensional data to be decomposed.

[0121] Specifically, a shape transformation operation, i.e., a reshape operation, is performed on the two-dimensional data to be decomposed, and the arrangement positions of the elements in the data to be decomposed are changed. The formula for performing the shape transformation operation is:

[0122]

[0123] In the formula, is two-dimensional data to be decomposed; is three-dimensional data to be decomposed; ; .

[0124] For example, the input data is a 197*768 matrix, and through the shape transformation operation, a 197*12*64 three-dimensional tensor is obtained.

[0125] A3: Execute a tensor decomposition process on the three-dimensional data to be decomposed to obtain a tensor decomposition result corresponding to the data to be decomposed.

[0126] In actual application, any one of the quantized tensor column decomposition process, the Tucker tensor decomposition process, and the tensor column decomposition process can be used to perform the tensor decomposition process on the three-dimensional data to be decomposed to obtain the tensor decomposition result corresponding to the data to be decomposed, which can be selected according to actual application requirements.

[0127] In this embodiment, a quantized tensor column decomposition process is used to perform a tensor decomposition process on three-dimensional data to be decomposed. The process is as follows:

[0128] First, an element supplement operation is performed on the three-dimensional data to be decomposed to obtain a target three-dimensional tensor.

[0129] The three-dimensional data to be decomposed The added 0 element in the target three-dimensional tensor is obtained. The number of elements in the three dimensions is 256, 16, and 64, respectively.

[0130] Then, the target three-dimensional tensor is quantized to obtain a target tensor.

[0131] During the quantization process, the number of elements in the target three-dimensional tensor remains unchanged, only the position arrangement of the elements in the target three-dimensional tensor is changed, and the target three-dimensional tensor is rearranged into a target tensor of 2*2*...*2 :

[0132]

[0133] The left side of the equation is the target three-dimensional tensor The corresponding indicator is The right side of the equation is the target tensor The corresponding indicator is elements that satisfy:

[0134] ;

[0135] in, i , j and k The m in each expression is i , j and k The corresponding indicator after quantification of each dimension.

[0136] Finally, the target tensor is decomposed into tensor columns to obtain a tensor decomposition result corresponding to the data to be decomposed.

[0137] The tensor decomposition result obtained by performing tensor column decomposition on the target tensor can be expressed as:

[0138]

[0139] In the formula, is the rank of the quantized tensor column decomposition; The kernel for the decomposition of the quantized tensor sequence;

[0140] Furthermore, for the convenience of representation, the tensor decomposition result can be compactly expressed as:

[0141]

[0142] In the formula, The scale is The three-dimensional tensor , is the boundary condition.

[0143] If any quantity It can be expressed as the above formula, then the above formula can be called a tensor The rank of The quantized tensor column decomposition representation of The complexity can be given by Reduce to .

[0144] in, .

[0145] The storage complexity of a quantized tensor column decomposition is logarithmically dependent on the original size of each dimension of the tensor. , and because After decomposition, a very small number is obtained, so compared with the original data scale of the tensor, the tensor decomposition strategy can reduce the number of matrix elements corresponding to the input data, the residual calculation results and the third tensor V, so as to reduce the storage complexity of the input data, the residual calculation results and the third tensor V. After the quantized tensor column is decomposed, the storage complexity of the data is greatly reduced, thereby occupying very little storage space, thereby reducing the pressure on the large storage space requirement during the encoder's reasoning process.

[0146] S103: Generate a classification result of the original image according to the final output data of the encoder.

[0147] After the encoder obtains the final output data, the final output data is processed by the MLP Head and the classification result of the original image can be output.

[0148] Reference Figure 6, shows a schematic diagram of executing the image processing acceleration method provided in an embodiment of the present application, the method comprising the following processes:

[0149] B1: Get the original image and preprocess it to obtain the preprocessed data as the input data of the encoder.

[0150] B2: Execute the tensor decomposition strategy on the input data, generate the tensor decomposition results corresponding to the input data and store them in registers or cache.

[0151] B3: After normalizing the input data, the first tensor Q, the second tensor K and the third tensor V are generated and then input into the multi-head attention mechanism.

[0152] B4: Execute the tensor decomposition strategy on the third tensor V, generate a tensor decomposition result corresponding to the third tensor V and store it in a register or cache.

[0153] B5: In the multi-head attention mechanism, the third calculation result is obtained based on the first tensor Q and the second tensor K.

[0154] B6: Read the tensor decomposition result corresponding to the third tensor V in the register or cache, and multiply it by the third calculation result to obtain the first calculation result.

[0155] B7: Read the tensor decomposition result corresponding to the input data in the register or cache, perform residual calculation on the first calculation result, and obtain the residual calculation result.

[0156] B8: Execute a tensor decomposition strategy on the residual calculation result, generate a tensor decomposition result corresponding to the residual calculation result and store it in a register or cache.

[0157] B9: After normalizing the residual calculation result, it is input into the multi-layer perceptron to obtain the second calculation result output by the multi-layer perceptron.

[0158] B10: Read the tensor decomposition result corresponding to the residual calculation result in the register or cache, perform residual calculation with the second calculation result, and obtain the output data of the encoder.

[0159] B11: Take the output data of the encoder as the input result, iterate the target number of times, and then output the final output data of the encoder.

[0160] B12: After the final output data of the encoder is processed through the layer structure used for classification, the classification result of the original image is obtained.

[0161] The image processing acceleration method provided by this method has at least the following beneficial effects:

[0162] 1. When processing images in ViT technology, based on the image composed of pixels, the matrix composed of pixels can be converted into tensor form, and the complex matrix can be decomposed into a matrix with less complexity using tensor decomposition method; especially when processing high-resolution images, by decomposing the complex matrix into smaller and sparser representation methods, the number of model parameters can be effectively reduced;

[0163] 2. In the process of image processing, the tensor decomposition method is used to process data, which can significantly reduce the complexity of calculation in the subsequent matrix multiplication operation, thereby speeding up the reasoning speed of the model. In addition, in the repeated iterations of the entire reasoning process, the performance of the overall data reasoning process will be significantly improved as the number of iterations accumulates;

[0164] 3. The data in ViT technology has a great demand for storage space, and the data that is not temporarily involved in the calculation needs to be stored in the shared memory or video memory. When needed in the subsequent reasoning process, this part of the data is taken out from the shared memory or video memory for calculation. However, the reading consumption and delay caused by reading this part of the data are large. This method can not only reduce the storage space occupation by decomposing the data that is not temporarily involved in the calculation into tensors, but also store the data in registers or caches. When reading, it can be read in a high-bandwidth manner, which can reduce the time consumption of the data reading process and further improve the efficiency of the image data processing process.

[0165] Reference Figure 7 , shows a functional module diagram of an image processing acceleration device provided in an embodiment of the present application, the device comprising:

[0166] The image classification module 100 is used to obtain preprocessed data obtained after preprocessing the original image, use the preprocessed data as input data of the encoder, execute the processing of the encoder, and generate a classification result of the original image according to the final output data of the encoder;

[0167] The image classification module 100 includes an encoder processing module 101, and the encoder processing module 101 is used to:

[0168] Execute a tensor decomposition strategy on the input data, generate a tensor decomposition result corresponding to the input data and store it in a register or a cache, and obtain a first calculation result based on the input data, where the first calculation result is a result generated by a multi-head attention mechanism in the encoder;

[0169] Obtaining a tensor decomposition result corresponding to the input data and performing residual calculation on the first calculation result, executing a tensor decomposition strategy on the obtained residual calculation result, generating a tensor decomposition result corresponding to the residual calculation result and storing the result in the register or the cache;

[0170] Obtain a tensor decomposition result corresponding to the residual calculation result and perform residual calculation on the second calculation result to obtain output data, wherein the second calculation result is a result generated by a multilayer perceptron in the encoder according to the residual calculation result.

[0171] Optionally, the device further comprises a preprocessing module, wherein the preprocessing module is used for:

[0172] Acquire the original image, generate multiple image blocks of the original image, and add a classification mark to each of the multiple image blocks;

[0173] The preprocessed data is obtained according to the multiple image blocks and the position encoding data after adding the classification marks.

[0174] Optionally, the encoder processing module includes a first calculation result generating unit, and the first calculation result generating unit is used to:

[0175] After normalizing the input data, a three-dimensional tensor is generated, wherein the three-dimensional tensor includes a first tensor Q, a second tensor K, and a third tensor V;

[0176] The three-dimensional tensor is input into the multi-head attention mechanism to obtain the first calculation result.

[0177] Optionally, the first calculation result generating unit includes:

[0178] The first calculation result generating subunit is used to execute the tensor decomposition strategy on the third tensor V, generate the tensor decomposition result corresponding to the third tensor V and store it in a register or a cache; obtain the third calculation result according to the first tensor Q and the second tensor K; and calculate the first calculation result according to the tensor decomposition result corresponding to the third tensor V read in the register or the cache and the third calculation result.

[0179] Optionally, the encoder processing module includes a second calculation result generating unit, and the second calculation result generating unit is used to:

[0180] After normalizing the residual calculation result, the residual calculation result is input into the multi-layer perceptron to obtain the second calculation result.

[0181] Optionally, the encoder processing module comprises a tensor decomposition unit, and the tensor decomposition unit is used to:

[0182] Obtain any data to be decomposed, and determine the dimension of the data to be decomposed, wherein the data to be decomposed includes the input data, the residual calculation result, and the third tensor V;

[0183] When the data to be decomposed is two-dimensional data, a shape transformation operation is performed to obtain three-dimensional data to be decomposed;

[0184] A tensor decomposition process is performed on the three-dimensional data to be decomposed to obtain a tensor decomposition result corresponding to the data to be decomposed.

[0185] Optionally, the tensor decomposition unit is further used for:

[0186] A quantized tensor column decomposition process is performed on the three-dimensional data to be decomposed to obtain a tensor decomposition result corresponding to the data to be decomposed.

[0187] Optionally, the tensor decomposition unit is further used for:

[0188] Performing an element supplement operation on the three-dimensional data to be decomposed to obtain a target three-dimensional tensor;

[0189] Quantizing the target three-dimensional tensor to obtain a target tensor;

[0190] The target tensor is decomposed into a tensor column to obtain a tensor decomposition result corresponding to the data to be decomposed.

[0191] Optionally, the tensor decomposition unit is further used for:

[0192] A Tucker tensor decomposition process is performed on the three-dimensional data to be decomposed to obtain a tensor decomposition result corresponding to the data to be decomposed.

[0193] Optionally, the tensor decomposition unit is further used for:

[0194] A tensor column decomposition process is performed on the three-dimensional data to be decomposed to obtain a tensor decomposition result corresponding to the data to be decomposed.

[0195] Optionally, the encoder processing module is used to: use the output data of the encoder as the input data of the encoder, and obtain the final output data of the encoder after iterating the processing process of the encoder for a target number of times.

[0196] An embodiment of the present application also provides an image processing model, which includes an encoder and is used to execute the image processing acceleration method described in the embodiment.

[0197] Reference Figure 8, shows a schematic diagram of a computer device provided in an embodiment of the present application, the computer device comprising: at least one processor 801, and a memory 802, the memory 802 storing a computer program that can be run on the processor 801, wherein the processor 701 executes the image processing acceleration method described in the embodiment when executing the computer program, including: obtaining preprocessed data obtained after preprocessing the original image, using the preprocessed data as input data of the encoder, executing the processing process of the encoder, and generating a classification result of the original image according to the final output data of the encoder.

[0198] Among them, the processing process of the encoder includes: executing a tensor decomposition strategy on the input data, generating a tensor decomposition result corresponding to the input data and storing it in a register or a cache, and obtaining a first calculation result based on the input data, wherein the first calculation result is the result generated by the multi-head attention mechanism in the encoder; obtaining a tensor decomposition result corresponding to the input data and performing residual calculation on the first calculation result, executing a tensor decomposition strategy on the obtained residual calculation result, generating a tensor decomposition result corresponding to the residual calculation result and storing it in the register or the cache; obtaining a tensor decomposition result corresponding to the residual calculation result and performing residual calculation on the second calculation result to obtain output data, wherein the second calculation result is the result generated by the multilayer perceptron in the encoder based on the residual calculation result.

[0199] Reference Fig. 9 , shows a schematic diagram of a non-volatile readable storage medium provided in an embodiment of the present application, wherein the non-volatile readable storage medium 900 stores a computer program 901, wherein the computer program 901, when executed by a processor, performs the image processing acceleration method described in the embodiment, including: obtaining preprocessed data obtained after preprocessing the original image, using the preprocessed data as input data of an encoder, executing the processing process of the encoder, and generating a classification result of the original image according to the final output data of the encoder.

[0200] Among them, the processing process of the encoder includes: executing a tensor decomposition strategy on the input data, generating a tensor decomposition result corresponding to the input data and storing it in a register or a cache, and obtaining a first calculation result based on the input data, wherein the first calculation result is the result generated by the multi-head attention mechanism in the encoder; obtaining a tensor decomposition result corresponding to the input data and performing residual calculation on the first calculation result, executing a tensor decomposition strategy on the obtained residual calculation result, generating a tensor decomposition result corresponding to the residual calculation result and storing it in the register or the cache; obtaining a tensor decomposition result corresponding to the residual calculation result and performing residual calculation on the second calculation result to obtain output data, wherein the second calculation result is the result generated by the multilayer perceptron in the encoder based on the residual calculation result.

[0201] An embodiment of the present application also provides a computer program product, which includes a computer program / instructions. When the computer program / instructions are executed by a processor, the image processing acceleration method described in the embodiment is implemented, including: obtaining preprocessed data obtained after preprocessing the original image, using the preprocessed data as input data of an encoder, executing the processing process of the encoder, and generating a classification result of the original image based on the final output data of the encoder.

[0202] Among them, the processing process of the encoder includes: executing a tensor decomposition strategy on the input data, generating a tensor decomposition result corresponding to the input data and storing it in a register or a cache, and obtaining a first calculation result based on the input data, wherein the first calculation result is the result generated by the multi-head attention mechanism in the encoder; obtaining a tensor decomposition result corresponding to the input data and performing residual calculation on the first calculation result, executing a tensor decomposition strategy on the obtained residual calculation result, generating a tensor decomposition result corresponding to the residual calculation result and storing it in the register or the cache; obtaining a tensor decomposition result corresponding to the residual calculation result and performing residual calculation on the second calculation result to obtain output data, wherein the second calculation result is the result generated by the multilayer perceptron in the encoder based on the residual calculation result.

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

[0204] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, devices, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

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

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

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

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

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

[0210] Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. An image processing acceleration method, characterized in that: The method comprises: Acquire preprocessed data obtained after preprocessing the original image, use the preprocessed data as input data of the encoder, execute the processing process of the encoder, and generate a classification result of the original image according to the final output data of the encoder; The processing of the encoder includes: Execute a tensor decomposition strategy on the input data, generate a tensor decomposition result corresponding to the input data and store it in a register or a cache, and obtain a first calculation result according to the input data, wherein the first calculation result is a result generated by a multi-head attention mechanism in the encoder, and in the process of generating the first calculation result by the multi-head attention mechanism, generate a first tensor Q, a second tensor K and a third tensor V according to the input data, execute a tensor decomposition strategy on the third tensor V, generate a tensor decomposition result corresponding to the third tensor V and store it in a register or a cache, and after the third calculation result is generated by the first tensor Q and the second tensor K, calculate the first calculation result according to the tensor decomposition result corresponding to the third tensor V read in the register or the cache and the third calculation result; Obtaining a tensor decomposition result corresponding to the input data and performing residual calculation on the first calculation result, executing a tensor decomposition strategy on the obtained residual calculation result, generating a tensor decomposition result corresponding to the residual calculation result and storing the result in the register or the cache; The multilayer perceptron in the encoder generates a second calculation result according to the residual calculation result, obtains a tensor decomposition result corresponding to the residual calculation result in the register or the cache, and calculates the second calculation result to obtain output data; Among them, the tensor decomposition strategy is used to reduce the number of matrix elements corresponding to the input data, the residual calculation result and the third tensor V, so as to reduce the storage complexity of the input data, the residual calculation result and the third tensor V.

2. The method according to claim 1, characterized in that Before obtaining the preprocessed data obtained after preprocessing the original image, the method further includes: Acquire the original image, generate multiple image blocks of the original image, and add a classification mark to each of the multiple image blocks; The preprocessed data is obtained according to the multiple image blocks and the position encoding data after adding the classification marks.

3. The method according to claim 1, characterized in that Generating a first tensor Q, a second tensor K, and a third tensor V according to the input data includes: Normalizing the input data; Generate a three-dimensional tensor according to the normalized input data, wherein the three-dimensional tensor includes a first tensor Q, a second tensor K, and a third tensor V; The three-dimensional tensor is input into the multi-head attention mechanism to obtain the first calculation result.

4. The method according to claim 3, characterized in that Inputting the three-dimensional tensor into the multi-head attention mechanism to obtain the first calculation result includes: Execute a tensor decomposition strategy on the third tensor V, generate a tensor decomposition result corresponding to the third tensor V and store it in a register or a cache; Obtain a third calculation result according to the first tensor Q and the second tensor K; The first calculation result is calculated based on the tensor decomposition result corresponding to the third tensor V read from the register or cache and the third calculation result.

5. The method according to claim 1, characterized in that The second calculation result generated by the multilayer perceptron in the encoder according to the residual calculation result includes: Normalizing the residual calculation result; The normalized residual calculation result is input into the multi-layer perceptron to obtain the second calculation result.

6. The method according to claim 4, characterized in that Execute tensor decomposition strategies, including: Obtain any data to be decomposed, and determine the dimension of the data to be decomposed, wherein the data to be decomposed includes the input data, the residual calculation result, and the third tensor V; When the data to be decomposed is two-dimensional data, a shape transformation operation is performed to obtain three-dimensional data to be decomposed; A tensor decomposition process is performed on the three-dimensional data to be decomposed to obtain a tensor decomposition result corresponding to the data to be decomposed.

7. The method according to claim 6, characterized in that The formula for performing the shape transformation operation is: In the formula, is two-dimensional data to be decomposed; is three-dimensional data to be decomposed; ; .

8. The method according to claim 6, characterized in that Performing a tensor decomposition process on the three-dimensional data to be decomposed to obtain a tensor decomposition result corresponding to the data to be decomposed, including: A quantized tensor column decomposition process is performed on the three-dimensional data to be decomposed to obtain a tensor decomposition result corresponding to the data to be decomposed.

9. The method according to claim 8, characterized in that Performing a quantized tensor column decomposition process on the three-dimensional data to be decomposed to obtain a tensor decomposition result corresponding to the data to be decomposed, including: Performing an element supplement operation on the three-dimensional data to be decomposed to obtain a target three-dimensional tensor; Quantizing the target three-dimensional tensor to obtain a target tensor; The target tensor is decomposed into a tensor column to obtain a tensor decomposition result corresponding to the data to be decomposed.

10. The method according to claim 9, characterized in that Performing an element supplement operation on the three-dimensional data to be decomposed to obtain a target three-dimensional tensor, including: The three-dimensional data to be decomposed The added 0 element in the target three-dimensional tensor is obtained. The number of elements in the three dimensions is 256, 16, and 64, respectively.

11. The method according to claim 10, characterized in that The process of quantizing the target three-dimensional tensor to obtain the target tensor is as follows: in: Among them, the target tensor is .

12. The method according to claim 11, characterized in that The target tensor is decomposed into tensor columns to obtain the tensor decomposition result corresponding to the data to be decomposed: In the formula, The scale is The three-dimensional tensor ; is the rank of the quantized tensor column decomposition; Kernel for the decomposition of the quantized tensor array.

13. The method according to claim 6, characterized in that Performing a tensor decomposition process on the three-dimensional data to be decomposed to obtain a tensor decomposition result corresponding to the data to be decomposed, including: A Tucker tensor decomposition process is performed on the three-dimensional data to be decomposed to obtain a tensor decomposition result corresponding to the data to be decomposed.

14. The method according to claim 6, characterized in that Performing a tensor decomposition process on the three-dimensional data to be decomposed to obtain a tensor decomposition result corresponding to the data to be decomposed, including: A tensor column decomposition process is performed on the three-dimensional data to be decomposed to obtain a tensor decomposition result corresponding to the data to be decomposed.

15. The method according to claim 1, characterized in that The method further comprises: The output data of the encoder is used as the input data of the encoder, and after the processing process of the encoder is iterated a target number of times, the final output data of the encoder is obtained.

16. The method according to claim 15, characterized in that Generating a classification result of the original image according to the final output data of the encoder, including: After the final output data of the encoder is input into the multi-layer perception head for processing, the classification result of the original image is output.

17. An image processing acceleration device, characterized in that: The device comprises: An image classification module is used to obtain preprocessed data obtained after preprocessing the original image, use the preprocessed data as input data of the encoder, execute the processing process of the encoder, and generate a classification result of the original image according to the final output data of the encoder; The image classification module includes an encoder processing module, and the encoder processing module is used to: Execute a tensor decomposition strategy on the input data, generate a tensor decomposition result corresponding to the input data and store it in a register or a cache, and obtain a first calculation result according to the input data, wherein the first calculation result is a result generated by a multi-head attention mechanism in the encoder, and in the process of generating the first calculation result by the multi-head attention mechanism, generate a first tensor Q, a second tensor K and a third tensor V according to the input data, execute a tensor decomposition strategy on the third tensor V, generate a tensor decomposition result corresponding to the third tensor V and store it in a register or a cache, and after the third calculation result is generated by the first tensor Q and the second tensor K, calculate the first calculation result according to the tensor decomposition result corresponding to the third tensor V read in the register or the cache and the third calculation result; Obtaining a tensor decomposition result corresponding to the input data and performing residual calculation on the first calculation result, executing a tensor decomposition strategy on the obtained residual calculation result, generating a tensor decomposition result corresponding to the residual calculation result and storing the result in the register or the cache; The multilayer perceptron in the encoder generates a second calculation result according to the residual calculation result, obtains a tensor decomposition result corresponding to the residual calculation result in the register or the cache, and calculates the second calculation result to obtain output data; Among them, the tensor decomposition strategy is used to reduce the number of matrix elements corresponding to the input data, the residual calculation result and the third tensor V, so as to reduce the storage complexity of the input data, the residual calculation result and the third tensor V.

18. A computer device, characterized in that: include: At least one processor, and a memory, wherein the memory stores a computer program that can be run on the processor, wherein the processor executes the image processing acceleration method described in any one of claims 1-16 when executing the computer program.

19. A non-volatile readable storage medium, characterized in that: The non-volatile readable storage medium stores a computer program, wherein the computer program, when executed by a processor, performs the image processing acceleration method according to any one of claims 1 to 16.

20. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instruction is executed by a processor, the image processing acceleration method described in any one of claims 1-16 is implemented.