Model conversion method and device, storage medium and electronic device
By obtaining the target operator parameters and priorities of the target layer to determine the target implementation method, the deep learning model is directly converted into an executable model for the target device, which solves the problem of low conversion efficiency in the existing technology, simplifies the operation process and improves the conversion efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-14
- Publication Date
- 2026-03-20
AI Technical Summary
In existing technologies, deep learning models are inefficient to convert on edge devices, requiring a cumbersome predefined format conversion process.
By obtaining the target operator parameters corresponding to the target layer of the model to be converted, and determining the target implementation method based on the target priority, the deep learning model can be directly converted into a model executable by the target device, simplifying the conversion process and improving efficiency.
It enables the conversion of deep learning models into target models executable on specific device types without the need to set up a deep learning framework environment, simplifying the operation process and improving conversion efficiency.
Smart Images

Figure CN115511060B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present application relate to the technical field of deep learning, in particular, to a model conversion method and device, a storage medium and an electronic device. BACKGROUND
[0002] With the rapid development of the field of artificial intelligence, various deep learning frameworks have been produced, such as caffe, tensorflow, pytorch, etc. Different deep learning frameworks correspond to different training and execution operations. In order to execute models of different frameworks, different deep learning environments need to be deployed. And the current trend is to land the algorithm model, that is, to obtain a target model through a certain conversion of the deep learning model, so that it can be executed on a device (for example, an edge device or other types of devices, hereinafter an edge device will be taken as an example for illustration).
[0003] In the prior art, when a deep learning model is converted to obtain a target model that can be executed on an edge device, the trained deep learning model needs to be converted into a model of a predefined format, and then the predefined model is converted into a model executable on the chip of the edge device according to the type of the chip on the edge device. Because the deep learning model needs to be converted into a model of a predefined format first, the way of model conversion is relatively cumbersome, resulting in low efficiency of model conversion.
[0004] In view of the above problems existing in the related art, no effective solution has been proposed so far. SUMMARY
[0005] Embodiments of the present application provide a model conversion method and device, a storage medium and an electronic device to at least solve the problem of low efficiency of model conversion in the related art.
[0006] According to an embodiment of the present application, a model conversion method is provided, comprising: obtaining a target operator parameter corresponding to a first target layer of a first model to be converted, wherein the target operator parameter is determined according to a layer type of the first target layer; determining a target implementation method for running the target operator parameter in a target device based on the target operator parameter and a target priority determined in advance, wherein the target priority is used to indicate the priority of each implementation method; obtaining a second target layer of a target model based on the target implementation method and the target operator parameter.
[0007] Optionally, before determining the target implementation method for running the target operator parameter in the target device based on the target operator parameter and the target priority, the method further comprises: determining the target priority by at least one of the following manners: a first manner, wherein the first manner comprises determining the priority of each implementation method corresponding to the target operator parameter configured in advance; a second manner, wherein the second manner comprises determining the priority of each implementation method corresponding to the target device configured in advance; and a third manner, wherein the third manner comprises determining the time length consumed by each implementation method for running the target operator parameter, and determining the priority of each implementation method based on the time length.
[0008] Optionally, the priority of the first manner is higher than the priority of the second manner, and the priority of the second manner is higher than the priority of the third manner.
[0009] Optionally, determining the target implementation method for running the target operator parameter in the target device based on the target operator parameter and the target priority comprises: determining a target calculation method in one or more calculation methods based on the target operator parameter and a preset limitation condition, wherein the calculation method comprises a calculation method of an operator parameter corresponding to the same layer type of different models; obtaining one or more first implementation methods for implementing the target calculation method; and determining the target implementation method for running the target operator parameter in the target device in one or more first implementation methods according to the target priority.
[0010] Optionally, obtaining the second target layer of the target model based on the target implementation method and the target operator parameter comprises: obtaining the second target layer of the target model by saving the target implementation method and the target operator parameter.
[0011] Optionally, obtaining the target operator parameter corresponding to the first target layer of the first model comprises: obtaining a first network structure parameter of the first target layer; determining a first operator corresponding to the layer type of the first target layer; and assigning the first network structure parameter to the first operator to obtain the target operator parameter.
[0012] Optionally, after obtaining the second target layer of the target model based on the target implementation method and the target operator parameter, the method further comprises: obtaining parameter data amount information included in the first network structure parameter; and allocating storage memory for the second target layer according to the parameter data amount information.
[0013] According to another embodiment of the present application, a model conversion device is provided, comprising: an obtaining module configured to obtain a target operator parameter corresponding to a first target layer of a first model to be converted, wherein the target operator parameter is determined according to a layer type of the first target layer; a determining module configured to determine a target implementation method for running the target operator parameter in a target device based on the target operator parameter and a target priority determined in advance, wherein the target priority is used to indicate a priority of each implementation method; and an obtaining module configured to obtain a second target layer of a target model based on the target implementation method and the target operator parameter.
[0014] According to still another embodiment of the present application, a computer readable storage medium is provided, wherein the computer readable storage medium stores a computer program, and the computer program is executed by a processor to implement the steps of the method in any one of the above embodiments.
[0015] According to still another embodiment of the present application, an electronic device is provided, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to implement the steps of any one of the above method embodiments.
[0016] According to the present application, by obtaining a target operator parameter corresponding to a first target layer of a first model to be converted, and determining a target implementation method for running the target operator parameter in a target device based on the target operator parameter and a target priority determined in advance, a second target layer of a target model can be obtained based on the target implementation method and the target operator parameter, and then by converting the first target layer of the first model into the second target layer of the target model, the first model is converted into a target model that can run in the target device layer by layer. According to the present application, a deep learning model can be converted into a target model executable on a specific device type without building a deep learning framework environment, which simplifies the operation process of converting a deep learning model into a device executable model in the prior art, and determines the optimal network layer implementation during the conversion process, thereby improving the efficiency of converting a deep learning model into a device executable model to a certain extent. BRIEF DESCRIPTION OF DRAWINGS
[0017] Figure 1 is a mobile terminal hardware structure block diagram of a model conversion method according to an embodiment of the present application;
[0018] Figure 2 is a flowchart of a model conversion method according to an embodiment of the present application;
[0019] Figure 3 is a whole flowchart of a model conversion method according to an embodiment of the present application;
[0020] Figure 4 is an optional model analysis flowchart according to an embodiment of the present application;
[0021] Figure 5 is an optional model conversion flowchart according to an embodiment of the present application;
[0022] Figure 6 is a structural schematic diagram of a model conversion device according to an embodiment of the present application. DETAILED DESCRIPTION
[0023] Hereinafter, embodiments of the present application will be described in detail with reference to the accompanying drawings and in conjunction with embodiments.
[0024] It should be noted that the terms "first", "second", and the like in the description and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and do not necessarily have to be used to describe a specific order or sequence.
[0025] The method embodiments provided in the embodiments of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Taking the case of running on a mobile terminal, Figure 1 is a hardware structural block diagram of a mobile terminal of a model conversion method according to an embodiment of the present application. As shown in Figure 1 , the mobile terminal can include one or more (only one is shown in Figure 1 ) processors 102 (the processor 102 can include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the above-mentioned mobile terminal can further include a transmission device 106 for communication function and an input and output device 108. Those skilled in the art can understand that Figure 1 the structure shown is only schematic, which does not limit the structure of the above-mentioned mobile terminal. For example, the mobile terminal can further include more or less components than those shown in Figure 1 , or have a different configuration from Figure 1 .
[0026] The memory 104 can be used to store computer programs, such as software programs of application software and modules, such as a computer program corresponding to the model conversion method in the embodiments of the present application. The processor 102 can execute various functional applications and data processing, i.e., implement the above method, by running the computer programs stored in the memory 104. The memory 104 can include a high-speed random access memory, and can further include a non-volatile memory, such as one or more magnetic storage devices, flash memories, or other non-volatile solid-state memories. In some examples, the memory 104 can further include memories remotely arranged with respect to the processor 102, which can be connected to the mobile terminal through a network. Examples of the above network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.
[0027] The transmission device 106 is used to receive or send data via a network. Specific examples of the above network can include a wireless network provided by a communication provider of the mobile terminal. In one example, the transmission device 106 includes a network adapter (NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet in a wireless manner.
[0028] In the embodiments, a model conversion method running on the above mobile terminal is provided, Figure 2 which is a flowchart of the model conversion method according to the embodiments of the present application, as shown in Figure 2 which includes the following steps:
[0029] In step S202, a target operator parameter corresponding to a first target layer of a first model to be converted is obtained, wherein the target operator parameter is determined according to a layer type of the first target layer;
[0030] The first model can be a deep learning framework model, such as caffe, tensorflow, pytorch, etc. The first target layer can be a layer in the deep learning framework model, such as a data layer, a convolutional layer, or a pooling layer, etc. The layer type of the first target layer is not limited here. The target operator parameter can be an operator parameter corresponding to the first target layer. Assuming that the first target layer is a convolutional layer, the layer type of the first target layer can be determined as a convolutional type, and the target operator parameter corresponding to the first target layer can be determined as a convolutional operator parameter.
[0031] In step S204, a target implementation method for running the target operator parameter in the target device is determined based on the target operator parameter and a target priority, wherein the target priority is used to indicate a priority of each implementation method.
[0032] The target operator parameter can be a convolution operator parameter, a pooling operator parameter or other operator parameter corresponding to a deep learning framework layer, the target device can be an edge device of a specific brand, the target implementation method can be a C implementation, an ARM implementation or other hardware implementation method that can run the convolution operator parameter in the target device, and the target priority can be a preset priority, for example, the priority of the C implementation can be set to be higher than that of the ARM implementation. The target device can be an edge device or other type of device. Assuming that the target device is an edge device of a specific brand and the target operator parameter is a convolution operator parameter, the target implementation method for running the convolution operator parameter in the edge device of the specific brand can be determined as the C implementation according to the target priority.
[0033] In step S206, a second target layer of a target model is obtained based on the target implementation method and the target operator parameter.
[0034] The target model is a bottom layer model that can run on the target device. Assuming that the target implementation method is a C implementation and the target operator parameter is a convolution operator parameter, the second target layer of the target model can be obtained according to the C implementation and the convolution operator parameter.
[0035] Optionally, the execution subject of the above steps can be a background processor or other device with similar processing capability, and can also be a machine integrated with at least a data processing device, wherein the data processing device can include a computer, a mobile phone or other terminal, but is not limited thereto.
[0036] Through the above steps, the target operator parameter corresponding to the first target layer of the first model to be converted is obtained, and the target implementation method for running the target operator parameter in the target device is determined based on the target operator parameter and a target priority. The second target layer of the target model can be obtained based on the target implementation method and the target operator parameter. Then, the first target layer of the first model is converted into the second target layer of the target model, so as to convert the first model into the target model that can run in the target device. Through the present application, the deep learning model can be converted into the target model executable on the specific device type without building a deep learning framework environment, thereby simplifying the operation process of converting the deep learning model into the executable model on the device in the prior art, and determining the optimal implementation of the network layer in the conversion process, which improves the efficiency of converting the deep learning model into the executable model on the device to a certain extent.
[0037] Optionally, before determining the target implementation method for running the target operator parameter in the target device based on the target operator parameter and a predetermined target priority, the method further comprises determining the target priority by at least one of the following: a first way, wherein the first way comprises determining a priority of each implementation method corresponding to the target operator parameter; a second way, wherein the second way comprises determining a priority of each implementation method corresponding to the target device; and a third way, wherein the third way comprises determining a time length of each implementation method for running the target operator parameter, and determining a priority of each implementation method based on the time length.
[0038] As an optional implementation, the target priority can be determined in multiple ways. For example, the operator priority can be used as the first way. The operator priority can be a priority of each implementation method corresponding to the target operator parameter. For example, the target operator parameter can be a convolution operator parameter, and the priority of the C implementation can be higher than the priority of the ARM implementation.
[0039] The device priority can also be used as the second way. The device priority can be a priority of each implementation method corresponding to the target device. For example, the target device can be a specific brand of edge device, and the priority of the C implementation can be higher than the priority of the ARM implementation.
[0040] The time-consuming priority can also be used as the third way. Assuming that the target operator parameter corresponds to two implementations, including the C implementation and the ARM implementation, and the target operator parameter is a convolution operator parameter, the time length of the C implementation and the ARM implementation for running the convolution operator parameter can be determined as 3 milliseconds and 2 milliseconds, respectively. Then, the priority of the implementation method can be determined based on the time lengths, for example, the priority of the implementation method with less time consumption can be the highest.
[0041] Optionally, the priority of selecting the first way is higher than the priority of selecting the second way, and the priority of selecting the second way is higher than the priority of selecting the third way.
[0042] As an optional implementation, assuming that the first way is the operator priority, the second way is the device priority, and the third way is the time-consuming priority, in the case where at least two of the three ways exist at the same time, the priority of selecting the operator priority is higher than the priority of selecting the device priority, and the priority of selecting the device priority is higher than the priority of selecting the time-consuming priority.
[0043] Optionally, based on the target operator parameter and a predetermined target priority, determining the target implementation method for running the target operator parameter in the target device comprises: determining a target calculation method in one or more calculation methods based on the target operator parameter and a preset restriction condition, wherein the calculation method comprises a calculation method of an operator parameter corresponding to the same layer type of different models; obtaining one or more first implementation methods for implementing the target calculation method; and determining the target implementation method for running the target operator parameter in the target device in the one or more first implementation methods according to the target priority.
[0044] As an optional implementation, the preset restriction condition can be an input data dimension, a data type, or the like. Here, the preset restriction condition is not limited. Assuming that the restriction condition is an input data dimension, the target operator parameter is a convolution operator parameter, and the input parameter of the convolution operator parameter is 5-dimensional data, the preset restriction condition can be that the input parameter is 5-dimensional data. Assuming that there are two calculation methods that can run the convolution operator parameter, namely, calculation method 1 and calculation method 2, and the calculation method 1 can run 4-dimensional operator parameter data, and the calculation method 2 can run 5-dimensional operator parameter data, in the calculation method 1 and the calculation method 2, the calculation method 2 that can run 5-dimensional operator parameter data is determined as the target calculation method. Assuming that there are two implementation methods for implementing the target calculation method 2, namely, implementation method A and implementation method B, in the implementation method A and the implementation method B, the target implementation method for running the convolution operator parameter in the target device is determined according to the target priority. Assuming that the priority of the implementation method A is higher than that of the implementation method B in the target priority, the implementation method A can be determined as the target implementation method.
[0045] Optionally, based on the target implementation method and the target operator parameter, the second target layer of the target model is obtained by corresponding saving the target implementation method and the target operator parameter.
[0046] As an optional implementation, assuming that the target operator parameter is a convolution operator parameter, and the target implementation method is a C implementation, the second target layer of the target model running on the target device can be obtained by corresponding saving the C implementation and the convolution operator parameter.
[0047] Optionally, the target operator parameter corresponding to the first target layer of the first model comprises: obtaining a first network structure parameter of the first target layer; determining a first operator corresponding to a layer type of the first target layer; and assigning the first network structure parameter to the first operator to obtain the target operator parameter.
[0048] As an optional implementation, assuming that the first model is a caffe model and the first target layer is a convolution layer, the network structure parameters of the convolution layer are obtained, the network structure parameters can be network feature parameters, weight parameters or other parameters that can represent the network structure, the first operator corresponding to the layer type of the convolution layer is determined as a convolution operator, and the network structure parameters are assigned to the convolution operator to obtain the convolution operator parameters corresponding to the convolution layer.
[0049] Optionally, after obtaining the second target layer of the target model based on the target implementation method and the target operator parameters, the method further comprises: obtaining parameter data amount information included in the first network structure parameters; and allocating storage memory for the second target layer according to the parameter data amount information.
[0050] As an optional implementation, assuming that the first model is a caffe model and the first target layer is a convolution layer, the parameter data amount information corresponding to the network structure parameters of the convolution layer is obtained, the parameter data amount information can be information about the data amount size of the network structure parameters, and the storage memory for the second target layer that can run on the target device can be allocated according to the parameter data amount size, for storing the parameter data information of each layer.
[0051] As an optional implementation, the present application provides a multi-framework model analysis and conversion method, which supports multiple deep frameworks such as caffe, onnx, etc., has a simple operation process, does not need to be converted into an intermediate product of a framework first, but can be directly converted into a target model according to a predetermined device type, and automatically selects the optimal implementation.
[0052] Different deep learning frameworks display network structures or weights in different ways, but the network layer types are consistent, so the layers in the deep learning framework can be corresponded to the operators in the present application. In order to minimize the precision loss of the converted model, the same type of layers in different deep learning frameworks are compatible, the appropriate data types are constructed to store the parameter information after model analysis, and the corresponding calculation method is determined according to the analysis parameter satisfaction condition, wherein the calculation method is the calculation method of the same layer in different frameworks. And each calculation method corresponds to different implementations, including but not limited to c, arm and other hardware implementations.
[0053] The application is convenient to select different implementation methods according to different device types, improves performance while ensuring the accuracy of the conversion model, and sets two priorities for different device types. One is the default priority, which represents the general priority of each device type; the other is the operator priority, which represents the priority between different implementations of an operator. The relationship between the two priorities is: the single operator priority is higher than the default priority; the relationship between single operator priorities is: when the high-priority method does not meet the requirements, the low-priority method is automatically called to ensure the execution of the operator. When selecting the optimal operator implementation according to the device type, setting the operator priority for a specific operator can ensure which calculation method is selected when the operator is executed, and the minimum time-consuming method is not selected according to the time-consuming information. When the implementation with high priority does not meet the requirements, the subsequent priority method is called, and the operation process is more flexible.
[0054] The application first determines the operator type according to the layer type, then determines the calculation method according to the parameter information, then determines the operator implementation according to the device type, and finally obtains the conversion model, as shown in the overall flowchart Figure 3 .
[0055] As an optional implementation, the model analysis flowchart is shown in Figure 4 , and is described in detail as follows. First, determine the deep learning framework corresponding to the input model according to the input model suffix, such as Caffe model, TensorFlow model, Onnx model or Pytorch model, etc.; second, analyze the model to obtain the framework layer and save the parameter information of each layer; finally, determine the operator layer by layer according to the layer type of the framework layer, and assign the parameter information to the operator to obtain the analyzed operator parameter list; it should be noted that the calculation method in the present application refers to the calculation method of the determination result of the same type layer of different models.
[0056] Figure 5 The flowchart for determining the final operator implementation method according to the calculation method, target device type and operator parameter in the model conversion process, wherein A, B and C implementation includes but is not limited to C implementation, arm implementation, or other hardware implementation that can run operator parameters on target devices. First, verify the operator parameters, determine the calculation method according to the limit conditions satisfied by the parameters, wherein the calculation method refers to the calculation method of the determination result of the same type layer of different frameworks, run the operator according to the calculation method, and obtain the time-consuming information of different implementation methods of the operator under the same input size, second, if the operator has a set operator priority and the operator parameters meet the highest priority, select the implementation corresponding to the highest priority, otherwise, select the implementation with the minimum time-consuming according to the time-consuming information and record it.
[0057] The storage memory is allocated according to the input and output size of the model operator, weight information and the like. Through the three steps of model analysis, model conversion and memory allocation, the conversion of one layer of the deep learning model is realized. The three steps of model analysis, model conversion and memory allocation are repeatedly executed, and the network structure, weight information and the like are saved layer by layer according to certain rules to obtain the converted target model.
[0058] As an optional implementation, the rapid development of the artificial intelligence field puts forward higher requirements for the generalization of deep learning models, but the differences between deep learning frameworks and the manpower and material resources required to build the corresponding deep learning framework environment for running models of different frameworks to some extent increase the implementation cost of the artificial intelligence field. In terms of running deep learning models, converting different deep learning framework models into models suitable for different devices is an effective method to improve the generalization of deep learning models. Therefore, the present application proposes a multi-framework model analysis and conversion method for converting deep learning framework models into target models that can run on specified devices. The technical points of the present application are as follows: 1. A simple multi-framework model analysis, conversion and running method is proposed, and the model conversion does not need to be converted into an intermediate product of a certain model framework, but can be directly converted into a target model; 2. The method in the present application does not need to construct the corresponding running environment according to the input deep learning framework model, and then obtain the target conversion model through running instances, but only needs to input the original deep framework model; 3. In the model analysis aspect, the operator in the present application is determined according to the layer type, and the operator in the present case is compatible with multiple deep learning frameworks, and the calculation method is determined according to the analysis parameters, so as to reduce the precision loss caused by model conversion; 4. In the present application, two priority levels are set for each device type, which are the default priority level and the operator priority level. The default priority level is for the entire device, and the operator priority level is for each operator, and the operator priority level is higher than the device priority level. The priority level is for the implementation method supported by the device, including but not limited to arm, C and the like.
[0059] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be realized by means of software and necessary general hardware platform, of course, it can also be realized by hardware, but in many cases the former is a better implementation. Based on such understanding, the technical solutions of the present application can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes a plurality of instructions for making a terminal device (which can be a mobile phone, computer, server or network device) execute the method described in each embodiment of the present application.
[0060] A model conversion apparatus is also provided in the embodiments, which is configured to implement the above-described embodiments and preferred embodiments, and will not be described again. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the apparatus described in the following embodiments is preferably implemented in software, implementation in hardware, or a combination of software and hardware, is also possible and contemplated.
[0061] Figure 6 is a structural block diagram of a model conversion apparatus according to an embodiment of the present application, as shown in Figure 6 The apparatus includes: an obtaining module 62, configured to obtain a target operator parameter corresponding to a first target layer of a first model to be converted, wherein the target operator parameter is determined according to a layer type of the first target layer; a first determining module 64, configured to determine a target implementation method for running the target operator parameter in a target device based on the target operator parameter and a target priority determined in advance, wherein the target priority is used to indicate a priority of each of the implementation methods; and an obtaining module 66, configured to obtain a second target layer of a target model based on the target implementation method and the target operator parameter.
[0062] Optionally, the apparatus further includes a second determining module, configured to determine the target priority by at least one of the following ways before determining the target implementation method for running the target operator parameter in the target device based on the target operator parameter and the target priority: a first way, wherein the first way includes determining a priority of each of the implementation methods configured in advance for the target operator parameter; a second way, wherein the second way includes determining a priority of each of the implementation methods configured in advance for the target device; and a third way, wherein the third way includes determining a time length consumed by each of the implementation methods for running the target operator parameter, and determining a priority of each of the implementation methods based on the time length.
[0063] Optionally, the priority of the first way is higher than the priority of the second way, and the priority of the second way is higher than the priority of the third way.
[0064] Optionally, the first determining module further includes: a first determining unit, configured to determine a target calculation method from one or more calculation methods based on the target operator parameter and a preset restriction condition, wherein the calculation methods include calculation methods of operator parameters corresponding to the same layer type in different models; a first obtaining unit, configured to obtain one or more first implementation methods for implementing the target calculation method; and a second determining unit, configured to determine the target implementation method for running the target operator parameter in the target device according to the target priority from the one or more first implementation methods.
[0065] Optionally, the obtaining module includes a saving unit configured to save the target implementation method and the target operator parameter correspondingly to obtain the second target layer of the target model.
[0066] Optionally, the obtaining module is further configured to obtain the target operator parameter corresponding to the first target layer of the first model by: obtaining a first network structure parameter of the first target layer; determining a first operator corresponding to a layer type of the first target layer; and assigning the first network structure parameter to the first operator to obtain the target operator parameter.
[0067] Optionally, the apparatus is further configured to, after obtaining the second target layer of the target model based on the target implementation method and the target operator parameter, obtain parameter data amount information included in the first network structure parameter; and allocate storage memory for the second target layer according to the parameter data amount information.
[0068] It should be noted that each of the above modules can be implemented by software or hardware, and for the latter, the following implementation manners can be used, but are not limited thereto: all the modules are located in the same processor; or each of the modules is located in a different processor in any combination.
[0069] Embodiments of the present application also provide a computer readable storage medium, which stores a computer program, wherein the computer program is executed by a processor to implement the steps of the method described in any one of the above embodiments.
[0070] Optionally, in the present embodiment, the storage medium can be configured to store a computer program for executing the following steps:
[0071] S1, obtaining a target operator parameter corresponding to a first target layer of a first model to be converted, wherein the target operator parameter is determined according to a layer type of the first target layer;
[0072] S2, determine a target implementation method for running the target operator parameter in a target device based on the target operator parameter and a predetermined target priority, wherein the target priority is used to indicate a priority of each implementation method;
[0073] S3, obtain a second target layer of a target model based on the target implementation method and the target operator parameter.
[0074] In an example embodiment, the computer readable storage medium described above can include, but is not limited to, a U disk, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and various media that can store computer programs.
[0075] Embodiments of the present application also provide an electronic device including a memory and a processor, the memory storing a computer program, and the processor being configured to execute the computer program to perform the steps in any of the method embodiments described above.
[0076] In an example embodiment, the electronic device described above can further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0077] Optionally, in the present embodiment, the processor can be configured to perform the following steps through the computer program:
[0078] S1, obtain a target operator parameter corresponding to a first target layer of a first model to be converted, wherein the target operator parameter is determined according to a layer type of the first target layer;
[0079] S2, determine a target implementation method for running the target operator parameter in a target device based on the target operator parameter and a predetermined target priority, wherein the target priority is used to indicate a priority of each implementation method;
[0080] S3, obtain a second target layer of a target model based on the target implementation method and the target operator parameter.
[0081] The specific examples in the present embodiment can refer to the examples described in the above embodiments and example embodiments, which will not be described herein again.
[0082] It should be apparent to those skilled in the art that the modules or steps of the application described above can be implemented with general computing devices, which can be centralized on a single computing device or distributed on a network of multiple computing devices, which can be implemented with program codes executable by the computing devices, so that they can be stored in storage devices and executed by the computing devices, and in some cases, the steps shown or described can be executed in different orders than shown, or made into individual integrated circuit modules, or made into a single integrated circuit module. Thus, the application is not limited to any particular combination of hardware and software.
[0083] The preferred embodiments of the application described above are intended to be merely exemplary and those skilled in the art will recognize that many changes and modifications can be made to the application without departing from the spirit and scope of the application. Any modifications, equivalent substitutions, improvements, etc. made within the principles of the application shall be included in the protection scope of the application.
Claims
1. A model conversion method, characterized in that, include: Obtain the target operator parameters corresponding to the first target layer of the first model to be transformed, wherein the target operator parameters are determined according to the layer type of the first target layer; Based on the target operator parameters and the predetermined target priority, a target implementation method for running the target operator parameters in the target device is determined, wherein the target priority is used to indicate the priority of each implementation method; Based on the target implementation method and the target operator parameters, a second target layer that supports the target model running in the target device is obtained; Based on the target operator parameters and a pre-determined target priority, determining the target implementation method for running the target operator parameters in the target device includes: determining a target calculation method from one or more calculation methods based on the target operator parameters and preset constraints, wherein the calculation methods include calculation methods for operator parameters corresponding to the same layer type for different models, and the preset constraints include the dimension of the target operator parameters and / or the type of the target operator parameters; obtaining one or more first implementation methods for implementing the target calculation method; and determining the target implementation method for running the target operator parameters in the target device according to the target priority among the one or more first implementation methods.
2. The method according to claim 1, characterized in that, Before determining the target implementation method for running the target operator parameters in the target device based on the target operator parameters and the pre-determined target priority, the method further includes: The target priority is determined by at least one of the following methods: A first approach, wherein the first approach includes determining a priority for each implementation method pre-configured for the target operator parameters; The second approach includes determining a priority for each of the implementation methods pre-configured for the target device; The third approach includes determining the time consumed by each of the implementation methods to run the target operator parameters, and determining the priority of each implementation method based on the time consumed.
3. The method according to claim 2, characterized in that, The priority of selecting the first method is higher than the priority of selecting the second method, and the priority of selecting the second method is higher than the priority of selecting the third method.
4. The method according to claim 1, characterized in that, Based on the target implementation method and the target operator parameters, the second target layer of the target model is obtained as follows: The target implementation method and the target operator parameters are saved accordingly to obtain the second target layer of the target model.
5. The method according to claim 1, characterized in that, Obtain the target operator parameters corresponding to the first target layer of the first model, including: Obtain the first network structure parameters of the first target layer; Determine the first operator corresponding to the layer type of the first target layer; The first network structure parameters are assigned to the first operator to obtain the target operator parameters.
6. The method according to claim 5, characterized in that, After obtaining the second target layer of the target model based on the target implementation method and the target operator parameters, the method further includes: Obtain the parameter data volume information included in the first network structure parameters; Based on the parameter data volume information, storage memory is allocated for the second target layer.
7. A model conversion device, characterized in that, include: The acquisition module is used to acquire the target operator parameters corresponding to the first target layer of the first model to be converted, wherein the target operator parameters are determined according to the layer type of the first target layer; The first determining module is used to determine, based on the target operator parameters and a pre-determined target priority, a target implementation method for running the target operator parameters in a target device, wherein the target priority is used to indicate the priority of each implementation method; The module is configured to obtain a second target layer that supports the target model running in the target device, based on the target implementation method and the target operator parameters. The first determining module further includes: a first determining unit, configured to determine a target calculation method among one or more calculation methods based on the target operator parameters and preset constraints, wherein the calculation method includes calculation methods for operator parameters corresponding to the same layer type for different models, and the preset constraints include the dimension of the target operator parameters and / or the type of the target operator parameters; a first obtaining unit, configured to obtain one or more first implementation methods for implementing the target calculation method; and a second determining unit, configured to determine, among one or more first implementation methods, the target implementation method for running the target operator parameters in the target device according to the target priority.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the steps of the method described in any one of claims 1 to 6.
9. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to run the computer program to perform the method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Model generation method and device and information recognition method and device
CN108764487A
Conversion method, apparatus, computer apparatus and storage medium
CN109492241A