Neural network model conversion method based on MXNet and ONNX

By providing a neural network model conversion method based on MXNet and ONNX, the problem of model conversion between MXNet and ONNX frameworks is solved, efficient conversion and deployment of the model is achieved, and the portability and flexibility of the model are enhanced.

CN119337922AActive Publication Date: 2025-01-21XIDIAN UNIV
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202411552680.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-01
Publication Date
2025-01-21
Estimated Expiration
2044-11-01

AI Technical Summary

Technical Problem

In the prior art, the neural network model under the MXNet framework and the neural network model under the ONNX framework cannot be converted to each other, resulting in poor interoperability between different deep learning frameworks and difficult to deploy and use in different environments.

Method used

Provides a neural network model conversion method based on MXNet and ONNX. By judging the framework of the input model, reading symbol files and weight parameter files, performing data processing and operator conversion, a model under the ONNX framework is constructed, and serialized and saved. .

Benefits of technology

The neural network model under the MXNet framework is completely and efficiently converted to the ONNX framework, and the ONNX format model is converted to the MXNet framework, which enhances the portability and flexibility of the neural network model and solves version compatibility during model conversion. sex and performance issues.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119337922A_ABST
    Figure CN119337922A_ABST
Patent Text Reader

Abstract

According to the neural network model conversion method based on the MXNet and the ONNX, the problem that neural network models under an MXNet framework and an ONNX framework cannot be mutually converted in the prior art is solved; the method comprises the following steps: realizing the conversion process from a neural network model of an MXNet framework to an ONNX model through the processes of MXNet model loading and analysis, operator correspondence and conversion, conversion data processing, network layer conversion, ONNX model construction, ONNX model storage and the like; the process of converting the neural network model of the ONNX framework into the MXNet model is realized through the processes of ONNX model loading and analysis, operator correspondence and conversion, conversion data processing, computational graph conversion, MXNet model export and the like; according to the method, the neural network model under the MXNet framework is completely and efficiently converted into the ONNX framework, and the portability and flexibility of the neural network model are enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of deep learning and artificial intelligence technology, and in particular to a neural network model conversion method based on MXNet (Multilayer Neural Network) and ONNX (Open Neural Network Exchange). Background Art

[0002] In recent years, artificial intelligence technology has gradually developed in a more intelligent and autonomous direction, bringing many conveniences to human life. The development of deep learning technology has also led to the continuous progress of deep learning frameworks. However, for some neural network models that need to be converted between different frameworks, the characteristics of different deep learning frameworks in terms of usage and applicable scenarios have become a shackle. Specifically, each deep learning framework has its own internal format to represent and train deep learning models, and these formats are usually not recognized by other frameworks, resulting in their respective characteristics and advantages restricting the model conversion between different neural network frameworks, and the optimization and improvement of deep learning frameworks are often concentrated within the framework. These reasons ultimately lead to difficulties in interoperability between different frameworks. In actual production applications, scenarios where the development environment and the deployment environment are different often occur. For example, a neural network model trained in a heavyweight deep learning environment (such as TensorFlow, PyTorch, MXNet) needs to be deployed in a resource-constrained environment (such as an IoT device), which may require a lightweight deep learning framework; or compared to the development environment, the deployment environment needs to support a wider set of functions, allowing deeper model modifications and optimizations to be clearly defined.

[0003] The root cause of the above problems is the lack of a unified standardized model format. Based on this, ONNX came into being. ONNX stands for Open Neural Network Exchange, which is an open neural network exchange format. ONNX enhances the interoperability of neural network models between various deep learning frameworks by defining a set of environment- and platform-independent standard formats.

[0004] Apache MXNet is a lightweight, flexible, and highly scalable open source distributed deep learning framework. MXNet provides multi-language API interfaces and supports running on a variety of hardware devices, with significant cross-platform advantages. What is obviously different from most current deep learning systems is that MXNet uses a seamless combination of imperative programming and symbolic programming, achieving a good balance between flexibility and efficiency. The widespread use of MXNet determines the necessity of realizing the mutual conversion of neural network models between the MXNet framework and other deep learning frameworks.

[0005] Using ONNX as a unified intermediate representation format to achieve neural network model conversion between different deep learning frameworks takes into account the overall coverage of classic deep learning frameworks and the extended support for emerging deep learning frameworks. On this basis, supporting the MXNet framework means converting the deep learning model trained in the MXNet framework to the ONNX representation format, or converting the deep learning model in the ONNX file format to the MXNet framework.

[0006] Currently, the industry and academia have developed a series of conversion tools to solve the problem of model conversion between different deep learning frameworks. However, there are two types of problems in the overall design: First, the tool fragmentation. Different tools support a limited number of deep learning frameworks and are not easy to expand. The scattered tools cannot guarantee the effect of model conversion and their role is extremely limited. Second, the current tools do not provide sufficient support for MXNet framework model conversion. The widespread use of the MXNet framework, which is known for its flexibility and efficiency, reflects the necessity of implementing MXNet framework model conversion.

[0007] At the same time, with the rapid development of deep learning technology, existing technologies have gradually shown some problems, specifically: poor compatibility. The current support for model conversion may be limited to one or some versions of the deep learning framework. Since the deep learning framework itself is constantly updated and iterated, there may be some API differences between different versions. The support for model conversion lags behind the development of the deep learning framework itself, which makes neural network model conversion tools prone to version compatibility issues. In addition, performance cannot be guaranteed. The current work on neural network model conversion focuses more on the conversion itself, and there is a lack of a complete theoretical basis for measuring and comparing the conversion effect.

[0008] For the MXNet framework, the currently widely used conversion tool MMDnn has its own original intermediate representation format, and this format is only used to temporarily save the parsed model information and will not be exported as a specific file. Although this independent intermediate representation format is more lightweight, it is precisely because of its maximum format simplification that it becomes difficult to expand some new nodes. Summary of the invention

[0009] The present invention provides a neural network model conversion method based on MXNet and ONNX, thereby solving the problem in the prior art that the neural network model under the MXNet framework and the neural network model under the ONNX framework cannot be converted to each other, and realizes the complete and efficient conversion of the neural network model under the MXNet framework to the ONNX framework, and can also complete the complete and efficient conversion of the neural network model in the ONNX format to the MXNet framework, thereby enhancing the portability and flexibility of the neural network model.

[0010] The present invention provides a neural network model conversion method based on MXNet and ONNX, the method comprising:

[0011] Determine whether the input neural network model to be converted is a neural network model under the MXNet framework. If so, obtain initial conditions from the neural network model to be converted;

[0012] Read the symbol file in the initial condition, and convert the symbol file into a Symbol object;

[0013] Read the weight parameter file in the initial condition, and perform data processing on the weight parameter file to obtain the weight parameter file of the MXNet model under the MXNet framework; wherein the weight parameter file includes: data tags of each data;

[0014] Determine the name of each network layer in the neural network model to be converted, and mark the useless network layers in the neural network model to be converted to obtain the marked network layers;

[0015] Perform data processing on the weight parameter file of the MXNet model to obtain a general NumPy array;

[0016] Initialize the input node list, output node list and operation node list under the MXNet framework, construct the operator conversion function of the MXNet framework and the ONNX framework, traverse all the operation nodes in the labeled network layer, determine the operator type of each operation node, call the operator conversion function according to the operator type, convert the operation nodes under the MXNet framework into operation nodes under the MXNet framework, and update the input node list, the output node list and the operation node list; wherein the operation node includes an operator and an operator parameter;

[0017] Construct a neural network model under the ONNX framework according to the input node list, the output node list, the operation node list and the general NumPy array;

[0018] The neural network model under the ONNX framework is serialized to obtain a binary string, and the binary string is persisted.

[0019] In a possible implementation, the step of obtaining initial conditions from the neural network model to be converted includes:

[0020] Determine the symbol file and weight parameter file of the neural network model to be converted;

[0021] Obtain the tensor layout of the neural network model to be converted in MXNet;

[0022] Determine a save path of a converted neural network model under ONNX corresponding to the neural network model to be converted.

[0023] In a possible implementation, reading the symbol file in the initial condition and converting the symbol file into a Symbol object includes:

[0024] Read the symbol file in the initial condition and convert the symbol file into a Python object;

[0025] Convert the binary data in the Python object to a Symbol object.

[0026] In a possible implementation, the weight parameter file is processed to obtain a weight parameter file of the MXNet model under the MXNet framework, including:

[0027] Convert the read weight parameter file into a node attribute dictionary list and a node weight dictionary list;

[0028] The node attribute dictionary list and the node weight dictionary list are correspondingly merged to obtain the weight parameter file of the MXNet model under the MXNet framework.

[0029] In a possible implementation, the operator conversion function of constructing the MXNet framework and the ONNX framework includes:

[0030] Determine the mapping relationship between all operators in the neural network model to be converted and all operators under the ONNX framework, obtain the operator conversion function, and register the operator conversion function;

[0031] The operator parameters in the neural network model to be converted are converted into parameters of the corresponding operator property requirements under the ONNX framework;

[0032] The operator under the ONNX framework is constructed according to the parameters of the corresponding operator under the ONNX framework to obtain the operator conversion function.

[0033] In a possible implementation, the useless network layer includes: a unique model layer of the neural network model to be converted.

[0034] In a possible implementation, the weight parameter file of the MXNet model is processed to obtain a general NumPy array, including:

[0035] The data types of the elements in the weight parameter file of the MXNet model are converted and the data tags are deleted.

[0036] In a possible implementation, traversing all operation nodes in the labeled network layer, determining the operator type of each operation node, calling the operator conversion function according to the operator type, converting the operation node under the MXNet framework into the operation node under the MXNet framework, and updating the input node list, the output node list and the operation node column include:

[0037] Get the list of nodes in the network layer after annotation in the MXNet framework;

[0038] Traversing all operation nodes in the node list, determining the operator type of the operation node, and calling the operator conversion function according to the operation node and the operator type to implement operation node conversion and obtain a converted operation node;

[0039] The input node list, the output node list and the operation node list are updated according to the converted operation node and the operator type.

[0040] In a possible implementation, constructing a neural network model under the ONNX framework according to the input node list, the output node list, the operation node list and the general NumPy array includes:

[0041] Construct an ONNX computation graph under the ONNX framework according to the updated input node list, the output node list, the operation node list and the general NumPy array;

[0042] Construct a neural network model under the ONNX framework according to the ONNX calculation graph and the neural network model to be converted.

[0043] In a possible implementation, serializing the neural network model under the ONNX framework to obtain a binary string and persisting the binary string includes:

[0044] Use the SerializeToString() method to serialize the neural network model under the ONNX framework to obtain the binary string corresponding to the neural network model under the ONNX framework;

[0045] Write the binary string to a file for persistence.

[0046] One or more technical solutions provided in the present invention have at least the following technical effects or advantages:

[0047] (1) The present invention provides a neural network model conversion method based on MXNet and ONNX, which can convert the MXNet pre-trained neural network model into the ONNX format, and can also convert the ONNX neural network model to the MXNet framework, meeting the needs of researchers for cross-framework research on neural network models;

[0048] (2) The present invention provides a neural network model conversion method based on MXNet and ONNX, which maps the operators used in the MXNet framework to equivalent operators in the ONNX framework, and defines conversion functions of different operations for different operators, and performs special processing on the parameters of different operators;

[0049] (3) The present invention provides a neural network model conversion method based on MXNet and ONNX, which can complete the loading and parsing of the source neural network model, the efficient conversion of operators, calculation graphs, and models, and the serialization and preservation of the target model. The structure of the converted model is consistent with that before the conversion, and the model reasoning accuracy is also consistent with that before the conversion, and the model conversion accuracy reaches a maximum value of 1. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] Figure 1 A flowchart of the steps of the neural network model conversion method based on MXNet and ONNX provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0051] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0052] The present invention provides a neural network model conversion method based on MXNet and ONNX, such as Figure 1 As shown, the method includes the following steps S101 to S107.

[0053] S101, determining whether the input neural network model to be converted is a neural network model under the MXNet framework, and if so, obtaining initial conditions according to the neural network model to be converted;

[0054] Specifically, in step S101, initial conditions are obtained according to the neural network model to be converted, including the following steps S1011 to S1013.

[0055] S1011, determining the symbol file and weight parameter file of the neural network model to be converted;

[0056] S1012, obtaining the tensor layout of the neural network model to be converted in MXNet;

[0057] S1013, determine the saving path of the converted neural network model corresponding to the neural network model to be converted under ONNX.

[0058] Exemplarily, the neural network format conversion software between MXNet and ONNX frameworks in the implementation of the present invention includes two directions, among which, the conversion of the neural network model from MXNet to ONNX requires the input of three aspects of content. The first aspect is the neural network model information that conforms to the MXNet format, which usually includes the model structure (calculation graph structure), weight parameters, node attributes of various network layers, input tensor size, etc., all of which are directly or indirectly obtained by reading the MXNet model file; the second aspect needs to be combined with the specific needs of the model conversion, mainly used to unify the tensor layout of the neural network model in the two formats before and after the model conversion; the third aspect of information mainly involves the specific requirements for exporting ONNX files, including the path of the export file, the opset version of the ONNX format, etc. After the three steps of loading the MXNet model file, converting the calculation graph of the neural network model in the MXNet format to the neural network model in the ONNX format, and serializing and saving the ONNX model, the conversion process is completed.

[0059] S102, read the symbol file in the initial condition, convert the symbol file into a Symbol object, read the weight parameter file in the initial condition, and perform data processing on the weight parameter file to obtain the weight parameter file of the MXNet model under the MXNet framework; wherein the weight parameter file includes: data tags of each data;

[0060] Specifically, in step S102, the symbol file in the initial condition is read, and the symbol file is converted into a Symbol object, including the following steps S1021 to S1022.

[0061] S1021, read the symbol file in the initial condition and convert the symbol file into a Python object;

[0062] S1022, convert the binary data in the Python object into a Symbol object.

[0063] Exemplarily, an ONNX model file is read. The ONNX model structure and weight information are saved in a file with a suffix of .onnx in Protobuf format, and the ONNX file content is read out in binary mode using the ONNX model loading interface.

[0064] The reading of symbol files mainly depends on the mxnet.symbol.load() function, which receives the symbol file path of string type, uses the json.load() method to read the file content into memory and convert it into a Python object, then creates a Symbol object in the MXNet framework to save the neural network model structure, and improves the parameters and properties of the Symbol object according to the properties saved in the Python object, and finally obtains a complete MXNet type Symbol object.

[0065] Specifically, in step S102, the weight parameter file in the initial condition is read, and the weight parameter file is processed to obtain the weight parameter file of the MXNet model under the MXNet framework; wherein the weight parameter file includes: data tags of each data;

[0066] Perform data processing on the weight parameter file to obtain the weight parameter file of the MXNet model under the MXNet framework, including:

[0067] (1) Convert the read weight parameter file into a node attribute dictionary list and a node weight dictionary list;

[0068] (2) Merge the node attribute dictionary list and the node weight dictionary list accordingly to obtain the weight parameter file of the MXNet model under the MXNet framework.

[0069] Exemplarily, the binary data is parsed and the byte data read in step S102 is deserialized using the ONNX model parsing interface.

[0070] The reading of weight parameter files mainly depends on the mxnet.ndarray.load() function, which also receives the parameter file path of string type, loads the parameter information into memory and saves it as a dictionary object.

[0071] S103, determining the name of each network layer in the neural network model to be converted, and marking the useless network layers in the neural network model to be converted to obtain the marked network layers;

[0072] Specifically, in step S103, the useless network layer includes: a unique model layer of the neural network model to be converted.

[0073] For example, the penultimate network layer of the MXNet neural network model is unique to the MXNet framework and does not represent an actual operator. The network layer name is constructed by obtaining the name of the last intermediate layer node and adding the "_label" suffix to it, which facilitates the subsequent deletion of the corresponding operator by name.

[0074] S104, performing data processing on the weight parameter file of the MXNet model to obtain a general NumPy array;

[0075] Specifically, in step S104, the weight parameter file of the MXNet model is processed to obtain a general NumPy array, including: converting the data type of the elements in the weight parameter file of the MXNet model and deleting the data mark.

[0076] For example, the tensor information of the TensorProto type in the ONNX model is first converted into a general NumPy array for transition, and then converted into the mxnet.ndarray type unique to the MXNet framework.

[0077] S105, initialize the input node list, output node list and operation node list under the MXNet framework, construct the operator conversion function of the MXNet framework and the ONNX framework, traverse all the operation nodes in the labeled network layer, determine the operator type of each operation node, call the operator conversion function according to the operator type, convert the operation node under the MXNet framework into the operation node under the MXNet framework, and update the input node list, output node list and operation node list; wherein the operation node includes an operator and an operator parameter;

[0078] Specifically, in step S105, an operator conversion function between the MXNet framework and the ONNX framework is constructed, including:

[0079] (1) Determine the mapping relationship between the operator in the neural network model to be converted and the operator under the ONNX framework, obtain the operator conversion function, and register the operator conversion function;

[0080] (2) The operator parameters in the neural network model to be converted are converted into the parameters of the corresponding operator attribute requirements under the ONNX framework;

[0081] (3) Construct the operator under the ONNX framework according to the parameters of the corresponding operator under the ONNX framework and obtain the operator conversion function.

[0082] Exemplarily, first determine the operator conversion function from the ONNX framework to the MXNet framework, and construct the operator conversion function.

[0083] Then process the ONNX operator parameters according to the format and type required by the MXNet framework.

[0084] Then call the MXNet operator creation interface to process the ONNX operator parameters according to the format and type required by the MXNet framework.

[0085] Finally, the operator conversion function is obtained.

[0086] Specifically, in step S105, all operation nodes in the labeled network layer are traversed to determine the operator type of each operation node, and the operator conversion function is called according to the operator type to convert the operation nodes under the MXNet framework into operation nodes under the MXNet framework, and update the input node list, output node list and operation node list, including:

[0087] (1) Obtain the list of nodes in the network layer after annotation under the MXNet framework;

[0088] (2) Traverse all operation nodes in the node list, determine the operator type of the operation node, and call the operator conversion function according to the operation node and the operator type to realize the operation node conversion and obtain the converted operation node;

[0089] (3) Update the input node list, output node list and operation node list according to the converted operation node and operator type.

[0090] For example, the operation nodes of the computation graph under the ONNX framework are traversed to generate the corresponding MXNet computation graph. Specifically, it includes:

[0091] (1) Convert the input information of the computation graph;

[0092] (2) Process the ONNX operator parameters according to the format and type required by the MXNet framework;

[0093] (3) Determine the corresponding MXNet operator type based on the ONNX operator type and operator mapping table; call the MXNet operator creation interface, pass in the input information, build the MXNet operator and return the current MXNet calculation graph.

[0094] (4) Split the ONNX network parameters into weight parameters and auxiliary parameters and mark them with "arg" and "aux" respectively.

[0095] (5) Convert the computation graph output information and update the input node list, output node list, and operation node list.

[0096] S106, constructing a neural network model under the ONNX framework according to the input node list, the output node list, the operation node list and the general NumPy array;

[0097] Specifically, in step S106, a neural network model under the ONNX framework is constructed according to the input node list, the output node list, the operation node list and the general NumPy array, including:

[0098] (1) Construct an ONNX computational graph under the ONNX framework based on the updated input node list, output node list, operation node list, and general NumPy array;

[0099] (2) Construct a neural network model under the ONNX framework based on the ONNX computational graph and the neural network model to be converted.

[0100] Exemplarily, the model parameters with "arg" and "aux" tags are merged into a dictionary, and the function of saving the NDArray array provided by MXNet is used, and the "arg" and "aux" tags are deleted to perform the parameter file persistence operation.

[0101] The ONNX operator built in the order of MXNet nodes is first called by the static graph construction interface provided by ONNX, and various information such as the node list, input list, output list, and initialization tensor list of the calculation graph are passed in to construct the corresponding ONNX static graph. Then, combined with the metadata information of the model, the built ONNX calculation graph object is associated with the model to obtain a complete neural network model under the ONNX framework.

[0102] S107, serialize the neural network model under the ONNX framework to obtain a binary string, and persist the binary string.

[0103] Specifically, in step S107, the neural network model under the ONNX framework is serialized to obtain a binary string, and the binary string is persisted, including the following steps S1071 to S1072.

[0104] S1071, serialize the neural network model under the ONNX framework using the SerializeToString() method to obtain a binary string corresponding to the neural network model under the ONNX framework;

[0105] S1072, write the binary string into a file for persistence.

[0106] Exemplarily, the ONNX model object is serialized into a binary string using the SerializeToString() method provided by Protocol Buffers; the binary string is written to a file using the Python built-in write() method.

[0107] The present invention provides software for converting the formats of MXNet neural network models to ONNX neural network models. The software can convert the MXNet pre-trained neural network model to the ONNX format, and can also convert the ONNX neural network model to the MXNet framework, meeting the needs of researchers for cross-framework research on neural network models.

[0108] In a specific embodiment provided by the present invention, when the required neural network model cannot match the current system framework, the method provided by the present invention is first used to convert the neural network models under different frameworks to obtain a neural network model that can adapt to the current system, so that it can adapt to multiple different frameworks during the specific model use process.

[0109] For example, when the neural network model RESNET50 developed under the MXNet framework cannot be directly run under the ONNX framework, when the developer's development environment is ONNX, it is necessary to convert the neural network model RESNET50 developed under the MXNet framework to the ONNX framework. At this time, the network model conversion method provided by the present invention can quickly solve this problem, and the converted neural network model RESNET50 can run stably in the ONNX environment.

[0110] The neural network conversion method provided by the present invention can improve the portability and compatibility of the model: through model conversion, a model trained in one framework can be migrated to another framework, so that the model can run in different environments, improving the compatibility and portability of the model. This is very useful for deploying models on different platforms and devices.

[0111] Optimizing performance and resource utilization: Different deep learning frameworks may differ in performance and resource utilization. Through model conversion, you can choose a framework that is more suitable for a specific hardware platform, thereby optimizing the model's operating efficiency and resource utilization. For example, converting a model from TensorFlow to ncnn can significantly improve the running speed on mobile devices.

[0112] Reduce costs and simplify deployment: Retraining models requires a lot of computing resources and time, but model conversion can avoid this process, saving time and cost. In addition, model conversion can also simplify the deployment process, making the model easier to apply in different production environments.

[0113] Support multiple application scenarios: Different frameworks may be more suitable for different application scenarios. Through model conversion, you can choose the most suitable framework according to specific needs, thereby improving the adaptability and effect of the model.

[0114] Promoting technological innovation and standardization: The development of model conversion technology has promoted technical exchanges and integration between different frameworks, and promoted the process of technological innovation and standardization. This helps to form a more open and collaborative deep learning ecosystem.

[0115] In summary, network model conversion under different frameworks has significant beneficial effects in improving model portability, optimizing performance, reducing costs, simplifying deployment, and promoting technological innovation.

[0116] The various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. All or part of the present invention can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld devices or portable devices, tablet devices, mobile communication terminals, multi-processor systems, microprocessor-based systems, programmable electronic devices, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc.

[0117] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some or all of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the present invention.

Claims

1. A neural network model conversion method based on MXNet and ONNX, characterized in that: include: Determine whether the input neural network model to be converted is a neural network model under the MXNet framework. If so, obtain initial conditions from the neural network model to be converted; Read the symbol file in the initial condition, convert the symbol file into a Symbol object, read the weight parameter file in the initial condition, and perform data processing on the weight parameter file to obtain the weight parameter file of the MXNet model under the MXNet framework; wherein the weight parameter file includes: data tags of each data; Determine the name of each network layer in the neural network model to be converted, and mark the useless network layers in the neural network model to be converted to obtain the marked network layers; Perform data processing on the weight parameter file of the MXNet model to obtain a general NumPy array; Initialize the input node list, output node list and operation node list under the MXNet framework, construct the operator conversion function of the MXNet framework and the ONNX framework, traverse all the operation nodes in the labeled network layer, determine the operator type of each operation node, call the operator conversion function according to the operator type, convert the operation nodes under the MXNet framework into operation nodes under the MXNet framework, and update the input node list, the output node list and the operation node list; wherein the operation node includes an operator and an operator parameter; Construct a neural network model under the ONNX framework according to the input node list, the output node list, the operation node list and the general NumPy array; The neural network model under the ONNX framework is serialized to obtain a binary string, and the binary string is persisted.

2. The neural network model conversion method based on MXNet and ONNX according to claim 1, characterized in that: The step of obtaining initial conditions from the neural network model to be converted comprises: Determine the symbol file and weight parameter file of the neural network model to be converted; Obtain the tensor layout of the neural network model to be converted in MXNet; Determine a save path of a converted neural network model under ONNX corresponding to the neural network model to be converted.

3. The neural network model conversion method based on MXNet and ONNX according to claim 1, characterized in that: The reading of the symbol file in the initial condition and converting the symbol file into a Symbol object comprises: Read the symbol file in the initial condition and convert the symbol file into a Python object; Convert the binary data in the Python object to a Symbol object.

4. The neural network model conversion method based on MXNet and ONNX according to claim 1, characterized in that: The weight parameter file is processed to obtain a weight parameter file of the MXNet model under the MXNet framework, including: Convert the read weight parameter file into a node attribute dictionary list and a node weight dictionary list; The node attribute dictionary list and the node weight dictionary list are correspondingly merged to obtain the weight parameter file of the MXNet model under the MXNet framework.

5. The neural network model conversion method based on MXNet and ONNX according to claim 1, characterized in that: The operator conversion function of constructing the MXNet framework and the ONNX framework includes: Determine the mapping relationship between the operator in the neural network model to be converted and the operator under the ONNX framework, obtain the operator conversion function, and register the operator conversion function; The operator parameters in the neural network model to be converted are converted into parameters of the corresponding operator property requirements under the ONNX framework; The operator under the ONNX framework is constructed according to the parameters of the corresponding operator under the ONNX framework to obtain the operator conversion function.

6. The neural network model conversion method based on MXNet and ONNX according to claim 1, characterized in that: The useless network layer includes: a unique model layer of the neural network model to be converted.

7. The neural network model conversion method based on MXNet and ONNX according to claim 1, characterized in that: The weight parameter file of the MXNet model is processed to obtain a general NumPy array, including: The data types of the elements in the weight parameter file of the MXNet model are converted, and the data tags are deleted.

8. The neural network model conversion method based on MXNet and ONNX according to claim 1, characterized in that: The traversing of all operation nodes in the labeled network layer, determining the operator type of each operation node, calling the operator conversion function according to the operator type, converting the operation node under the MXNet framework into the operation node under the MXNet framework, and updating the input node list, the output node list and the operation node list, including: Get the list of nodes in the network layer after annotation in the MXNet framework; Traversing all operation nodes in the node list, determining the operator type of the operation node, and calling the operator conversion function according to the operation node and the operator type to implement operation node conversion and obtain a converted operation node; The input node list, the output node list and the operation node list are updated according to the converted operation node and the operator type.

9. The neural network model conversion method based on MXNet and ONNX according to claim 1, characterized in that: The step of constructing a neural network model under the ONNX framework according to the input node list, the output node list, the operation node list and the general NumPy array includes: Construct an ONNX computation graph under the ONNX framework according to the updated input node list, the output node list, the operation node list and the general NumPy array; Construct a neural network model under the ONNX framework according to the ONNX calculation graph and the neural network model to be converted.

10. The neural network model conversion method based on MXNet and ONNX according to claim 1, characterized in that: The process of serializing the neural network model under the ONNX framework to obtain a binary string and persisting the binary string includes: Use the SerializeToString() method to serialize the neural network model under the ONNX framework to obtain the binary string corresponding to the neural network model under the ONNX framework; Write the binary string to a file for persistence.

Citation Information

Patent Citations

  • Model architecture conversion method and device, equipment and storage medium

    CN114356356A

  • Method and device for exporting deep learning model compatible with multiple frameworks to ONNX

    CN116560674A

  • Software deployment method and device, storage medium and product

    CN117971251A

  • Data management method and system for open neural network switching model

    CN118113697A

  • Ai network information transmission method and apparatus, and communication device

    WO2023125869A1