parameters: (cls, inputs, y, model_name="sonnx")
return_statement: return graph_def
docstring: get onnx model from singa computational graph
          Args:
              inputs: a list of input tensors (each is initialized with a name)
          Args:
              y: a list of tensors, usually the outputs of the graph
          Returns: 
              the onnx model
docstring_summary: get onnx model from singa computational graph
          Args:
              inputs: a list of input tensors (each is initialized with a name)
          Args:
              y: a list of tensors, usually the outputs of the graph
          Returns: 
              the onnx model
docstring_tokens: get onnx model from singa computational graph Args : inputs : a list of input tensors ( each is initialized with a name ) Args : y : a list of tensors usually the outputs of the graph Returns : the onnx model
function: def singa_to_onnx_graph(cls, inputs, y, model_name="sonnx"):
          """
          get onnx model from singa computational graph
          Args:
              inputs: a list of input tensors (each is initialized with a name)
          Args:
              y: a list of tensors, usually the outputs of the graph
          Returns: 
              the onnx model
          """
          assert len(
              y
          ) == 1, "Not support multiple output now."  # assume there is only one output
          y = y[0]
  
          graph_def = GraphProto()
          graph_def.name = model_name
          topol, ws, ins = utils.post_order_recursive(y.creator, y)
  
          # prepare the input
          X = []
          for op_name, op_t in ins.items():
              op_t = inputs.pop(0)
              dtype = TensorProto.INT32 if op_t.dtype == tensor.int32 else TensorProto.FLOAT
              X.append(helper.make_tensor_value_info(op_name, dtype, op_t.shape))
  
          # prepare the output
          y_optype = cls._get_singa_op_type(y.creator)
          if y_optype in cls._bool_operators:
              y_dtype = cls._bool_operators[y_optype]
          elif y.dtype == tensor.int32:
              y_dtype = TensorProto.INT32
          else:
              y_dtype = TensorProto.FLOAT
          Y = [helper.make_tensor_value_info(y.name, y_dtype, y.shape)]
  
          # prepare the weight
          W = []
          for op_name, op_t in ws.items():
              dtype = TensorProto.INT32 if op_t.dtype == tensor.int32 else TensorProto.FLOAT
              wt = tensor.to_numpy(op_t)
              wt = numpy_helper.from_array(wt)
              wt.name = op_name
              W.append(wt)
              X.append(helper.make_tensor_value_info(op_name, dtype, op_t.shape))
  
          # iterate the node graph
          for op_name, op in topol.items():
              optype = cls._get_singa_op_type(op)
              if optype in cls._unhandled_operators:
                  cls.handle_special_ops(op, X, W)
              graph_def.node.extend(cls.singa_op_to_onnx_node(op, op_t))
  
          graph_def.input.extend(X)
          graph_def.output.extend(Y)
          graph_def.initializer.extend(W)
          return graph_def
function_tokens: def singa_to_onnx_graph ( cls , inputs , y , model_name = "sonnx" ) : assert len ( y ) == 1 , "Not support multiple output now." # assume there is only one output y = y [ 0 ] graph_def = GraphProto ( ) graph_def . name = model_name topol , ws , ins = utils . post_order_recursive ( y . creator , y ) # prepare the input X = [ ] for op_name , op_t in ins . items ( ) : op_t = inputs . pop ( 0 ) dtype = TensorProto . INT32 if op_t . dtype == tensor . int32 else TensorProto . FLOAT X . append ( helper . make_tensor_value_info ( op_name , dtype , op_t . shape ) ) # prepare the output y_optype = cls . _get_singa_op_type ( y . creator ) if y_optype in cls . _bool_operators : y_dtype = cls . _bool_operators [ y_optype ] elif y . dtype == tensor . int32 : y_dtype = TensorProto . INT32 else : y_dtype = TensorProto . FLOAT Y = [ helper . make_tensor_value_info ( y . name , y_dtype , y . shape ) ] # prepare the weight W = [ ] for op_name , op_t in ws . items ( ) : dtype = TensorProto . INT32 if op_t . dtype == tensor . int32 else TensorProto . FLOAT wt = tensor . to_numpy ( op_t ) wt = numpy_helper . from_array ( wt ) wt . name = op_name W . append ( wt ) X . append ( helper . make_tensor_value_info ( op_name , dtype , op_t . shape ) ) # iterate the node graph for op_name , op in topol . items ( ) : optype = cls . _get_singa_op_type ( op ) if optype in cls . _unhandled_operators : cls . handle_special_ops ( op , X , W ) graph_def . node . extend ( cls . singa_op_to_onnx_node ( op , op_t ) ) graph_def . input . extend ( X ) graph_def . output . extend ( Y ) graph_def . initializer . extend ( W ) return graph_def