Data processing method and device, equipment, storage medium and program product

By mapping and compiling the input data format of the neural network model, a target model file matching the processor is generated, which solves the problem of fixed data format of the neural network model when the processor is running, and improves processing flexibility and efficiency.

CN118690781APending Publication Date: 2024-09-24TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202310295178.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-03-22
Publication Date
2024-09-24

AI Technical Summary

Technical Problem

In the existing technology, the shape of the input data of the neural network model is fixed when the processor is running, resulting in low flexibility and inability to adapt to multiple data formats.

Method used

By obtaining the input data format and model file of the neural network model, operator mapping processing is performed, the sub-data format is obtained, and combined with the processor attribute information for compilation, a matching target model file is generated, so that the processor supports input of multiple data formats .

Benefits of technology

It improves the processing flexibility of the neural network model for multiple data formats and enables efficient operation of the processor in different data formats.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118690781A
    Figure CN118690781A
Patent Text Reader

Abstract

The embodiment of the invention discloses a data processing method and device, equipment, a storage medium and a program product. In the embodiment of the invention, a data format of input data of a neural network model is acquired, and a model file of the neural network model is acquired, and the model file comprises an operator of the neural network model; according to the operator, performing mapping processing on the data format to obtain a sub-data format of the input data of the operator; obtaining attribute information of the processor, and compiling the model file according to the attribute information and the sub-data format to obtain a target model file matched with the processor; and operating the target model file through the processor to process the to-be-processed data of the neural network model to obtain a processing result of the to-be-processed data. According to the embodiment of the invention, the flexibility of processing the to-be-processed data through the neural network model operated by the processor can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and specifically to a data processing method, device, equipment, storage medium and program product. Background Art

[0002] With the development of science and technology, the application of neural network models is becoming more and more extensive. Generally, the neural network model can be run through a processor to process the input data of the neural network model.

[0003] At present, when a neural network model is run through a processor, the shape of the input data of the neural network model can only be fixed and cannot be changed. That is, the shape of the input data of the processor can only be fixed, which makes the flexibility of the neural network model run through the processor to process the input data low. Summary of the invention

[0004] The embodiments of the present application provide a data processing method, apparatus, device, storage medium and program product, which can solve the technical problem of low flexibility when processing input data through a neural network model running on a processor.

[0005] The present application provides a data processing method, including:

[0006] Obtaining the data format of the input data of the neural network model, and obtaining the model file of the neural network model, wherein the model file includes the operator of the neural network model;

[0007] According to the above operator, the above data format is mapped to obtain the sub-data format of the input data of the above operator;

[0008] Acquire the attribute information of the processor, and compile the model file according to the attribute information and the sub-data format to obtain a target model file matching the processor;

[0009] The target model file is run by the processor to process the data to be processed of the neural network model to obtain the processing result of the data to be processed.

[0010] Accordingly, an embodiment of the present application provides a data processing device, including:

[0011] An acquisition module, used to acquire the data format of the input data of the neural network model, and to acquire the model file of the neural network model, wherein the model file includes the operator of the neural network model;

[0012] A mapping module, used to perform mapping processing on the above data format according to the above operator to obtain a sub-data format of the input data of the above operator;

[0013] A compiling module, used to obtain the attribute information of the processor, and compile the model file according to the attribute information and the sub-data format to obtain a target model file matching the processor;

[0014] A processing module is used to process the data to be processed of the neural network model by running the target model file through the processor to obtain the processing result of the data to be processed.

[0015] Optionally, the mapping module is specifically used to perform:

[0016] Get the format mapping strategy corresponding to the above operator;

[0017] The above data format is mapped using the above format mapping strategy to obtain the sub-data format of the input data of the above operator.

[0018] Optionally, the mapping module is specifically used to perform:

[0019] Filter out a startup operator from the above operators, and use the above data format as the sub-data format of input data of the above startup operator;

[0020] According to the startup operator, mapping processing is performed on the sub-data format of the input data of the startup operator to obtain the sub-data format of the output data of the startup operator;

[0021] If the next operator of the startup operator exists in the above operator, the sub-data format of the output data of the above startup operator is used as the data format, and the above next operator is used as the startup operator, and the step of using the above data format as the sub-data format of the input data of the above startup operator is returned to be executed;

[0022] If the next operator of the above-mentioned start operator does not exist in the above-mentioned operators, the sub-data format of the input data of the above-mentioned operator is determined according to the sub-data format of the input data of the above-mentioned start operator.

[0023] Optionally, the mapping module is specifically used to perform:

[0024] Filtering a target operator from the above operators, and determining a historical operator before the above target operator in the above neural network model;

[0025] According to the above historical operator, the above data format is mapped to obtain the sub-data format of the input data of the above target operator;

[0026] According to the sub-data format of the input data of the target operator, the sub-data format of the input data of the operator is determined.

[0027] Optionally, the mapping module is specifically used to perform:

[0028] Determine the conversion model parameters according to the model parameters of the above historical operators;

[0029] The data format is mapped according to the conversion model parameters to obtain the sub-data format of the input data of the target operator.

[0030] Optionally, the processor includes multiple processors. Accordingly, the compiling module is specifically used to execute:

[0031] Obtain an original computation graph, the original computation graph including nodes, the nodes representing the operators;

[0032] According to the attribute information, the original computation graph is divided to obtain a subgraph matching each of the processors.

[0033] The model file is compiled according to the attribute information, the sub-data format and the sub-graph to obtain a target model file matching each of the processors.

[0034] Optionally, the compilation module is specifically used to perform:

[0035] According to the original computation graph, determine the initial data type of the input data of the subgraph;

[0036] Determine the target data type of the input data of the subgraph according to the attribute information;

[0037] The model file is compiled according to the attribute information, the sub-data format, the initial data type and the target data type to obtain a target model file matching each of the processors.

[0038] Optionally, the compilation module is specifically used to perform:

[0039] If the initial data type and the target data type are not the same, a data type conversion operator is obtained;

[0040] The subgraph is adjusted according to the data type conversion operator to obtain a first adjusted subgraph;

[0041] The model file is compiled according to the attribute information, the sub-data format and the first adjusted sub-graph to obtain a target model file matching each of the processors.

[0042] Optionally, the compilation module is specifically used to perform:

[0043] Determine the type of operator in the above subgraph;

[0044] If the type of the operator in the above subgraph is a preset type, adjusting the operator in the above subgraph to obtain a second adjusted subgraph;

[0045] The model file is compiled according to the attribute information, the sub-data format and the second adjusted sub-graph to obtain a target model file matching each of the processors.

[0046] Optionally, the processing module is specifically used to execute:

[0047] Determining a target data format of the data to be processed by the neural network model;

[0048] If the target data format does not match the sub-data format in the target model file, the target data format of the data to be processed is adjusted to obtain adjusted data to be processed;

[0049] The target model file is run by the processor to process the adjusted data to be processed, so as to obtain a processing result of the data to be processed.

[0050] Optionally, the processing module is specifically used to execute:

[0051] The processor runs the target model file to process the data to be processed by the neural network model to obtain a candidate processing result of the data to be processed;

[0052] Determine the output data format of the candidate processing result;

[0053] According to the target model file, the output data format of the candidate processing result is adjusted to obtain the processing result of the data to be processed.

[0054] In addition, an embodiment of the present application also provides an electronic device, including a processor and a memory, wherein the memory stores a computer program, and the processor is used to run the computer program in the memory to implement the data processing method provided in the embodiment of the present application.

[0055] In addition, an embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. The computer program is suitable for loading by a processor to execute any data processing method provided in the embodiment of the present application.

[0056] In addition, an embodiment of the present application also provides a computer program product, including a computer program, and when the computer program is executed by a processor, any data processing method provided in the embodiment of the present application is implemented.

[0057] In an embodiment of the present application, the data format of the input data of the neural network model is obtained, and the model file of the neural network model is obtained, the model file includes the operator of the neural network model; according to the operator, the data format is mapped to obtain the sub-data format of the input data of the operator; the attribute information of the processor is obtained, and according to the attribute information and the sub-data format, the model file is compiled to obtain a target model file matching the processor, so that the target model file includes the sub-data format and the target model file is a file supported by the processor, so that when the target data format of the data to be processed of the neural network model is the data format, the target model file can be run by the processor to process the data to be processed of the neural network model to obtain the processing result of the data to be processed. Since the data format can be any data format, the embodiment of the present application can realize the input of multiple data formats of the data to be processed to the processor, thereby improving the flexibility of processing the data to be processed by the neural network model run by the processor. BRIEF DESCRIPTION OF THE DRAWINGS

[0058] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0059] Figure 1 It is a schematic diagram of a scenario of a data processing process provided by an embodiment of the present application;

[0060] Figure 2 It is a flowchart of a data processing method provided in an embodiment of the present application;

[0061] Figure 3 It is a flowchart of another data processing method provided in an embodiment of the present application;

[0062] Figure 4 is a schematic diagram of a sub-data format and a sub-graph provided in an embodiment of the present application;

[0063] Figure 5 is a schematic diagram of a data processing method provided in an embodiment of the present application;

[0064] Figure 6 is a structural schematic diagram of a data processing device provided in an embodiment of the present application;

[0065] Figure 7 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0066] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.

[0067] The embodiments of the present application provide a data processing method, apparatus, device, storage medium and program product, wherein the device may be an electronic device, the storage medium may be a computer storage medium, and the program product may be a computer program product. The data processing device may be integrated in an electronic device, and the electronic device may be a server, a terminal or other device.

[0068] Among them, the server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, network acceleration services (Content Delivery Network, CDN), as well as big data and artificial intelligence platforms.

[0069] Furthermore, multiple servers may form a blockchain, and the servers are nodes on the blockchain.

[0070] The terminal may be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited thereto. The terminal and the server may be directly or indirectly connected via wired or wireless communication, and this application does not limit this.

[0071] For example, Figure 1 As shown, the server obtains the data format of the input data of the neural network model, and obtains the model file of the neural network model, the model file includes the operator of the neural network model; according to the operator, the data format is mapped to obtain the sub-data format of the input data of the operator; the attribute information of the processor is obtained, and according to the attribute information and the sub-data format, the model file is compiled to obtain the target model file matching the processor. The server sends the target model file to the terminal, and the terminal processes the data to be processed of the neural network model through the processor running the target model file to obtain the processing result of the data to be processed.

[0072] In addition, the term "plurality" in the embodiments of the present application refers to two or more than two. The terms "first" and "second" in the embodiments of the present application are used to distinguish descriptions and should not be understood as implying relative importance.

[0073] Artificial Intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology in computer science that attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is to study the design principles and implementation methods of various intelligent machines so that machines have the functions of perception, reasoning and decision-making.

[0074] Artificial intelligence technology is a comprehensive discipline that covers a wide range of fields, including both hardware-level and software-level technologies. The basic technologies of artificial intelligence generally include sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics and other technologies. Artificial intelligence software technology mainly includes computer vision technology, speech processing technology, natural language processing technology, and machine learning / deep learning.

[0075] Computer Vision (CV) is a science that studies how to make machines "see". To put it more specifically, it refers to machine vision such as using cameras and computers to replace human eyes to identify and measure targets, and further perform graphic processing so that computer processing becomes an image that is more suitable for human eye observation or transmission to instrument detection. As a scientific discipline, computer vision studies related theories and technologies, and attempts to establish an artificial intelligence system that can obtain information from images or multi-dimensional data. Computer vision technology usually includes image processing, image recognition, image semantic understanding, image retrieval, OCR, video processing, video semantic understanding, video content / behavior recognition, three-dimensional object reconstruction, 3D technology, virtual reality, augmented reality, simultaneous positioning and map construction, and other technologies, as well as common biometric recognition technologies such as face recognition and fingerprint recognition.

[0076] Machine Learning (ML) is a multi-disciplinary subject that involves probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory and other disciplines. It specializes in studying how computers simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications are spread across all areas of artificial intelligence. Machine learning and deep learning usually include artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and teaching learning.

[0077] The solutions provided in the embodiments of the present application involve artificial intelligence computer vision technology and machine learning technology, which are specifically described by the following embodiments. It should be noted that the description order of the following embodiments is not intended to limit the preferred order of the embodiments.

[0078] In this embodiment, the description will be made from the perspective of a data processing device. The data processing device can be specifically integrated in a device such as a server or a terminal. In order to facilitate the description of the data processing method of the present application, the following will be described in detail with the data processing device integrated in the terminal, that is, the terminal will be used as the execution subject for detailed description.

[0079] See also Figure 2 , Figure 2 : is a flow chart of a data processing method provided by an embodiment of the present application. The data processing method may include:

[0080] S201. Obtain the data format of the input data of the neural network model, and obtain the model file of the neural network model, where the model file includes the operators of the neural network model.

[0081] The data format of the input data refers to the existence form of the tensor corresponding to the input data, which may include at least one of the data type and the data shape. The data type refers to the storage format of the input data, for example, the data type may be an integer (int) or a floating point (float). The data shape refers to the layout of the input data, for example, the data shape of the input data may be (N, C, H, W) or (N, H, W, C), where N represents the number, C represents the number of channels, H represents the height, and W represents the width. (1, 3, 224, 224) and (1, 3, 448, 448) represent two data shapes.

[0082] The data format of the input data may include at least one, and the user may set the data format of the input data according to actual needs.

[0083] A model file refers to a file that includes a neural network model, which may include operators of the neural network model and network flow information of the neural network model, etc.

[0084] Optionally, the model file may include the identifier of the operator of the neural network model and model parameters, or the model file may also include the identifier of the operator of the neural network model, model parameters and code for implementing the operator, etc.

[0085] A neural network model refers to an algorithmic mathematical model that imitates the behavioral characteristics of an animal neural network to perform information processing. It can be a trained neural network model, or it can be an initialized neural network model, that is, an untrained neural network model.

[0086] The type of neural network model can be selected according to actual conditions. For example, the neural network model can be a recursive neural network model or an autoencoder, etc., which is not limited in the embodiments of the present application.

[0087] An operator (OP) refers to a mapping from one function space to another function space, which can be understood as a computing unit. For example, an operator can be a convolution operator or a pooling operator.

[0088] The terminal may first obtain the data format of the input data of the neural network model, and then obtain the model file of the neural network model. Alternatively, the terminal may first obtain the model file of the neural network model, and then obtain the data format of the input data of the neural network model. Alternatively, the terminal may obtain the model file of the neural network model while obtaining the data format of the input data of the neural network model.

[0089] The method for the terminal to obtain the data format and model file can be selected according to actual conditions, and the embodiment of the present application does not limit it here.

[0090] S202: Map the data format according to the operator to obtain a sub-data format of the input data of the operator.

[0091] A sub-data format can be the format of the input data of an operator or the format of the output data of an operator. For example, if the neural network model is operator op1→operator op2→operator op3, the sub-data format of the input data of operator op3 can be the sub-data format of the output data of operator op2.

[0092] Therefore, according to the operator, the data format is mapped and processed, and the sub-data format of the output data of the operator can also be obtained.

[0093] In some embodiments, according to the operator, the data format is mapped to obtain the sub-data format of the input data of the operator, including:

[0094] Get the format mapping strategy corresponding to the operator;

[0095] The data format is mapped through the format mapping strategy to obtain the sub-data format of the operator's input data.

[0096] Among them, the format mapping strategy can exist in the form of a format mapping function or in the form of a format mapping table, which is not limited in the example of this application.

[0097] In an embodiment of the present application, a format mapping strategy corresponding to each operator is pre-set, and then the data format is directly mapped through the format mapping strategy to obtain the sub-data format of the operator's input data. The sub-data format of the operator's input data can be obtained without performing other operations, thereby improving the speed of obtaining the sub-data format of the operator's input data.

[0098] For example, the data format is d1, the neural network model is operator op1→operator op2→operator op3, the format mapping strategy corresponding to operator op1 is s1, the format mapping strategy corresponding to operator op2 is s2, and the format mapping strategy corresponding to operator op3 is s3. Then, d1 is mapped through s1 to obtain the sub-data format of the input data of operator op1, d1 is mapped through s2 to obtain the sub-data format of the input data of operator op2, and d1 is mapped through s3 to obtain the sub-data format of the input data of operator op3.

[0099] In other embodiments, the process of mapping the data format according to the operator to obtain the sub-data format of the input data of the operator may also be:

[0100] Filter out the startup operator from various operators, and use the data format as the sub-data format of the input data of the startup operator;

[0101] According to the startup operator, mapping processing is performed on the sub-data format of the input data of the startup operator to obtain the sub-data format of the output data of the startup operator;

[0102] If there is a next operator of the start operator in the operator, the sub-data format of the output data of the start operator is used as the data format, and the next operator is used as the start operator, and the step of using the data format as the sub-data format of the input data of the start operator is returned to be executed;

[0103] If the next operator of the initiating operator does not exist in the operator, the sub-data format of the input data of the operator is determined according to the sub-data format of the input data of the initiating operator.

[0104] The startup operator selected from various operators can be understood as the first operator in the neural network model.

[0105] For example, if the data format is d1, and the neural network model is operator op1→operator op2→operator op3, then operator op1 is the starting operator, and d1 is used as the sub-data format of the input data of operator op1. According to operator op1, d1 is mapped to obtain the sub-data format d2 of the output data of operator op1. Since there is the next operator "operator op2" of operator op1, sub-data format d2 is used as the sub-data format of the input data of operator op2. According to operator op2, d2 is mapped to obtain the sub-data format d3 of the output data of operator op2. Since there is the next operator "operator op3" of operator op2, sub-data format d3 is used as the sub-data format of the input data of operator op3. According to operator op3, d3 is mapped to obtain the sub-data format d4 of the output data of operator op3. Since there is no next operator of operator op3, the calculation is stopped, and the sub-data format of the input data of operator op1 is obtained to be d1, the sub-data format of the input data of operator op2 is d2, and the sub-data format of the input data of operator op3 is d3.

[0106] At this time, according to the startup operator, the sub-data format of the input data of the startup operator is mapped, and the process of obtaining the sub-data format of the output data of the startup operator can be:

[0107] According to the first format mapping strategy corresponding to the startup operator, the sub-data format of the input data of the startup operator is mapped to obtain the sub-data format of the output data of the startup operator.

[0108] Among them, when the startup operator is the first operator of the neural network model, the first format mapping strategy corresponding to the first operator can be the same as the format mapping strategy corresponding to the first operator.

[0109] Alternatively, according to the startup operator, the sub-data format of the input data of the startup operator is mapped to obtain the sub-data format of the output data of the startup operator. The process may also be:

[0110] According to the model parameters of the startup operator, the sub-data format of the input data of the startup operator is mapped to obtain the sub-data format of the output data of the startup operator.

[0111] The model parameters of the startup operator refer to parameters that change the sub-data format of the input data of the startup operator. For example, when the startup operator is a convolution operator, the model parameters of the startup operator may refer to the size of the convolution kernel and the sliding step size of the convolution operator.

[0112] In an embodiment of the present application, a startup operator is screened out from various operators, and the data format is used as the sub-data format of the input data of the startup operator; according to the startup operator, the sub-data format of the input data of the startup operator is mapped to obtain the sub-data format of the output data of the startup operator; if there is a next operator of the startup operator in the operator, the sub-data format of the output data of the startup operator is used as the data format, and the next operator is used as the startup operator, and the step of using the data format as the sub-data format of the input data of the startup operator is returned to be executed; if there is no next operator of the startup operator in the operator, the sub-data format of the input data of the operator is determined according to the sub-data format of the input data of the startup operator, so as to obtain the sub-data format of the input data of the next operator according to the sub-data format of the output data of the startup operator.

[0113] In other embodiments, the process of mapping the data format according to the operator to obtain the sub-data format of the input data of the operator may also be:

[0114] Filter out a target operator from the operators, and determine the historical operators before the target operator in the neural network model;

[0115] According to the historical operator, the data format is mapped to obtain the sub-data format of the input data of the target operator;

[0116] The sub-data format of the input data of the operator is determined according to the sub-data format of the input data of the target operator.

[0117] Among them, the terminal can arbitrarily select the target operator from the operators, or the terminal can also select the target operator from the operators in sequence according to the execution order of each operator in the neural network model.

[0118] For example, the neural network model is operator op1→operator op2→operator op3. If the target operator is randomly selected from the operators, the target operator selected from the operators for the first time may be operator op1, operator op2, or operator op3. If the target operators are selected from the operators in the order of the operators in the neural network model, the target operator selected from the operators for the first time is operator op1, the target operator selected from the operators for the second time is operator op2, and the target operator selected from the operators for the third time is operator op3.

[0119] The historical operator before the target operator in the neural network model refers to the operator whose execution order in the neural network model is before the execution order of the target operator. For example, the neural network model is operator op1→operator op2→operator op3, the execution order of operator op1 is prior to the execution order of operator op2, and the execution order of operator op2 is prior to the execution order of operator op3. When the target operator is operator op2, the historical operator is operator op1, and when the target operator is operator op3, the historical operator may include at least one of operator op1 and operator op2.

[0120] It should be understood that if the target operator is a startup operator, since there is no historical operator for the startup operator in the neural network model, after obtaining the target operator, the terminal can determine whether the target operator is a startup operator. If it is a startup operator, the data format is used as the sub-data format of the input data of the target operator. If it is not a startup operator, the historical operator before the target operator in the neural network model is determined.

[0121] In an embodiment of the present application, a target operator is screened out from the operators, and the historical operators before the target operator in the neural network model are determined; according to the historical operators, the data format is mapped to obtain the sub-data format of the input data of the target operator, and then the sub-data format of the input data of the target operator is used as the sub-data format of the input data of the operator, thereby obtaining the sub-data format of the input data of each operator.

[0122] Optionally, according to the historical operator, the data format is mapped to obtain the sub-data format of the input data of the target operator as follows:

[0123] Determine conversion model parameters according to model parameters of historical operators;

[0124] According to the conversion model parameters, the data format is mapped to obtain the sub-data format of the input data of the target operator.

[0125] For example, the neural network model is operator op1→operator op2→operator op3, the target operator is operator op3, the historical operators are operator op1 and operator op2, and the conversion model parameters are determined according to the model parameters of operator op1 and the model parameters of operator op2. Then, according to the conversion model parameters, the data format is mapped to obtain the sub-data format of the output data of operator op2, and then the sub-data format of the output data of operator op2 is used as the sub-data format of the input data of operator op3, so that there is no need to obtain the sub-data format of the output data of the historical operator (operator op1) that is not adjacent to operator op3.

[0126] In this embodiment, the conversion model parameters are determined according to the model parameters of the historical operator, and then the data format is mapped according to the conversion model parameters to obtain the sub-data format of the input data of the target operator, so as to realize the calculation of the sub-data format of the input data of the target operator without obtaining the sub-data format of the output data of non-adjacent historical operators.

[0127] Alternatively, the process of mapping the data format according to the historical operator to obtain the sub-data format of the input data of the target operator can be:

[0128] Filter out the startup operator from the historical operators, and use the data format as the sub-data format of the input data of the startup operator;

[0129] According to the startup operator, mapping processing is performed on the sub-data format of the input data of the startup operator to obtain the sub-data format of the output data of the startup operator;

[0130] If there is a next operator of the start operator in the history operator, the sub-data format of the output data of the start operator is used as the data format, and the next operator is used as the start operator, and the step of using the data format as the sub-data format of the input data of the start operator is returned to be executed;

[0131] If the next operator of the start operator does not exist in the history operators, the sub-data format of the input data of the start operator is used as the sub-data format of the input data of the target operator.

[0132] S203: Acquire attribute information of the processor, and compile the model file according to the attribute information and the sub-data format to obtain a target model file that matches the processor.

[0133] The processor refers to the final execution unit for information processing and program running, which may include at least one of a central processing unit (CPU), a graphics processing unit (GPU), and a neural network processor (NPU).

[0134] The attribute information of the processor refers to the information describing the characteristics of the processor. For example, the attribute information of the processor can be the instruction set supported by the processor, the operator type supported by the processor, or the type of the processor. The attribute information of different processors is different. For example, the instruction sets supported by different processors are different. When the processor is an Intel or Amd processor, the instruction set supported by the Intel or Amd processor is the x86 / x64 instruction set. When the processor is a Qualcomm or HiSilicon processor, the Qualcomm or HiSilicon processor supports the arm instruction set. Therefore, in an embodiment of the present application, according to the attribute information of the processor, the model file is compiled so that the compiled model file is a file supported by the processor.

[0135] According to the sub-data format, the model file is compiled and processed, so that the compiled model file includes the sub-data format, that is, the compiled model file can include not only each operator, but also the sub-data format of each operator. Therefore, according to the attribute information and the sub-data format, the model file is compiled and processed to obtain a target model file that matches the processor, so that the target model file can be a file supported by the processor and containing the sub-data format, so that when the target model file is run by the processor, the data to be processed with the data format can be processed by the target model file, and then the data to be processed with the data format can be processed by the neural network model. Since the data format can be any data format, the embodiment of the present application can realize the input of multiple data formats of the data to be processed to the processor, and improve the flexibility of the neural network model running by the processor to process the data to be processed.

[0136] Furthermore, in an embodiment of the present application, the data format is mapped according to the operator to obtain the sub-data format of the operator's input data, and then the model file is compiled according to the attribute information and the sub-data format to obtain the target model file that matches the processor, so that there is no need to set the sub-data format according to the attribute information of the processor, so that no matter which processor is used, the sub-data format can be determined by the embodiment of the present application. Therefore, the method of the embodiment of the present application for mapping the data format according to the operator to obtain the sub-data format of the operator's input data, and compiling the model file according to the attribute information and the sub-data format to obtain the target model file that matches the processor is universal.

[0137] It should be noted that when an electronic device includes multiple processors, after compiling the model file according to the attribute information and sub-data format, a target model file matching each processor can be obtained, and the operators included in the target model file are the operators supported by the processor.

[0138] For example, the model file includes operators op1 and op2, the processor includes a central processing unit and a neural network processor, the central processing unit supports operator op1, and the neural network processor supports operator op2. Then the target model file matching the central processing unit may include operator op1, and the target model file matching the neural network processor may include operator op2.

[0139] In some embodiments, the processor includes multiple processors, and compiles the model file according to the attribute information and the sub-data format to obtain a target model file matching the processor, including:

[0140] Get the original computation graph, which includes nodes, each of which represents an operator.

[0141] According to the attribute information, the original computation graph is divided to obtain a subgraph matching each processor;

[0142] The model file is compiled according to the attribute information, sub-data format and sub-graph to obtain a target model file matching each processor.

[0143] In the embodiment of the present application, the operator in the model file exists in the form of an original computation graph, which is a data structure including nodes and edges, where nodes represent operators and edges represent the flow direction of data of the operator. A subgraph may include at least one operator, and the operators included in the subgraph are all operators that match the processor.

[0144] Since different processors support different operators, and operators that are not supported by the processor cannot run on the processor, in an embodiment of the present application, multiple processors are included, and then the original computational graph is divided according to the attribute information of each processor to obtain a subgraph that matches each processor, that is, a subgraph supported by each processor, and then the model file is compiled according to the attribute information, sub-data format and subgraph to obtain a target model file that matches each processor.

[0145] For example, the original calculation graph may be operator op1→operator op2→operator op3, operator op1 is an operator supported by the central processing unit, and operator op2 and operator op3 are operators supported by the neural network processing. Then, the original calculation graph is divided, and the sub-graph matching the neural network processor is operator op2→operator op3, and the sub-graph matching the central processing unit is operator op1.

[0146] In other embodiments, in order to increase the speed at which subsequent processors run the target model file, the original computation graph is divided according to the attribute information to obtain a subgraph matching each processor. The process may be:

[0147] Determine the starting operator in the original computation graph, and start traversing from the starting operator based on the attribute information;

[0148] If the startup operator is an operator that matches the attribute information, the startup operator is marked, and the subordinate operator of the startup operator is used as the startup operator, and the execution is returned to the steps of traversing from the startup operator according to the attribute information;

[0149] If the startup operator is an operator that does not match the attribute information, the marked startup operator is divided from the original calculation graph to obtain a subgraph that matches the attribute information, and the subordinate operator of the startup operator is used as the startup operator. Return to execute the steps starting from the startup operator according to the attribute information;

[0150] The subgraph matching the attribute information is used as the subgraph matching each processor.

[0151] For example, the original calculation graph is op1→operator op2→operator op3→operator op4→operator op5. Operator op3 is an operator supported by the central processing unit, and operators op1, op2, op4, and op5 are operators supported by the neural network processor. The starting operator in the original calculation graph is operator op1.

[0152] The traversal starts from operator op1. Since operator op1 is an operator supported by the neural network processor, operator op1 is marked, and the subordinate operator of operator op1 is operator op2. Since operator op2 is an operator supported by the neural network processor, operator op2 is marked, and the subordinate operator of operator op2 is operator op3. Since operator op3 is not an operator supported by the neural network processor, the marked operator op1 and the marked operator op2 are separated, and the subgraph matching the neural network processor is op1→operator op2.

[0153] Because operator op3 has a subordinate operator "operator op4", the traversal starts from operator op4. Since operator op4 is an operator supported by the neural network processor, operator op4 is marked. The subordinate operator of operator op4 is operator op5. Since operator op5 is an operator supported by the neural network processor, operator op5 is marked. Since there is no subordinate operator of operator op5, the marked operator op4 and the marked operator op5 are separated, and the subgraph matching the neural network processor is op4→operator op5.

[0154] At this time, the target model file matching the neural network model processor may include two, one target model file matching the neural network model processor includes the subgraph "op1→operator op2", and the other target model file matching the neural network model processor includes the subgraph "op4→operator op5".

[0155] In an embodiment of the present application, a startup operator in an original calculation graph is determined, and traversal is started from the startup operator according to the attribute information; if the startup operator is an operator that matches the attribute information, the startup operator is marked, and the subordinate operator of the startup operator is used as the startup operator, and the step of traversal from the startup operator according to the attribute information is returned; if the startup operator is an operator that does not match the attribute information, the marked startup operator is divided from the original calculation graph to obtain a subgraph that matches the attribute information, and the subordinate operator of the startup operator is used as the startup operator, and the step of traversal from the startup operator according to the attribute information is returned; the subgraph that matches the attribute information is used as a subgraph that matches each processor, so that multiple operators that match the processor and have edges can be divided into the same subgraph, so that multiple operators that match the processor and have edges can be stored in the same target model file, so that when the target model file is subsequently run by the processor, the number of times the processor is called can be reduced, and the speed at which the processor runs the target model file can be improved.

[0156] In other embodiments, when the data format is a data shape, the process of compiling the model file according to the attribute information, the sub-data format and the sub-graph to obtain the target model file matching each processor may be:

[0157] According to the original computation graph, determine the initial data type of the input data of the subgraph;

[0158] Determine the target data type of the input data of the subgraph according to the attribute information;

[0159] The model file is compiled according to the attribute information, the sub-data format, the initial data type and the target data type to obtain a target model file matching each processor.

[0160] The process of compiling the model file according to the attribute information, the sub-data format, the initial data type and the target data type to obtain the target model file matching each processor may be as follows:

[0161] If the initial data type and the target data type are not the same, obtain the data type conversion operator;

[0162] The subgraph is adjusted according to the data type conversion operator to obtain a first adjusted subgraph;

[0163] The model file is compiled according to the attribute information, the sub-data format and the first adjusted sub-graph to obtain a target model file matching each processor.

[0164] If the initial data type and the target data type are not the same, it indicates that the target data type needs to be converted to the initial data type. Therefore, a data type conversion operator can be added to the subgraph to convert the data type of the input data of the subgraph into the initial data type so that the target model file can be run through the processor later.

[0165] If the initial data type and the target data type are the same, indicating that the target data type does not need to be converted, the model file can be directly compiled according to the attribute information, sub-data format and sub-graph to obtain a target model file that matches the processor.

[0166] For example, the processor is CoreML, and the initial data type of the input data of CoreML is Int32. If the target data type of the input data of the original calculation graph is Int64, a data type conversion operator (cast operator) is added to the subgraph to obtain the first adjusted subgraph.

[0167] In other embodiments, when the data format is a data shape, the process of compiling the model file according to the attribute information, the sub-data format and the sub-graph to obtain the target model file matching each processor may also be:

[0168] Determine, according to the original computation graph, a first initial data type of the output data of the subgraph;

[0169] Determine, according to the attribute information, a first target data type of the output data of the subgraph;

[0170] If the first initial data type and the first target data type are not the same, obtaining an output data type conversion operator;

[0171] The subgraph is adjusted according to the output data type conversion operator to obtain a third adjusted subgraph;

[0172] The model file is compiled according to the attribute information, the sub-data format and the third adjusted sub-graph to obtain a target model file matching each processor.

[0173] If the first initial data type and the first target data type are not the same, it indicates that the first target data type needs to be converted into the first initial data type. Therefore, an output data type conversion operator can be added to the subgraph to convert the data type of the output data of the subgraph into the first initial data type, so that the data type of the output data when the target model file is subsequently run through the processor meets the user's needs.

[0174] If the first initial data type and the first target data type are the same, indicating that the first target data type does not need to be converted, the model file can be directly compiled according to the attribute information, sub-data format and sub-graph to obtain a target model file that matches the processor.

[0175] For example, the processor is CoreML, and the first initial data type of the output data of CoreML is Flat32. If the first target data type of the output data of the original calculation graph is Int8, an output data type conversion operator is added to the subgraph to obtain the third adjusted subgraph.

[0176] It should be understood that the terminal can also obtain the initial data type, the target data type, the first initial data type and the first target data type at the same time, and then adjust the sub-image according to the initial data type, the target data type, the first initial data type and the first target data type to obtain a fourth adjusted sub-image.

[0177] For example, the processor is CoreML, the initial data type of CoreML's input data is Int32, and the first initial data type of CoreML's output data is Flat32. If the target data type of the input data of the original calculation graph is Int64, and the first target data type of the output data of the original calculation graph is Int8, then a data type conversion operator and an output data type conversion operator are added to the subgraph to obtain the fourth adjusted subgraph.

[0178] In other embodiments, the model file is compiled according to the attribute information, the sub-data format and the sub-graph to obtain a target model file matching each processor, including:

[0179] Determine the type of operator in the subgraph;

[0180] If the type of the operator in the subgraph is a preset type, the operator in the subgraph is adjusted to obtain a second adjusted subgraph;

[0181] The model file is compiled according to the attribute information, the sub-data format and the second adjusted sub-graph to obtain a target model file matching each processor.

[0182] Since some operations can be implemented by different operators and the speeds of running different operators through the processor are different, the preset type of the operator can be set in advance. If the type of the operator in the subgraph is the preset type, the operator in the subgraph is adjusted to obtain a second adjusted subgraph, and then the model file is compiled according to the attribute information, the sub-data format and the second adjusted subgraph to obtain a target model file matching each processor, so that the processor can run the operator in the target model file matching the processor faster.

[0183] For example, the addition operator in the subgraph can be converted into a subtraction operator, and the addition operation can be implemented through the subtraction operator. The division operator in the subgraph can be converted into a multiplication operator, and the division operation can be implemented through the multiplication operator. The convolution operator and the addition operator in the subgraph can be fused into one operator.

[0184] S204, processing the data to be processed of the neural network model by running the target model file through the processor to obtain the processing result of the data to be processed.

[0185] The type of data to be processed can be selected according to actual conditions. For example, the data to be processed can be an image to be processed, or another example is that the data to be processed can be audio to be processed, etc. The embodiment of the present application does not limit this.

[0186] The type of processing for the data to be processed can be selected according to actual conditions. For example, the data to be processed may be classified, or text may be extracted from the data to be processed. This embodiment of the present application does not limit this.

[0187] After obtaining the target model file, the terminal may immediately run the target model file through the processor, or the terminal may also run the target model file through the processor after obtaining the running instruction.

[0188] If the terminal includes multiple processors, that is, there are multiple target model files matching the processors, the terminal can call each processor and run each target model file according to the execution order of the operators in each target model file.

[0189] For example, the target model file includes a target model file f1 and a target model file f2, the execution order of the operators in the target model file f1 precedes the execution order of the operators in the target model file f2, the target model file f1 is a target model file that matches the central processing unit, and the target model file 21 is a target model file that matches the neural network processor. After the terminal obtains the data to be processed, it first calls the central processing unit to run the target model file f1 to process the data to be processed to obtain candidate data, and then calls the neural network model processor to run the target model file f2 to process the candidate data to obtain the processing result of the data to be processed, thereby realizing the processing of the data to be processed through the neural network model.

[0190] In some embodiments, the processor runs the target model file to process the data to be processed of the neural network model to obtain the processing result of the data to be processed, including:

[0191] Determining a target data format for data to be processed by a neural network model;

[0192] If the target data format does not match the sub-data format in the target model file, the target data format of the data to be processed is adjusted to obtain the adjusted data to be processed;

[0193] The target model file is run by the processor to process the adjusted data to be processed, and a processing result of the data to be processed is obtained.

[0194] The target data format does not match the sub-data format in the target model file, which may mean that the target data format is different from the sub-data format of the startup operator in the target model file.

[0195] For example, the target model file includes operator op1→operator op2→operator op3, and the target data format does not match the sub-data format in the target model file, which may mean that the target data format is different from the sub-data format of operator op1.

[0196] The terminal may obtain the sub-data format from the target model file, or, after obtaining the sub-data format, the terminal may associate the identifier of each operator with the sub-data format and store it in a format storage unit, and then obtain the sub-data format corresponding to the operator in the target model file from the format storage unit.

[0197] In an embodiment of the present application, before the data to be processed is processed through the target model file, the target data format of the data to be processed is checked first. If the target data format does not match the sub-data format in the target model file, the target data format of the data to be processed is corrected to obtain adjusted data to be processed; finally, the adjusted data to be processed is processed by running the target model file through the processor, so as to process the adjusted data to be processed through the neural network model to obtain the processing result of the data to be processed.

[0198] In other embodiments, the processor runs the target model file to process the data to be processed of the neural network model to obtain the processing result of the data to be processed, including:

[0199] Processing the data to be processed by the neural network model by running the target model file through the processor to obtain candidate processing results of the data to be processed;

[0200] determining an output data format of the candidate processing result;

[0201] According to the target model file, the output data format of the candidate processing result is adjusted to obtain the processing result of the data to be processed.

[0202] In an embodiment of the present application, when the data format is mapped according to the operator, the sub-data format of the operator's input data and the sub-data format of the output data can be obtained at the same time, that is, the target model file can simultaneously include the sub-data format of the input data and the sub-data format of the output data of each operator. Then, after obtaining the candidate processing result, the terminal can determine whether the output data format of the candidate processing result is the same as the sub-data format of the output data of the operator in the target model file. If they are not the same, the output data format of the candidate processing result is adjusted to the sub-data format of the output data of the operator in the target model file to obtain the processing result, thereby improving the accuracy of the processing result.

[0203] From the above, it can be seen that in an embodiment of the present application, the data format of the input data of the neural network model is obtained, and the model file of the neural network model is obtained, the model file includes the operator of the neural network model; according to the operator, the data format is mapped to obtain the sub-data format of the input data of the operator; the attribute information of the processor is obtained, and the model file is compiled according to the attribute information and the sub-data format to obtain a target model file matching the processor, so that the target model file includes the sub-data format and the target model file is a file supported by the processor, so that when the target data format of the data to be processed of the neural network model is the data format, the target model file can be run by the processor to process the data to be processed of the neural network model to obtain the processing result of the data to be processed. Since the data format can be any data format, the embodiment of the present application can realize the input of multiple data formats of the data to be processed to the processor, thereby improving the flexibility of processing the data to be processed by the neural network model run by the processor.

[0204] The method described in the above embodiment is further described in detail below with examples.

[0205] In this embodiment, the data format is data shape as an example, the sub-data format is sub-data shape as an example, the format mapping strategy is shape mapping strategy as an example, the to-be-processed data is an to-be-processed image as an example, and the data processing is text extraction as an example. This embodiment can be implemented by an inference engine, which refers to a system component that applies logical rules to a knowledge base to infer new information.

[0206] See also Figure 3 , Figure 3 A flow chart of a data processing method provided in an embodiment of the present application. The data processing method flow may include:

[0207] S301. The terminal obtains the data shape of the input data of the trained neural network model, and obtains the initial model file of the trained neural network model, where the initial model file includes the operators of the trained neural network model.

[0208] The file format of the initial model file may be a general file, for example, the initial model file may be an ONNX model file or an NCNN model file.

[0209] S302: The terminal converts the file format of the initial model file to obtain a model file supported by the inference engine.

[0210] Since the inference engine has its own recognizable file format, after obtaining the initial model file, the terminal can convert the file format of the initial model file to obtain a model file supported by the inference engine.

[0211] For example, when the inference engine is WeChat's self-developed inference engine and the initial model file is an ONNX model file, the ONNX model file can be converted into an XNet model file.

[0212] S303: The terminal obtains the shape mapping strategy corresponding to each operator in the model file, and maps the data shape using the shape mapping strategy to obtain the sub-data shape of the input data and the sub-data shape of the output data of the operator.

[0213] S304. The terminal stores the sub-data shape of the input data and the sub-data shape of the output data of the operator in the model file to obtain a candidate model file, and stores the sub-data shape of the input data and the sub-data shape of the output data of the operator in the format storage unit.

[0214] For example, the sub-data shape of the input data and the sub-data shape of the output data of the operator can be stored in the format storage unit as follows: Figure 4 shown.

[0215] Among them, steps S301-S304 can be called the model conversion stage, for example, Figure 5 The model conversion phase refers to converting the initial model file in a common file format into a model file in a file format automatically defined by the inference engine.

[0216] It should be understood that the data shape can be at least one, and after mapping the data shape, the sub-data shape of the input data and the sub-data shape of the output data of the operator for each data shape can be obtained. That is, at this time, the candidate model file and the format storage unit can include the sub-data shape of the input data and the sub-data shape of the output data of the operator for all data shapes.

[0217] S305. The terminal obtains an original calculation graph corresponding to the candidate model file. The original calculation graph includes nodes, each node represents an operator, and an edge of the original calculation graph represents a flow direction of data of the node.

[0218] S306. The terminal obtains the attribute information of the neural network processor and the attributes of the central processing unit, and divides the original calculation graph according to the attribute information to obtain a subgraph matching the neural network processor and a subgraph matching the central processing unit.

[0219] This step can be called the computational graph partitioning step. The computational graph partitioning step can be performed by the subgraph partitioning unit and the operator selection unit in the inference engine. The subgraph partitioning unit is a general unit that can be used to accelerate the subgraph partitioning of the hardware. Based on the operator selection unit, a subgraph is selected. All operators in the subgraph are operators selected by the operator selection unit, and there are no operators on the paths between operators in the subgraph that are not selected by the operator selection unit.

[0220] The operator selection unit is used to configure different neural network processors. Different neural network processors support different operators. The operator selection unit is used to select an operator that is implemented in the neural network processor and has better performance.

[0221] S307. The terminal determines the initial data type of the input data and the first initial data type of the output data of the subgraph according to the original calculation graph, and determines the target data type of the input data and the first target data type of the output data of the subgraph according to the attribute information.

[0222] S308: If the initial data type is different from the target data type, the terminal obtains a data type conversion operator.

[0223] S309: If the first initial data type is different from the first target data type, the terminal obtains an output data type conversion operator.

[0224] S3010. The terminal adjusts the subgraph according to the data type conversion operator and / or the output data type conversion operator to obtain a fourth adjusted subgraph.

[0225] Among them, the subgraphs in steps S307-S3010 can be subgraphs that match the neural network processor and subgraphs that match the central processing unit. Steps S307-S3010 can be called subgraph legitimacy check steps, which can be performed by a check correction unit, that is, the check correction unit is used to check whether the data type of the input data of the original calculation graph is the same as the data type of the input data of the subgraph, and to check whether the data type of the output data of the original calculation graph is the same as the data type of the output data of the subgraph.

[0226] S3011. The terminal determines the type of the operator in the fourth adjusted subgraph, and if the type of the operator in the fourth adjusted subgraph is a preset type, adjusts the operator in the fourth adjusted subgraph to obtain a second adjusted subgraph.

[0227] S3012. The terminal compiles the candidate model file according to the attribute information and the second adjusted sub-graph to obtain a target model file that matches the neural network processor and a target model file that matches the central processing unit.

[0228] Among them, step S3012 can be executed by a conversion unit, that is, converting the operator definition in the candidate model file into the operator definition of the neural network processor and the operator definition of the central processing unit.

[0229] Steps S3011 - S3012 may be referred to as subgraph optimization steps, which may be performed by a subgraph optimization unit, where the subgraph optimization unit is used to optimize the subgraph.

[0230] Steps S305-S3012 may be referred to as the model compilation phase, for example, Figure 5 The model compilation phase is performed once before the trained neural network model is executed, and it can select a specific processor implementation.

[0231] Optionally, during the model compilation phase, the intermediate expression of the neural network processor can also be stored through the Cache storage unit. For example, when the neural network processor is a CoreML processor, the mlmodelc file is stored through the Cache storage unit, and when the neural network processor is a HiSilicon processor, the om file is stored through the Cache storage unit.

[0232] S3013. The terminal obtains the image to be processed of the trained neural network model, and determines the target data shape of the image tensor corresponding to the image to be processed.

[0233] S3014. The terminal obtains the sub-data shape of the input data of the sub-graph in the target model file matching the neural network processor from the format storage unit, and checks the target data shape according to the sub-data shape of the input data of the sub-graph in the target model file matching the neural network processor.

[0234] S3015. If the target data shape does not match the sub-data shape of the input data of the sub-graph in the target model file that matches the neural network processor, the terminal modifies the target data shape of the image tensor to obtain an adjusted image tensor.

[0235] For example, a subgraph in a target model file matching a neural network processor can be Figure 4 As shown, the subgraph includes operators op1, op2, op3 and op4, and operator op1 is an input node, that is, operator op1 is a start operator, and the target data shape is checked according to the sub-data shape of the input data of operator op1.

[0236] S3016. The terminal calls the neural network processor to run the target model file that matches the neural network processor, performs feature processing on the adjusted image tensor, and obtains the original features corresponding to the image to be processed.

[0237] S3017. The terminal obtains the sub-data shape of the output data of the sub-graph in the target model file matching the neural network processor from the format storage unit, and checks the output data shape of the original feature based on the sub-data shape of the output data of the sub-graph in the target model file matching the neural network processor.

[0238] S3018. If the output data shape does not match the sub-data shape of the output data of the operator in the target model file matching the neural network processor, the terminal modifies the output data shape of the original feature to the sub-data shape of the output data of the sub-graph in the target model file matching the neural network processor, and obtains the candidate feature corresponding to the image to be processed.

[0239] For example, a subgraph in a target model file matching a neural network processor can be Figure 4 As shown, the subgraph includes operators op1, op2, op3 and op4, and operator op4 is an output node, that is, operator op4 is the last operator, and the output data shape of the original feature is checked according to the sub-data shape of the output data of operator op4.

[0240] In an embodiment of the present application, the output data shape of the output data of the neural network processor is checked to avoid errors in the data shape of the output data when there are multiple data shapes.

[0241] S3019, the terminal calls the central processing unit to run the target model file that matches the central processing unit, performs feature recognition on the candidate features, and obtains the text corresponding to the image to be processed.

[0242] When the terminal calls the central processing unit to run the target model file that matches the central processing unit, the data shape of the candidate features and the data shape of the text corresponding to the image to be processed can also be checked. For details, please refer to the process of checking the target data shape and the output data shape when calling the neural network processor to run the target model file that matches the neural network processor. The embodiments of the present application will not be repeated here.

[0243] Steps S3013-S3019 can be executed by a processing module, which can also be called an execution module. The interface improved by the manufacturer of the neural network processor is called through the execution module to call the neural network processor.

[0244] Steps S3013-S3019 may be referred to as the model execution phase, that is, the process of deploying the trained neural network model to the neural network processor and the central processing unit in this embodiment, which may include a model conversion phase, a model compilation phase, and a model execution phase.

[0245] Compared with the central processing unit, the neural network processor has greater computing power and is more focused on high-density computing. For example, the theoretical computing power peak of Apple's a14 neural network processor (theoretical computing power peak refers to the maximum number of floating-point / fixed-point calculations that the hardware can complete in a certain period of time) has reached 11T FLOP / s (FLOP / s means the number of floating-point calculations that can be completed per second), while the theoretical computing power peak of a large core of a central processing unit is only 96GFLOP / s.

[0246] Therefore, the embodiment of the present application deploys a trained neural network model through a neural network processor, which can increase the speed of extracting text from an image to be processed through the trained neural network model.

[0247] Furthermore, the central processing unit in the embodiment of the present application may be a high-performance processor developed by WeChat. Deploying a trained neural network model on the high-performance processor developed by WeChat can also improve the speed of extracting text from the image to be processed through the trained neural network model.

[0248] Since the power consumption of a neural network processor is lower than that of an image processor, the embodiment of the present application deploys a trained neural network model through a neural network processor, thereby reducing the power consumption when extracting text from an image to be processed through the trained neural network model.

[0249] Therefore, an embodiment of the present application provides a use framework for a neural network processor, which is combined with WeChat's self-developed high-performance operator implementation, thereby greatly improving the text extraction speed of the trained neural network model deployed on the neural network processor and the central processing unit.

[0250] The specific implementation method and beneficial effects of this embodiment can be specifically referred to the above-mentioned data processing method embodiment, and this embodiment will not be repeated here.

[0251] In order to better implement the data processing method provided in the embodiment of the present application, the embodiment of the present application also provides a device based on the above data processing method. The meanings of the terms are the same as those in the above data processing method, and the specific implementation details can refer to the description in the method embodiment.

[0252] For example, Figure 6 As shown, the data processing device may include:

[0253] The acquisition module 601 is used to obtain the data format of the input data of the neural network model, and to obtain the model file of the neural network model, wherein the model file includes the operator of the neural network model.

[0254] The mapping module 602 is used to perform mapping processing on the data format according to the operator to obtain the sub-data format of the input data of the operator.

[0255] The compiling module 603 is used to obtain the attribute information of the processor, and compile the model file according to the attribute information and the sub-data format to obtain a target model file matching the processor.

[0256] The processing module 604 is used to process the data to be processed of the neural network model by running the target model file through the processor to obtain the processing result of the data to be processed.

[0257] Optionally, the mapping module 602 is specifically configured to execute:

[0258] Get the format mapping strategy corresponding to the operator;

[0259] The data format is mapped through the format mapping strategy to obtain the sub-data format of the operator's input data.

[0260] Optionally, the mapping module 602 is specifically configured to execute:

[0261] Filter out the startup operator from the operators, and use the data format as the sub-data format of the input data of the startup operator;

[0262] According to the startup operator, mapping processing is performed on the sub-data format of the input data of the startup operator to obtain the sub-data format of the output data of the startup operator;

[0263] If there is a next operator of the start operator in the operator, the sub-data format of the output data of the start operator is used as the data format, and the next operator is used as the start operator, and the step of using the data format as the sub-data format of the input data of the start operator is returned to be executed;

[0264] If the next operator of the initiating operator does not exist in the operator, the sub-data format of the input data of the operator is determined according to the sub-data format of the input data of the initiating operator.

[0265] Optionally, the mapping module 602 is specifically configured to execute:

[0266] Filter out a target operator from the operators, and determine the historical operators before the target operator in the neural network model;

[0267] According to the historical operator, the data format is mapped to obtain the sub-data format of the input data of the target operator;

[0268] The sub-data format of the input data of the operator is determined according to the sub-data format of the input data of the target operator.

[0269] Optionally, the mapping module 602 is specifically configured to execute:

[0270] Determine conversion model parameters according to model parameters of historical operators;

[0271] According to the conversion model parameters, the data format is mapped to obtain the sub-data format of the input data of the target operator.

[0272] Optionally, the processor includes multiple processors. Accordingly, the compiling module 603 is specifically used to execute:

[0273] Get the original computation graph, which includes nodes, each of which represents an operator.

[0274] According to the attribute information, the original computation graph is divided to obtain a subgraph matching each processor;

[0275] The model file is compiled according to the attribute information, sub-data format and sub-graph to obtain a target model file matching each processor.

[0276] Optionally, the compiling module 603 is specifically used to execute:

[0277] According to the original computation graph, determine the initial data type of the input data of the subgraph;

[0278] Determine the target data type of the input data of the subgraph according to the attribute information;

[0279] The model file is compiled according to the attribute information, the sub-data format, the initial data type and the target data type to obtain a target model file matching each processor.

[0280] Optionally, the compiling module 603 is specifically used to execute:

[0281] If the initial data type and the target data type are not the same, obtain the data type conversion operator;

[0282] The subgraph is adjusted according to the data type conversion operator to obtain a first adjusted subgraph;

[0283] The model file is compiled according to the attribute information, the sub-data format and the first adjusted sub-graph to obtain a target model file matching each processor.

[0284] Optionally, the compiling module 603 is specifically used to execute:

[0285] Determine the type of operator in the subgraph;

[0286] If the type of the operator in the subgraph is a preset type, the operator in the subgraph is adjusted to obtain a second adjusted subgraph;

[0287] The model file is compiled according to the attribute information, the sub-data format and the second adjusted sub-graph to obtain a target model file matching each processor.

[0288] Optionally, the processing module 604 is specifically configured to execute:

[0289] Determining a target data format for data to be processed by a neural network model;

[0290] If the target data format does not match the sub-data format in the target model file, the target data format of the data to be processed is adjusted to obtain the adjusted data to be processed;

[0291] The target model file is run by the processor to process the adjusted data to be processed, and a processing result of the data to be processed is obtained.

[0292] Optionally, the processing module 604 is specifically configured to execute:

[0293] Processing the data to be processed by the neural network model by running the target model file through the processor to obtain candidate processing results of the data to be processed;

[0294] determining an output data format of the candidate processing result;

[0295] According to the target model file, the output data format of the candidate processing result is adjusted to obtain the processing result of the data to be processed.

[0296] In specific implementation, the above modules can be implemented as independent entities, or can be arbitrarily combined and implemented as the same or several entities. The specific implementation methods and corresponding beneficial effects of the above modules can be found in the previous method embodiments, which will not be repeated here.

[0297] The present application also provides an electronic device, which may be a server or a terminal, etc. Figure 7 As shown, it shows a schematic diagram of the structure of the electronic device involved in the embodiment of the present application, specifically:

[0298] The electronic device may include components such as a processor 701 with one or more processing cores, a memory 702 with one or more computer-readable storage media, a power supply 703, and an input unit 704. Those skilled in the art will appreciate that Figure 7 The electronic device structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.

[0299] The processor 701 is the control center of the electronic device, which uses various interfaces and lines to connect various parts of the entire electronic device, and executes various functions of the electronic device and processes data by running or executing computer programs and / or modules stored in the memory 702, and calling data stored in the memory 702. Optionally, the processor 701 may include one or more processing cores; preferably, the processor 701 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 701.

[0300] The memory 702 can be used to store computer programs and modules. The processor 701 executes various functional applications and data processing by running the computer programs and modules stored in the memory 702. The memory 702 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, a computer program required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 702 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 702 may also include a memory controller to provide the processor 701 with access to the memory 702.

[0301] The electronic device also includes a power supply 703 for supplying power to each component. Preferably, the power supply 703 can be logically connected to the processor 701 through a power management system, so as to manage charging, discharging, and power consumption through the power management system. The power supply 703 can also include any components such as one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, and power status indicators.

[0302] The electronic device may further include an input unit 704, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.

[0303] Although not shown, the electronic device may further include a display unit, etc., which will not be described in detail herein. Specifically in this embodiment, the processor 701 in the electronic device will load the executable files corresponding to the processes of one or more computer programs into the memory 702 according to the following instructions, and the processor 701 will run the computer programs stored in the memory 702, thereby realizing various functions, such as:

[0304] Obtaining the data format of the input data of the neural network model, and obtaining the model file of the neural network model, wherein the model file includes the operator of the neural network model;

[0305] According to the operator, the data format is mapped to obtain the sub-data format of the operator's input data;

[0306] Acquire the attribute information of the processor, and compile the model file according to the attribute information and the sub-data format to obtain a target model file matching the processor;

[0307] The target model file is run by the processor to process the data to be processed of the neural network model, so as to process the data to be processed through the neural network model and obtain the processing result of the data to be processed.

[0308] The specific implementation methods and corresponding beneficial effects of the above operations can be found in the detailed description of the data processing method above, which will not be elaborated here.

[0309] Those skilled in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by a computer program, or by controlling related hardware through a computer program. The computer program may be stored in a computer-readable storage medium and loaded and executed by a processor.

[0310] To this end, an embodiment of the present application provides a computer-readable storage medium, in which a computer program is stored, and the computer program can be loaded by a processor to execute the steps in any data processing method provided in the embodiment of the present application. For example, the computer program can execute the following steps:

[0311] Obtaining the data format of the input data of the neural network model, and obtaining the model file of the neural network model, wherein the model file includes the operator of the neural network model;

[0312] According to the operator, the data format is mapped to obtain the sub-data format of the operator's input data;

[0313] Acquire the attribute information of the processor, and compile the model file according to the attribute information and the sub-data format to obtain a target model file matching the processor;

[0314] The target model file is run by the processor to process the data to be processed of the neural network model to obtain the processing result of the data to be processed.

[0315] The specific implementation methods and corresponding beneficial effects of the above operations can be found in the previous embodiments, which will not be described in detail here.

[0316] The computer-readable storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0317] Since the computer program stored in the computer-readable storage medium can execute the steps in any data processing method provided in the embodiments of the present application, the beneficial effects that can be achieved by any data processing method provided in the embodiments of the present application can be achieved. Please refer to the previous embodiments for details and will not be repeated here.

[0318] According to one aspect of the present application, a computer program product or a computer program is provided, the computer program product or the computer program includes computer instructions, the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the above-mentioned data processing method.

[0319] The above is a detailed introduction to a data processing method, device, equipment, storage medium and program product provided in the embodiments of the present application. Specific examples are used in this article 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 technical personnel in this field, according to the idea of ​​the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A data processing method, characterized in that: Applied to an electronic device, the electronic device includes a processor, and the method includes: Acquire the data format of input data of the neural network model, and acquire the model file of the neural network model, wherein the model file includes the operator of the neural network model; According to the operator, mapping processing is performed on the data format to obtain a sub-data format of the input data of the operator; Acquire the attribute information of the processor, and compile the model file according to the attribute information and the sub-data format to obtain a target model file matching the processor; The processor runs the target model file to process the data to be processed of the neural network model to obtain a processing result of the data to be processed.

2. The data processing method according to claim 1, characterized in that: The mapping process is performed on the data format according to the operator to obtain a sub-data format of the input data of the operator, including: Obtaining the format mapping strategy corresponding to the operator; The data format is mapped using the format mapping strategy to obtain a sub-data format of the input data of the operator.

3. The data processing method according to claim 1, characterized in that: The mapping process is performed on the data format according to the operator to obtain a sub-data format of the input data of the operator, including: Filtering out a startup operator from the operators, and using the data format as a sub-data format of input data of the startup operator; According to the startup operator, mapping processing is performed on the sub-data format of the input data of the startup operator to obtain the sub-data format of the output data of the startup operator; If the next operator of the start operator exists in the operator, the sub-data format of the output data of the start operator is used as the data format, and the next operator is used as the start operator, and the step of using the data format as the sub-data format of the input data of the start operator is returned to be executed; If the next operator of the initiating operator does not exist in the operators, the sub-data format of the input data of the operator is determined according to the sub-data format of the input data of the initiating operator.

4. The data processing method according to claim 1, characterized in that: The mapping process is performed on the data format according to the operator to obtain a sub-data format of the input data of the operator, including: Filtering a target operator from the operators, and determining a historical operator before the target operator in the neural network model; According to the historical operator, mapping processing is performed on the data format to obtain a sub-data format of the input data of the target operator; The sub-data format of the input data of the operator is determined according to the sub-data format of the input data of the target operator.

5. The data processing method according to claim 4, characterized in that: The mapping process is performed on the data format according to the historical operator to obtain the sub-data format of the input data of the target operator, including: Determining conversion model parameters according to the model parameters of the historical operator; The data format is mapped according to the conversion model parameters to obtain a sub-data format of the input data of the target operator.

6. The data processing method according to claim 1, characterized in that: The processor includes a plurality of processors, and the model file is compiled according to the attribute information and the sub-data format to obtain a target model file matching the processor, including: Obtaining an original computation graph, wherein the original computation graph includes nodes, and the nodes represent the operators; According to the attribute information, the original computation graph is divided to obtain a subgraph matching each of the processors; The model file is compiled according to the attribute information, the sub-data format and the sub-graph to obtain a target model file matching each of the processors.

7. The data processing method according to claim 6, characterized in that: The compiling process of the model file according to the attribute information, the sub-data format and the sub-graph to obtain a target model file matching each of the processors includes: Determine the initial data type of the input data of the subgraph according to the original computation graph; Determining a target data type of input data of the subgraph according to the attribute information; The model file is compiled according to the attribute information, the sub-data format, the initial data type and the target data type to obtain a target model file matching each of the processors.

8. The data processing method according to claim 7, characterized in that: The compiling process of the model file according to the attribute information, the sub-data format, the initial data type and the target data type to obtain a target model file matching each processor includes: If the initial data type and the target data type are different, obtaining a data type conversion operator; Adjust the subgraph according to the data type conversion operator to obtain a first adjusted subgraph; The model file is compiled according to the attribute information, the sub-data format and the first adjusted sub-graph to obtain a target model file matching each of the processors.

9. The data processing method according to claim 6, characterized in that: The compiling process of the model file according to the attribute information, the sub-data format and the sub-graph to obtain a target model file matching each of the processors includes: Determine the type of operator in the subgraph; If the type of the operator in the subgraph is a preset type, adjusting the operator in the subgraph to obtain a second adjusted subgraph; The model file is compiled according to the attribute information, the sub-data format and the second adjusted sub-graph to obtain a target model file matching each of the processors.

10. The data processing method according to any one of claims 1 to 9, characterized in that: The processing of the to-be-processed data of the neural network model by running the target model file by the processor to obtain the processing result of the to-be-processed data includes: Determining a target data format of the data to be processed by the neural network model; If the target data format does not match the sub-data format in the target model file, adjusting the target data format of the data to be processed to obtain adjusted data to be processed; The processor runs the target model file to process the adjusted data to be processed to obtain a processing result of the data to be processed.

11. The data processing method according to any one of claims 1 to 9, characterized in that: The processing of the to-be-processed data of the neural network model by running the target model file by the processor to obtain the processing result of the to-be-processed data includes: The processor runs the target model file to process the data to be processed by the neural network model to obtain a candidate processing result of the data to be processed; Determining an output data format of the candidate processing result; According to the target model file, the output data format of the candidate processing result is adjusted to obtain the processing result of the data to be processed.

12. A data processing device, characterized in that: include: An acquisition module, used to acquire the data format of input data of a neural network model, and to acquire a model file of the neural network model, wherein the model file includes operators of the neural network model; A mapping module, used to perform mapping processing on the data format according to the operator to obtain a sub-data format of the input data of the operator; A compiling module, used for acquiring the attribute information of the processor, and compiling the model file according to the attribute information and the sub-data format to obtain a target model file matching the processor; A processing module is used to process the data to be processed of the neural network model by running the target model file through the processor to obtain the processing result of the data to be processed.

13. An electronic device, characterized in that: It comprises a processor and a memory, wherein the memory stores a computer program, and the processor is used to run the computer program in the memory to execute the data processing method according to any one of claims 1 to 11.

14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program is suitable for being loaded by a processor to execute the data processing method according to any one of claims 1 to 11.

15. A computer program product, characterized in that The computer program product stores a computer program, and the computer program is suitable for being loaded by a processor to execute the data processing method according to any one of claims 1 to 11.

Citation Information

Cited By

  • Data processing apparatus and method, and chip, electronic device and storage medium

    WO2026174872A1