Data Processing Method, Device, Terminal Device and Computer Readable Storage Medium
By setting the calculation parameters of the basic operator and using them to calculate, converting its output into a target tensor that conforms to the output shape of the operator to be processed, the problem of low efficiency of the neural network processor when executing complex operators is solved, and the efficiency of processing tasks is improved.
Patent Information
- Application Number
- CN202111652480.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-30
- Publication Date
- 2025-06-13
- Estimated Expiration
- 2041-12-30
AI Technical Summary
When a neural network processor executes a logically complex operator, such as a reorg operator, the execution efficiency is low, which affects the processing efficiency of image processing tasks or audio and video processing tasks.
By obtaining the input tensor and calculation parameters of the pending operator, setting the calculation parameters of the basic operator, making its algorithm complexity lower than that of the pending operator, then using the basic operator to perform calculations, and converting its output tensor into a target tensor that conforms to the shape of the output tensor of the pending operator.
Converting logically complex processing tasks into logically simple processing tasks improves the execution efficiency of neural network processors, thereby improving the processing efficiency of image processing tasks or audio and video processing tasks.
Smart Images

Figure CN114491399B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the technical field of data processing, and particularly relates to a data processing method, apparatus, terminal device, and computer-readable storage medium. Background Art
[0002] A neural network processor is a processor used to execute the computing tasks of a neural network model, such as for executing object detection tasks and object tracking tasks based on a neural network. A neural network model includes various operators, such as a convolution operator, a transformation operator, and a reorg operator, etc. The neural network processor can execute the computing tasks of some operators with relatively simple logic, such as a convolution operator and a transformation operator, etc. However, for an operator with relatively complex logic such as a reorg operator, the execution efficiency of the neural network processor is low. Summary of the Invention
[0003] Embodiments of this application provide a data processing method, apparatus, terminal device, and computer-readable storage medium, which can improve the execution efficiency of a neural network processor for operators with complex logic.
[0004] In a first aspect, an embodiment of this application provides a data processing method applied to a neural network processor. The method includes:
[0005] Obtain an input tensor of an operator to be processed and a first calculation parameter;
[0006] Set a second calculation parameter of a basic operator of the neural network processor according to the first calculation parameter, where the algorithm complexity of the basic operator is lower than that of the operator to be processed;
[0007] Based on the second calculation parameter, use the basic operator to calculate the input tensor of the operator to be processed to obtain an output tensor of the basic operator;
[0008] Convert the tensor shape of the output tensor of the basic operator to obtain a target tensor, where the tensor shape of the target tensor is the same as the tensor shape of the output tensor of the operator to be processed.
[0009] In an embodiment of the present application, the second calculation parameters of the basic operator are set according to the first calculation parameters of the operator to be processed, so as to execute the calculation task of the operator to be processed through the basic operator; finally, the output tensor of the basic operator is converted into a target tensor that conforms to the tensor shape of the output tensor of the operator to be processed. In the above method, the calculation task corresponding to the operator to be processed is equivalently converted into a calculation task composed of basic operators. Since the algorithm complexity of the basic operator is lower than that of the operator to be processed, therefore, through the above method, when the neural network processor executes a logically complex image processing task or audio-video processing task, the logically complex processing task can be converted into a logically simple processing task, which can effectively improve the execution efficiency of the neural network processor, and further effectively improve the processing efficiency of the image processing task or audio-video processing task.
[0010] In a possible implementation manner of the first aspect, the basic operator is a two-dimensional convolution operator. Correspondingly, the second calculation parameters include a weight matrix, a stride, and a convolution kernel;
[0011] The setting of the second calculation parameters of the basic operator of the neural network processor according to the first calculation parameters includes:
[0012] Generating the weight matrix, wherein the tensor shape of the weight matrix is determined by the first calculation parameters;
[0013] Setting the size of each dimension of the stride to the first calculation parameter;
[0014] Setting the size of each dimension of the convolution kernel to the first calculation parameter.
[0015] In a possible implementation manner of the first aspect, the generating of the weight matrix includes:
[0016] Calculating the first tensor shape according to the first calculation parameters;
[0017] Obtaining an identity matrix that matches the first calculation parameters;
[0018] Converting the identity matrix into a weight matrix that conforms to the first tensor shape.
[0019] In a possible implementation manner of the first aspect, the calculating, based on the second calculation parameters, the input tensor of the operator to be processed by using the basic operator to obtain the output tensor of the basic operator includes:
[0020] Converting the tensor shape of the input tensor of the operator to be processed to obtain a first intermediate tensor, and the tensor shape of the first intermediate tensor matches the second calculation parameters;
[0021] Based on the second calculation parameter, use the basic operator to calculate the first intermediate tensor to obtain the output tensor of the basic operator.
[0022] In a possible implementation manner of the first aspect, the converting the tensor shape of the input tensor of the operator to be processed to obtain the first intermediate tensor includes:
[0023] Calculate a second tensor shape according to the tensor shape of the input tensor of the operator to be processed and the first calculation parameter;
[0024] Convert the input tensor of the operator to be processed into the first intermediate tensor that conforms to the second tensor shape.
[0025] In a possible implementation manner of the first aspect, the converting the tensor shape of the output tensor of the basic operator to obtain the target tensor includes:
[0026] Calculate a third tensor shape according to the tensor shape of the input tensor of the operator to be processed and the first calculation parameter;
[0027] Convert the output tensor of the basic operator into the target tensor that conforms to the third tensor shape.
[0028] In a second aspect, an embodiment of the present application provides a data processing device, which is applied to a neural network processor. The device includes:
[0029] An acquisition unit, configured to acquire the input tensor of the operator to be processed and the first calculation parameter;
[0030] A setting unit, configured to set a second calculation parameter of the basic operator of the neural network processor according to the first calculation parameter;
[0031] A calculation unit, configured to calculate the input tensor of the operator to be processed by using the basic operator based on the second calculation parameter to obtain the output tensor of the basic operator;
[0032] A conversion unit, configured to convert the tensor shape of the output tensor of the basic operator to obtain a target tensor, and the tensor shape of the target tensor is the same as the tensor shape of the output tensor of the operator to be processed.
[0033] In a third aspect, an embodiment of the present application provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. The terminal device is characterized in that when the processor executes the computer program, the data processing method described in any one of the first aspects above is implemented.
[0034] Fourth aspect, an embodiment of the present application provides a computer-readable storage medium storing a computer program, characterized in that when the computer program is executed by a processor, it implements the data processing method according to any one of the above first aspects.
[0035] Fifth aspect, an embodiment of the present application provides a computer program product, which, when running on a terminal device, causes the terminal device to execute the data processing method according to any one of the above first aspects.
[0036] It can be understood that the beneficial effects of the above second to fifth aspects can be referred to the relevant descriptions in the above first aspect, and will not be elaborated here. Description of the Drawings
[0037] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0038] Figure 1 It is a schematic diagram of the convolution process provided by an embodiment of the present application;
[0039] Figure 2 It is a schematic diagram of data conversion provided by an embodiment of the present application;
[0040] Figure 3 It is a schematic diagram of data processing of the reorg operator provided by an embodiment of the present application;
[0041] Figure 4 It is a schematic flowchart of the data processing method provided by an embodiment of the present application;
[0042] Figure 5 It is a block diagram of the structure of the data processing device provided by an embodiment of the present application;
[0043] Figure 6 It is a schematic diagram of the structure of the terminal device provided by an embodiment of the present application. Detailed Embodiments
[0044] In the following description, specific details such as specific system structures and technologies are proposed for the purpose of illustration rather than limitation, so as to thoroughly understand the embodiments of the present application. However, those skilled in the art should understand that the present application can also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid unnecessary details from interfering with the description of the present application.
[0045] It should be understood that when used in the specification of this application and the appended claims, the term "comprising" indicates the presence of the described features, wholes, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components, and / or their combinations.
[0046] It should also be understood that the term "and / or" used in the specification of this application and the appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0047] As used in the specification of this application and the appended claims, the term "if" may be interpreted, depending on the context, as "when", "once", "in response to determining", or "in response to detecting". Similarly, the phrases "if determined" or "if [the described condition or event] is detected" may be interpreted, depending on the context, as meaning "once determined", "in response to determining", "once [the described condition or event] is detected", or "in response to detecting [the described condition or event]".
[0048] In addition, in the description of the specification of this application and the appended claims, the terms "first", "second", "third", etc. are only used for distinguishing descriptions and should not be construed as indicating or implying relative importance.
[0049] Reference to "one embodiment" or "some embodiments" etc. described in the specification of this application means that a specific feature, structure, or characteristic described in connection with that embodiment is included in one or more embodiments of this application. Thus, statements such as "in one embodiment", "in some embodiments", "in other some embodiments", "in still other embodiments", etc. that appear in different places in this specification do not necessarily all refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways.
[0050] First, the technical background of this application is introduced.
[0051] A neural network model includes various operators, such as a convolution operator, a transformation operator, a reorg operator, etc. Exemplarily, the following several operators are introduced.
[0052] The convolution operator is used to implement convolution calculation. Refer to Figure 1 , which is a schematic diagram of the convolution process provided by an embodiment of this application. As Figure 1 shown in (a) of Figure 1As shown in (b) therein, start convolution from the starting position in the upper left corner of the image to be processed, weight the convolution kernel with the pixels within the shaded box in the left figure, and obtain a convolution value. Assume that the convolution step size is 1, that is, move the shaded box one pixel to the right, as Figure 1 shown in (c) therein. Continue to weight the pixels within the shaded box at this time with the convolution kernel to obtain a second convolution value. By analogy, the final convolution value can be obtained, as Figure 1 shown in (d) therein. Among them, the size of the convolution kernel determines the size of the receptive field, and the size of the step size determines the accuracy of the extracted data.
[0053] The conversion operator is used to implement data conversion. For example, the reshape operator is used to convert the input data into data with a specific dimension. As Figure 2 shown, on the left is a 3×4 matrix A, set the target dimension to 2×6, and after reshaping, a 2×6 matrix B is obtained. The reshape operator can not only implement the conversion of data dimensions, but also ensure that the original data remains unchanged.
[0054] The reorg operator is used to implement data rearrangement, connecting feature maps of different levels and different sizes. As Figure 3 shown, on the left is a 2W×2W feature map P. Input this feature map into the reorg operator, and 4 W×W feature maps Q on the right can be obtained. Each time, 4 elements are taken from the feature map P and respectively assigned to the 4 feature maps Q. Traversing from left to right and top to bottom in this way, 4 W*W feature maps Q can be obtained.
[0055] The neural network processor is usually used to execute tasks such as image processing (such as object recognition, object tracking, etc.) and audio and video processing (such as sound detection, etc.). During the execution of the above processing tasks, some computationally complex tasks are often involved. For example, for the above reorg operator, the neural network processor executes this operator to implement the rearrangement of image or audio and video features. The neural network processor can execute the computational tasks of some operators with relatively simple logic, such as the convolution operator and the conversion operator, etc. However, for an operator with relatively complex logic such as the reorg operator, the execution efficiency of the neural network processor is low, thereby affecting the processing efficiency of the image processing task or the audio and video processing task.
[0056] To solve the above problems, an embodiment of the present application provides a data processing method. Refer to Figure 4 , which is a schematic flowchart of the data processing method provided by the embodiment of the present application. By way of example and not limitation, the method may include the following steps:
[0057] S401, obtain the input tensor of the operator to be processed and the first calculation parameter.
[0058] In the embodiments of the present application, the operator to be processed refers to an operator with relatively complex calculation logic. For the convenience of description, the following embodiments will take the reorg operator as an example for introduction.
[0059] The input / output data of each layer in the neural network is usually tensor data, that is, multi-dimensional data. Usually, the dimensions of the input / output tensor are (N, C, H, W), where N represents the number of batches (batch) of two-dimensional data, C represents the number of channels, H represents the height of the two-dimensional data, and W represents the width of the two-dimensional data.
[0060] The tensor shape of the input tensor of the reorg operator is (N, C, H, W). As shown in the calculation logic code of the above reorg operator, its first calculation parameter is the stride (S).
[0061] S402. Set the second calculation parameter of the basic operator of the neural network processor according to the first calculation parameter.
[0062] The basic operator in the embodiments of the present application refers to an operator with relatively simple calculation logic. It should be noted that in the embodiments of the present application, one basic operator or a combination of multiple basic operators can be used to implement the calculation task of the operator to be processed. For the convenience of description, the following embodiments will take the convolution operator as an example for introduction.
[0063] In one embodiment, the basic operator is a two-dimensional convolution operator. Correspondingly, the second calculation parameter includes a weight matrix, a stride, and a convolution kernel.
[0064] Correspondingly, S402 includes:
[0065] Generate the weight matrix, where the tensor shape of the weight matrix is determined by the first calculation parameter; set the size of each dimension of the stride to the first calculation parameter; set the size of each dimension of the convolution kernel to the first calculation parameter.
[0066] Optionally, the method for generating the weight matrix is:
[0067] Calculate the first tensor shape according to the first calculation parameter; obtain an identity matrix that matches the first calculation parameter; convert the identity matrix into a weight matrix that conforms to the first tensor shape.
[0068] Specifically, the first tensor shape can be determined according to the formula new_shape1=(S*S, 1, S, S)), where S is the first calculation parameter, that is, the stride in the reorg operator.
[0069] The size of each dimension of the identity matrix is S×S, that is, the tensor shape is (S×S, S×S). For example, if S = 2, the identity matrix is:
[0070]
[0071] The reshape operator can be used to transform the identity matrix. For the specific transformation principle, please refer to Figure 2 the description in the embodiments. Exemplarily, the transformation process is represented by the function Weight_out = Reshape(weight_in, new_shape=(S*S, 1, S, S)). Among them, the first parameter in the Reshape function is the input data, and the second parameter is the tensor shape of the output data. In the above function, the input data is the identity matrix weight_in, and the tensor shape of the output data is the first tensor shape new_shape1=(S*S, 1, S, S)).
[0072] Exemplarily, when the convolutional kernel is two-dimensional, the size of the convolutional kernel is [S, S]. Correspondingly, the stride is also [S, S].
[0073] S403. Based on the second calculation parameter, use the basic operator to calculate the input tensor of the operator to be processed, and obtain the output tensor of the basic operator.
[0074] The tensor shape of the input tensor of the operator to be processed may be inconsistent with the tensor shape of the input data of the basic operator. To solve this problem, it is necessary to first transform the tensor shape of the input tensor of the operator to be processed.
[0075] In one embodiment, S403 includes:
[0076] Transform the tensor shape of the input tensor of the operator to be processed to obtain a first intermediate tensor, the tensor shape of the first intermediate tensor matching the second calculation parameter; based on the second calculation parameter, use the basic operator to calculate the first intermediate tensor to obtain the output tensor of the basic operator.
[0077] Optionally, the way to obtain the first intermediate tensor is:
[0078] According to the tensor shape of the input tensor of the operator to be processed and the first calculation parameter, calculate the second tensor shape; convert the input tensor of the operator to be processed into the first intermediate tensor that conforms to the second tensor shape.
[0079] Specifically, the second tensor shape can be determined by the formula new_shape2=(N, 1, C*H / S, W*S). The reshape operator can be used to transform the tensor shape of the input tensor of the operator to be processed. For the specific transformation principle, please refer to Figure 2 the description in the embodiments.
[0080] Set the parameters of the basic operator to the second calculation parameter. After obtaining the first intermediate tensor, use the first intermediate tensor as the input data of the basic operator. After calculation by the basic operator, the output tensor of the basic operator is obtained.
[0081] Exemplarily, the calculation of the convolution operator is represented by the function Y = Conv2D(X, Weight_out, strides=(S, S), kernel_size=(S, S)). Where X is the first intermediate tensor.
[0082] S404. Convert the tensor shape of the output tensor of the basic operator to obtain a target tensor, and the tensor shape of the target tensor is consistent with the tensor shape of the output tensor of the operator to be processed.
[0083] The tensor shape of the output tensor of the basic operator is inconsistent with the tensor shape of the output tensor of the operator to be processed. In order to obtain a calculation result equivalent to the operator to be processed, it is necessary to convert the tensor shape of the output tensor of the basic operator.
[0084] In one embodiment, the way to obtain the target tensor is:
[0085] Calculate the first tensor shape according to the tensor shape of the input tensor of the operator to be processed and the first calculation parameter; convert the output tensor of the basic operator into the target tensor that conforms to the first tensor shape.
[0086] Specifically, the third tensor shape can be determined by the formula new_shape3=(N, C*S*S, H / S, W / S). Similarly, the reshape operator can be used to convert the tensor shape of the input tensor of the operator to be processed. The specific conversion principle can be referred to the description in the Figure 2 embodiment.
[0087] In the embodiments of the present application, set the second calculation parameter of the basic operator according to the first calculation parameter of the operator to be processed, so as to execute the calculation task of the operator to be processed through the basic operator; finally, convert the output tensor of the basic operator into a target tensor that conforms to the tensor shape of the output tensor of the operator to be processed. In the above method, it is equivalent to converting the calculation task corresponding to the operator to be processed into a calculation task composed of basic operators. Since the algorithm complexity of the basic operator is lower than that of the operator to be processed, therefore, through the above method, when the neural network processor executes a logically complex image processing task or audio-visual processing task, the logically complex processing task can be converted into a logically simple processing task, effectively improving the execution efficiency of the neural network processor, and further effectively improving the processing efficiency of the image processing task or audio-visual processing task.
[0088] In addition, since no data is lost during the reshape process and the original data can be ensured to remain unchanged, therefore, converting the calculation task of the reorg operator to be implemented by reshape and conv (convolution operator) can improve the execution efficiency of the neural network processor while ensuring that the execution result is consistent with the execution result of the reorg operator.
[0089] It should be understood that the magnitudes of the sequence numbers of the steps in the above embodiments do not imply the order of execution. The order of execution of each process should be determined according to its function and internal logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.
[0090] Corresponding to the data processing method described in the above embodiments, Figure 5 is a structural block diagram of a data processing device provided by an embodiment of the present application. For the sake of convenience of description, only the parts related to the embodiments of the present application are shown.
[0091] Referring to Figure 5 , the device includes:
[0092] An acquisition unit 51, configured to acquire an input tensor of an operator to be processed and a first calculation parameter.
[0093] A setting unit 52, configured to set a second calculation parameter of a basic operator of the neural network processor according to the first calculation parameter, where the algorithm complexity of the basic operator is lower than that of the operator to be processed.
[0094] A calculation unit 53, configured to calculate the input tensor of the operator to be processed by using the basic operator based on the second calculation parameter to obtain an output tensor of the basic operator.
[0095] A conversion unit 54, configured to convert the tensor shape of the output tensor of the basic operator to obtain a target tensor, and the tensor shape of the target tensor is consistent with the tensor shape of the output tensor of the operator to be processed.
[0096] Optionally, the basic operator is a two-dimensional convolution operator. Correspondingly, the second calculation parameter includes a weight matrix, a stride, and a convolution kernel.
[0097] Correspondingly, the setting unit 52 is further configured to:
[0098] Generate the weight matrix, where the tensor shape of the weight matrix is determined by the first calculation parameter; set the size of each dimension of the stride to the first calculation parameter; set the size of each dimension of the convolution kernel to the first calculation parameter.
[0099] Optionally, the setting unit 52 is further configured to:
[0100] Calculate the shape of the first tensor according to the first calculation parameter;
[0101] Obtain the identity matrix that matches the first calculation parameter;
[0102] Convert the identity matrix into a weight matrix that conforms to the shape of the first tensor.
[0103] Optionally, the calculation unit 53 is further configured to:
[0104] Convert the tensor shape of the input tensor of the operator to be processed to obtain a first intermediate tensor, and the tensor shape of the first intermediate tensor matches the second calculation parameter;
[0105] Based on the second calculation parameter, use the basic operator to calculate the first intermediate tensor to obtain the output tensor of the basic operator.
[0106] Optionally, the calculation unit 53 is further configured to:
[0107] Calculate the shape of the second tensor according to the tensor shape of the input tensor of the operator to be processed and the first calculation parameter;
[0108] Convert the input tensor of the operator to be processed into the first intermediate tensor that conforms to the shape of the second tensor.
[0109] Optionally, the conversion unit 54 is further configured to:
[0110] Calculate the shape of the third tensor according to the tensor shape of the input tensor of the operator to be processed and the first calculation parameter;
[0111] Convert the output tensor of the basic operator into the target tensor that conforms to the shape of the third tensor.
[0112] It should be noted that for the information interaction, execution process, etc. between the above-mentioned devices / units, since they are based on the same concept as the method embodiment of the present application, for their specific functions and the technical effects brought, please refer to the method embodiment part for details, and will not be elaborated here.
[0113] In addition, Figure 5 The data processing device shown can be a software unit, a hardware unit, or a unit combining software and hardware built into an existing terminal device, can also be integrated into the terminal device as an independent attachment, or can exist as an independent terminal device.
[0114] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the above-mentioned division of each functional unit and module is used as an example. In actual applications, the above functions can be allocated to different functional units and modules according to needs, that is, the internal structure of the device is divided into different functional units or modules to complete all or part of the functions described above. Each functional unit and module in the embodiment can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above integrated unit can be implemented in the form of hardware or in the form of a software functional unit. In addition, the specific names of each functional unit and module are only for the convenience of mutual distinction and do not limit the protection scope of this application. The specific working process of the units and modules in the above system can refer to the corresponding process in the foregoing method embodiment and will not be elaborated here.
[0115] Figure 6 is a schematic structural diagram of a terminal device provided by an embodiment of this application. As Figure 6 shown, the terminal device 6 in this embodiment includes: at least one processor 60 ( Figure 6 only one is shown in the figure), a processor, a memory 61, and a computer program 62 stored in the memory 61 and executable on the at least one processor 60. When the processor 60 executes the computer program 62, the steps in any of the foregoing data processing method embodiments are implemented.
[0116] The terminal device may be a computing device such as a desktop computer, a notebook, a palm computer, and a cloud server. The terminal device may include, but is not limited to, a processor and a memory. Those skilled in the art can understand that Figure 6 this is only an example of the terminal device 6 and does not constitute a limitation on the terminal device 6. It may include more or fewer components than shown in the figure, or combine some components, or different components. For example, it may also include input / output devices, network access devices, etc.
[0117] The so-called processor 60 may be a Central Processing Unit (CPU), and the processor 60 may also be other general-purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field-Programmable Gate Arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0118] In some embodiments, the memory 61 may be an internal storage unit of the terminal device 6, such as the hard disk or memory of the terminal device 6. In some other embodiments, the memory 61 may also be an external storage device of the terminal device 6, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, etc., equipped on the terminal device 6. Further, the memory 61 may also include both the internal storage unit and the external storage device of the terminal device 6. The memory 61 is used to store an operating system, application programs, a BootLoader, data, and other programs, such as the program code of the computer program, etc. The memory 61 may also be used to temporarily store data that has been output or is to be output.
[0119] The embodiment of the present application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the above-mentioned various method embodiments can be implemented.
[0120] The embodiment of the present application provides a computer program product. When the computer program product runs on a terminal device, the terminal device can be made to execute the steps in the above-mentioned various method embodiments.
[0121] When the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, to implement all or part of the processes in the above-described embodiment methods of this application, a computer program can be used to instruct relevant hardware to complete. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, the steps of the above-described method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in the form of source code, object code, executable file, or some intermediate form, etc. The computer-readable medium can at least include: any entity or device that can carry the computer program code to the device / terminal device, recording medium, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electrical carrier signal, telecommunication signal, and software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk, or an optical disc, etc. In some jurisdictions, according to legislation and patent practice, the computer-readable medium cannot be an electrical carrier signal and a telecommunication signal.
[0122] In the above embodiments, the descriptions of the various embodiments have their own emphases. For parts not detailed or recorded in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0123] Those of ordinary skill in the art can realize that the units and algorithm steps of the examples described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.
[0124] In the embodiments provided in this application, it should be understood that the disclosed device / terminal device and method can be implemented in other ways. For example, the device / terminal device embodiments described above are merely illustrative. For example, the division of the modules or units is only a logical function division. In actual implementation, there can be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection to each other can be through some interfaces. The indirect coupling or communication connection of the device or unit can be in an electrical, mechanical, or other form.
[0125] The unit described as a separation component may or may not be physically separated. The component shown as a unit may or may not be a physical unit, that is, it may be located in one place or distributed across multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0126] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the various embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A data processing method, characterized in that, applied to a neural network processor, the method comprising: obtaining an input tensor of an operator to be processed and a first calculation parameter; setting a second calculation parameter of a basic operator of the neural network processor according to the first calculation parameter, wherein an algorithm complexity of the basic operator is lower than an algorithm complexity of the operator to be processed; calculating, based on the second calculation parameter, the input tensor of the operator to be processed by using the basic operator to obtain an output tensor of the basic operator; converting a tensor shape of the output tensor of the basic operator to obtain a target tensor, wherein the tensor shape of the target tensor is consistent with a tensor shape of an output tensor of the operator to be processed.
2. The data processing method according to claim 1, characterized in that, the basic operator is a two-dimensional convolution operator, and correspondingly, the second calculation parameter includes a weight matrix, a stride, and a convolution kernel; the setting the second calculation parameter of the basic operator of the neural network processor according to the first calculation parameter includes: generating the weight matrix, wherein a tensor shape of the weight matrix is determined by the first calculation parameter; setting a size of each dimension of the stride to the first calculation parameter; setting a size of each dimension of the convolution kernel to the first calculation parameter.
3. The data processing method according to claim 2, characterized in that, the generating the weight matrix includes: calculating a first tensor shape according to the first calculation parameter; obtaining an identity matrix matching the first calculation parameter; converting the identity matrix into a weight matrix conforming to the first tensor shape.
4. The data processing method according to claim 1, characterized in that, the calculating, based on the second calculation parameter, the input tensor of the operator to be processed by using the basic operator to obtain an output tensor of the basic operator includes: converting a tensor shape of the input tensor of the operator to be processed to obtain a first intermediate tensor, wherein the tensor shape of the first intermediate tensor matches the second calculation parameter; calculating, based on the second calculation parameter, the first intermediate tensor by using the basic operator to obtain an output tensor of the basic operator.
5. The data processing method according to claim 4, characterized in that, the converting the tensor shape of the input tensor of the operator to be processed to obtain a first intermediate tensor includes: calculating a second tensor shape according to the tensor shape of the input tensor of the operator to be processed and the first calculation parameter; converting the input tensor of the operator to be processed into the first intermediate tensor conforming to the second tensor shape.
6. The data processing method according to claim 1, characterized in that, the converting the tensor shape of the output tensor of the basic operator to obtain a target tensor includes: calculating a third tensor shape according to the tensor shape of the input tensor of the operator to be processed and the first calculation parameter; converting the output tensor of the basic operator into the target tensor conforming to the third tensor shape.
7. A data processing device, characterized in that, applied to a neural network processor, the device comprising: An acquisition unit, configured to acquire an input tensor and a first calculation parameter of an operator to be processed; A setting unit, configured to set a second calculation parameter of a basic operator of the neural network processor according to the first calculation parameter, where an algorithm complexity of the basic operator is lower than an algorithm complexity of the operator to be processed; A calculation unit, configured to perform a calculation on the input tensor of the operator to be processed by using the basic operator based on the second calculation parameter, and obtain an output tensor of the basic operator; A conversion unit, configured to convert a tensor shape of the output tensor of the basic operator to obtain a target tensor, where the tensor shape of the target tensor is consistent with a tensor shape of an output tensor of the operator to be processed.
8. The data processing device according to claim 7, wherein, the basic operator is a two-dimensional convolution operator, and correspondingly, the second calculation parameter includes a weight matrix, a stride, and a convolution kernel; the setting unit is further configured to: generate the weight matrix, where a tensor shape of the weight matrix is determined by the first calculation parameter; set a size of each dimension of the stride to the first calculation parameter; set a size of each dimension of the convolution kernel to the first calculation parameter.
9. A terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein, when the processor executes the computer program, the method according to any one of claims 1 to 6 is implemented.
10. A computer-readable storage medium, where the computer-readable storage medium stores a computer program, wherein, when the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
CO2 welding pool image recognition method based on convolutional neural network
CN112183665A
Convolutional neural network system and operation method thereof
US20180129935A1