WO2021169844A1 - 神经网络模型的转换方法、模型精度定位方法及装置 - Google Patents

神经网络模型的转换方法、模型精度定位方法及装置 Download PDF

Info

Publication number
WO2021169844A1
WO2021169844A1 PCT/CN2021/076754 CN2021076754W WO2021169844A1 WO 2021169844 A1 WO2021169844 A1 WO 2021169844A1 CN 2021076754 W CN2021076754 W CN 2021076754W WO 2021169844 A1 WO2021169844 A1 WO 2021169844A1
Authority
WO
WIPO (PCT)
Prior art keywords
neural network
model
network model
accuracy
target
Prior art date
Application number
PCT/CN2021/076754
Other languages
English (en)
French (fr)
Inventor
罗培超
徐迟
张行程
Original Assignee
上海商汤智能科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 上海商汤智能科技有限公司 filed Critical 上海商汤智能科技有限公司
Priority to JP2021570957A priority Critical patent/JP2022540300A/ja
Priority to SG11202113120YA priority patent/SG11202113120YA/en
Priority to KR1020217041100A priority patent/KR20220008336A/ko
Publication of WO2021169844A1 publication Critical patent/WO2021169844A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/045Combinations of networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods

Definitions

  • the present disclosure relates to the technical field of artificial intelligence (AI), and in particular to a neural network model conversion method, model accuracy positioning method and device.
  • AI artificial intelligence
  • the conversion of a neural network model refers to the conversion of a neural network model defined in a certain framework to another framework.
  • the present disclosure provides a technical solution for neural network model conversion.
  • a neural network model conversion method includes: a model conversion device obtains a first neural network model, model input data, and information of a target frame in a source frame; the model conversion device is based on the model Input data performs model conversion processing on the first neural network model under the source frame to obtain the second neural network model under the target frame; the model conversion device is based on the first neural network model and the second neural network The model separately processes the first inference result and the second inference result obtained by processing the model input data to obtain the accuracy verification result of the second neural network model.
  • the model conversion device may perform model conversion processing based on a user instruction.
  • the user instruction is used to instruct to convert the first neural network model under the source frame to the target frame.
  • the user instruction includes the first neural network model under the source frame and model input. Data and information about the target framework.
  • the model conversion device can also perform model conversion processing based on internal operating instructions, such as model conversion instructions.
  • the internal operating instructions are used to instruct to convert the first neural network model under the source frame to the target frame.
  • the internal operating instructions include The first neural network model under the source frame, model input data, and information about the target frame.
  • the model conversion device obtains the first inference result of the first neural network model on the model input data in the process of performing model conversion processing on the first neural network model.
  • the model conversion device locally stores the first inference result.
  • the model conversion device processes the model input data through the second neural network model to obtain a second reasoning result.
  • the model conversion device obtains the accuracy verification result of the second neural network model by comparing the first inference result with the second inference result.
  • the performing model conversion processing on the first neural network model under the source framework to obtain the second neural network model under the target framework includes: performing a first process on the source The first neural network model under the framework performs model conversion processing to obtain the second neural network model under the target framework; the method further includes: creating a second process through the first process; calling through the first process The second process is to process the model input data through the second neural network model in the second process to obtain a second inference result.
  • the model conversion device is based on a first inference result and a second inference result obtained by separately processing the model input data on the first neural network model and the second neural network model,
  • Obtaining the accuracy verification result of the second neural network model includes: if the difference between the first inference result and the second inference result is within a preset error range, determining the accuracy of the second neural network model The verification result is accuracy alignment; or if the difference between the first inference result and the second inference result exceeds the preset error range, it is determined that the accuracy verification result of the second neural network model is accuracy misalignment.
  • the method further includes: in response to determining that the accuracy verification result of the second neural network model is accuracy misalignment, the model conversion device locates the accuracy misalignment in the second neural network model The target network layer; the model conversion device outputs the information of the target network layer.
  • the locating a target network layer whose accuracy is not aligned in the second neural network model includes: establishing the first neural network model and the second neural network model by the model conversion device The mapping relationship between the network layers in the model conversion device; the output data of each network layer and the output data of each network layer in the process of processing the model input data based on the first neural network model and the second neural network model respectively The mapping relationship is used to determine the target network layer whose accuracy is not aligned in the second neural network model.
  • the target network layer is the network layer in which the accuracy is not aligned first among the multiple network layers included in the second neural network model.
  • the target network layer is a plurality of network layers whose accuracy is not aligned in the second neural network model.
  • it includes not only the network layer where the accuracy misalignment occurs first, but also the subsequent network layers of the network layer.
  • the information of the target network layer includes at least one of the following: the identification, parameters, output data of the target network layer, the output data and the first neural network model The error between the output data of the network layer corresponding to the target network layer.
  • the model conversion device performs model conversion processing on the first neural network model again, wherein, in the process of performing the model conversion processing again, the first neural network model is acquired Output data of each network layer, and/or establish a mapping relationship between the network layers in the first neural network model and the second neural network model.
  • the model conversion device performs model conversion processing on the first neural network model in the source frame to obtain the second neural network model in the target frame, including: the model conversion device Building a network topology diagram through the processing of the input data of the model by the first neural network model, wherein the network topology diagram includes the information of the network layers in the first neural network model and the connection relationship of the network layers; The model conversion device obtains the second neural network model based on the network topology map and the information of the target frame.
  • a model conversion device in a second aspect, includes: an acquisition unit for acquiring a first neural network model, model input data, and information about a target framework in a source framework; and a conversion unit for evaluating the Perform model conversion processing on the first neural network model in the source framework to obtain the second neural network model in the target framework; the verification unit is configured to perform a comparison between the first neural network model and the second neural network model based on the first neural network model and the second neural network model.
  • the first inference result and the second inference result obtained by processing the input data of the model obtain the accuracy verification result of the second neural network model.
  • an electronic device including a memory and a processor, wherein the memory stores program instructions, and the processor is used to call the program instructions stored in the memory to execute the first aspect or the first aspect. Any one of the aspects implements the described method.
  • a computer-readable storage medium stores instructions that, when run on a computer, cause the computer to execute the above-mentioned first aspect or any one of the implementations of the first aspect. The method described.
  • a computer program product containing instructions which when run on a computer, causes the computer to execute the method described in the first aspect or any one of the first aspects.
  • the accuracy verification results of the second neural network model can be automatically obtained, which improves the neural network model conversion The accuracy of the verification efficiency.
  • the embodiment of the present application also provides a model accuracy positioning solution.
  • a model accuracy positioning method including: a model accuracy positioning device acquires a first neural network model, model input data, and information about a target frame in a source frame; The neural network model performs model conversion processing to obtain a second neural network model under the target framework; the model accuracy positioning device performs model input data on the model input data based on the first neural network model and the second neural network model The output data of each network layer obtained in the process of processing locates the target network layer whose accuracy is not aligned in the second neural network model; the model accuracy positioning device outputs the information of the target network layer.
  • the model accuracy positioning device may perform model accuracy positioning based on a user instruction, and the user instruction is used to instruct to locate the accuracy of the second neural network model.
  • the aligned target network layer, the user instruction includes the first neural network model under the source frame, model input data, and information about the target frame.
  • the model accuracy positioning device can also perform model accuracy positioning based on internal operating instructions, such as model accuracy positioning instructions.
  • the model accuracy positioning device acquires an instruction that the accuracy of the second neural network model and the first neural network model are not aligned, it triggers the model accuracy positioning instruction.
  • the internal operation instruction is used to instruct the positioning of the target network layer whose accuracy is not aligned in the second neural network model, and the internal operation instruction includes the first neural network model under the source framework, model input data, and information about the target framework.
  • the model input data is processed through the second neural network model to obtain the output data of each network layer in the second neural network model.
  • the output data of each network layer where the first neural network model processes the model input data is obtained in the process of the model conversion processing.
  • the target network layer is the network layer in which the accuracy is not aligned first among the multiple network layers included in the second neural network model.
  • the target network layer is a plurality of network layers whose accuracy is not aligned in the second neural network model.
  • it includes not only the network layer where the accuracy misalignment occurs first, but also the subsequent network layers of the network layer.
  • the target network layer can be determined by comparing the output data of each network layer in the first neural network model and the second neural network model.
  • the network is considered The layer is a network layer whose accuracy is not aligned.
  • the information of the target network layer includes at least one of the following: the identification, parameters, output data of the target network layer, the output data and the first neural network model The error between the output data of the network layer corresponding to the target network layer.
  • the method further includes: the model accuracy positioning device establishes a relationship between the network layers in the first neural network model and the second neural network model based on the model conversion processing Mapping relationship; the model accuracy positioning device locates the second neural network based on the output data of each network layer obtained by processing the model input data on the first neural network model and the second neural network model
  • the target network layer whose accuracy is not aligned in the model includes: the model accuracy positioning device determines the target network layer based on the output data of each network layer in the first neural network model and the second neural network model and the mapping relationship. The target network layer whose accuracy is not aligned in the second neural network model is described.
  • the model accuracy positioning device determines the second neural network based on the output data of each network layer in the first neural network model and the second neural network model and the mapping relationship.
  • the target network layer whose accuracy is not aligned in the network model includes: the model accuracy positioning device sequentially compares the output data of the corresponding network layer in the first neural network model and the second neural network model based on the mapping relationship; and responding If the difference between the output data of the corresponding network layer in the first neural network model and the second neural network model exceeds the preset error range, the corresponding network layer is classified as the second neural network model.
  • the network layer is determined as the target network layer.
  • the model accuracy positioning device performs model conversion processing on the first neural network model under the source frame to obtain the second neural network model under the target frame, including: the model accuracy The positioning device establishes a network topology diagram through the processing of the input data of the model by the first neural network model, wherein the network topology diagram includes the information of the network layer in the first neural network model and the connections of the network layers Relationship; the model accuracy positioning device obtains the second neural network model based on the network topology map and the information of the target frame.
  • a model accuracy positioning device including: an acquisition unit for acquiring a first neural network model under a source framework, model input data, and information about a target framework; and a conversion unit for evaluating the first neural network model
  • the neural network model performs model conversion processing to obtain the second neural network model under the target framework; the positioning unit is used to process the input data of the model based on the first neural network model and the second neural network model.
  • the output data of each network layer in the process locates the target network layer whose accuracy is not aligned in the second neural network model; the output unit is used to output the information of the target network layer.
  • an electronic device including a memory and a processor, wherein the memory stores program instructions, and the processor is used to call the program instructions stored in the memory to execute the sixth aspect or the sixth aspect Any one of the implementations of the described method.
  • a computer-readable storage medium stores instructions that, when run on a computer, cause the computer to execute the aforementioned sixth aspect or any one of the implementations of the sixth aspect. The method described.
  • a computer program product containing instructions which when running on a computer, causes the computer to execute the method described in any one of the sixth aspect or the sixth aspect.
  • the target network with misaligned accuracy in the second neural network model can be located Layer, to achieve accurate positioning of the network layer when the accuracy is not aligned.
  • FIG. 1 is a schematic flowchart of a neural network model conversion method provided by an embodiment of the disclosure
  • FIG. 2 is a schematic diagram of a conversion process of a neural network model provided by an embodiment of the disclosure
  • FIG. 3 is a schematic diagram of another process of the neural network model conversion method provided by the embodiments of the disclosure.
  • FIG. 4 is a schematic diagram of a network topology obtained in a process of positioning a target network layer according to an embodiment of the disclosure
  • FIG. 5 is a schematic flowchart of a model accuracy positioning method provided by an embodiment of the disclosure.
  • FIG. 6 is a schematic diagram of another process of the model accuracy positioning method provided by an embodiment of the present disclosure.
  • FIG. 7 is a schematic structural diagram of a model conversion device provided by an embodiment of the disclosure.
  • FIG. 8 is a schematic structural diagram of a model accuracy positioning device provided by an embodiment of the disclosure.
  • FIG. 9 is a schematic diagram of the hardware structure of an electronic device provided by an embodiment of the disclosure.
  • FIG. 1 is a schematic flowchart of a neural network model conversion method provided by an embodiment of the present disclosure. The method includes the following steps:
  • the model conversion device acquires the first neural network model under the source frame, the model input data, and the information of the target frame.
  • the neural network model can be converted between frameworks.
  • Each framework has its own network structure definition and toolkit.
  • the conversion of a neural network model refers to the conversion of a neural network model defined in a certain framework to another framework, for example, the neural network model under the tensorflow framework is converted to the pytorch framework, or the neural network model under the custom framework
  • the network model is converted to a more general framework such as pytorch or tensorflow, or vice versa, and so on.
  • the corresponding frame before the neural network model conversion is called the "source frame”
  • the corresponding frame after the neural network model conversion is called the "target frame”.
  • the embodiments of the present disclosure do not limit the specific implementation of the source frame and the target frame.
  • the model conversion device may perform model conversion processing based on a user instruction.
  • the user instruction is used to instruct to convert the first neural network model under the source frame to the target frame.
  • the user instruction includes the first neural network model under the source frame and model input. Data and information about the target framework.
  • the model conversion device can also perform model conversion processing based on internal operating instructions, such as model conversion instructions.
  • the internal operating instructions are used to instruct to convert the first neural network model under the source frame to the target frame.
  • the internal operating instructions include The first neural network model under the source frame, model input data, and information about the target frame.
  • the first neural network model is a general neural network model, which can be a neural network model with any function.
  • the first neural network model includes one or more network layers, such as a convolutional layer, a pooling layer, a fully connected layer, a normalization layer, and so on.
  • the first neural network model under the source framework includes the structure description file of each network layer in the first neural network model under the source framework, etc.
  • the structure description file is used to describe the name of the network layer, the index of the layer, and the like.
  • the model input data refers to model input data used for neural network model inference, or can be called test data.
  • the input data of the model can be a picture, a paragraph of text, and so on.
  • the target framework information includes the target framework's identification, format, toolkit, etc.
  • the model conversion device performs model conversion processing on the first neural network model in the source frame to obtain the second neural network model in the target frame.
  • the first neural network model under the source frame needs to be model-transformed, that is, the first neural network model is converted to the target frame.
  • FIG. 2 which is a schematic diagram of the conversion process of the neural network model provided by the embodiment of the present disclosure
  • a model conversion device also called a neural network model conversion tool
  • the neural network model conversion tool can be used to perform the frame conversion of the neural network model.
  • Use the neural network model conversion tool to convert the network layers of the first neural network model under the source frame into the format of the target frame, and obtain the network layers of the second neural network model under the target frame, thereby obtaining the first neural network model under the target frame.
  • Neural network model where a network layer of the first neural network model may be converted into one or more network layers of the second neural network model, and a network layer of the second neural network model may correspond to the first neural network model One or more network layers, which are not limited in the embodiment of the present disclosure.
  • the model conversion device runs the inference process of the first neural network model on the input data of the model to obtain the first inference result, for example, as shown in FIG. 2 Shown as output 1.
  • the inference result can be stored or recorded locally as the first inference result.
  • the first inference result can be used to verify the accuracy of the second neural network model. That is, in the process of model conversion, the inference result of the first neural network model on the input data of the model can be obtained without re-running the inference process. Thereby improving the efficiency of accuracy verification.
  • the model conversion device may also re-input the model input data to the first neural network model, run the inference process of the first neural network model on the model input data, and obtain the first inference result.
  • the model conversion device may pre-store the first inference result of the first neural network model on the model input data.
  • the model conversion device performs model conversion processing on the first neural network model under the source frame to obtain the second neural network model under the target frame. Specifically, first, the model conversion device performs model analysis processing on the first neural network model to obtain a network topology diagram of the first neural network model, where, optionally, the model analysis processing can input the model through the first neural network model
  • the network topology diagram can also be referred to as a calculation diagram, which can include the various network layers in the first neural network model and the connection relationship of the various network layers, such as the network topology structure shown in FIG. 4. Among them, the network topology diagram may not include the output of each network layer, which is beneficial to improve the model conversion efficiency.
  • the model conversion device obtains the second neural network model based on the network topology map and the information of the target frame.
  • the target framework has its own network structure definition and toolkit.
  • the model conversion device can use the network structure definition of the target framework based on the network topology diagram of the first neural network and/ Or the toolkit performs adaptive network construction on the network topology map of the first neural network to obtain the second neural network model.
  • the model conversion device separately processes the model input data based on the first inference result and the second inference result obtained by the first neural network model and the second neural network model, and obtains the accuracy verification result of the second neural network model.
  • the above model input data can be input to the second neural network model, and the model input data can be used to run inferences on each network layer of the second neural network model.
  • the inference result output by one network layer can be used as the input data of the next network layer, and finally the final inference result of the second neural network model, that is, the second inference result, is obtained.
  • the first inference result is the inference result of the output of the last layer obtained by processing the input data of the model by the first neural network model under the source framework or the meaningful inference result of a certain reciprocal layer.
  • the second inference result is the inference result of the output of the last layer obtained by processing the input data of the model by the second neural network model under the target framework or the meaningful inference result of a certain reciprocal layer.
  • the present disclosure does not limit this.
  • the model input data is input into the first neural network model under the source frame and the second neural network model under the target frame, respectively, to obtain output 1 (that is, the above-mentioned first inference result) and output 2 (that is, the above-mentioned first inference result). 2. Reasoning results).
  • the first and second inference results are obtained by using the same model input data to run inferences in the first neural network model and the second neural network model, respectively.
  • the accuracy verification result of the second neural network model under the target framework can be obtained.
  • multiple parameter values of the second inference result can be matched with the corresponding parameter values in the first inference result one by one to obtain the matching result, that is, the aforementioned accuracy verification result can be obtained.
  • the accuracy verification result may indicate a comparison result of the model accuracy of the second neural network model and the first neural network model, such as accuracy alignment or accuracy misalignment, or the accuracy verification result may indicate the second neural network model Whether the accuracy of the model meets expectations or a set standard, for example, the accuracy meets the standard or the accuracy does not meet the standard, etc., the embodiment of the present disclosure does not limit this.
  • the accuracy verification result may be output, or the information of the second neural network model may also be saved, and the embodiments of the present disclosure are not limited thereto.
  • the accuracy verification is performed according to the output 1 of the neural network model under the source frame and the output 2 of the neural network model under the target frame.
  • the inference results obtained by the first neural network model under the source frame and the second neural network model under the target frame respectively on the input data of the same model can be automatically obtained
  • the accuracy verification result of the second neural network model improves the accuracy verification efficiency of the neural network model conversion.
  • FIG. 3 is a schematic diagram of another flow chart of the neural network model conversion method provided by the embodiment of the present disclosure.
  • the method includes the following steps:
  • the model conversion device obtains the first neural network model in the source frame, the model input data, and the information of the target frame.
  • step S101 in the embodiment shown in FIG. 1.
  • step S102 Part of the implementation of this step can refer to step S102 in the embodiment shown in FIG. 1.
  • the above-mentioned model conversion process is carried out in the first process.
  • a new process can be created through the above-mentioned first process, that is, the second process, which is identical to the above-mentioned first process.
  • the resources occupied by the process are different.
  • the neural network model conversion tool and the first neural network model under the source framework are generally developed based on a certain platform, but when the neural network model is converted, it will be based on different The target framework chooses different execution methods. Therefore, the second process created may be a process under the system environment or a process under the platform.
  • the neural network model conversion tool and the source framework can be developed based on the Python platform.
  • the target framework is the Caffe framework
  • Caffe provides the Python interface of pycaffe
  • the neural network model conversion tool and the source framework can be developed based on the Python platform.
  • the os.system of the Python os module can be used to create a new process to execute commands in the system environment. Start the target framework.
  • S204 Invoke the second process through the first process, so that the second process executes the processing of the second neural network model on the input data of the model, and obtains a second inference result.
  • step S205 Determine whether the difference between the first inference result and the second inference result is within a preset error range, if so, proceed to step S206; if not, proceed to S207.
  • S207 Determine that the accuracy verification result of the second neural network model is accuracy misalignment.
  • the accuracy verification result of the second neural network model under the target framework can be obtained. Specifically, if the difference between the first inference result and the second inference result is within a preset error range, it is determined that the accuracy verification result of the second neural network model is accuracy alignment. If the difference between the first inference result and the second inference result exceeds the preset error range, it is determined that the accuracy verification result of the second neural network model is accuracy misalignment.
  • the model conversion device In response to determining that the accuracy verification result of the second neural network model is accuracy misalignment, the model conversion device locates a target network layer in the second neural network model whose accuracy is not aligned.
  • the target network layer is the network layer in which the accuracy is not aligned first among the multiple network layers included in the second neural network model.
  • the target network layer is the first network layer in which the difference between the output data of the corresponding network layer of the first neural network model and the corresponding network layer of the second neural network model exceeds the preset error range.
  • the inference results (also referred to as output data) of any layer are generally not saved.
  • the neural network model conversion tool performs a neural network model conversion and inference again for positioning accuracy problems. That is, the model conversion device performs model conversion processing on the first neural network model again.
  • the output data volume of each layer of the neural network model is relatively large.
  • the output data of each layer of the neural network model is not stored in the memory, but the output data is localized, that is, stored locally. Therefore, in the process of performing the model conversion process again, the output data of each network layer in the first neural network model is saved locally.
  • the source framework Since the neural network model conversion tool is used to convert each network layer of the first neural network model under the source framework into the format of the target framework, the source framework will use the model input data to run the reasoning on the first neural network model. , The information of the network layer in the first neural network model and the connection relationship of the network layer can be obtained. Then, the model conversion device can adaptively configure the network topology of the first neural network model based on the network topology of the first neural network model by using the network structure definition of the target framework and the toolkit to obtain the second neural network model. Therefore, further, in the process of performing the model conversion process again, the mapping relationship between the network layers in the first neural network model and the second neural network model can also be established. The mapping relationship between the network layers of the first neural network model and the second neural network model may be one-to-many, many-to-one, or one-to-one. Accordingly, the target network layer may be one or more network layers.
  • the model conversion device obtains the output data of each network layer in the first neural network model and the second neural network model, and the mapping relationship between the network layers in the first neural network model and the second neural network model, Based on the output data and the mapping relationship of each network layer in the first neural network model and the second neural network model, it can be determined that the target network layer whose accuracy is not aligned first appears in the second neural network model.
  • a serial number is assigned to each network layer in the first neural network model.
  • the sequence number may be in ascending order, so that when positioning accuracy is a problem, each network layer in the first neural network model can be called in turn according to the sequence numbers of multiple network layers in the first neural network model.
  • the reasoning result output by the previous network layer is input to the next network layer for reasoning, and the reasoning result of each network layer is obtained. And, according to the serial number of each network layer, the inference result of each network layer is correspondingly stored locally. And also identify the inference results of each network layer.
  • a network layer may have multiple inputs. Only save the inference results of each layer output, because in addition to the initial input data, the inputs of other layers are the output of the previous layer, so once the initial input of the first neural network model and the output of each layer are recorded, it is equivalent to The input and output of all layers are recorded. As shown in FIG.
  • the neural network model includes multiple network layers: a convolutional layer, an activation function, a normalization layer, an Eltwise layer and Pooling layer, etc. After the initial input data to the first network layer of the neural network model, the output of each network layer is used as the input of the next network layer.
  • the inference result of the neural network model includes initial input data and input/output data 1-10.
  • Each network layer in the first neural network model is individually converted to the target frame to obtain the second neural network model. Input the same model input data to the second neural network model, and then use the input of each layer to run the inference results of each layer of the model in the second neural network model, and save it locally, with the serial number of each network layer when saving Is the index.
  • the reasoning under the target framework also needs to be carried out in a new process.
  • the first neural network model in the source frame can be compared in turn.
  • the inference result and the inference result of the corresponding network layer in the second neural network model under the target framework are located, and the network layer in the second neural network model whose accuracy is not aligned with the first neural network model first, that is, the target network layer is located.
  • the model conversion device outputs the information of the target network layer.
  • the model conversion device can output the information of the target network layer.
  • the information of the target network layer includes the identification, parameters, input data, output results, etc. of the network layer.
  • the administrator or user can analyze the reason for the misalignment of accuracy based on the information of the target network layer.
  • the inference results obtained by the first neural network model under the source frame and the second neural network model under the target frame respectively on the input data of the same model can be automatically obtained
  • the accuracy verification result of the second neural network model improves the accuracy verification efficiency of the neural network model conversion; and the input data of the same model is obtained according to the first neural network model under the source frame and the second neural network model under the target frame.
  • the output data of each network layer can locate the target network layer whose accuracy is not aligned in the second neural network model, and realize the accurate positioning of the network layer when the accuracy is not aligned.
  • the open source neural network model conversion tools do not verify whether the output accuracy of the neural network model before and after the conversion is consistent. The user needs to manually run and save the results under the two frameworks, and then compare them.
  • the accuracy is inconsistent, the user needs to modify the neural network model based on experience, output the results of some layers in the modified neural network model, and locate the network layer that makes the inference results under the two frameworks inconsistent. This method will take a lot of time, and for some relatively large neural network models, it is often very difficult to locate the problem.
  • FIG. 5 is a schematic flowchart of a model accuracy positioning method provided by an embodiment of the present disclosure. The method includes the following steps:
  • the model accuracy positioning device acquires the first neural network model under the source frame, the model input data, and the information of the target frame.
  • the model accuracy positioning device in this embodiment is only the difference in name from the model conversion device and neural network model conversion tool in the foregoing embodiment, and the same function can be realized.
  • the model accuracy positioning device may perform model accuracy positioning based on a user instruction, and the user instruction is used to instruct to locate the accuracy of the second neural network model.
  • the aligned target network layer, the user instruction includes the first neural network model under the source frame, model input data, and information about the target frame. For example, when the user obtains the result that the accuracy of the second neural network model and the first neural network model are not aligned, the user instruction is sent to the model accuracy positioning device.
  • the model accuracy positioning device can also perform model accuracy positioning based on internal operating instructions, such as model accuracy positioning instructions. For example, when the model accuracy positioning device acquires an instruction that the accuracy of the second neural network model and the first neural network model are not aligned, it triggers the model accuracy positioning instruction.
  • the internal operation instruction is used to instruct the positioning of the target network layer whose accuracy is not aligned in the second neural network model, and the internal operation instruction includes the first neural network model under the source framework, model input data, and information about the target framework.
  • the model accuracy positioning device performs model conversion processing on the first neural network model to obtain a second neural network model under the target framework.
  • step S102 in the embodiment shown in FIG. 1 or step S202 in the embodiment shown in FIG. 3.
  • the model accuracy positioning device processes the output data of each network layer of the model input data respectively based on the first neural network model and the second neural network model, and locates the target network layer whose accuracy is not aligned in the second neural network model.
  • the model accuracy positioning device runs the inference process of the first neural network model on the model input data, and can obtain each of the processing of the model input data by the first neural network model.
  • the output data of the network layer can be stored or recorded locally.
  • the model accuracy positioning device can also re-input the model input data to the first neural network model, run the inference process of the first neural network model on the model input data, and obtain the first neural network model to perform the model input data The output data of each network layer processed.
  • the model accuracy positioning device may pre-store the output data of each network layer obtained by the first neural network model inferring the model input data.
  • the above model input data can be input to the second neural network model, and the model input data can be used to run inferences on each network layer of the second neural network model.
  • the inference result output by one network layer can be used as the input data of the next network layer to obtain the output data of each network layer in the second neural network model.
  • the first and second inference results are obtained by using the same model input data to run inferences in the first neural network model and the second neural network model, respectively.
  • the accuracy verification result of the second neural network model under the target framework can be obtained.
  • multiple parameter values in the second inference result can be matched with the corresponding parameter values in the first inference result one by one to obtain a matching result, that is, the aforementioned accuracy verification result can be obtained.
  • the accuracy verification result may indicate a comparison result of the model accuracy of the second neural network model and the first neural network model, such as accuracy alignment or accuracy misalignment, or the accuracy verification result may indicate the second neural network model Whether the accuracy of the model meets expectations or a set standard, for example, the accuracy meets the standard or the accuracy does not meet the standard, etc., the embodiment of the present disclosure does not limit this.
  • the output results of each network layer of the first neural network model and the output results of each network layer of the second neural network model are obtained, the output results of each network layer of the first neural network model and the second neural network model
  • the output result of each network layer of the network model is obtained by using the same model input data to run inferences in the first neural network model and the second neural network model. Therefore, according to the first neural network model of each network layer
  • the output result and the output result of each network layer of the second neural network model can locate the target network layer whose accuracy is not aligned in the second neural network model.
  • the target network layer is the network layer in which the accuracy is not aligned first among the multiple network layers included in the second neural network model. Specifically, if the difference between the output data of the network layer included in the second neural network model and the corresponding network layer of the first neural network model exceeds the preset error range, the network layer is determined to be a network layer with unaligned accuracy.
  • the target network layer is a plurality of network layers with misaligned accuracy in the second neural network model.
  • it includes not only the network layer where the accuracy misalignment occurs first, but also the subsequent network layers of the network layer.
  • the number of subsequent network layers can be preset.
  • the model accuracy positioning device outputs the information of the target network layer.
  • the model accuracy positioning device can output the information of the target network layer.
  • the information of the target network layer includes the identification, parameters, output data of the target network layer, and the error between the output data and the output data of the network layer corresponding to the target network layer in the first neural network model.
  • the administrator or user can analyze the reason for the misalignment of accuracy based on the information of the target network layer.
  • the output data of each network layer obtained from the input data of the same model according to the first neural network model under the source framework and the second neural network model under the target framework respectively,
  • the target network layer whose accuracy is not aligned in the second neural network model can be located, and the accurate positioning of the target network layer when the accuracy is not aligned is realized.
  • FIG. 6 is a schematic diagram of another flow chart of the model accuracy positioning method provided by an embodiment of the present disclosure.
  • the method includes the following steps:
  • the model accuracy positioning device acquires the first neural network model under the source frame, the model input data, and the information of the target frame.
  • the model accuracy positioning device establishes a network topology map through the processing of the input data of the model by the first neural network model, where the network topology map includes the information of the network layers in the first neural network model and the connection relationship of the network layers.
  • the model accuracy positioning device establishes a network topology diagram through the processing of the input data of the model by the first neural network model, wherein the network topology diagram includes the information of the network layer in the first neural network model and the connection relationship of the network layers.
  • the source framework will use the model input data to run the inference on the first neural network model.
  • the information of the network layer in the first neural network model and the connection relationship of the network layer can be obtained.
  • the information of the network layer in the first neural network model and the connection relationship of the network layers constitute the network topology diagram of the first neural network model.
  • the model accuracy positioning device obtains the second neural network model based on the network topology map and the information of the target frame, and records the output data of each network layer in the process of processing the input data of the model by the first neural network model, and performs conversion processing based on the model Establish the mapping relationship between the network layers in the first neural network model and the second neural network model.
  • the target framework After the model accuracy positioning device obtains the network topology diagram of the first neural network, the target framework has its own network structure definition and toolkit.
  • the model accuracy positioning device can be based on the network topology diagram of the first neural network and use the network structure definition of the target framework
  • the toolkit adaptively configures the network topology of the first neural network to obtain the second neural network model.
  • the source framework Since the neural network model conversion tool is used to convert each network layer of the first neural network model under the source framework into the format of the target framework, the source framework will use the model input data to run the reasoning on the first neural network model. , The information of the network layer in the first neural network model and the connection relationship of the network layer can be obtained. Then, the model accuracy positioning device can be based on the network topology of the first neural network, using the network structure definition of the target framework and the toolkit to adaptively configure the network topology of the first neural network to obtain the second neural network model. Therefore, further, in the process of model conversion processing, the mapping relationship between the network layers in the first neural network model and the second neural network model can also be established. The mapping relationship between the network layers of the first neural network model and the second neural network model may be one-to-many, many-to-one, or one-to-one. Accordingly, the target network layer may be one or more network layers.
  • the model accuracy positioning device processes the model input data through the second neural network model to obtain output data of each network layer in the second neural network model.
  • step S103 in the embodiment shown in FIG. 1 or step S203 in the embodiment shown in FIG. 3.
  • the difference is that in this embodiment, the output data of each network layer of the second neural network model is recorded, while in the embodiment shown in FIG. 1 or 3, the output data of the second neural network model is recorded.
  • the final inference result is the output data of the last network layer of the second neural network model.
  • the model accuracy positioning device determines a target network layer whose accuracy is not aligned in the second neural network model based on the output data and the mapping relationship of each network layer in the first neural network model and the second neural network model.
  • the model accuracy positioning device obtains the output data of each network layer in the first neural network model and the second neural network model, and the mapping relationship between the network layers in the first neural network model and the second neural network model, Based on the output data and the mapping relationship of each network layer in the first neural network model and the second neural network model, it can be determined that the target network layer whose accuracy is not aligned first appears in the second neural network model.
  • a serial number is assigned to each network layer in the first neural network model.
  • the sequence number may be in ascending order, so that when positioning accuracy is a problem, each network layer in the first neural network model can be called in turn according to the sequence numbers of multiple network layers in the first neural network model.
  • the reasoning result output by the previous network layer is input to the next network layer for reasoning, and the reasoning result of each network layer is obtained. And, according to the serial number of each network layer, the inference result of each network layer is correspondingly stored locally. And also identify the inference results of each network layer.
  • a network layer may have multiple inputs. Only save the inference results of each layer output, because in addition to the initial input data, the inputs of other layers are the output of the previous layer, so once the initial input of the first neural network model and the output of each layer are recorded, it is equivalent to The input and output of all layers are recorded.
  • the neural network model includes multiple network layers: convolutional layer, activation function, normalization layer, Eltwise Layer and pooling layer, etc. After the initial input data to the first network layer of the neural network model, the output of each network layer is used as the input of the next network layer.
  • the inference result of the neural network model includes initial input data and input/output data 1-10.
  • Each network layer in the first neural network model is individually converted to the target frame to obtain the second neural network model. Input the same model input data to the second neural network model, and then use the input of each layer to run the inference results of each layer of the model in the second neural network model, and save it locally, with the serial number of each network layer when saving Is the index.
  • the reasoning under the target framework also needs to be carried out in a new process.
  • the first neural network model in the source frame can be compared in turn.
  • the inference result and the inference result of the corresponding network layer in the second neural network model under the target framework are located, and the network layer in the second neural network model whose accuracy is not aligned with the first neural network model first, that is, the target network layer is located.
  • the model accuracy positioning device outputs the information of the target network layer.
  • the output data of each network layer obtained from the input data of the same model according to the first neural network model under the source framework and the second neural network model under the target framework respectively,
  • the target network layer whose accuracy is not aligned in the second neural network model can be located, and the accurate positioning of the network layer when the accuracy is not aligned is realized.
  • an embodiment of the present disclosure further provides a model conversion device, and the device 1000 includes:
  • the obtaining unit 11 is used to obtain the first neural network model under the source frame, the model input data, and the information of the target frame;
  • the conversion unit 12 is configured to perform model conversion processing on the first neural network model in the source framework to obtain the second neural network model in the target framework;
  • the verification unit 13 is configured to obtain the second neural network based on the first inference result and the second inference result obtained by separately processing the model input data based on the first neural network model and the second neural network model The accuracy of the model is verified.
  • the conversion unit 12 is configured to perform a model conversion process on the first neural network model under the source framework through a first process to obtain the second neural network model under the target framework;
  • the device also includes:
  • the creating unit 14 is configured to create a second process through the first process
  • the inference unit 15 is configured to invoke the second process through the first process, so that the second process executes the processing of the second neural network model on the input data of the model to obtain a second inference result.
  • the verification unit 13 is configured to determine the accuracy verification result of the second neural network model if the difference between the first inference result and the second inference result is within a preset error range For precision alignment; or
  • the verification unit 13 is further configured to determine that the accuracy verification result of the second neural network model is that the accuracy of the second neural network model is misaligned if the difference between the first inference result and the second inference result exceeds the preset error range .
  • the device further includes:
  • the positioning unit 16 is configured to locate a target network layer whose accuracy is not aligned in the second neural network model in response to determining that the accuracy verification result of the second neural network model is accuracy misalignment;
  • the output unit 17 is configured to output the information of the target network layer.
  • the positioning unit 16 includes:
  • the establishment unit 161 is configured to establish a mapping relationship between the network layers in the first neural network model and the second neural network model;
  • the determining unit 162 is configured to determine the second neural network model and the second neural network model based on the output data of each network layer in the process of processing the input data of the model and the mapping relationship.
  • the target network layer whose accuracy is not aligned in the neural network model.
  • model conversion device performs model conversion processing on the first neural network model again, wherein, in the process of performing the model conversion processing again, the first neural network model is acquired Output data of each network layer, and/or establish a mapping relationship between the network layers in the first neural network model and the second neural network model.
  • the conversion unit 12 is configured to process the input data of the model through the first neural network model to establish a network topology diagram, wherein the network topology diagram includes the first neural network model The information of the network layer in and the connection relationship of the network layer; and the second neural network model is obtained based on the network topology diagram and the information of the target framework.
  • the second neural network model can be automatically obtained according to the inference results obtained by the first neural network model under the source framework and the second neural network model under the target framework on the input data of the same model.
  • the accuracy verification result of the network model improves the accuracy verification efficiency of the neural network model conversion.
  • an embodiment of the present disclosure further provides a model accuracy positioning device, and the device 2000 includes:
  • the obtaining unit 21 is configured to obtain the first neural network model under the source frame, the model input data, and the information of the target frame;
  • the conversion unit 22 is configured to perform model conversion processing on the first neural network model to obtain a second neural network model under the target framework;
  • the positioning unit 23 is configured to locate the output data of each network layer in the process of separately processing the input data of the model based on the first neural network model and the second neural network model, and locate the accuracy in the second neural network model Unaligned target network layer;
  • the output unit 24 is configured to output the information of the target network layer.
  • the information of the target network layer includes at least one of the following: the identification, parameters, output data of the target network layer, and the output data and the first neural network model and the target network The error between the output data of the network layer corresponding to the layer.
  • the device further includes:
  • the first establishing unit 25 is configured to establish a mapping relationship between the network layers in the first neural network model and the second neural network model based on the model conversion processing;
  • the positioning unit 23 is configured to determine that the accuracy of the second neural network model is not aligned based on the output data of each network layer in the first neural network model and the second neural network model and the mapping relationship The target network layer.
  • the positioning unit 23 includes:
  • the calling unit 231 is configured to sequentially compare output data of corresponding network layers in the first neural network model and the second neural network model based on the mapping relationship;
  • the determining unit 232 is configured to respond to the difference between the output data of the corresponding network layer in the first neural network model and the second neural network model exceeding a preset error range, and classify the corresponding network layer as belonging to the The network layer in the second neural network model is determined as the target network layer.
  • the conversion unit 22 includes:
  • the second establishing unit 221 is used to process the input data of the model through the first neural network model to establish a network topology diagram, wherein the network topology diagram includes the network layer in the first neural network model The connection between information and network layers;
  • the second obtaining unit 222 is configured to obtain the second neural network model based on the network topology map and the information of the target frame.
  • the output data of each network layer obtained from the input data of the same model according to the first neural network model under the source framework and the second neural network model under the target framework,
  • the target network layer whose accuracy is not aligned in the second neural network model can be located, and the accurate positioning of the network layer when the accuracy is not aligned is realized.
  • FIG. 9 a schematic diagram of the hardware structure of an electronic device is also provided, and the electronic device is used to execute the above-mentioned neural network model conversion method/model accuracy positioning method.
  • Part or all of the above methods can be implemented by hardware, and can also be implemented by software or firmware.
  • the electronic device may be a chip or an integrated circuit during specific implementation.
  • the neural network model conversion method/model accuracy positioning method of the foregoing embodiment when part or all of the neural network model conversion method/model accuracy positioning method of the foregoing embodiment is implemented by software or firmware, it may be implemented by an electronic device 3000 provided in FIG. 9. As shown in FIG. 9, the electronic device 3000 may include:
  • the memory 33 and the processor 34 may be one or more, and one processor is taken as an example in FIG. 9
  • the processor 34 may also include an input device 31 and an output device 32.
  • the input device 31, the output device 32, the memory 33, and the processor 34 may be connected by a bus or other means, wherein the connection by a bus is taken as an example in FIG. 9.
  • the processor 34 is used to execute the method steps executed in FIG. 1, FIG. 3, FIG. 5, and FIG. 6.
  • the program of the above-mentioned neural network model conversion method/model accuracy positioning method may be stored in the memory 33.
  • the memory 33 may be a physically independent unit, or may be integrated with the processor 34.
  • the memory 33 can also be used to store data.
  • the electronic device may also only include a processor.
  • the memory used to store the program is located outside the electronic device, and the processor is connected to the memory through a circuit or wire for reading and executing the program stored in the memory.
  • the processor may be a central processing unit (CPU), a network processor (NP), or a WLAN (Wireless Local Area Network) device.
  • CPU central processing unit
  • NP network processor
  • WLAN Wireless Local Area Network
  • the processor may further include a hardware chip.
  • the above-mentioned hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD) or a combination thereof.
  • the above-mentioned PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.
  • the memory may include volatile memory (volatile memory), such as random-access memory (RAM); the memory may also include non-volatile memory (non-volatile memory), such as flash memory (flash memory) , A hard disk drive (HDD) or a solid-state drive (solid-state drive, SSD); the memory may also include a combination of the foregoing types of memory.
  • volatile memory such as random-access memory (RAM)
  • non-volatile memory such as flash memory (flash memory)
  • flash memory flash memory
  • HDD hard disk drive
  • solid-state drive solid-state drive
  • one or more embodiments of the present disclosure may be provided as a method, a system, or a computer program product. Therefore, one or more embodiments of the present disclosure may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, one or more embodiments of the present disclosure may adopt computer programs implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes. The form of the product.
  • computer-usable storage media including but not limited to disk storage, CD-ROM, optical storage, etc.
  • the embodiments of the present disclosure also provide a computer-readable storage medium, and the storage medium may store a computer program.
  • the program When the program is executed by a processor, the steps of the neural network model conversion method described in any of the embodiments of the present disclosure are realized. And/or, implement the steps of the model accuracy positioning method described in any embodiment of the present disclosure.
  • the embodiments of the subject and functional operations described in the present disclosure can be implemented in the following: digital electronic circuits, tangible computer software or firmware, computer hardware including the structures disclosed in the present disclosure and structural equivalents thereof, or among them A combination of one or more.
  • the embodiments of the subject matter described in the present disclosure may be implemented as one or more computer programs, that is, one or one of the computer program instructions encoded on a tangible non-transitory program carrier to be executed by a data processing device or instruct the operation of the data processing device Multiple modules.
  • the program instructions may be encoded on artificially generated propagated signals, such as machine-generated electrical, optical or electromagnetic signals, which are generated to encode information and transmit it to a suitable receiver device for data transmission.
  • the processing device executes.
  • the computer storage medium may be a machine-readable storage device, a machine-readable storage substrate, a random or serial access memory device, or a combination of one or more of them.
  • the processing and logic flow described in the present disclosure can be executed by one or more programmable computers executing one or more computer programs to perform corresponding functions by operating according to input data and generating output.
  • the processing and logic flow can also be executed by a dedicated logic circuit, such as a field programmable gate array (FPGA) or an application specific integrated circuit (ASIC), and the device can also be implemented as a dedicated logic circuit.
  • FPGA field programmable gate array
  • ASIC application specific integrated circuit
  • Computers suitable for executing computer programs include, for example, general-purpose and/or special-purpose microprocessors, or any other type of central processing unit.
  • the central processing unit will receive instructions and data from a read-only memory and/or a random access memory.
  • the basic components of a computer include a central processing unit for implementing or executing instructions and one or more memory devices for storing instructions and data.
  • the computer will also include one or more mass storage devices for storing data, such as magnetic disks, magneto-optical disks, or optical disks, or the computer will be operatively coupled to this mass storage device to receive data from or send data to it. It transmits data, or both.
  • the computer does not have to have such equipment.
  • the computer can be embedded in another device, such as a mobile phone, a personal digital assistant (PDA), a mobile audio or video player, a game console, a global positioning system (GPS) receiver, or, for example, a universal serial bus (USB ) Flash drives are portable storage devices, just to name a few.
  • PDA personal digital assistant
  • GPS global positioning system
  • USB universal serial bus
  • Computer-readable media suitable for storing computer program instructions and data include all forms of non-volatile memory, media, and memory devices, including, for example, semiconductor memory devices (such as EPROM, EEPROM, and flash memory devices), magnetic disks (such as internal hard disks or Removable disks), magneto-optical disks, CD ROM and DVD-ROM disks.
  • semiconductor memory devices such as EPROM, EEPROM, and flash memory devices
  • magnetic disks such as internal hard disks or Removable disks
  • magneto-optical disks CD ROM and DVD-ROM disks.
  • the processor and the memory can be supplemented by or incorporated into a dedicated logic circuit.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Health & Medical Sciences (AREA)
  • Computing Systems (AREA)
  • Biomedical Technology (AREA)
  • Biophysics (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Evolutionary Computation (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Molecular Biology (AREA)
  • Artificial Intelligence (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Health & Medical Sciences (AREA)
  • Image Analysis (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)
  • Navigation (AREA)

Abstract

一种神经网络模型的转换方法、模型精度定位方法及装置。在神经网络模型的转换的方案中,模型转换装置根据源框架下的第一神经网络模型和目标框架下的第二神经网络模型对同一模型输入数据分别得到的推理结果,可以自动得到第二神经网络模型的精度验证结果,提高了神经网络模型转换的精度验证效率。在模型精度定位的方案中,模型精度定位装置根据源框架下的第一神经网络模型和目标框架下的第二神经网络模型对同一模型输入数据分别得到的每个网络层的输出数据,可以定位第二神经网络模型中精度未对齐的目标网络层,实现了精度未对齐时的网络层的准确定位。

Description

神经网络模型的转换方法、模型精度定位方法及装置
相关申请的交叉引用
本申请要求在2020年2月28日提交中国专利局、申请号为202010129010.0的中国专利申请的优先权,其全部内容通过引用结合在本公开中。
技术领域
本公开涉及人工智能(artificial intelligence,AI)技术领域,尤其涉及一种神经网络模型的转换方法、模型精度定位方法及装置。
背景技术
目前业界开发了各种各样的深度学习模型框架,每个框架具备自己的网络结构定义和工具包。由于不同的框架在训练、部署、平台兼容性等方面上有各自的优势,因此经常需要对深度学习模型进行框架之间的转换。神经网络模型的转换是指把在某个框架下定义的神经网络模型转换到另一个框架下。
然而,在神经网络模型转换后,需要通过程序员手动来验证模型精度,精度验证效率低下。
发明内容
本公开提供了一种神经网络模型的转换技术方案。
第一方面,提供了一种神经网络模型的转换方法,所述方法包括:模型转换装置获取源框架下的第一神经网络模型、模型输入数据以及目标框架的信息;模型转换装置基于所述模型输入数据对所述源框架下的第一神经网络模型进行模型转换处理,得到所述目标框架下的第二神经网络模型;模型转换装置基于所述第一神经网络模型和所述第二神经网络模型分别对所述模型输入数据进行处理得到的第一推理结果和第二推理结果,得到所述第二神经网络模型的精度验证结果。
模型转换装置可以基于用户指令进行模型转换处理,该用户指令用于指示将源框架下的第一神经网络模型转换到目标框架下,该用户指令包括源框架下的第一神经网络模型、模型输入数据以及目标框架的信息。模型转换装置也可以基于内部的操作指令进行模型转换处理,例如模型转换指令,该内部的操作指令用于指示将源框架下的第一神经网络模型转换到目标框架下,该内部的操作指令包括源框架下的第一神经网络模型、模型输入数据以及目标框架的信息。
在一种可能的实现中,模型转换装置在对第一神经网络模型进行模型转换处理的过程中得到所述第一神经网络模型对所述模型输入数据的第一推理结果。
在一种可能的实现中,模型转换装置在本地存储所述第一推理结果。
在一种可能的实现中,模型转换装置通过所述第二神经网络模型对所述模型输入数据进行处理,得到第二推理结果。
在一种可能的实现中,模型转换装置通过比较第一推理结果和第二推理结果,得到第二神经网络模型的精度验证结果。
在一种可能的实现中,所述对所述源框架下的第一神经网络模型进行模型转换处理,得到所述目标框架下的第二神经网络模型,包括:通过第一进程对所述源框架下的第一神经网络模型进行模型转换处理,得到所述目标框架下的第二神经网络模型;所述方法还包括:通过所述第一进程创建第二进程;通过所述第一进程调用所述第二进程,以在所述第二进程中通过所述第二神经网络模型对所述模型输入数据进行处理,得到第二推理结果。
在一种可能的实现中,所述模型转换装置基于所述第一神经网络模型和所述第二神经网络模型分别对所述模型输入数据进行处理得到的第一推理结果和第二推理结果,得到所述第二神经网络模型的精度验证结果,包括:若所述第一推理结果与所述第二推理结果之间的差别处于预设误差范围内,确定所述第二神经网络模型的精度验证结果为精度对齐;或若所述第一推理结果与所述第二推 理结果之间的差别超出所述预设误差范围,确定所述第二神经网络模型的精度验证结果为精度未对齐。
在一种可能的实现中,所述方法还包括:响应于确定所述第二神经网络模型的精度验证结果为精度未对齐,所述模型转换装置定位所述第二神经网络模型中精度未对齐的目标网络层;所述模型转换装置输出所述目标网络层的信息。
在一种可能的实现中,所述定位所述第二神经网络模型中精度未对齐的目标网络层,包括:所述模型转换装置建立所述第一神经网络模型和所述第二神经网络模型中的网络层之间的映射关系;所述模型转换装置基于所述第一神经网络模型和所述第二神经网络模型分别处理所述模型输入数据的过程中每个网络层的输出数据以及所述映射关系,确定所述第二神经网络模型中精度未对齐的目标网络层。
在一种可能的实现中,所述目标网络层为第二神经网络模型包括的多个网络层中最先出现精度未对齐的网络层。
在另一种可能的实现中,所述目标网络层为所述第二神经网络模型中出现精度未对齐的多个网络层。例如不仅包括最先出现精度未对齐的网络层,还包括所述网络层的后续网络层。
在一种可能的实现中,所述目标网络层的信息,包括下列中的至少一项:所述目标网络层的标识、参数、输出数据、该输出数据与第一神经网络模型中与所述目标网络层对应的网络层的输出数据之间的误差。
在一种可能的实现中,所述模型转换装置对所述第一神经网络模型再次进行模型转换处理,其中,在所述再次进行模型转换处理的过程中,获取所述第一神经网络模型中的每个网络层的输出数据,和/或建立所述第一神经网络模型和所述第二神经网络模型中的网络层之间的映射关系。
在一种可能的实现中,所述模型转换装置对所述源框架下的第一神经网络模型进行模型转换处理,得到所述目标框架下的第二神经网络模型,包括:所述模型转换装置通过所述第一神经网络模型对所述模型输入数据的处理,建立网络拓扑图,其中,所述网络拓扑图包括所述第一神经网络模型中的网络层的信息以及网络层的连接关系;所述模型转换装置基于所述网络拓扑图以及所述目标框架的信息,得到所述第二神经网络模型。
第二方面,提供了一种模型转换装置,所述装置包括:获取单元,用于获取源框架下的第一神经网络模型、模型输入数据以及目标框架的信息;转换单元,用于对所述源框架下的第一神经网络模型进行模型转换处理,得到所述目标框架下的第二神经网络模型;验证单元,用于基于所述第一神经网络模型和所述第二神经网络模型分别对所述模型输入数据进行处理得到的第一推理结果和第二推理结果,得到所述第二神经网络模型的精度验证结果。
第三方面,提供了一种电子设备,包括存储器和处理器,其中,所述存储器中存储程序指令,且所述处理器用于调用所述存储器中存储的程序指令,执行第一方面或第一方面的任一个实现所述的方法。
第四方面,提供了一种计算机可读存储介质,所述计算机可读存储介质中存储有指令,当其在计算机上运行时,使得计算机执行上述第一方面或第一方面的任一个实现所述的方法。
第五方面,提供了一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行上述第一方面或第一方面的任一个实现所述的方法。
采用本公开的神经网络模型的转换方案,具有如下技术效果:
根据源框架下的第一神经网络模型和目标框架下的第二神经网络模型对同一模型输入数据分别得到的推理结果,可以自动得到第二神经网络模型的精度验证结果,提高了神经网络模型转换的精度验证效率。
本申请实施例还提供一种模型精度定位方案。
第六方面,提供了一种模型精度定位方法,包括:模型精度定位装置获取源框架下的第一神经网络模型、模型输入数据以及目标框架的信息;所述模型精度定位装置对所述第一神经网络模型进行模型转换处理,得到所述目标框架下的第二神经网络模型;所述模型精度定位装置基于所述第一神经网络模型和所述第二神经网络模型对所述模型输入数据进行处理的过程中得到的每个网络层的 输出数据,定位所述第二神经网络模型中精度未对齐的目标网络层;所述模型精度定位装置输出所述目标网络层的信息。
在已知第二神经网络模型与第一神经网络模型的精度未对齐的情况下,模型精度定位装置可以基于用户指令进行模型精度定位,该用户指令用于指示定位第二神经网络模型中精度未对齐的目标网络层,该用户指令包括源框架下的第一神经网络模型、模型输入数据以及目标框架的信息。例如,用户在获取到第二神经网络模型与第一神经网络模型的精度未对齐的结果时,则向模型精度定位装置发送该用户指令。模型精度定位装置也可以基于内部的操作指令进行模型精度定位,例如模型精度定位指令。例如,模型精度定位装置在获取到第二神经网络模型与第一神经网络模型的精度未对齐的指令时,则触发模型精度定位指令。该内部的操作指令用于指示定位第二神经网络模型中精度未对齐的目标网络层,该内部的操作指令包括源框架下的第一神经网络模型、模型输入数据以及目标框架的信息。在一种可能的实现方式中,通过所述第二神经网络模型对所述模型输入数据进行处理,得到所述第二神经网络模型中每个网络层的输出数据。
在一种可能的实现方式中,在所述模型转换处理的过程中得到所述第一神经网络模型对所述模型输入数据进行处理的每个网络层的输出数据。
在一种可能的实现中,所述目标网络层为第二神经网络模型包括的多个网络层中最先出现精度未对齐的网络层。
在另一种可能的实现中,所述目标网络层为所述第二神经网络模型中出现精度未对齐的多个网络层。例如不仅包括最先出现精度未对齐的网络层,还包括所述网络层的后续网络层。
在一种可能的实现中,可以通过比较第一神经网络模型和第二神经网络模型中各个网络层的输出数据,确定目标网络层。
在一种可能的实现方式中,若所述第二神经网络模型包括的网络层与所述第一神经网络模型的对应网络层的输出数据之间的差别超过预设误差范围,则认定该网络层为精度未对齐的网络层。
在一种可能的实现中,所述目标网络层的信息,包括下列中的至少一项:所述目标网络层的标识、参数、输出数据、该输出数据与第一神经网络模型中与所述目标网络层对应的网络层的输出数据之间的误差。
在一种可能的实现中,所述方法还包括:所述模型精度定位装置基于所述模型转换处理,建立所述第一神经网络模型和所述第二神经网络模型中的网络层之间的映射关系;所述模型精度定位装置基于所述第一神经网络模型和所述第二神经网络模型对所述模型输入数据进行处理得到的每个网络层的输出数据,定位所述第二神经网络模型中精度未对齐的目标网络层,包括:所述模型精度定位装置基于所述第一神经网络模型和所述第二神经网络模型中每个网络层的输出数据以及所述映射关系,确定所述第二神经网络模型中精度未对齐的目标网络层。
在一种可能的实现中,所述模型精度定位装置基于所述第一神经网络模型和所述第二神经网络模型中每个网络层的输出数据以及所述映射关系,确定所述第二神经网络模型中精度未对齐的目标网络层,包括:所述模型精度定位装置基于所述映射关系依次比较所述第一神经网络模型和所述第二神经网络模型中对应网络层的输出数据;响应于所述第一神经网络模型和所述第二神经网络模型中对应网络层的输出数据之间的差别超出预设误差范围,将所述对应网络层中属于所述第二神经网络模型中的网络层确定为所述目标网络层。
在一种可能的实现中,所述模型精度定位装置对所述源框架下的第一神经网络模型进行模型转换处理,得到所述目标框架下的第二神经网络模型,包括:所述模型精度定位装置通过所述第一神经网络模型对所述模型输入数据的处理,建立网络拓扑图,其中,所述网络拓扑图包括所述第一神经网络模型中的网络层的信息以及网络层的连接关系;所述模型精度定位装置基于所述网络拓扑图以及所述目标框架的信息,得到所述第二神经网络模型。
第七方面,提供了一种模型精度定位装置,包括:获取单元,用于获取源框架下的第一神经网络模型、模型输入数据以及目标框架的信息;转换单元,用于对所述第一神经网络模型进行模型转换处理,得到所述目标框架下的第二神经网络模型;定位单元,用于基于所述第一神经网络模型和所述第二神经网络模型分别处理所述模型输入数据的过程中每个网络层的输出数据,定位所述第二神经网络模型中精度未对齐的目标网络层;输出单元,用于输出所述目标网络层的信息。
第八方面,提供了一种电子设备,包括存储器和处理器,其中,所述存储器中存储程序指令, 且所述处理器用于调用所述存储器中存储的程序指令执行第六方面或第六方面的任一个实现所述的方法。
第九方面,提供了一种计算机可读存储介质,所述计算机可读存储介质中存储有指令,当其在计算机上运行时,使得计算机执行上述第六方面或第六方面的任一个实现所述的方法。
第十方面,提供了一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行上述第六方面或第六方面的任一个实现所述的方法。
采用本公开的模型精度定位方案,具有如下技术效果:
根据源框架下的第一神经网络模型和目标框架下的第二神经网络模型对同一模型输入数据分别得到的每个网络层的输出数据,可以定位第二神经网络模型中精度未对齐的目标网络层,实现了精度未对齐时的网络层的准确定位。
附图说明
图1为本公开实施例提供的神经网络模型的转换方法的流程示意图;
图2为本公开实施例提供的神经网络模型的转换过程的示意图;
图3为本公开实施例提供的神经网络模型的转换方法的又一流程示意图;
图4为本公开实施例提供的目标网络层定位过程中得到的网络拓扑示意图;
图5为本公开实施例提供的模型精度定位方法的流程示意图;
图6为本公开实施例提供的模型精度定位方法的又一流程示意图;
图7为本公开实施例提供的模型转换装置的结构示意图;
图8为本公开实施例提供的模型精度定位装置的结构示意图;
图9为本公开实施例提供的电子设备的硬件结构示意图。
具体实施方式
下面将结合本公开实施例中的附图,对本公开实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本公开一部分实施例,而不是全部的实施例。基于本公开中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本公开保护的范围。
应理解,本公开中术语“和/或”,仅仅是一种描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。另外,本文中字符“/”,一般表示前后关联对象是一种“或”的关系。本公开中的术语“第一”、“第二”等是用于区别不同对象,而不是用于描述特定顺序。
请参阅图1,为本公开实施例提供的神经网络模型的转换方法的流程示意图,该方法包括以下步骤:
S101、模型转换装置获取源框架下的第一神经网络模型、模型输入数据以及目标框架的信息。
由于不同的框架在训练、部署、平台兼容性等方面上有各自的优势,因此可以对神经网络模型进行框架之间的转换。每个框架具备自己的网络结构定义和工具包。神经网络模型的转换是指把在某个框架下定义的神经网络模型转换到另一个框架下,例如,将tensorflow框架下的神经网络模型转换到pytorch框架下,或者,将自定义框架下的神经网络模型转换到pytorch或者tensorflow等较为通用的框架或者反之,等等。神经网络模型转换之前对应的框架称为“源框架”,神经网络模型转换之后对应的框架称为“目标框架”,本公开实施例对源框架和目标框架的具体实现不做限定。
模型转换装置可以基于用户指令进行模型转换处理,该用户指令用于指示将源框架下的第一神经网络模型转换到目标框架下,该用户指令包括源框架下的第一神经网络模型、模型输入数据以及目标框架的信息。模型转换装置也可以基于内部的操作指令进行模型转换处理,例如模型转换指令,该内部的操作指令用于指示将源框架下的第一神经网络模型转换到目标框架下,该内部的操作指令 包括源框架下的第一神经网络模型、模型输入数据以及目标框架的信息。其中,第一神经网络模型是一种通用的神经网络模型,可以是任意功能的神经网络模型。该第一神经网络模型包括一个或多个网络层,例如卷积层、池化层、全连接层、归一化层等。该源框架下的第一神经网络模型,包括源框架下的第一神经网络模型中每一个网络层的结构描述文件等,该结构描述文件用于描述网络层的名称、层的索引等。该模型输入数据,是指用于神经网络模型推理的模型输入数据,或者可以称为测试数据。该模型输入数据可以是一个图片、一段文字等。该目标框架的信息包括目标框架的标识、格式、工具包等。
S102、模型转换装置对源框架下的第一神经网络模型进行模型转换处理,得到目标框架下的第二神经网络模型。
要获得目标框架下的第二神经网络模型,需对源框架下的第一神经网络模型进行模型转换处理,即将第一神经网络模型转换到目标框架下。如图2所示,为本公开实施例提供的神经网络模型的转换过程的示意图,可以采用模型转换装置(也被称为神经网络模型转换工具)进行神经网络模型的框架转换。利用神经网络模型转换工具把源框架下的第一神经网络模型的各个网络层分别转换成目标框架的格式,得到目标框架下的第二神经网络模型的各个网络层,从而得到目标框架下的第二神经网络模型,其中,第一神经网络模型的一个网络层可能会转换成第二神经网络模型的一个或多个网络层,第二神经网络模型的一个网络层可能对应第一神经网络模型的一个或多个网络层,本公开实施例对此不做限定。
在一些实施例中,模型转换装置在对第一神经网络模型进行上述模型转换处理的过程中,运行第一神经网络模型对模型输入数据的推理过程,可以得到第一推理结果,例如图2所示的输出1。可选地,可以将该推理结果作为第一推理结果在本地进行存储或记录。该第一推理结果可以用于第二神经网络模型的精度的验证。即在模型转换过程中,即可得到第一神经网络模型对模型输入数据的推理结果,而无需重新运行一遍推理过程。从而提高了精度验证的效率。
在另外一些实施例中,模型转换装置也可以重新输入模型输入数据到第一神经网络模型,运行第一神经网络模型对模型输入数据的推理过程,得到第一推理结果。
在另外一些实施例中,模型转换装置可能预先存储了第一神经网络模型对模型输入数据的第一推理结果。
模型转换装置对源框架下的第一神经网络模型进行模型转换处理,得到目标框架下的第二神经网络模型。具体地,首先,模型转换装置对第一神经网络模型进行模型解析处理,得到第一神经网络模型的网络拓扑图,其中,可选地,该模型解析处理可以通过第一神经网络模型对模型输入数据的推理或者其他方式得到,该网络拓扑图也可以称为计算图,可以包括第一神经网络模型中的各个网络层以及各个网络层的连接关系,例如如图4所示的网络拓扑结构,其中,该网络拓扑图可以不包含每个网络层的输出,有利于提高模型转换效率。
然后,模型转换装置基于网络拓扑图以及目标框架的信息,得到第二神经网络模型。模型转换装置在获得第一神经网络的网络拓扑图后,目标框架具备自己的网络结构定义和工具包,模型转换装置可以基于第一神经网络的网络拓扑图,利用目标框架的网络结构定义和/或工具包对该第一神经网络的网络拓扑图进行适应性网络构建,得到第二神经网络模型。
S103、模型转换装置基于第一神经网络模型和第二神经网络模型分别对模型输入数据进行处理得到的第一推理结果和第二推理结果,得到第二神经网络模型的精度验证结果。
在获得目标框架下的第二神经网络模型之后,可以将上述模型输入数据输入到第二神经网络模型,用该模型输入数据在该第二神经网络模型上的每一个网络层运行一遍推理,上一个网络层输出的推理结果可以作为下一个网络层的输入数据,最后得到第二神经网络模型的最终的推理结果,即第二推理结果。
可以理解的是,该第一推理结果是在源框架下的第一神经网络模型对模型输入数据进行处理得到的最后一层的输出的推理结果或者倒数的某一层的有意义的推理结果,相应地,该第二推理结果是在目标框架下的第二神经网络模型对模型输入数据进行处理得到的最后一层的输出的推理结果或者倒数的某一层的有意义的推理结果,本公开实施例对此不做限定。
如图2所示,模型输入数据分别输入源框架下的第一神经网络模型和目标框架下的第二神经网络模型,分别得到输出1(即上述第一推理结果)和输出2(即上述第二推理结果)。
在获得第一推理结果和第二推理结果后,由于该第一推理结果和第二推理结果是采用同一模型输入数据分别在第一神经网络模型和第二神经网络模型中运行推理得到的,因此,根据该第一推理结果和第二推理结果,例如,比较该第一推理结果和第二推理结果,可以得到目标框架下的第二神经网络模型的精度验证结果。又例如,可以将第二推理结果的多个参数值,与第一推理结果中的相应的参数值一一进行匹配,得到匹配结果,即可以得到上述精度验证结果。在一些实施例中,该精度验证结果可以指示第二神经网络模型与第一神经网络模型的模型精度的比较结果,例如精度对齐或精度未对齐,或者该精度验证结果可以指示第二神经网络模型的模型精度是否满足预期或者设定标准,例如,精度达标或精度不达标,等等,本公开实施例对此不做限定。
在一些实施例中,可以输出该精度验证结果,或者也可以保存第二神经网络模型的信息,本公开实施例不限于此。
如图2所示,根据源框架下的神经网络模型的输出1和目标框架下的神经网络模型的输出2,进行精度验证。
根据本公开实施例提供的一种神经网络模型的转换方法,根据源框架下的第一神经网络模型和目标框架下的第二神经网络模型对同一模型输入数据分别得到的推理结果,可以自动得到第二神经网络模型的精度验证结果,提高了神经网络模型转换的精度验证效率。
请参阅图3,为本公开实施例提供的神经网络模型的转换方法的又一流程示意图,该方法包括以下步骤:
S201、模型转换装置获取源框架下的第一神经网络模型、模型输入数据以及目标框架的信息。
该步骤的具体实现可参考图1所示实施例中的步骤S101。
S202、通过第一进程对源框架下的第一神经网络模型进行模型转换处理,得到目标框架下的第二神经网络模型,并记录第一神经网络模型对模型输入数据处理得到的第一推理结果。
该步骤的部分实现可参考图1所示实施例中的步骤S102。
上述模型转换过程是在第一进程中进行的。
S203、通过第一进程创建第二进程。
利用同一模型输入数据在第二神经网络模型中运行推理时,为了防止运行推理过程中的资源冲突,可以通过上述第一进程创建新的进程,即第二进程,该第二进程与上述第一进程所占用的资源不同。
可以理解的是,在多进程的调用上,神经网络模型转换工具和源框架下的第一神经网络模型一般是基于某个平台开发的,但在进行神经网络模型的框架转换时,会根据不同的目标框架选择不同的执行方式。因而,创建的该第二进程可以是系统环境下的进程,也可以是该平台下的进程。在一些实施例中,神经网络模型转换工具和源框架可基于Python平台开发,在目标框架是Caffe框架时,由于Caffe提供pycaffe的Python接口,可使用Python的multiprocessing模块创建新进程以继续在Python环境下使用目标框架。在一些实施例中,神经网络模型转换工具和源框架可基于Python平台开发,在目标框架支持命令行形式的调用时,可使用Python的os模块的os.system在系统环境下创建新进程执行命令启动目标框架。
通过创建新的进程,在该新进程中运行第二神经网络模型对模型输入数据的推理,可以避免在推理过程中,第二神经网络模型和第一神经网络模型在同一进程中的某些系统调用的冲突,导致程序奔溃。提高了推理过程的可靠性。
S204、通过第一进程调用第二进程,以使得第二进程执行第二神经网络模型对模型输入数据的处理,得到第二推理结果。
通过第一进程调用新创建的第二进程,将上述模型输入数据输入第二神经网络模型,用该模型输入数据在该第二神经网络模型上的每一个网络层运行一遍推理,上一个网络层输出的推理结果可以作为下一个网络层的输入数据,最后得到第二神经网络模型的最终的推理结果,即第二推理结果。
S205、判断第一推理结果与第二推理结果之间的差别是否处于预设误差范围内,若是,则进行到步骤S206;若否,则进行到S207。
S206、确定第二神经网络模型的精度验证结果为精度对齐。
S207、确定第二神经网络模型的精度验证结果为精度未对齐。
在获得第一推理结果和第二推理结果后,由于该第一推理结果和第二推理结果是采用同一模型输入数据分别在第一神经网络模型和第二神经网络模型中运行推理得到的,因此,根据该第一推理结果和第二推理结果,可以得到目标框架下的第二神经网络模型的精度验证结果。具体地,如果第一推理结果与第二推理结果之间的差别处于预设误差范围内,则确定第二神经网络模型的精度验证结果为精度对齐。如果第一推理结果与第二推理结果之间的差别超出预设误差范围,则确定第二神经网络模型的精度验证结果为精度未对齐。
S208、响应于确定第二神经网络模型的精度验证结果为精度未对齐,模型转换装置定位第二神经网络模型中精度未对齐的目标网络层。
当确定第二神经网络模型的精度验证结果为精度未对齐时,需要定位出第一神经网络模型和第二神经网络模型中首先出现精度未对齐的网络层,即定位首先出现推理结果不一致的网络层,该定位出的网络层称为目标网络层。其中,该目标网络层为第二神经网络模型包括的多个网络层中最先出现精度未对齐的网络层。或者说,该目标网络层为第二神经网络模型包括的多个网络层中与第一神经网络模型的对应网络层的输出数据之间的差别超过预设误差范围的首个网络层。
为了提升神经网络模型转换工具的效率,在前述神经网络模型的精度验证过程中,一般不保存任何层的推理结果(也被称为输出数据)。当精度验证结果为精度未对齐时,神经网络模型转换工具重新进行一次神经网络模型转换和推理,用于定位精度问题。即模型转换装置对第一神经网络模型再次进行模型转换处理。神经网络模型每一层的输出数据量都较大,一般不将神经网络模型每一层的输出数据保存在内存中,而是将输出数据本地化,即存储在本地。因此,在再次进行模型转换处理的过程中,在本地保存第一神经网络模型中的每个网络层的输出数据。在验证某一个网络层的精度时把该网络层的输出数据从本地加载到内存中。
由于利用神经网络模型转换工具把源框架下的第一神经网络模型的各个网络层分别转换成目标框架的格式的过程中,源框架会用该模型输入数据在第一神经网络模型上运行一遍推理,可以获得第一神经网络模型中的网络层的信息以及网络层的连接关系。然后,模型转换装置可以基于第一神经网络模型的网络拓扑图,利用目标框架的网络结构定义和工具包对该第一神经网络模型的网络拓扑图进行适应性配置,得到第二神经网络模型。因此,进一步地,在再次进行模型转换处理的过程中,还可以建立第一神经网络模型和第二神经网络模型中的网络层之间的映射关系。其中,第一神经网络模型和第二神经网络模型的网络层之间的映射关系可以为一对多、多对一或者一对一,相应地,目标网络层可以为一个或多个网络层。
然后将同一模型输入数据输入到第二神经网络模型中,记录第二神经网络模型处理模型输入数据的过程中每个网络层的输出数据。
模型转换装置在获得了于第一神经网络模型和第二神经网络模型中每个网络层的输出数据,以及第一神经网络模型和第二神经网络模型中的网络层之间的映射关系后,可以基于第一神经网络模型和第二神经网络模型中每个网络层的输出数据以及映射关系,确定第二神经网络模型中首先出现精度未对齐的目标网络层。
具体地,在精度定位过程中,为了准确定位首先出现精度未对齐的目标网络层,给第一神经网络模型中的每个网络层配置一个序号。该序号可以是升序的,从而在定位精度问题时,可以根据第一神经网络模型中的多个网络层的序号,依次调用第一神经网络模型中的每一个网络层。
对于调用的每一个网络层,将上一个网络层输出的推理结果输入下一个网络层进行推理,得到每一个网络层的推理结果。并且,根据每一个网络层的序号,在本地对应存储每一个网络层的推理结果。并且给每一个网络层的推理结果也进行标识。其中,一个网络层可能存在多个输入。只保存每层输出的推理结果,因为除了最初的输入数据,其它层的输入都是上一层的输出,因此一旦记录了第一神经网络模型的最初的输入和每一层的输出,相当于记录了所有层的输入和输出。如图4所示,为本公开实施例提供的目标网络层定位过程中得到的网络拓扑示意图,该神经网络模型包括多个网络层:卷积层、激活函数、归一化层、Eltwise层和池化层等。初始输入数据到神经网络模型的第一个网络层后,每个网络层的输出作为下一个网络层的输入。该神经网络模型的推理结果包括初始输入数据、输入/输出数据1~10。
把第一神经网络模型中的每个网络层单独地转换到目标框架下,得到第二神经网络模型。输入同一模型输入数据到第二神经网络模型,然后使用每层的输入运行出模型的每一层在第二神经网络 模型中的推理结果,并保存在本地,保存时以每个网络层的序号为索引。当然,在目标框架下的推理同样需要在新的进程中进行。
在获得了神经网络模型的每个网络层在源框架和目标框架下的推理结果之后,可以根据每个网络层的序号,依次比较源框架下的第一神经网络模型中的每一个网络层的推理结果与目标框架下的第二神经网络模型中的对应的网络层的推理结果,定位第二神经网络模型中与第一神经网络模型首先精度未对齐的网络层,即目标网络层。
S209、模型转换装置输出目标网络层的信息。
模型转换装置在确定了目标网络层后,可以输出该目标网络层的信息。该目标网络层的信息包括网络层的标识、参数、输入数据、输出结果等。管理员或用户可根据该目标网络层的信息分析精度未对齐的原因。
根据本公开实施例提供的一种神经网络模型的转换方法,根据源框架下的第一神经网络模型和目标框架下的第二神经网络模型对同一模型输入数据分别得到的推理结果,可以自动得到第二神经网络模型的精度验证结果,提高了神经网络模型转换的精度验证效率;且根据源框架下的第一神经网络模型和目标框架下的第二神经网络模型对同一模型输入数据分别得到的每个网络层的输出数据,可以定位第二神经网络模型中精度未对齐的目标网络层,实现了精度未对齐时的网络层的准确定位。
当把源框架的神经网络模型转换到目标框架时,给神经网络模型同一个模型输入数据,判断源框架的输出与在目标框架的输出偏差是否在误差范围内。若不在误差范围内,则需要定位神经网络模型的哪一个网络层导致在两个框架下的推理结果不同。目前已开源的神经网络模型转换工具均不验证神经网络模型转换前后的输出精度是否一致,需要用户手动在两个框架下运行保存结果,然后进行比对。精度不一致时用户便需要根据经验修改神经网络模型,输出修改后的神经网络模型中一些层的结果,定位出使两个框架下的推理结果不一致的网络层。这样的方式会花费很多时间,同时对于一些比较大的神经网络模型,定位问题往往非常困难。
请参阅图5,为本公开实施例提供的模型精度定位方法的流程示意图,该方法包括以下步骤:
S301、模型精度定位装置获取源框架下的第一神经网络模型、模型输入数据以及目标框架的信息。
在该实施例中的模型精度定位装置与上述实施例中模型转换装置、神经网络模型转换工具仅是名字上的差异,可实现相同的功能。在已知第二神经网络模型与第一神经网络模型的精度未对齐的情况下,模型精度定位装置可以基于用户指令进行模型精度定位,该用户指令用于指示定位第二神经网络模型中精度未对齐的目标网络层,该用户指令包括源框架下的第一神经网络模型、模型输入数据以及目标框架的信息。例如,用户在获取到第二神经网络模型与第一神经网络模型的精度未对齐的结果时,则向模型精度定位装置发送该用户指令。模型精度定位装置也可以基于内部的操作指令进行模型精度定位,例如模型精度定位指令。例如,模型精度定位装置在获取到第二神经网络模型与第一神经网络模型的精度未对齐的指令时,则触发模型精度定位指令。该内部的操作指令用于指示定位第二神经网络模型中精度未对齐的目标网络层,该内部的操作指令包括源框架下的第一神经网络模型、模型输入数据以及目标框架的信息。
该步骤的具体实现可参考图1所示实施例的步骤S101,或者图3所示实施例的步骤S201。
S302、模型精度定位装置对第一神经网络模型进行模型转换处理,得到目标框架下的第二神经网络模型。
该步骤的具体实现可参考图1所示实施例的步骤S102,或者图3所示实施例的步骤S202。
S303、模型精度定位装置基于第一神经网络模型和第二神经网络模型分别处理模型输入数据的每个网络层的输出数据,定位第二神经网络模型中精度未对齐的目标网络层。
模型精度定位装置在对第一神经网络模型进行上述模型转换处理的过程中,运行第一神经网络模型对模型输入数据的推理过程,可以得到第一神经网络模型对模型输入数据进行处理的每个网络层的输出数据。可选地,可以将第一神经网络模型的每个网络层的输出数据在本地进行存储或记录。
在另外一些实施例中,模型精度定位装置也可以重新输入模型输入数据到第一神经网络模型,运行第一神经网络模型对模型输入数据的推理过程,得到第一神经网络模型对模型输入数据进行处理的每个网络层的输出数据。
在另外一些实施例中,模型精度定位装置可能预先存储了第一神经网络模型对模型输入数据进行推理得到的每个网络层的输出数据。
在获得目标框架下的第二神经网络模型之后,可以将上述模型输入数据输入到第二神经网络模型,用该模型输入数据在该第二神经网络模型上的每一个网络层运行一遍推理,上一个网络层输出的推理结果可以作为下一个网络层的输入数据,得到第二神经网络模型中每个网络层的输出数据。
在获得第一推理结果和第二推理结果后,由于该第一推理结果和第二推理结果是采用同一模型输入数据分别在第一神经网络模型和第二神经网络模型中运行推理得到的,因此,根据该第一推理结果和第二推理结果,例如,比较该第一推理结果和第二推理结果,可以得到目标框架下的第二神经网络模型的精度验证结果。又例如,可以将第二推理结果中的多个参数值,与第一推理结果中的相应的参数值一一进行匹配,得到匹配结果,即可以得到上述精度验证结果。在一些实施例中,该精度验证结果可以指示第二神经网络模型与第一神经网络模型的模型精度的比较结果,例如精度对齐或精度未对齐,或者该精度验证结果可以指示第二神经网络模型的模型精度是否满足预期或者设定标准,例如,精度达标或精度不达标,等等,本公开实施例对此不做限定。
在获得第一神经网络模型的每个网络层的输出结果和第二神经网络模型的每个网络层的输出结果后,由于该第一神经网络模型的每个网络层的输出结果和第二神经网络模型的每个网络层的输出结果是采用同一模型输入数据分别在第一神经网络模型和第二神经网络模型中运行推理得到的,因此,根据该第一神经网络模型的每个网络层的输出结果和第二神经网络模型的每个网络层的输出结果,可以定位第二神经网络模型中精度未对齐的目标网络层。
在一个实现中,该目标网络层为第二神经网络模型包括的多个网络层中最先出现精度未对齐的网络层。具体地,若第二神经网络模型包括的网络层与第一神经网络模型的对应网络层的输出数据之间的差别超过预设误差范围,则认定该网络层为精度未对齐的网络层。
在另一个实现中,目标网络层为第二神经网络模型中出现精度未对齐的多个网络层。例如不仅包括最先出现精度未对齐的网络层,还包括网络层的后续网络层。后续网络层的层数可以预先设定。
具体地,依次比较源框架下的第一神经网络模型中的每一个网络层的推理结果与目标框架下的第二神经网络模型中的对应的网络层的推理结果,定位第二神经网络模型中与第一神经网络模型首先精度未对齐的网络层,即目标网络层。
S304、模型精度定位装置输出目标网络层的信息。
模型精度定位装置在确定了目标网络层后,可以输出该目标网络层的信息。该目标网络层的信息包括目标网络层的标识、参数、输出数据、以及该输出数据与在第一神经网络模型中与目标网络层对应的网络层的输出数据之间的误差等。管理员或用户可根据该目标网络层的信息分析精度未对齐的原因。
根据本公开实施例提供的一种模型精度定位方法,根据源框架下的第一神经网络模型和目标框架下的第二神经网络模型对同一模型输入数据分别得到的每个网络层的输出数据,可以定位第二神经网络模型中精度未对齐的目标网络层,实现了精度未对齐时的目标网络层的准确定位。
请参阅图6,为本公开实施例提供的模型精度定位方法的又一流程示意图,该方法包括以下步骤:
S401、模型精度定位装置获取源框架下的第一神经网络模型、模型输入数据以及目标框架的信息。
该步骤的具体实现可参考图1所示实施例的步骤S101,或者图3所示实施例的步骤S201,或者图5所示实施例的步骤S301。
S402、模型精度定位装置通过第一神经网络模型对模型输入数据的处理,建立网络拓扑图,其中,该网络拓扑图包括第一神经网络模型中的网络层的信息以及网络层的连接关系。
模型精度定位装置通过第一神经网络模型对模型输入数据的处理,建立网络拓扑图,其中,该网络拓扑图包括第一神经网络模型中的网络层的信息以及网络层的连接关系。利用神经网络模型转换工具把源框架下的第一神经网络模型的各个网络层分别转换成目标框架的格式的过程中,源框架会用该模型输入数据在第一神经网络模型上运行一遍推理,可以获得第一神经网络模型中的网络层的信息以及网络层的连接关系。上述第一神经网络模型中的网络层的信息以及网络层的连接关系构成第一神经网络模型的网络拓扑图。
S403、模型精度定位装置基于网络拓扑图以及目标框架的信息,得到第二神经网络模型,并记录第一神经网络模型处理模型输入数据的过程中每个网络层的输出数据,并基于模型转换处理,建立第一神经网络模型和第二神经网络模型中的网络层之间的映射关系。
模型精度定位装置在获得第一神经网络的网络拓扑图后,目标框架具备自己的网络结构定义和工具包,模型精度定位装置可以基于第一神经网络的网络拓扑图,利用目标框架的网络结构定义和工具包对该第一神经网络的网络拓扑图进行适应性配置,得到第二神经网络模型。
由于利用神经网络模型转换工具把源框架下的第一神经网络模型的各个网络层分别转换成目标框架的格式的过程中,源框架会用该模型输入数据在第一神经网络模型上运行一遍推理,可以获得第一神经网络模型中的网络层的信息以及网络层的连接关系。然后,模型精度定位装置可以基于第一神经网络的网络拓扑图,利用目标框架的网络结构定义和工具包对该第一神经网络的网络拓扑图进行适应性配置,得到第二神经网络模型。因此,进一步地,在进行模型转换处理的过程中,还可以建立第一神经网络模型和第二神经网络模型中的网络层之间的映射关系。其中,第一神经网络模型和第二神经网络模型的网络层之间的映射关系可以为一对多、多对一或者一对一,相应地,目标网络层可以为一个或多个网络层。
S404、模型精度定位装置通过第二神经网络模型对模型输入数据进行处理,得到第二神经网络模型中每个网络层的输出数据。
该步骤的具体实现可参考图1所示实施例的步骤S103,或者图3所示实施例的步骤S203。
所不同的是,本实施例中,记录的是第二神经网络模型的每个网络层的输出数据,而在图1或图3所示的实施例中,记录的是第二神经网络模型的最后的推理结果,即第二神经网络模型的最后一个网络层的输出数据。
S405、模型精度定位装置基于第一神经网络模型和第二神经网络模型中每个网络层的输出数据以及映射关系,确定第二神经网络模型中精度未对齐的目标网络层。
模型精度定位装置在获得了第一神经网络模型和第二神经网络模型中每个网络层的输出数据,以及第一神经网络模型和第二神经网络模型中的网络层之间的映射关系后,可以基于第一神经网络模型和第二神经网络模型中每个网络层的输出数据以及映射关系,确定第二神经网络模型中首先出现精度未对齐的目标网络层。
具体地,在精度定位过程中,为了准确定位首先出现精度未对齐的目标网络层,给第一神经网络模型中的每个网络层配置一个序号。该序号可以是升序的,从而在定位精度问题时,可以根据第一神经网络模型中的多个网络层的序号,依次调用第一神经网络模型中的每一个网络层。
对于调用的每一个网络层,将上一个网络层输出的推理结果输入下一个网络层进行推理,得到每一个网络层的推理结果。并且,根据每一个网络层的序号,在本地对应存储每一个网络层的推理结果。并且给每一个网络层的推理结果也进行标识。其中,一个网络层可能存在多个输入。只保存每层输出的推理结果,因为除了最初的输入数据,其它层的输入都是上一层的输出,因此一旦记录了第一神经网络模型的最初的输入和每一层的输出,相当于记录了所有层的输入和输出。如图4所示,为示例的神经网络模型转换后精度未对齐时的目标网络层的定位过程示意图,该神经网络模型包括多个网络层:卷积层、激活函数、归一化层、Eltwise层和池化层等。初始输入数据到神经网络模型的第一个网络层后,每个网络层的输出作为下一个网络层的输入。该神经网络模型的推理结果包括初始输入数据、输入/输出数据1~10。
把第一神经网络模型中的每个网络层单独地转换到目标框架下,得到第二神经网络模型。输入同一模型输入数据到第二神经网络模型,然后使用每层的输入运行出模型的每一层在第二神经网络模型中的推理结果,并保存在本地,保存时以每个网络层的序号为索引。当然,在目标框架下的推理同样需要在新的进程中进行。
在获得了神经网络模型的每个网络层在源框架和目标框架下的推理结果之后,可以根据每个网络层的序号,依次比较源框架下的第一神经网络模型中的每一个网络层的推理结果与目标框架下的第二神经网络模型中的对应的网络层的推理结果,定位第二神经网络模型中与第一神经网络模型首先精度未对齐的网络层,即目标网络层。
S406、模型精度定位装置输出目标网络层的信息。
该步骤的具体实现可参考图5所示实施例的步骤S304。
根据本公开实施例提供的一种模型精度定位方法,根据源框架下的第一神经网络模型和目标框架下的第二神经网络模型对同一模型输入数据分别得到的每个网络层的输出数据,可以定位第二神经网络模型中精度未对齐的目标网络层,实现了精度未对齐时的网络层的准确定位。
基于上述神经网络模型的转换方法的同一构思,如图7所示,本公开实施例还提供一种模型转换装置,该装置1000包括:
获取单元11,用于获取源框架下的第一神经网络模型、模型输入数据以及目标框架的信息;
转换单元12,用于对所述源框架下的第一神经网络模型进行模型转换处理,得到所述目标框架下的第二神经网络模型;
验证单元13,用于基于所述第一神经网络模型和所述第二神经网络模型分别对所述模型输入数据进行处理得到的第一推理结果和第二推理结果,得到所述第二神经网络模型的精度验证结果。
在一个实现中,所述转换单元12用于通过第一进程对所述源框架下的第一神经网络模型进行模型转换处理,得到所述目标框架下的第二神经网络模型;
所述装置还包括:
创建单元14,用于通过所述第一进程创建第二进程;
推理单元15,用于通过所述第一进程调用所述第二进程,以使得所述第二进程执行所述第二神经网络模型对所述模型输入数据的处理,得到第二推理结果。
在又一个实现中,所述验证单元13用于若所述第一推理结果与所述第二推理结果之间的差别处于预设误差范围内,确定所述第二神经网络模型的精度验证结果为精度对齐;或
所述验证单元13还用于若所述第一推理结果与所述第二推理结果之间的差别超出所述预设误差范围,确定所述第二神经网络模型的精度验证结果为精度未对齐。
在又一个实现中,所述装置还包括:
定位单元16,用于响应于确定所述第二神经网络模型的精度验证结果为精度未对齐,定位所述第二神经网络模型中精度未对齐的目标网络层;
输出单元17,用于输出所述目标网络层的信息。
在又一个实现中,所述定位单元16包括:
建立单元161,用于建立所述第一神经网络模型和所述第二神经网络模型中的网络层之间的映射关系;
确定单元162,用于基于所述第一神经网络模型和所述第二神经网络模型分别处理所述模型输入数据的过程中每个网络层的输出数据以及所述映射关系,确定所述第二神经网络模型中精度未对齐的目标网络层。
在又一个实现中,其中,所述模型转换装置对所述第一神经网络模型再次进行模型转换处理,其中,在所述再次进行模型转换处理的过程中,获取所述第一神经网络模型中的每个网络层的输出数据,和/或建立所述第一神经网络模型和所述第二神经网络模型中的网络层之间的映射关系。
在又一个实现中,所述转换单元12用于通过所述第一神经网络模型对所述模型输入数据的处理,建立网络拓扑图,其中,所述网络拓扑图包括所述第一神经网络模型中的网络层的信息以及网络层的连接关系;以及基于所述网络拓扑图以及所述目标框架的信息,得到所述第二神经网络模型。
有关上述各单元的具体实现可参考图1或图3所示的神经网络模型的转换方法中的相关描述,在此不再赘述。
根据本公开实施例提供的一种模型转换装置,根据源框架下的第一神经网络模型和目标框架下的第二神经网络模型对同一模型输入数据分别得到的推理结果,可以自动得到第二神经网络模型的精度验证结果,提高了神经网络模型转换的精度验证效率。
基于上述模型精度定位方法的同一构思,如图8所示,本公开实施例还提供一种模型精度定位装置,该装置2000包括:
获取单元21,用于获取源框架下的第一神经网络模型、模型输入数据以及目标框架的信息;
转换单元22,用于对所述第一神经网络模型进行模型转换处理,得到所述目标框架下的第二神经网络模型;
定位单元23,用于基于所述第一神经网络模型和所述第二神经网络模型分别处理所述模型输入数据的过程中每个网络层的输出数据,定位所述第二神经网络模型中精度未对齐的目标网络层;
输出单元24,用于输出所述目标网络层的信息。
在一个实现中,所述目标网络层的信息,包括下列中的至少一项:所述目标网络层的标识、参数、输出数据、以及该输出数据与第一神经网络模型中与所述目标网络层对应的网络层的输出数据之间的误差。
在又一个实现中,所述装置还包括:
第一建立单元25,用于基于所述模型转换处理,建立所述第一神经网络模型和所述第二神经网络模型中的网络层之间的映射关系;
所述定位单元23,用于基于所述第一神经网络模型和所述第二神经网络模型中每个网络层的输出数据以及所述映射关系,确定所述第二神经网络模型中精度未对齐的目标网络层。
在又一个实现中,所述定位单元23包括:
调用单元231,用于基于所述映射关系依次比较所述第一神经网络模型和所述第二神经网络模型中对应网络层的输出数据;
确定单元232,用于响应于所述第一神经网络模型和所述第二神经网络模型中对应网络层的输出数据之间的差别超出预设误差范围,将所述对应网络层中属于所述第二神经网络模型中的网络层确定为所述目标网络层。
在又一个实现中,所述转换单元22包括:
第二建立单元221,用于通过所述第一神经网络模型对所述模型输入数据的处理,建立网络拓扑图,其中,所述网络拓扑图包括所述第一神经网络模型中的网络层的信息以及网络层的连接关系;
第二获取单元222,用于基于所述网络拓扑图以及所述目标框架的信息,得到所述第二神经网络模型。
有关上述各单元的具体实现可参考图5或图6所示实施例中的具体描述,在此不再赘述。
根据本公开实施例提供的一种模型精度定位装置,根据源框架下的第一神经网络模型和目标框架下的第二神经网络模型对同一模型输入数据分别得到的每个网络层的输出数据,可以定位第二神经网络模型中精度未对齐的目标网络层,实现了精度未对齐时的网络层的准确定位。
如图9所示,还提供了一种电子设备的硬件结构示意图,该电子设备用于执行上述神经网络模型的转换方法/模型精度定位方法。上述方法中的部分或全部可以通过硬件来实现,也可以通过软件或固件来实现。
可选的,该电子设备在具体实现时可以是芯片或者集成电路。
可选的,当上述实施例的神经网络模型的转换方法/模型精度定位方法中的部分或全部通过软件或固件来实现时,可以通过图9提供的一种电子设备3000来实现。如图9所示,该电子设备3000可包括:
存储器33和处理器34(装置中的处理器34可以是一个或多个,图9中以一个处理器为例),还可以包括输入装置31、输出装置32。在本实施例中,输入装置31、输出装置32、存储器33和处理器34可通过总线或其它方式连接,其中,图9中以通过总线连接为例。
其中,处理器34用于执行图1、图3、图5、图6中所执行的方法步骤。
可选的,上述神经网络模型的转换方法/模型精度定位方法的程序可以存储在存储器33中。该存储器33可以是物理上独立的单元,也可以与处理器34集成在一起。该存储器33也可以用于存储数据。
可选的,当上述实施例的神经网络模型的转换方法/模型精度定位方法中的部分或全部通过软件实现时,该电子设备也可以只包括处理器。用于存储程序的存储器位于该电子设备之外,处理器通过电路或电线与存储器连接,用于读取并执行存储器中存储的程序。
处理器可以是中央处理器(central processing unit,CPU),网络处理器(network processor,NP),或WLAN(Wireless Local Area Network)设备。
处理器还可以进一步包括硬件芯片。上述硬件芯片可以是专用集成电路(application-specific integrated circuit,ASIC),可编程逻辑器件(programmable logic device,PLD)或其组合。上述PLD可以是复杂可编程逻辑器件(complex programmable logic device,CPLD),现场可编程逻辑门阵列(field-programmable gate array,FPGA),通用阵列逻辑(generic array logic,GAL)或其任意组合。
存储器可以包括易失性存储器(volatile memory),例如随机存取存储器(random-access memory,RAM);存储器也可以包括非易失性存储器(non-volatile memory),例如快闪存储器(flash memory),硬盘(hard disk drive,HDD)或固态硬盘(solid-state drive,SSD);存储器还可以包括上述种类的存储器的组合。
本领域技术人员应明白,本公开一个或多个实施例可提供为方法、系统或计算机程序产品。因此,本公开一个或多个实施例可采用完全硬件实施例、完全软件实施例或结合软件和硬件方面的实施例的形式。而且,本公开一个或多个实施例可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。
本公开实施例还提供一种计算机可读存储介质,该存储介质上可以存储有计算机程序,所述程序被处理器执行时实现本公开任一实施例描述的神经网络模型的转换方法的步骤,和/或,实现本公开任一实施例描述的模型精度定位方法的步骤。
本公开中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于上述装置实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。
上述对本公开特定实施例进行了描述。其它实施例在所附权利要求书的范围内。在一些情况下,在权利要求书中记载的行为或步骤可以按照不同于实施例中的顺序来执行并且仍然可以实现期望的结果。另外,在附图中描绘的过程不一定要求示出的特定顺序或者连续顺序才能实现期望的结果。在某些实施方式中,多任务处理和并行处理也是可以的或者可能是有利的。
本公开中描述的主题及功能操作的实施例可以在以下中实现:数字电子电路、有形体现的计算机软件或固件、包括本公开中公开的结构及其结构性等同物的计算机硬件、或者它们中的一个或多个的组合。本公开中描述的主题的实施例可以实现为一个或多个计算机程序,即编码在有形非暂时性程序载体上以被数据处理装置执行或指示数据处理装置的操作的计算机程序指令中的一个或多个模块。可替代地或附加地,程序指令可以被编码在人工生成的传播信号上,例如机器生成的电、光或电磁信号,该信号被生成以将信息编码并传输到合适的接收机装置以由数据处理装置执行。计算机存储介质可以是机器可读存储设备、机器可读存储基板、随机或串行存取存储器设备、或它们中的一个或多个的组合。
本公开中描述的处理及逻辑流程可以由执行一个或多个计算机程序的一个或多个可编程计算机执行,以通过根据输入数据进行操作并生成输出来执行相应的功能。所述处理及逻辑流程还可以由专用逻辑电路—例如现场可编程门阵列(FPGA)或专用集成电路(ASIC)来执行,并且装置也可以实现为专用逻辑电路。
适合用于执行计算机程序的计算机包括,例如通用和/或专用微处理器,或任何其他类型的中央处理单元。通常,中央处理单元将从只读存储器和/或随机存取存储器接收指令和数据。计算机的基本组件包括用于实施或执行指令的中央处理单元以及用于存储指令和数据的一个或多个存储器设备。通常,计算机还将包括用于存储数据的一个或多个大容量存储设备,例如磁盘、磁光盘或光盘等,或者计算机将可操作地与此大容量存储设备耦接以从其接收数据或向其传送数据,抑或两种情况兼而有之。然而,计算机不是必须具有这样的设备。此外,计算机可以嵌入在另一设备中,例如移动电话、个人数字助理(PDA)、移动音频或视频播放器、游戏操纵台、全球定位系统(GPS)接收机、或例如通用串行总线(USB)闪存驱动器的便携式存储设备,仅举几例。
适合于存储计算机程序指令和数据的计算机可读介质包括所有形式的非易失性存储器、媒介和存储器设备,例如包括半导体存储器设备(例如EPROM、EEPROM和闪存设备)、磁盘(例如内部硬盘或可移动盘)、磁光盘以及CD ROM和DVD-ROM盘。处理器和存储器可由专用逻辑电路补充或并入专用逻辑电路中。
虽然本公开包含许多具体实施细节,但是这些不应被解释为限制任何发明的范围或所要求保护的范围,而是主要用于描述特定发明的具体实施例的特征。本公开内在多个实施例中描述的某些特征也可以在单个实施例中被组合实施。另一方面,在单个实施例中描述的各种特征也可以在多个实施例中分开实施或以任何合适的子组合来实施。此外,虽然特征可以如上所述在某些组合中起作用并且甚至最初如此要求保护,但是来自所要求保护的组合中的一个或多个特征在一些情况下可以从该组合中去除,并且所要求保护的组合可以指向子组合或子组合的变型。
类似地,虽然在附图中以特定顺序描绘了操作,但是这不应被理解为要求这些操作以所示的特定顺序执行或顺次执行、或者要求所有例示的操作被执行,以实现期望的结果。在某些情况下,多任务和并行处理可能是有利的。此外,上述实施例中的各种系统模块和组件的分离不应被理解为在所有实施例中均需要这样的分离,并且应当理解,所描述的程序组件和系统通常可以一起集成在单个软件产品中,或者封装成多个软件产品。
由此,主题的特定实施例已被描述。其他实施例在所附权利要求书的范围以内。在某些情况下,权利要求书中记载的动作可以以不同的顺序执行并且仍实现期望的结果。此外,附图中描绘的处理并非必需所示的特定顺序或顺次顺序,以实现期望的结果。在某些实现中,多任务和并行处理可能是有利的。
以上所述仅为本公开一个或多个实施例的较佳实施例而已,并不用以限制本公开一个或多个实施例,凡在本公开一个或多个实施例的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本公开一个或多个实施例保护的范围之内。

Claims (20)

  1. 一种神经网络模型的转换方法,其特征在于,所述方法包括:
    模型转换装置获取源框架下的第一神经网络模型、模型输入数据以及目标框架的信息;
    所述模型转换装置对所述源框架下的第一神经网络模型进行模型转换处理,得到所述目标框架下的第二神经网络模型;
    所述模型转换装置基于所述第一神经网络模型和所述第二神经网络模型分别对所述模型输入数据进行处理得到的第一推理结果和第二推理结果,得到所述第二神经网络模型的精度验证结果。
  2. 根据权利要求1所述的方法,其特征在于,所述对所述源框架下的第一神经网络模型进行模型转换处理,得到所述目标框架下的第二神经网络模型,包括:
    通过第一进程对所述源框架下的第一神经网络模型进行模型转换处理,得到所述目标框架下的第二神经网络模型;
    所述方法还包括:
    通过所述第一进程创建第二进程;
    通过所述第一进程调用所述第二进程,以在所述第二进程中通过所述第二神经网络模型对所述模型输入数据进行处理,得到第二推理结果。
  3. 根据权利要求1或2所述的方法,其特征在于,所述模型转换装置基于所述第一神经网络模型和所述第二神经网络模型分别对所述模型输入数据进行处理得到的第一推理结果和第二推理结果,得到所述第二神经网络模型的精度验证结果,包括:
    若所述第一推理结果与所述第二推理结果之间的差别处于预设误差范围内,确定所述第二神经网络模型的精度验证结果为精度对齐;或
    若所述第一推理结果与所述第二推理结果之间的差别超出所述预设误差范围,确定所述第二神经网络模型的精度验证结果为精度未对齐。
  4. 根据权利要求1至3中任一项所述的方法,其特征在于,所述方法还包括:
    响应于确定所述第二神经网络模型的精度验证结果为精度未对齐,所述模型转换装置定位所述第二神经网络模型中精度未对齐的目标网络层;
    所述模型转换装置输出所述目标网络层的信息。
  5. 根据权利要求4所述的方法,其特征在于,所述定位所述第二神经网络模型中精度未对齐的目标网络层,包括:
    所述模型转换装置建立所述第一神经网络模型和所述第二神经网络模型中的网络层之间的映射关系;
    所述模型转换装置基于所述第一神经网络模型和所述第二神经网络模型分别处理所述模型输入数据的过程中每个网络层的输出数据以及所述映射关系,确定所述第二神经网络模型中精度未对齐的目标网络层。
  6. 根据权利要求5所述的方法,其特征在于,其中,所述模型转换装置对所述第一神经网络模型再次进行模型转换处理,其中,在所述再次进行模型转换处理的过程中,获取所述第一神经网络模型中的每个网络层的输出数据,和/或建立所述第一神经网络模型和所述第二神经网络模型中的网络层之间的映射关系。
  7. 根据权利要求1至6中任一项所述的方法,其特征在于,所述模型转换装置对所述源框架下的第一神经网络模型进行模型转换处理,得到所述目标框架下的第二神经网络模型,包括:
    所述模型转换装置通过所述第一神经网络模型对所述模型输入数据的处理,建立网络拓扑图,其中,所述网络拓扑图包括所述第一神经网络模型中的网络层的信息以及网络层的连接关系;
    所述模型转换装置基于所述网络拓扑图以及所述目标框架的信息,得到所述第二神经网络模型。
  8. 一种模型精度定位方法,其特征在于,包括:
    模型精度定位装置获取源框架下的第一神经网络模型、模型输入数据以及目标框架的信息;
    所述模型精度定位装置对所述第一神经网络模型进行模型转换处理,得到所述目标框架下的第二神经网络模型;
    所述模型精度定位装置基于所述第一神经网络模型和所述第二神经网络模型分别处理所述模型 输入数据的过程中每个网络层的输出数据,定位所述第二神经网络模型中精度未对齐的目标网络层;
    所述模型精度定位装置输出所述目标网络层的信息。
  9. 根据权利要求8所述的方法,其特征在于,所述方法还包括:
    所述模型精度定位装置基于所述模型转换处理,建立所述第一神经网络模型和所述第二神经网络模型中的网络层之间的映射关系;
    所述模型精度定位装置基于所述第一神经网络模型和所述第二神经网络模型分别处理所述模型输入数据的过程中每个网络层的输出数据,定位所述第二神经网络模型中精度未对齐的目标网络层,包括:
    所述模型精度定位装置基于所述第一神经网络模型和所述第二神经网络模型中每个网络层的输出数据以及所述映射关系,确定所述第二神经网络模型中精度未对齐的目标网络层。
  10. 根据权利要求9所述的方法,其特征在于,所述模型精度定位装置基于所述第一神经网络模型和所述第二神经网络模型中每个网络层的输出数据以及所述映射关系,确定所述第二神经网络模型中精度未对齐的目标网络层,包括:
    所述模型精度定位装置基于所述映射关系依次比较所述第一神经网络模型和所述第二神经网络模型中对应网络层的输出数据;
    响应于所述第一神经网络模型和所述第二神经网络模型中对应网络层的输出数据之间的差别超出预设误差范围,将所述对应网络层中属于所述第二神经网络模型中的网络层确定为所述目标网络层。
  11. 根据权利要求8~10中任一项所述的方法,其特征在于,所述模型精度定位装置对所述源框架下的第一神经网络模型进行模型转换处理,得到所述目标框架下的第二神经网络模型,包括:
    所述模型精度定位装置通过所述第一神经网络模型对所述模型输入数据的处理,建立网络拓扑图,其中,所述网络拓扑图包括所述第一神经网络模型中的网络层的信息以及网络层的连接关系;
    所述模型精度定位装置基于所述网络拓扑图以及所述目标框架的信息,得到所述第二神经网络模型。
  12. 一种模型转换装置,其特征在于,所述装置包括:
    获取单元,用于获取源框架下的第一神经网络模型、模型输入数据以及目标框架的信息;
    转换单元,用于对所述源框架下的第一神经网络模型进行模型转换处理,得到所述目标框架下的第二神经网络模型;
    验证单元,用于基于所述第一神经网络模型和所述第二神经网络模型分别对所述模型输入数据进行处理得到的第一推理结果和第二推理结果,得到所述第二神经网络模型的精度验证结果。
  13. 根据权利要求12所述的装置,其特征在于,所述转换单元用于通过第一进程对所述源框架下的第一神经网络模型进行模型转换处理,得到所述目标框架下的第二神经网络模型;
    所述装置还包括:
    创建单元,用于通过所述第一进程创建第二进程;
    推理单元,用于通过所述第一进程调用所述第二进程,以使得所述第二进程执行所述第二神经网络模型对所述模型输入数据的处理,得到第二推理结果。
  14. 根据权利要求12或13所述的装置,其特征在于,所述验证单元用于若所述第一推理结果与所述第二推理结果之间的差别处于预设误差范围内,确定所述第二神经网络模型的精度验证结果为精度对齐;和/或
    所述验证单元还用于若所述第一推理结果与所述第二推理结果之间的差别超出所述预设误差范围,确定所述第二神经网络模型的精度验证结果为精度未对齐。
  15. 根据权利要求12至14中任一项所述的装置,其特征在于,所述装置还包括:
    定位单元,用于响应于确定所述第二神经网络模型的精度验证结果为精度未对齐,定位所述第二神经网络模型中精度未对齐的目标网络层;
    输出单元,用于输出所述目标网络层的信息。
  16. 根据权利要求15所述的装置,其特征在于,所述定位单元包括:
    建立单元,用于建立所述第一神经网络模型和所述第二神经网络模型中的网络层之间的映射关系;
    确定单元,用于基于所述第一神经网络模型和所述第二神经网络模型分别处理所述模型输入数据的过程中每个网络层的输出数据以及所述映射关系,确定所述第二神经网络模型中精度未对齐的目标网络层。
  17. 根据权利要求16所述的装置,其特征在于,其中,所述模型转换装置对所述第一神经网络模型再次进行模型转换处理,其中,在所述再次进行模型转换处理的过程中,获取所述第一神经网络模型中的每个网络层的输出数据,和/或建立所述第一神经网络模型和所述第二神经网络模型中的网络层之间的映射关系。
  18. 一种模型精度定位装置,其特征在于,包括:
    获取单元,用于获取源框架下的第一神经网络模型、模型输入数据以及目标框架的信息;
    转换单元,用于对所述第一神经网络模型进行模型转换处理,得到所述目标框架下的第二神经网络模型;
    定位单元,用于基于所述第一神经网络模型和所述第二神经网络模型分别处理所述模型输入数据的过程中每个网络层的输出数据,定位所述第二神经网络模型中精度未对齐的目标网络层;
    输出单元,用于输出所述目标网络层的信息。
  19. 一种电子设备,其特征在于,所述装置包括存储器和处理器,其中,所述存储器中存储程序指令,且所述处理器用于调用所述存储器中存储的程序指令,执行如权利要求1~11中任一项所述的方法。
  20. 一种计算机存储介质,其特征在于,所述计算机可读存储介质中存储有指令,当其在计算机上运行时,使得计算机执行如权利要求1~11中任一项所述的方法。
PCT/CN2021/076754 2020-02-28 2021-02-18 神经网络模型的转换方法、模型精度定位方法及装置 WO2021169844A1 (zh)

Priority Applications (3)

Application Number Priority Date Filing Date Title
JP2021570957A JP2022540300A (ja) 2020-02-28 2021-02-18 ニューラルネットワークモデル変換方法、モデル精度位置決め方法、および装置
SG11202113120YA SG11202113120YA (en) 2020-02-28 2021-02-18 Methods and apparatuses for transforming neural network model, and methods and apparatuses for positioning model precision
KR1020217041100A KR20220008336A (ko) 2020-02-28 2021-02-18 뉴럴 네트워크 모델의 변환 방법, 모델 정확도 확립 방법 및 장치

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202010129010.0A CN113326913A (zh) 2020-02-28 2020-02-28 神经网络模型的转换方法、模型精度定位方法及装置
CN202010129010.0 2020-02-28

Publications (1)

Publication Number Publication Date
WO2021169844A1 true WO2021169844A1 (zh) 2021-09-02

Family

ID=77412746

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/076754 WO2021169844A1 (zh) 2020-02-28 2021-02-18 神经网络模型的转换方法、模型精度定位方法及装置

Country Status (6)

Country Link
JP (1) JP2022540300A (zh)
KR (1) KR20220008336A (zh)
CN (1) CN113326913A (zh)
SG (1) SG11202113120YA (zh)
TW (1) TW202133054A (zh)
WO (1) WO2021169844A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115878096A (zh) * 2023-01-31 2023-03-31 北京面壁智能科技有限责任公司 深度学习模型统一应用方法、装置、服务器及存储介质

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115187821B (zh) * 2022-07-05 2024-03-22 阿波罗智能技术(北京)有限公司 验证模型转换前后正确性的方法、相关装置及程序产品
CN117056238B (zh) * 2023-10-11 2024-01-30 深圳鲲云信息科技有限公司 验证部署框架下模型转换正确性的方法及计算设备

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108229652A (zh) * 2017-11-28 2018-06-29 北京市商汤科技开发有限公司 神经网络模型迁移方法和系统、电子设备、程序和介质
CN108229651A (zh) * 2017-11-28 2018-06-29 北京市商汤科技开发有限公司 神经网络模型迁移方法和系统、电子设备、程序和介质
CN109993300A (zh) * 2017-12-29 2019-07-09 华为技术有限公司 一种神经网络模型的训练方法及装置
CN110348566A (zh) * 2019-07-15 2019-10-18 上海点积实业有限公司 一种生成神经网络训练用数字信号的方法和系统
US20200005183A1 (en) * 2018-06-29 2020-01-02 Renesas Electronics Corporation Evaluation method for learning models, training method, device, and program

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108229646A (zh) * 2017-08-08 2018-06-29 北京市商汤科技开发有限公司 神经网络模型压缩方法、装置、存储介质和电子设备
KR102593438B1 (ko) * 2017-11-17 2023-10-24 삼성전자주식회사 뉴럴 네트워크 학습 방법 및 디바이스

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108229652A (zh) * 2017-11-28 2018-06-29 北京市商汤科技开发有限公司 神经网络模型迁移方法和系统、电子设备、程序和介质
CN108229651A (zh) * 2017-11-28 2018-06-29 北京市商汤科技开发有限公司 神经网络模型迁移方法和系统、电子设备、程序和介质
CN109993300A (zh) * 2017-12-29 2019-07-09 华为技术有限公司 一种神经网络模型的训练方法及装置
US20200005183A1 (en) * 2018-06-29 2020-01-02 Renesas Electronics Corporation Evaluation method for learning models, training method, device, and program
CN110348566A (zh) * 2019-07-15 2019-10-18 上海点积实业有限公司 一种生成神经网络训练用数字信号的方法和系统

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115878096A (zh) * 2023-01-31 2023-03-31 北京面壁智能科技有限责任公司 深度学习模型统一应用方法、装置、服务器及存储介质
CN115878096B (zh) * 2023-01-31 2023-05-23 北京面壁智能科技有限责任公司 深度学习模型统一应用方法、装置、服务器及存储介质

Also Published As

Publication number Publication date
CN113326913A (zh) 2021-08-31
SG11202113120YA (en) 2021-12-30
JP2022540300A (ja) 2022-09-15
TW202133054A (zh) 2021-09-01
KR20220008336A (ko) 2022-01-20

Similar Documents

Publication Publication Date Title
WO2021169844A1 (zh) 神经网络模型的转换方法、模型精度定位方法及装置
WO2017020654A1 (zh) 无线网络接入方法和装置
US10873512B2 (en) Methods for managing self-healing cloud infrastructure and applications
US11893331B2 (en) Device verification method, UVM verification platform, electronic apparatus and storage medium
US10354031B2 (en) Information processing by interpenetrating signal transmission channel in design for testability of chip
WO2020006878A1 (zh) 语音识别测试方法、装置、计算机设备及存储介质
WO2020237508A1 (zh) 一种断言验证代码绑定方法及装置
US10656934B2 (en) Efficient software testing
WO2020177385A1 (zh) 虚拟机性能检测方法及装置、电子设备、存储介质
US9846609B2 (en) System and method for testing configuration and operation of I/O devices
CN111930613A (zh) 待测芯片的测试用例生成方法、装置、电子设备以及介质
WO2021051879A1 (zh) 反向代理评价模型中目标参数选取方法及相关装置
CN113127357B (zh) 单元测试方法、装置、设备、存储介质及程序产品
WO2020186518A1 (en) Method and apparatus for debugging, and system on chip
CN112860587B (zh) Ui自动测试方法和装置
US9483593B2 (en) Method for decomposing a hardware model and for accelerating formal verification of the hardware model
WO2024041335A1 (zh) 一种寻址测试的方法、装置、存储介质及电子设备
WO2021253239A1 (zh) 云服务系统的资源配置确定方法及装置
CN113485697A (zh) 一种人工智能框架下的模型建设运营服务方法及系统
KR101794016B1 (ko) 분산 컴퓨팅 기반의 어플리케이션 객체 분석 방법, 이를 수행하는 어플리케이션 객체 분석 서버 및 이를 저장하는 기록매체
WO2023213094A1 (zh) 应用于集成电路器件的数据区域动态选取方法、系统、设备和计算机可读存储介质
CN113691403B (zh) 拓扑节点配置方法、相关装置及计算机程序产品
CN113791792B (zh) 应用调用信息的获取方法、设备以及存储介质
CN106484625A (zh) 一种基于通用测试软件开发平台测试子系统的方法
CN115034164A (zh) 验证方法、电子设备及存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21760426

Country of ref document: EP

Kind code of ref document: A1

ENP Entry into the national phase

Ref document number: 2021570957

Country of ref document: JP

Kind code of ref document: A

ENP Entry into the national phase

Ref document number: 20217041100

Country of ref document: KR

Kind code of ref document: A

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 21760426

Country of ref document: EP

Kind code of ref document: A1

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 27.03.2023)

122 Ep: pct application non-entry in european phase

Ref document number: 21760426

Country of ref document: EP

Kind code of ref document: A1