Пример #1
0
def graphdef_to_pbtxt(filename):
  with gfile.FastGFile(filename, 'rb') as f:
    graph_def = tf.GraphDef()
    graph_def.ParseFromString(f.read())
    tf.import_graph_def(graph_def, name='')
    tf.train.write_graph(graph_def, 'pbtxt/', 'protobuf.pbtxt', as_text=True)
  return
Пример #2
0
def pbtxt_to_graphdef(filename):
  with open(filename, 'r') as f:
    graph_def = tf.GraphDef()
    file_content = f.read()
    text_format.Merge(file_content, graph_def)
    tf.import_graph_def(graph_def, name='')
    tf.train.write_graph(graph_def, 'pbtxt/', 'protobuf.pb', as_text=False)
Пример #3
0
def pb_to_pbtxt(filename):
    assert filename.suffix == '.pb'
    with filename.open('rb') as f:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(f.read())

        tf.import_graph_def(graph_def, name='')
        tf.train.write_graph(graph_def, dump_dir, 'graph.pbtxt', as_text=True)
    return
Пример #4
0
def pbtxt_to_pb(filename):
    assert filename.suffix == '.pbtxt'
    with filename.open('r') as f:
        graph_def = tf.GraphDef()

        file_content = f.read()
        text_format.Merge(file_content, graph_def)

        tf.import_graph_def(graph_def, name='')
        tf.train.write_graph(graph_def, dump_dir, 'graph.pb', as_text=False)
Пример #5
0
def load_frozen_graph(frozen_graph_filename, print_op=False):
    """load a graph from protocol buffer file"""
    # We load the protobuf file from the disk and parse it to retrieve the
    # unserialized graph_def
    with tf.gfile.GFile(frozen_graph_filename, "rb") as in_f:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(in_f.read())

    # Then, we import the graph_def into a new Graph and returns it
    with tf.Graph().as_default() as graph:  #pylint: disable=not-context-manager
        # The name var will prefix every op/nodes in your graph
        # Since we load everything in a new graph, this is not needed
        tf.import_graph_def(graph_def,
                            input_map=None,
                            return_elements=None,
                            name="",
                            op_dict=None,
                            producer_op_list=None)
        if print_op:
            print_ops(graph, prefix='load_frozen_graph')
    return graph