parameters: (graph, proto, model)
return_statement: return {fake_node_name: shape for (fake_node_name, shape) in zip(input_names, input_dims)}
docstring: Converts proto/model layers to a graph. Edges are restored by bottom/top attributes.
      Graph nodes has two attributes: pb for prototxt definition and model_pb for caffemodel definition.
  
      Parameters
      ----------
      proto : NetParameter
         Protobuf message for NetParameter, representing .prototxt.
      model : NetParameter
         Protobuf message for NetParameter, representing .caffemodel.
  
      Returns
      ----------
          Graph
          built NX Directed graph.
docstring_summary: Converts proto/model layers to a graph. Edges are restored by bottom/top attributes.
      Graph nodes has two attributes: pb for prototxt definition and model_pb for caffemodel definition.
docstring_tokens: Converts proto / model layers to a graph . Edges are restored by bottom / top attributes . Graph nodes has two attributes : pb for prototxt definition and model_pb for caffemodel definition .
function: def caffe_pb_to_nx(graph, proto, model):
      """
      Converts proto/model layers to a graph. Edges are restored by bottom/top attributes.
      Graph nodes has two attributes: pb for prototxt definition and model_pb for caffemodel definition.
  
      Parameters
      ----------
      proto : NetParameter
         Protobuf message for NetParameter, representing .prototxt.
      model : NetParameter
         Protobuf message for NetParameter, representing .caffemodel.
  
      Returns
      ----------
          Graph
          built NX Directed graph.
      """
      # Blobs in prototxt model can be reused by inplace layer.
      # This requires loading of pb layers in order and tracking the latest
      # layer that writes a particular blob.
      blob_producers = {}  # maps layer blob name to node id in graph, port and layer name
      proto_layers = get_layers(proto)
      model_layers = None
      if model:
          model_layers = get_layers(model)
  
      input_dims = []
      input_names = []
      if len(proto.input_dim) > 0 and len(list(proto.input)) > 1:
          # example of proto input
          # input: "data"
          # input_dim: 1
          # input_dim: 3
          # input_dim: 500
          # input_dim: 500
          # input: "info"
          # input_dim: 1
          # input_dim: 3
          raise Error('Old-style inputs (via "input_dims") are not supported. ' +
                      'Please specify inputs via  "input_shape". ' +
                      refer_to_faq_msg(8))
      elif len(list(proto.input)) == 1 and len(list(proto.input_dim)):
          # example of proto input
          # input: "data"
          # input_dim: 1
          # input_dim: 3
          # input_dim: 500
          # input_dim: 500
          input_dims = [int64_array(list(proto.input_dim))]
          input_names = [proto.input[0]]
  
      elif len(list(proto.input)) == 1 and len(list(proto.input_shape)):
          # example of proto input
          # input: "data"
          # input_shape
          # {
          #     dim: 1
          #     dim: 3
          #     dim: 227
          #     dim: 227
          # }
          input_dims = [int64_array(proto.input_shape[0].dim)]
          input_names = [proto.input[0]]
  
      elif len(proto.input_shape) > 0:
          # example of proto input
          # input: "data"
          # input_shape
          # {
          #     dim: 1
          #     dim: 3
          #     dim: 600
          #     dim: 1000
          # }
          # input: "im_info"
          # input_shape
          # {
          #     dim: 1
          #     dim: 3
          # }
          for i in range(len(proto.input_shape)):
              input_dims.append(int64_array(proto.input_shape[i].dim))
              input_names.append(proto.input[i])
  
      for i in range(len(input_names)):
          input_name = input_names[i]
          input_dim = input_dims[i]
          # Input is defined at the top level of proto instead of distinct Input layer
          graph.add_node(input_name, pb=None, model_pb=None, type='GlobalInput', name=input_name, shape=input_dim,
                         kind='op')
          blob_producers[input_name] = (input_name, 0, input_name)
  
      used_blobs = set()
      for i, layer in enumerate(proto_layers):
  
          model_layer = None
  
          if model_layers:
              for ml in model_layers:
                  if ml.name == layer.name:
                      model_layer = ml
                      break
          if layer.type == 'Input':
              if hasattr(layer, 'input_param'):
                  input_param = layer.input_param
              else:
                  raise Error('Input layer has no input dims. ' +
                              refer_to_faq_msg(8))
              if hasattr(input_param, 'shape'):
                  """
                  example of proto input
                  layer
                  {
                      name: "data"
                      type: "Input"
                      top: "data"
                      input_param {shape: {dim: 1 dim: 3 dim: 600 dim: 1000}}
                  }
  
                  layer
                  {
                      name: "im_info"
                      type: "Input"
                      top: "im_info"
                      input_param {shape: {dim: 1 dim: 3}}
                  }
                  """
                  dims = map(int, list(filter(None, str(list(input_param.shape)[0]).split('dim:'))))
                  input_dims.append(int64_array(list(dims)))
                  input_names.append(layer.name)
  
          node_id = graph.unique_id(layer.name)
          graph.add_node(node_id, pb=layer, model_pb=model_layer, kind='op', type='Parameter')
          if hasattr(graph, 'op_names_statistic') and hasattr(layer, 'type'):
              graph.op_names_statistic[layer.type] += 1
  
          # connect inputs based on blob_producers dictionary
          for dst_port, bottom in enumerate(layer.bottom):
              add_edge_caffe(graph, bottom, node_id, blob_producers, dst_port)
              used_blobs.add(bottom)
  
          # update blob producers dictionary by output ports
          for src_port, top in enumerate(layer.top):
              if top in blob_producers:
                  log.debug("Detected reuse of blob {} by layer {}".format(top, node_id))
              blob_producers[top] = (node_id, src_port, layer.name)
  
      # Tensor names information corresponding to a node is stored on outgoing edges.
      # As output nodes do not have outgoing edges, fake outputs are required. In the following code
      # for each output Identity node is added, and tensor name for the output is kept
      # on (output, fake output) edge. After Result nodes adding transformation fake outputs
      # are deleted from graph.
      all_blobs = set(blob_producers.keys())
      add_outputs_identity(graph, all_blobs - used_blobs, add_edge_caffe,
                           {'blob_producers': blob_producers, 'dst_port': 0})
  
      if len(input_names) <= 0:
          raise Error('The topology contains no "input" layers. ' +
                      refer_to_faq_msg(79))
      return {fake_node_name: shape for (fake_node_name, shape) in zip(input_names, input_dims)}
function_tokens: def caffe_pb_to_nx ( graph , proto , model ) : # Blobs in prototxt model can be reused by inplace layer. # This requires loading of pb layers in order and tracking the latest # layer that writes a particular blob. blob_producers = { } # maps layer blob name to node id in graph, port and layer name proto_layers = get_layers ( proto ) model_layers = None if model : model_layers = get_layers ( model ) input_dims = [ ] input_names = [ ] if len ( proto . input_dim ) > 0 and len ( list ( proto . input ) ) > 1 : # example of proto input # input: "data" # input_dim: 1 # input_dim: 3 # input_dim: 500 # input_dim: 500 # input: "info" # input_dim: 1 # input_dim: 3 raise Error ( 'Old-style inputs (via "input_dims") are not supported. ' + 'Please specify inputs via  "input_shape". ' + refer_to_faq_msg ( 8 ) ) elif len ( list ( proto . input ) ) == 1 and len ( list ( proto . input_dim ) ) : # example of proto input # input: "data" # input_dim: 1 # input_dim: 3 # input_dim: 500 # input_dim: 500 input_dims = [ int64_array ( list ( proto . input_dim ) ) ] input_names = [ proto . input [ 0 ] ] elif len ( list ( proto . input ) ) == 1 and len ( list ( proto . input_shape ) ) : # example of proto input # input: "data" # input_shape # { #     dim: 1 #     dim: 3 #     dim: 227 #     dim: 227 # } input_dims = [ int64_array ( proto . input_shape [ 0 ] . dim ) ] input_names = [ proto . input [ 0 ] ] elif len ( proto . input_shape ) > 0 : # example of proto input # input: "data" # input_shape # { #     dim: 1 #     dim: 3 #     dim: 600 #     dim: 1000 # } # input: "im_info" # input_shape # { #     dim: 1 #     dim: 3 # } for i in range ( len ( proto . input_shape ) ) : input_dims . append ( int64_array ( proto . input_shape [ i ] . dim ) ) input_names . append ( proto . input [ i ] ) for i in range ( len ( input_names ) ) : input_name = input_names [ i ] input_dim = input_dims [ i ] # Input is defined at the top level of proto instead of distinct Input layer graph . add_node ( input_name , pb = None , model_pb = None , type = 'GlobalInput' , name = input_name , shape = input_dim , kind = 'op' ) blob_producers [ input_name ] = ( input_name , 0 , input_name ) used_blobs = set ( ) for i , layer in enumerate ( proto_layers ) : model_layer = None if model_layers : for ml in model_layers : if ml . name == layer . name : model_layer = ml break if layer . type == 'Input' : if hasattr ( layer , 'input_param' ) : input_param = layer . input_param else : raise Error ( 'Input layer has no input dims. ' + refer_to_faq_msg ( 8 ) ) if hasattr ( input_param , 'shape' ) : """
                  example of proto input
                  layer
                  {
                      name: "data"
                      type: "Input"
                      top: "data"
                      input_param {shape: {dim: 1 dim: 3 dim: 600 dim: 1000}}
                  }
  
                  layer
                  {
                      name: "im_info"
                      type: "Input"
                      top: "im_info"
                      input_param {shape: {dim: 1 dim: 3}}
                  }
                  """ dims = map ( int , list ( filter ( None , str ( list ( input_param . shape ) [ 0 ] ) . split ( 'dim:' ) ) ) ) input_dims . append ( int64_array ( list ( dims ) ) ) input_names . append ( layer . name ) node_id = graph . unique_id ( layer . name ) graph . add_node ( node_id , pb = layer , model_pb = model_layer , kind = 'op' , type = 'Parameter' ) if hasattr ( graph , 'op_names_statistic' ) and hasattr ( layer , 'type' ) : graph . op_names_statistic [ layer . type ] += 1 # connect inputs based on blob_producers dictionary for dst_port , bottom in enumerate ( layer . bottom ) : add_edge_caffe ( graph , bottom , node_id , blob_producers , dst_port ) used_blobs . add ( bottom ) # update blob producers dictionary by output ports for src_port , top in enumerate ( layer . top ) : if top in blob_producers : log . debug ( "Detected reuse of blob {} by layer {}" . format ( top , node_id ) ) blob_producers [ top ] = ( node_id , src_port , layer . name ) # Tensor names information corresponding to a node is stored on outgoing edges. # As output nodes do not have outgoing edges, fake outputs are required. In the following code # for each output Identity node is added, and tensor name for the output is kept # on (output, fake output) edge. After Result nodes adding transformation fake outputs # are deleted from graph. all_blobs = set ( blob_producers . keys ( ) ) add_outputs_identity ( graph , all_blobs - used_blobs , add_edge_caffe , { 'blob_producers' : blob_producers , 'dst_port' : 0 } ) if len ( input_names ) <= 0 : raise Error ( 'The topology contains no "input" layers. ' + refer_to_faq_msg ( 79 ) ) return { fake_node_name : shape for ( fake_node_name , shape ) in zip ( input_names , input_dims ) }