parameters: (self, onnx_graph, shape_override)
return_statement: return [anakin_nodes, weights, outputs, output_node]
docstring: Load onnx graph and parse node
          :param onnx_graph:
          :param shape_override:
          :return:
docstring_summary: Load onnx graph and parse node
          :param onnx_graph:
          :param shape_override:
          :return:
docstring_tokens: Load onnx graph and parse node : param onnx_graph : : param shape_override : : return :
function: def _parse_onnx_node(self, onnx_graph, shape_override):
          """
          Load onnx graph and parse node
          :param onnx_graph:
          :param shape_override:
          :return:
          """
  
          # ignore the following attributes
          ignored_attr = ["unknown_rank", "_class", "Tidx", "Tshape", "use_cudnn_on_gpu", "Index",
                          "Tpaddings", "TI", "Tparams", "Tindices", "Tlen", "Tdim",
                          "dynamic_size", "element_shape", "Tmultiples", "output_dtype",
                          "Tblock_shape", "Tcrops", "index_type", "Taxis", "U",
                          "maxval", "Tout"]
          # some stats
          op_cnt = collections.Counter()
          attr_cnt = collections.Counter()
          anakin_nodes = {}
          dtypes = {}
  
          # find ops
          ops = onnx_graph.node
  
          # minimal conversion of attributes
          # print '***********node*******'
          for node in ops:
              attr = {}
              takeit = True
  
              for a in node.attribute:
                  attr_cnt[a.name] += 1
                  if a.type == 1: ##FLAOT
                      attr[a.name] = a.f
                  elif a.type == 2: #INT
                      attr[a.name] = int(a.i)
                  elif a.type == 3: #String
                      attr[a.name] = a.s
                  elif a.type == 4: #tensor
                      val_list = onnx_to_anakin_tensor(a.t)
                      attr[a.name] = val_list
                  elif a.type == 5: #graph
                      attr[a.name] = a.t
                  elif a.type == 6: #FLOATS
                      val_list = []
                      for val in a.floats:
                          val_list.append(val)
                      attr[a.name] = val_list
                  elif a.type == 7: #INTS
                      val_list = []
                      #print 'type: ', a.name, type(a.ints[0])
                      for val in a.ints:
                          val_list.append(int(val))
                      attr[a.name] = val_list
                  else:
                      print 'Error type: ', a.type, a
                      # attr[a.name] = a.auto_pad
                      exit(0)
  
              if takeit:
                  try:
                      #input_names = [i for i in node.input]
                      #output_names = [i for i in node.output]
                      # if node.name == '':
                      #    node.name = node.output[0]
                      name = node.name #name + '_' +
                      node.name = name + '_' + str(node.op_type) + '_' + str(op_cnt[node.op_type])
                      op_cnt[node.op_type] += 1
                      #print node_name
                      #node_name = node.output[0];
                      anakin_nodes[node.name] = {'name': node.name, 'type': node.op_type,
                                                 'input': [str(i) for i in node.input],
                                                 'output': [str(i) for i in node.output],
                                                 'onnx_attr': attr, 'visited': False, 'name:': False,
                                                 'shape': None, 'ak_type': None, 'ak_attr': {}}
                  except Exception as ex:
                      log.error("pass1 convert failed for %s, ex=%s", node, ex)
                      raise
          # print 'anakin_node', anakin_nodes
         # exit()
          #weights and bias
          graph = onnx_graph.initializer
          # print 'weights: ', graph
          weights = {}
          for init_ptr in graph:
              # print 'init_ptr: ', init_ptr.name
             #  print ('onnx_to_anakin_tensor: ')
              [data, shape, dtype] = onnx_to_anakin_tensor(init_ptr)
              # print ('end')
              anakin_tensor = {}
              # print'before', shape
              if len(shape) == 3:
                  # print'before', shape
                  shape.append(1)
                  a = shape[2]
                  shape[2] = 1
                  shape[3] = a
              anakin_tensor['shape'] = shape
              anakin_tensor['data'] = data
              anakin_tensor['dtype'] = dtype
  
              # print('**************initializer*******')
              # print ('shape: ', shape)
              # print('len: ', len(data))
              #attr[init_ptr.name] = anakin_tensor
              #anakin_nodes[init_ptr.name] = {'name': init_ptr.name, 'onnx_attr': attr, 'visited': False,
               #                               'shape':None, 'ak_type': None, 'ak_attr': {}}
              weights[init_ptr.name] = anakin_tensor
              # if init_ptr.name == 'OC2_DUMMY_3':
              #     print (init_ptr, type(data), data, shape, dtype)
              #     exit(0)
             # print 'name: ', init_ptr.name, dtype, shape,
  
              #print 'tensor: ',  anakin_tensor
              #exit()
          input_name = onnx_graph.input
          inputs = {}
          input_shape = {}
          in_cnt = 0
          # print '--------input---------'
          # print input_name
          for input_a in input_name:
              shape = []
              for dim in input_a.type.tensor_type.shape.dim:
                  shape.append(dim.dim_value)
              if len(shape) == 3:
                  # print 'before', shape
                  shape.append(1)
                  a = shape[2]
                  shape[2] = 1
                  shape[3] = a
                  # print'after', shape
              #attr["shape"] = shape
              if input_a.name.startswith('data') or (input_a.name == ('gpu_0/data_0')) \
                  or (input_a.name == '0') or (input_a.name == 'image'):
                  inputs[input_a.name] = shape
                  output_node = []
                  print 'input: ', input_a.name
                  for node in anakin_nodes.values():
                      for name in node['input']:
                          if name == input_a.name:
                              output_node.append(name) #(node_name)
                  #print 'out: ', output_node
                  node_name = str('input') + '_' + str(in_cnt)
                  # change inputs name in anakin nodes
                  '''
                  for node in anakin_nodes.values():
                      in_name = node['input']
                      for i in range(len(in_name)):
                          if in_name[i] == input_a.name:
                              in_name[i] = node_name
                  '''
  
                  anakin_nodes[node_name] = {'name': node_name, 'type': 'Input',
                                              'input': [], 'output': output_node,
                                              'onnx_attr': {}, 'visited': True,
                                              'shape': shape, 'ak_type': 'Input',
                                              'ak_attr': {'shape': shape}}
  
                  in_cnt += 1
              else:
                  # print 'name: ', input_a.name
                  input_shape[input_a.name] = shape
  
          output_name = onnx_graph.output
          outputs = {}
          for output_a in output_name:
              shape = []
              for dim in output_a.type.tensor_type.shape.dim:
                  shape.append(dim.dim_value)
              outputs[output_a.name] = shape
              input_node = []
              for node in anakin_nodes.values():
                  for name in node['output']:
                      if name == output_a.name:
                          input_node.append(name)
  
              anakin_nodes[output_a.name] = {'name': output_a.name, 'type': 'Output',
                                            'input': input_node,
                                            'output': [], 'onnx_attr': {}, 'visited': True,
                                            'shape': shape, 'ak_type': None, 'ak_attr': {}}
          #print 'weights', len(weights)
          #print 'weights', weights
          '''
          for node_name in anakin_nodes.keys():
              for node_out in output_name:
                  if node_name == node_out:
                      anakin_nodes[node_name]['output'] = []
          '''
          # change inputs outputs name
          self._change_inout_nodename(anakin_nodes, weights)
          # print 'anakin_node', anakin_nodes
  
          output_node = {}
          for node in anakin_nodes.values():
              for out_name in node['output']:
                  if out_name in outputs:
                      output_node[node['name']] = outputs[out_name]
                      # delete output
                      node['output'].pop()
              outnode = node['output']
              for i in range(len(outnode)):
                  if outnode[i] in outputs:
                      outnode.pop(i)
  
          #print 'inputs', inputs
          #print 'outputs', outputs
          return [anakin_nodes, weights, outputs, output_node]
function_tokens: def _parse_onnx_node ( self , onnx_graph , shape_override ) : # ignore the following attributes ignored_attr = [ "unknown_rank" , "_class" , "Tidx" , "Tshape" , "use_cudnn_on_gpu" , "Index" , "Tpaddings" , "TI" , "Tparams" , "Tindices" , "Tlen" , "Tdim" , "dynamic_size" , "element_shape" , "Tmultiples" , "output_dtype" , "Tblock_shape" , "Tcrops" , "index_type" , "Taxis" , "U" , "maxval" , "Tout" ] # some stats op_cnt = collections . Counter ( ) attr_cnt = collections . Counter ( ) anakin_nodes = { } dtypes = { } # find ops ops = onnx_graph . node # minimal conversion of attributes # print '***********node*******' for node in ops : attr = { } takeit = True for a in node . attribute : attr_cnt [ a . name ] += 1 if a . type == 1 : ##FLAOT attr [ a . name ] = a . f elif a . type == 2 : #INT attr [ a . name ] = int ( a . i ) elif a . type == 3 : #String attr [ a . name ] = a . s elif a . type == 4 : #tensor val_list = onnx_to_anakin_tensor ( a . t ) attr [ a . name ] = val_list elif a . type == 5 : #graph attr [ a . name ] = a . t elif a . type == 6 : #FLOATS val_list = [ ] for val in a . floats : val_list . append ( val ) attr [ a . name ] = val_list elif a . type == 7 : #INTS val_list = [ ] #print 'type: ', a.name, type(a.ints[0]) for val in a . ints : val_list . append ( int ( val ) ) attr [ a . name ] = val_list else : print 'Error type: ' , a . type , a # attr[a.name] = a.auto_pad exit ( 0 ) if takeit : try : #input_names = [i for i in node.input] #output_names = [i for i in node.output] # if node.name == '': #    node.name = node.output[0] name = node . name #name + '_' + node . name = name + '_' + str ( node . op_type ) + '_' + str ( op_cnt [ node . op_type ] ) op_cnt [ node . op_type ] += 1 #print node_name #node_name = node.output[0]; anakin_nodes [ node . name ] = { 'name' : node . name , 'type' : node . op_type , 'input' : [ str ( i ) for i in node . input ] , 'output' : [ str ( i ) for i in node . output ] , 'onnx_attr' : attr , 'visited' : False , 'name:' : False , 'shape' : None , 'ak_type' : None , 'ak_attr' : { } } except Exception as ex : log . error ( "pass1 convert failed for %s, ex=%s" , node , ex ) raise # print 'anakin_node', anakin_nodes # exit() #weights and bias graph = onnx_graph . initializer # print 'weights: ', graph weights = { } for init_ptr in graph : # print 'init_ptr: ', init_ptr.name #  print ('onnx_to_anakin_tensor: ') [ data , shape , dtype ] = onnx_to_anakin_tensor ( init_ptr ) # print ('end') anakin_tensor = { } # print'before', shape if len ( shape ) == 3 : # print'before', shape shape . append ( 1 ) a = shape [ 2 ] shape [ 2 ] = 1 shape [ 3 ] = a anakin_tensor [ 'shape' ] = shape anakin_tensor [ 'data' ] = data anakin_tensor [ 'dtype' ] = dtype # print('**************initializer*******') # print ('shape: ', shape) # print('len: ', len(data)) #attr[init_ptr.name] = anakin_tensor #anakin_nodes[init_ptr.name] = {'name': init_ptr.name, 'onnx_attr': attr, 'visited': False, #                               'shape':None, 'ak_type': None, 'ak_attr': {}} weights [ init_ptr . name ] = anakin_tensor # if init_ptr.name == 'OC2_DUMMY_3': #     print (init_ptr, type(data), data, shape, dtype) #     exit(0) # print 'name: ', init_ptr.name, dtype, shape, #print 'tensor: ',  anakin_tensor #exit() input_name = onnx_graph . input inputs = { } input_shape = { } in_cnt = 0 # print '--------input---------' # print input_name for input_a in input_name : shape = [ ] for dim in input_a . type . tensor_type . shape . dim : shape . append ( dim . dim_value ) if len ( shape ) == 3 : # print 'before', shape shape . append ( 1 ) a = shape [ 2 ] shape [ 2 ] = 1 shape [ 3 ] = a # print'after', shape #attr["shape"] = shape if input_a . name . startswith ( 'data' ) or ( input_a . name == ( 'gpu_0/data_0' ) ) or ( input_a . name == '0' ) or ( input_a . name == 'image' ) : inputs [ input_a . name ] = shape output_node = [ ] print 'input: ' , input_a . name for node in anakin_nodes . values ( ) : for name in node [ 'input' ] : if name == input_a . name : output_node . append ( name ) #(node_name) #print 'out: ', output_node node_name = str ( 'input' ) + '_' + str ( in_cnt ) # change inputs name in anakin nodes '''
                  for node in anakin_nodes.values():
                      in_name = node['input']
                      for i in range(len(in_name)):
                          if in_name[i] == input_a.name:
                              in_name[i] = node_name
                  ''' anakin_nodes [ node_name ] = { 'name' : node_name , 'type' : 'Input' , 'input' : [ ] , 'output' : output_node , 'onnx_attr' : { } , 'visited' : True , 'shape' : shape , 'ak_type' : 'Input' , 'ak_attr' : { 'shape' : shape } } in_cnt += 1 else : # print 'name: ', input_a.name input_shape [ input_a . name ] = shape output_name = onnx_graph . output outputs = { } for output_a in output_name : shape = [ ] for dim in output_a . type . tensor_type . shape . dim : shape . append ( dim . dim_value ) outputs [ output_a . name ] = shape input_node = [ ] for node in anakin_nodes . values ( ) : for name in node [ 'output' ] : if name == output_a . name : input_node . append ( name ) anakin_nodes [ output_a . name ] = { 'name' : output_a . name , 'type' : 'Output' , 'input' : input_node , 'output' : [ ] , 'onnx_attr' : { } , 'visited' : True , 'shape' : shape , 'ak_type' : None , 'ak_attr' : { } } #print 'weights', len(weights) #print 'weights', weights '''
          for node_name in anakin_nodes.keys():
              for node_out in output_name:
                  if node_name == node_out:
                      anakin_nodes[node_name]['output'] = []
          ''' # change inputs outputs name self . _change_inout_nodename ( anakin_nodes , weights ) # print 'anakin_node', anakin_nodes output_node = { } for node in anakin_nodes . values ( ) : for out_name in node [ 'output' ] : if out_name in outputs : output_node [ node [ 'name' ] ] = outputs [ out_name ] # delete output node [ 'output' ] . pop ( ) outnode = node [ 'output' ] for i in range ( len ( outnode ) ) : if outnode [ i ] in outputs : outnode . pop ( i ) #print 'inputs', inputs #print 'outputs', outputs return [ anakin_nodes , weights , outputs , output_node ]