Method, device and equipment for packaging ONNX model into FMU
By encapsulating the ONNX model into FMU, automatically generates interfaces and standardizes data exchange, the low development efficiency and error-prone problems caused by manual writing interfaces are solved, and the seamless integration and collaboration of the ONNX model among different simulation tools is achieved, which improves the development efficiency of industrial system design.
Patent Information
- Application Number
- CN202510016021.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-06
- Publication Date
- 2025-04-25
AI Technical Summary
When using the ONNX model for industrial system simulation, it is necessary to manually write interfaces to achieve interaction with the simulation platform, resulting in low development efficiency and error-prone.
The model description document of the ONNX model is parsed through the dynamic link library source code file, and a dynamic link library file containing the functional simulation interface FMI is generated; the model description document is parsed based on the preset executable file, and a model description file is generated; the ONNX model, dynamic link library file and model description file are encapsulated to obtain the functional simulation unit FMU.
The automatic generation of the ONNX model interface is realized, and the data exchange interface with the simulation platform is standardized through FMI, supporting seamless integration and collaboration between different simulation tools, and improving the development efficiency of industrial system design.
Smart Images

Figure CN119883222A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a method, device and apparatus for encapsulating an ONNX model into an FMU. Background Art
[0002] In industrial system design, proxy models are often used to improve efficiency and reduce computational costs. These proxy models can be deep learning models stored in the Open Neural Network Exchange (ONNX) format to effectively fit and approximate complex input-output relationships in high-fidelity simulation models (such as computational fluid dynamics). By using these proxy models, developers (users) can significantly reduce the time and resources required for calculations without sacrificing accuracy.
[0003] In related technologies, when using ONNX models (deep learning models stored in ONNX format) for simulation, it is usually necessary to manually write the interface of the ONNX model to achieve interaction with the simulation platform. However, the manual interface writing method is not only time-consuming, but also prone to errors, which will affect the development efficiency of industrial system design. Summary of the invention
[0004] The present application provides a method, apparatus and device for encapsulating an ONNX model into an FMU to improve the development efficiency of industrial system design.
[0005] In a first aspect, the present application provides a method for encapsulating an ONNX model into an FMU, comprising:
[0006] According to the dynamic link library source code file, the model description document of the ONNX model is parsed to generate a dynamic link library file, wherein the dynamic link library file includes a functional simulation interface FMI for data exchange between the ONNX model and the simulation platform;
[0007] According to a preset executable file, the model description document is parsed to generate a model description file;
[0008] The ONNX model, the dynamic link library file, and the model description file are encapsulated to obtain a functional simulation unit FMU.
[0009] In a possible implementation, the model description document of the ONNX model is parsed according to the dynamic link library source code file to generate a dynamic link library file, including:
[0010] Parsing the model description document according to the interface function preset in the dynamic link library source code file to generate the FMI;
[0011] Obtaining the reasoning logic of the ONNX model through the FMI, wherein the reasoning logic refers to a mechanism by which the ONNX model calculates and returns output results to the simulation platform after receiving input data sent by the simulation platform;
[0012] The FMI and the reasoning logic are encapsulated to generate the dynamic link library file.
[0013] In a possible implementation, the reasoning logic includes:
[0014] Receiving input data of the simulation platform through an input interface in the FMI;
[0015] Inferring the input data input through the ONNX model to obtain the output result;
[0016] The output result is returned to the simulation platform through the output interface in the FMI.
[0017] In a possible implementation, the inference of the input data input by the ONNX model to obtain the output result includes:
[0018] The input data is inferred by the inference engine of the ONNX model to obtain the output result.
[0019] In a possible implementation, encapsulating the ONNX model, the dynamic link library file, and the model description file to obtain a functional simulation unit FMU includes:
[0020] Create resource folders, executable folders, and root folders;
[0021] The ONNX model is stored in the resource folder, the dynamic link library file is stored in the executable folder, and the model description file is stored in the root folder;
[0022] The resource folder, the executable folder, and the root folder are compressed to obtain the FMU.
[0023] In a possible implementation, before parsing the model description document of the ONNX model according to the dynamic link library source code file and generating the dynamic link library file, the method further includes:
[0024] In response to a user's compiling operation on the model code of the ONNX model, the model description document is generated.
[0025] In a possible implementation, the model description file includes: the number of input interfaces, the names of the input interfaces, the number of output interfaces, the names of the output interfaces, the ONNX model type, and simulation configuration parameters of the FMU.
[0026] In a second aspect, the present application provides a device for encapsulating an ONNX model into an FMU, including:
[0027] An acquisition module is used to parse the model description document of the ONNX model according to the dynamic link library source code file to generate a dynamic link library file, wherein the dynamic link library file includes a functional simulation interface FMI for the ONNX model to interact with the simulation platform;
[0028] A parsing module, used to parse the model description document according to a pre-written executable file to generate a model description file;
[0029] The processing module is used to encapsulate the ONNX model, the dynamic link library file, and the model description file to obtain a functional simulation unit FMU.
[0030] In a third aspect, the present application provides an electronic device, including: a memory, a processor;
[0031] The memory stores computer-executable instructions;
[0032] The processor executes the computer-executable instructions stored in the memory, so that the processor executes the method of encapsulating the ONNX model into an FMU as described in any one of the first aspects.
[0033] In a fourth aspect, the present application provides a computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are executed by a processor, they are used to implement the method of encapsulating an ONNX model into an FMU as described in any one of the first aspects.
[0034] In a fifth aspect, the present application provides a computer program product, comprising a computer program, which, when executed by a processor, is used to implement the method of encapsulating an ONNX model into an FMU as described in any one of the first aspects.
[0035] The method, device and equipment for encapsulating ONNX model into FMU provided in this application can parse the model description document of ONNX model through dynamic link library source code file, generate dynamic link library file containing FMI for data exchange between ONNX model and simulation platform; parse model description document according to preset executable file, generate model description file; encapsulate ONNX model, dynamic link library file and model description file to obtain FMU. FMU includes automatically generated FMI, which can realize seamless integration and collaboration between different simulation tools and improve the development efficiency of industrial system design. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0037] Figure 1 A schematic diagram of an application scenario provided by an embodiment of the present application;
[0038] Figure 2 A flowchart of a method for encapsulating an ONNX model into an FMU according to Embodiment 1 of the present application;
[0039] Figure 3 A flowchart of a second embodiment of the method for encapsulating an ONNX model into an FMU provided in the present application;
[0040] Figure 4 A schematic diagram of the structure of a first embodiment of a device for encapsulating an ONNX model into an FMU provided in the present application;
[0041] Figure 5 A schematic diagram of the structure of the second embodiment of the device for encapsulating the ONNX model into an FMU provided by the present application;
[0042] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.
[0043] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0044] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0045] First, the terms involved in this application are explained:
[0046] Functional Mock-up Unit (FMU): A model encapsulation technology based on the Functional Mock-up Interface (FMI) standard, widely used in the integration and collaboration between different simulation tools.
[0047] Open Neural Network Exchange (ONNX): An open format for machine learning models that promotes interoperability between different deep learning frameworks, allowing developers to easily convert models between different deep learning frameworks.
[0048] Dynamic Link Library (DLL): A file format that contains code and data that can be used by multiple programs simultaneously. The file allows program modularization and code reuse, thereby improving the efficiency and flexibility of software development.
[0049] As a model encapsulation technology based on the FMI standard, FMU provides a method to achieve seamless integration and collaboration between different simulation tools. The FMI standard is an open standard developed by multiple international institutions to support interoperability between different simulation tools. Through FMU, developers can encapsulate the model into an independent, portable unit that can run in any simulation environment that supports FMI. This capability greatly improves the reusability and flexibility of the model.
[0050] In the design of modern industrial systems, the application of simulation technology has become an indispensable component. Simulation technology not only plays a key role in product design, system optimization and performance evaluation, but also has significant advantages in reducing the need for physical prototypes and reducing development costs. In order to improve efficiency and reduce computing costs, ONNX models can be used to replace complex input-output relationships in high-fidelity simulation models (such as computational fluid dynamics), thereby significantly reducing the time and resources required for simulation calculations without reducing the accuracy of the simulation model.
[0051] In the related art, when using ONNX model for simulation, it is usually necessary to manually write the interface of ONNX model in order to achieve interaction with the simulation platform. However, this method of manually writing interface is not only time-consuming, but also prone to errors, which will affect the development efficiency of industrial system design.
[0052] In view of the above problems, the inventors consider that the ONNX model can be encapsulated as FMU to automatically generate the interface of the ONNX model. In the specific implementation, the model description document of the ONNX model can be parsed through the dynamic link library source code file to generate a dynamic link library file, which includes FMI for data exchange between the ONNX model and the simulation platform. Subsequently, the model description document can be parsed according to the preset executable file to generate a model description file; finally, the ONNX model, the dynamic link library file, and the model description file are encapsulated as FMU. FMU can automatically generate the interface of the ONNX model, and can standardize the data exchange interface with the simulation platform through FMI, so that different simulation tools can be easily integrated and work together. Based on this, the present application provides a method for encapsulating the ONNX model as FMU, which is used to automatically generate the interface of the ONNX model, thereby improving the development efficiency of industrial system design.
[0053] Figure 1 This is a schematic diagram of an application scenario provided by an embodiment of the present application. Figure 1 , including ONNX model and model description document of ONNX model, the model description document can be parsed to generate dynamic link library file and model description file, and then the ONNX model and the generated dynamic link library file and model description file can be encapsulated to obtain the functional simulation unit.
[0054] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0055] Figure 2 This is a flowchart of the first embodiment of the method for encapsulating the ONNX model into FMU provided in this application. Figure 2 , the method comprising:
[0056] S201. According to the dynamic link library source code file, the model description document of the ONNX model is parsed to generate a dynamic link library file.
[0057] The execution subject of the embodiment of the present application may be an electronic device, or a device that encapsulates the ONNX model as an FMU in the electronic device. The device that encapsulates the ONNX model as an FMU may be implemented by software, or by a combination of software and hardware. The device that encapsulates the ONNX model as an FMU may be a processor in an electronic device. For ease of understanding, the following description will be given by taking the execution subject as an electronic device as an example.
[0058] In this step, the electronic device can parse the model description document of the ONNX model through the dynamic link library source code file to generate a dynamic link library file, which includes a functional simulation interface FMI for data exchange and interaction between the ONNX model and the simulation platform.
[0059] Optionally, you can obtain the dynamic link library source code file by following the steps below:
[0060] Step ①, use the Integrated Development Environment (IDE) to create a new DLL source code project, where the DLL source code project can be a C++ project.
[0061] Step ②, add the required source code and header files to the DLL source code project, encode the code to implement specific functions, and after compiling the source code project, the generated DLL source code file can be dynamically loaded and used in other applications.
[0062] The model description document can be implemented through the specific configuration file config.txt. The model description document can include the number of input variables, input variable names, output variable number, and output variable names of the ONNX model. For example, the number of input variables of the ONNX model is 3, namely temperature, humidity, and atmospheric pressure, and the number of output variables is 2, namely precipitation probability and wind speed prediction.
[0063] In an optional implementation, the model description document can be parsed according to the interface function preset in the dynamic link library source code file to generate FMI, the reasoning logic of the ONNX model can be obtained through FMI, and the FMI and the reasoning logic can be encapsulated to generate a dynamic link library file. Among them, the reasoning logic refers to the mechanism by which the ONNX model calculates and returns the output result to the simulation platform after receiving the input data sent by the simulation platform.
[0064] S202: According to a preset executable file, the model description document is parsed to generate a model description file.
[0065] In this step, the electronic device can parse the model description document according to the preset executable file to generate a model description file. The model description file includes: the number of input interfaces of the FMU, the name of the input interface, the number of output interfaces, the name of the output interface, the ONNX model type, and the simulation configuration parameters.
[0066] For the executable file, it can be a pre-written .EXE file. Through the pre-written executable file, the model description document (such as config.txt) can be read to generate a model description file (such as modelDescription.xml) that complies with the FMI standard.
[0067] Specifically, the number of input interfaces of the FMU can be determined according to the number of input variables defined in the model description document; the input variable names can be extracted from the model description document to identify the input interfaces of the FMU; the number of output interfaces of the FMU can be determined according to the number of output variables defined in the model description document; the output variable names can be extracted from the model description document to identify the output interfaces of the FMU.
[0068] The executable file can parse the information about the model type in the model description document to determine the specific type of the ONNX model, which can include: convolutional neural network, recurrent neural network, fully connected network, etc.
[0069] For simulation configuration parameters, they can be various settings extracted by the executable file from the model description document, which are used to guide the execution of the simulation process. Specific simulation configuration parameters may include at least one of the following parameters: time step, simulation time range, initial condition, output frequency, and numerical precision.
[0070] Specifically, the time step refers to the time interval between each calculation step in the simulation process, which determines the precision and speed of the simulation calculation; the simulation time range refers to the start time and end time of the simulation, which determines the overall time span of the simulation; the initial variables refer to the initial state of each variable at the beginning of the simulation, which determines the initial state setting of the simulation results; the output frequency refers to the frequency of the output of the simulation results, which determines how often the output data is recorded during the simulation process; the numerical precision refers to the numerical precision used in the calculation process, which determines the accuracy and performance of the simulation calculation.
[0071] S203, encapsulating the ONNX model, dynamic link library file, and model description file to obtain a functional simulation unit FMU.
[0072] In this step, in the process of obtaining FMU, the ONNX model, the dynamic link library file generated by the model description document, and the model description file can be packaged and integrated into a unified FMU package so that it can run seamlessly in various simulation environments.
[0073] In an optional implementation, a resource folder, an executable folder, and a root folder can be established, the ONNX model can be stored in the resource folder, the dynamic link library file can be stored in the executable folder, and the model description file can be stored in the root folder; the resource folder, the executable folder, and the root folder can be compressed to obtain the FMU.
[0074] In an embodiment of the present application, the model description document of the ONNX model can be parsed according to the pre-written dynamic link library source code file, and the FMI for data exchange between the ONNX model and the simulation platform can be automatically generated; the model description document can be parsed according to the pre-written executable file to generate a model description interface; and then the ONNX model, dynamic link library file, and model description file can be encapsulated to obtain FMU. In the above process, the automatic generation of the ONNX model interface can be achieved by parsing the model description document. This method can adapt to a variety of complex ONNX model requirements, reduce the repetitive work of manually writing interfaces, and improve the development efficiency of industrial system design.
[0075] Furthermore, the method of encapsulating the ONNX model as FMU provided in the embodiment of the present application not only simplifies the interface generation process, but also significantly improves the portability and interoperability of the ONNX model. This method enables developers to more efficiently and seamlessly integrate complex ONNX models into various simulation platforms, whether existing or newly developed systems, through an automated packaging process. This process greatly shortens development time, reduces maintenance costs, and reduces the possibility of human error. In addition, the method ensures the consistency and reliability of the model in different environments, enhances the reusability and scalability of the model, and enables it to flexibly adapt to diverse application scenarios and needs.
[0076] exist Figure 2 Based on the embodiment shown below, combined with Figure 3 , the above method of encapsulating the ONNX model into FMU is further explained in detail.
[0077] Figure 3 This is a flowchart of the second embodiment of the method for encapsulating the ONNX model into FMU provided in this application. Figure 3 , the method comprising:
[0078] S301. In response to a user's compiling operation on the model code of the ONNX model, a model description document is generated.
[0079] In this step, the system may generate a model description document (such as config.txt) in response to the user's compiling operation on the model code of the ONNX model. The model description document may include information such as the number of input variables, input variable names, number of output variables, and output variable names of the ONNX model.
[0080] Optionally, the generated model description document may also include information such as model hierarchy, parameter settings, and dependencies.
[0081] For example, in a convolutional neural network, the model hierarchy may include multiple convolutional layers, pooling layers, and fully connected layers. These layers are arranged in a specific order to form an orderly hierarchy. The documentation can list in detail the type of each layer, the order, and the connection relationship between layers.
[0082] Parameter settings can be specific configurations involving each layer. For example, the parameter settings of the convolution layer may include the number of filters (such as 32 or 64), the filter size (such as 3x3 or 5x5), the stride, and the padding method. The parameter settings of the pooling layer may include the window size (such as 2x2) and the stride. The parameter settings of the fully connected layer may involve the number of neurons (such as 128 or 256). In addition, the parameter settings of the model may also include the learning rate (such as 0.001), the optimizer type, the regularization coefficient, etc. These parameters can be listed in detail in the documentation to help developers understand the training configuration and performance tuning of the model.
[0083] Dependencies can be input-output relationships between different layers. For example, the output of a convolutional layer can be directly used as the input of the next pooling layer, forming a direct dependency between layers.
[0084] In addition, some parameters may rely on specific data preprocessing steps. For example, the input data needs to be normalized or standardized to ensure the effectiveness and accuracy of the model.
[0085] Dependencies can also include the model's requirements for specific hardware or software environments, such as requiring a specific version of a deep learning framework (such as TensorFlow or PyTorch) to run. Describing these dependencies in detail in the documentation can ensure consistency and compatibility of the model during deployment and migration.
[0086] S302: Parse the model description document according to the interface function preset in the dynamic link library source code file to generate FMI.
[0087] In this step, an interface function may be reserved in the dynamic link library source code file, through which the model description document may be parsed to generate an FMI for data exchange and interaction between the ONNX model and the simulation platform.
[0088] Optionally, the interface function may be load Configuration(), which may be called in the initialization function init() in the FMI standard library to parse the model description document (such as config.txt) and generate FMI.
[0089] Specifically, the interface function can read the number of input variables, input variable names, number of output variables, output variable names and other information of the ONNX model included in the model description document, and dynamically generate the implementation code of the FMI standard interface.
[0090] In an optional implementation, when the developer adjusts the ONNX model, the interface function can automatically update the parsing logic to adapt to the new model structure. For example, the interface function can re-read the updated model description document, identify the number of input variables, input variable names, number of output variables, output variable names, etc. of the newly added or modified ONNX model, and adjust the implementation code of the FMI interface accordingly.
[0091] In addition, the interface function can also include error detection and handling mechanisms. For example, when parsing a model description document, the interface function can check the completeness and consistency of the document to ensure that all necessary information is provided, and provide a detailed error report when a problem is found. This mechanism helps developers quickly locate and solve problems, further improving development efficiency.
[0092] S303. Obtain the reasoning logic of the ONNX model through FMI.
[0093] In this step, the inference logic of the ONNX model can be obtained through FMI. The inference logic refers to the mechanism by which the ONNX model calculates and returns the output results to the simulation platform after receiving the input data sent by the simulation platform.
[0094] In a specific implementation, the reasoning logic includes: receiving input data from the simulation platform through an input interface in the FMI;
[0095] The input data is inferred through the ONNX model to obtain the output result;
[0096] The output results are returned to the simulation platform through the output interface in FMI.
[0097] Optionally, in the specific implementation of inferring the input data input through the ONNX model to obtain the output result, the input data input may be inferred through the inference engine of the ONNX model to obtain the output result. The inference engine may be an ONNX Runtime library.
[0098] The ONNX Runtime library is designed specifically for running machine learning models in the ONNX format. It aims to provide efficient, cross-platform reasoning capabilities so that models can be executed seamlessly in a variety of hardware and software environments. By leveraging hardware accelerators (such as graphics processors GPUs), ONNX Runtime can significantly improve the reasoning speed of the model while maintaining low latency and high throughput. In addition, ONNX Runtime supports custom operators and extensions, allowing developers to expand functionality based on specific needs, thereby improving flexibility and adaptability.
[0099] For example, you can perform reasoning operations through the ONNX Runtime library to infer the input data of the simulation platform and obtain output results. In the specific implementation, when performing reasoning operations through the ONNX Runtime library, you can use the reasoning function Integrate() to process the input data of the simulation platform and perform corresponding operations (such as time integration operations) to obtain output results.
[0100] It should be noted that before performing reasoning operations through the ONNX Runtime library, the input data of the simulation platform can also be initialized in the initialization function init() in the FMI standard library to ensure that the input data has been correctly configured and prepared when entering the ONNX model for reasoning, thereby improving the accuracy and efficiency of model reasoning. By initializing the input data in the init() function, developers can set the initial state, range, and format of the input data to ensure that it meets the expected requirements of the model.
[0101] In an optional implementation, other deep learning reasoning frameworks (such as TensorFlowLite or PyTorch) may be used instead of ONNX Runtime for reasoning.
[0102] S304: Encapsulate the FMI and reasoning logic to generate a dynamic link library file.
[0103] In this step, the FMI and reasoning logic can be encapsulated to generate a dynamic link library file. The dynamic link library file not only integrates the reasoning capability of the ONNX model, but also contains the FMI required to interact with the simulation platform.
[0104] In a specific implementation, the encapsulation of FMI and reasoning logic can be implemented through C++ code to generate a dynamic link library. The dynamic link library is directly used in the later stage of FMU encapsulation, adapted to different simulation platforms, and ensures the standardization and compatibility of the ONNX model.
[0105] S305: Parse the model description document according to the preset executable file to generate a model description file.
[0106] For example, the model description document can be parsed according to the preset executable file to generate a model description file including: the number of input interfaces of the FMU, the name of the input interface, the number of output interfaces, the name of the output interface, the ONNX model type, and the simulation configuration parameters.
[0107] Among them, the number of input interfaces of FMU can be 3, and the names of the input interfaces are temperature sensor input, humidity sensor input, and pressure input respectively. The number of output interfaces is 2, and the names of the output interfaces are precipitation probability and wind speed prediction respectively. The ONNX model type is convolutional neural network. The simulation configuration parameters include a time step of 0.01 seconds and a simulation time range of 0 seconds to 100 seconds.
[0108] S306: Create a resource folder, an executable folder, and a root folder.
[0109] In this step, you can create a resource folder for storing ONNX models, an executable folder for storing dynamic link library files, and a root folder for storing model description files.
[0110] Among them, the resource folder (Resources) is used to store all resource files required for FMU operation, such as ONNX models, configuration files, scripts, data files, etc. By centralizing resource files in one folder, these files can be easily managed and updated to ensure that the FMU can correctly access the required resources when running in different environments.
[0111] The executable folder (Binaries) is used to store compiled binary files, such as dynamic link libraries or shared object files (SO), which are the core components of FMU running on different operating systems. By centrally managing binary files, it is easier to support multi-platform deployment and ensure that the correct binary version is used on different systems.
[0112] The root folder is used to store the FMU model description file (usually modelDescription.xml in XML format, and other possible top-level files, such as FMU identification files or documents. These files provide metadata information about the FMU, including the number of input interfaces, input interface names, number of output interfaces, output interface names, ONNX model types, and simulation configuration parameters. As the entry point of the FMU, the root folder provides a clear structure that can help developers quickly understand the overall architecture and functions of the FMU.
[0113] S307. Store the ONNX model in a resource folder, store the dynamic link library file in an executable folder, and store the model description file in a root folder.
[0114] S308: compress the resource folder, the executable folder, and the root folder to obtain the FMU.
[0115] Optionally, when compressing resource folders, executable folders, and root folders, the electronic device may automatically perform the compression process using a pre-written automation script, thereby reducing human errors, improving efficiency, and ensuring that the compression process is performed in accordance with pre-defined rules.
[0116] In an embodiment of the present application, in response to the user's compiling operation on the model code of the ONNX model, after the model description document is generated, the model description document can be parsed to generate FMI, and the reasoning logic of the ONNX model can be obtained; the FMI and the reasoning logic are encapsulated into a dynamic link library file; the model description document is parsed to generate a model description file; resources, executable files and root folders are created to store ONNX models, dynamic link library files and model description files respectively; finally, the resources, executable files and root folders are compressed to obtain FMU. In the above process, the full process automation from ONNX model to FMU encapsulation is realized, providing users with an efficient solution without manual interface adjustment, thereby improving the development efficiency of industrial system design.
[0117] Furthermore, the method of encapsulating the ONNX model into FMU provided in the embodiment of the present application can adaptively adjust the input and output interfaces to meet the dynamic needs in multidisciplinary joint simulation, significantly improve the usability and industrial deployment efficiency of the proxy model, promote the deep integration of the proxy model with the traditional simulation system, and provide more extensive technical support for multi-field optimization.
[0118] Figure 4 This is a schematic diagram of the structure of the first embodiment of the device for encapsulating the ONNX model into FMU provided by this application. Figure 4, the device 10 for encapsulating the ONNX model into FMU includes:
[0119] An acquisition module 11 is used to parse the model description document of the ONNX model according to the dynamic link library source code file to generate a dynamic link library file, wherein the dynamic link library file includes a functional simulation interface FMI for the ONNX model to interact with the simulation platform;
[0120] The parsing module 12 is used to parse the model description document according to the pre-written executable file to generate a model description file;
[0121] The processing module 13 is used to encapsulate the ONNX model, the dynamic link library file, and the model description file to obtain a functional simulation unit FMU.
[0122] The device for encapsulating the ONNX model into FMU provided in the embodiment of the present application can execute the technical solution shown in the above method embodiment, and its implementation principle and beneficial effects are similar, which will not be repeated here.
[0123] In a possible implementation manner, the acquisition module 11 is specifically configured to:
[0124] Parsing the model description document according to the interface function preset in the dynamic link library source code file to generate the FMI;
[0125] Obtaining the reasoning logic of the ONNX model through the FMI, wherein the reasoning logic refers to a mechanism by which the ONNX model calculates and returns output results to the simulation platform after receiving input data sent by the simulation platform;
[0126] The FMI and the reasoning logic are encapsulated to generate the dynamic link library file.
[0127] In a possible implementation, the reasoning logic includes:
[0128] Receiving input data of the simulation platform through an input interface in the FMI;
[0129] Inferring the input data input through the ONNX model to obtain the output result;
[0130] The output result is returned to the simulation platform through the output interface in the FMI.
[0131] In a possible implementation, the reasoning logic further includes:
[0132] The input data is inferred by the inference engine of the ONNX model to obtain the output result.
[0133] In a possible implementation manner, the processing module 13 is specifically configured to:
[0134] Create resource folders, executable folders, and root folders;
[0135] The ONNX model is stored in the resource folder, the dynamic link library file is stored in the executable folder, and the model description file is stored in the root folder;
[0136] The resource folder, the executable folder, and the root folder are compressed to obtain the FMU.
[0137] Figure 5 This is a schematic diagram of the structure of the second embodiment of the device for encapsulating the ONNX model into FMU provided by this application. Figure 5 , based on the above embodiment, the device 10 for encapsulating the ONNX model into FMU further includes:
[0138] The compiling module 14 is used to generate the model description document in response to the user's compiling operation on the model code of the ONNX model.
[0139] In a possible implementation, the model description file includes: the number of input interfaces, the names of the input interfaces, the number of output interfaces, the names of the output interfaces, the ONNX model type, and simulation configuration parameters of the FMU.
[0140] The device for encapsulating the ONNX model into FMU provided in the embodiment of the present application can execute the technical solution shown in the above method embodiment, and its implementation principle and beneficial effects are similar, which will not be repeated here.
[0141] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 6 The electronic device 20 provided in the embodiment of the present application includes: at least one processor 21 and a memory 22. Optionally, the device 20 also includes a communication component 23. The processor 21, the memory 22 and the communication component 23 are connected via a bus 24.
[0142] In a specific implementation process, at least one processor 21 executes the computer-executable instructions stored in the memory 22, so that at least one processor 21 executes the above method.
[0143] The specific implementation process of the processor 21 can be found in the above method embodiment, and its implementation principle and technical effect are similar, so this embodiment will not be repeated here.
[0144] In the above embodiments, it should be understood that the processor can be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in the invention can be directly implemented as a hardware processor, or can be implemented by a combination of hardware and software modules in the processor.
[0145] The memory may include a high-speed memory (Random Access Memory, RAM), and may also include a non-volatile memory (NVM), such as at least one disk storage.
[0146] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of this application is not limited to only one bus or one type of bus.
[0147] The present application also provides a computer program product, including a computer program, which implements the above method when executed by a processor.
[0148] The present application also provides a computer-readable storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, the above method is implemented.
[0149] The above-mentioned readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The readable storage medium can be any available medium that can be accessed by a general or special-purpose computer.
[0150] An exemplary readable storage medium is coupled to a processor so that the processor can read information from the readable storage medium and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can be located in an application specific integrated circuit (Application Specific Integrated Circuits, referred to as: ASIC). Of course, the processor and the readable storage medium can also exist in the device as discrete components.
[0151] The division of units is only a logical function division, and there may be other divisions in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interface, device or unit, which can be electrical, mechanical or other forms.
[0152] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0153] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0154] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods of each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0155] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.
[0156] Finally, it should be noted that those skilled in the art will readily conceive of other embodiments of the present invention after considering the specification and practicing the invention disclosed herein. The present invention is intended to cover any variations, uses or adaptations of the present invention, which follow the general principles of the present invention and include common knowledge or customary technical means in the art not disclosed by the present invention, are not limited to the precise structure described above and shown in the drawings, and may be modified and changed in various ways without departing from the scope thereof. The scope of the present invention is limited only by the appended claims.
Claims
1. A method for encapsulating an ONNX model into an FMU, characterized in that: include: According to the dynamic link library source code file, the model description document of the ONNX model is parsed to generate a dynamic link library file, wherein the dynamic link library file includes a functional simulation interface FMI for data exchange between the ONNX model and the simulation platform; According to a preset executable file, the model description document is parsed to generate a model description file; The ONNX model, the dynamic link library file, and the model description file are encapsulated to obtain a functional simulation unit FMU.
2. The method according to claim 1, characterized in that According to the dynamic link library source code file, the model description document of the ONNX model is parsed to generate a dynamic link library file, including: Parsing the model description document according to the interface function preset in the dynamic link library source code file to generate the FMI; Obtaining the reasoning logic of the ONNX model through the FMI, wherein the reasoning logic refers to a mechanism by which the ONNX model calculates and returns output results to the simulation platform after receiving input data sent by the simulation platform; The FMI and the reasoning logic are encapsulated to generate the dynamic link library file.
3. The method according to claim 2, characterized in that The reasoning logic includes: Receiving input data of the simulation platform through an input interface in the FMI; Inferring the input data input through the ONNX model to obtain the output result; The output result is returned to the simulation platform through the output interface in the FMI.
4. The method according to claim 3, characterized in that The inference of the input data input by the ONNX model to obtain the output result includes: The input data is inferred by the inference engine of the ONNX model to obtain the output result.
5. The method according to claim 1, characterized in that The encapsulating the ONNX model, the dynamic link library file, and the model description file to obtain a functional simulation unit FMU includes: Create resource folders, executable folders, and root folders; The ONNX model is stored in the resource folder, the dynamic link library file is stored in the executable folder, and the model description file is stored in the root folder; The resource folder, the executable folder, and the root folder are compressed to obtain the FMU.
6. The method according to any one of claims 1 to 5, characterized in that: According to the dynamic link library source code file, the model description document of the ONNX model is parsed to generate the dynamic link library file, and before the method further comprises: In response to a user's compiling operation on the model code of the ONNX model, the model description document is generated.
7. The method according to any one of claims 1 to 5, characterized in that: The model description file includes: the number of input interfaces of the FMU, the name of the input interface, the number of output interfaces, the name of the output interface, the ONNX model type, and simulation configuration parameters.
8. A device for encapsulating an ONNX model into an FMU, characterized in that: include: An acquisition module is used to parse the model description document of the ONNX model according to the dynamic link library source code file to generate a dynamic link library file, wherein the dynamic link library file includes a functional simulation interface FMI for the ONNX model to interact with the simulation platform; A parsing module, used to parse the model description document according to a pre-written executable file to generate a model description file; The processing module is used to encapsulate the ONNX model, the dynamic link library file, and the model description file to obtain a functional simulation unit FMU.
9. An electronic device, characterized in that: include: Processor, memory; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory, so that the processor executes the method for encapsulating the ONNX model into an FMU according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method for encapsulating an ONNX model into an FMU as described in any one of claims 1 to 7.
Citation Information
Cited By
Method and system for generating a package of free-to-compile FMU files, method and system for executing
CN122526617A