Font Size: a A A

Research On Neural Network Format Conversion From PyTorch To ONNX

Posted on:2023-10-29Degree:MasterType:Thesis
Country:ChinaCandidate:T WangFull Text:PDF
GTID:2568306911481254Subject:Engineering
Abstract/Summary:PDF Full Text Request
With the improvement of computer performance and the advent of big data era,deep learning is more and more widely used.At present,many companies have developed frameworks for deep learning computing.Common deep learning frameworks include PyTorch,Tensor Flow,Caffe and Mind Spore.Due to the differences between the user’s framework and the framework used by the deep learning model provided by the open source website,scholars cannot directly use the trained deep learning model.To solve this problem,the Open source community proposed a Neural Network representation standard,ONNX(Open Neural Network Exchange),which can be used as an intermediate format to realize model format conversion between frameworks.Based on ONNX standard,this thesis designs and implements a tool,which is called PyTorch2 ONNX.The tool can convert neural network models from PyTorch format to ONNX format.After reading and analyzing the basic implementation principles of PyTorch framework and ONNX framework,I completed the implementation of PyTorch2 ONNX tool,which is mainly divided into three parts: loading model,converting model and saving model.Loading the model is to load the information in the PyTorch model.By analyzing the definition and underlying implementation of the PyTorch model,I design process extract the information required for the transformation,including operation types,forward propagation process and parameter information.The transformation model converts the loaded model information from PyTorch format to ONNX format and generates an ONNX model.The following steps are required to generate ONNX model: generate model input layer,generate model operation layer,generate model output layer,generate graph,and generate model.Save model is to serialize the generated ONNX model and save it to an ONNX file.This thesis also designed a direct calculation of the output feature shape,reduce the forward propagation reasoning times,improve the efficiency of the tool.The tool currently supports the transformation of nine common convolutional neural network operations,and can realize the transformation of neural network models composed of these nine operations,such as some classical neural network models: Le Net model,Alex Net model,Vgg model and Res Net model.At the end of the thesis,the performance of the tool is tested,including the validation of the transformed model structure and parameters,the validation of the transformed model accuracy and the validation of the transformed model efficiency.In this thesis,the validation dataset of ILSVRC2012 image classification dataset is used to verify the model.Experimental results show that the structure of the transformed model is consistent with the original model,the forward propagation result of the model is unchanged,and the prediction accuracy of the data set is the same,which proves the correctness of the transformation process.After comparison with the conversion tool provided by PyTorch,it was found that the ONNX model transformed by PyTorch achieved the consistency of forward propagation results,but changed the internal structure of the model.The official PyTorch tool does not convert Dropout and Batch Normalization operation.By changing the neighborhood operation,the transformed ONNX model is consistent with the forward propagation reasoning of PyTorch model.In addition,the conversion efficiency of the PyTorch2 ONNX tool implemented in this article is significantly better than that of the official PyTorch conversion tool.
Keywords/Search Tags:ONNX, PyTorch, Format Conversion, AlexNet, ResNet
PDF Full Text Request
Related items