ó ųĩČ[c@`s·dZddlmZddlmZddlmZddlmZddlZddlZddl m Z dd l m Z d d l mZd d lmZejd ed„ZdS(u/Exports an MXNet model to the ONNX model formati(tabsolute_import(tdivision(tprint_function(tunicode_literalsNi(t string_types(tsymboli(t MXNetGraph(t load_moduleu model.onnxcC`swyddlm}m}Wn!tk r=tddƒ‚nXtƒ}tj|ƒ} t|tƒrūt|tƒrūt j dƒt ||ƒ\} } |j | | ||j | d|ƒ} nUt|tjƒrt|tƒr|j ||||j | d|ƒ} n tdƒ‚|j| ƒ} t|dƒ@}| jƒ}|j|ƒt j d |ƒt j d |ƒWd QX|S( uExports the MXNet model file, passed as a parameter, into ONNX model. Accepts both symbol,parameter objects as well as json and params filepaths as input. Operator support and coverage - https://cwiki.apache.org/confluence/display/MXNET/MXNet-ONNX+Integration Parameters ---------- sym : str or symbol object Path to the json file or Symbol object params : str or symbol object Path to the params file or params dictionary. (Including both arg_params and aux_params) input_shape : List of tuple Input shape of the model e.g [(1,3,224,224)] input_type : data type Input data type e.g. np.float32 onnx_file_path : str Path where to save the generated onnx file verbose : Boolean If true will print logs of the model conversion Returns ------- onnx_file_path : str Onnx file path i(thelpertmappingu(Onnx and protobuf need to be installed. u6Instructions to install - https://github.com/onnx/onnxu1Converting json and weight file to sym and paramstverboseu6Input sym and params should either be files or objectsuwbuInput shape of the model %s u#Exported ONNX file %s saved to diskN(tonnxRR t ImportErrorRtnptdtypet isinstanceRtloggingtinfoRtcreate_onnx_graph_prototNP_TYPE_TO_TENSOR_TYPERtSymboltdictt ValueErrort make_modeltopentSerializeToStringtwrite(tsymtparamst input_shapet input_typetonnx_file_pathR RR t convertert data_formattsym_objt params_objt onnx_grapht onnx_modelt file_handlet serialized((sg/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/contrib/onnx/mx2onnx/export_model.pyt export_model#s2     !     (t__doc__t __future__RRRRRtnumpyR tbaseRtRt export_onnxRt_export_helperRtfloat32tFalseR((((sg/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/contrib/onnx/mx2onnx/export_model.pyts