MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / write_graph

Function write_graph

tensorflow/python/framework/graph_io.py:31–75  ·  view source on GitHub ↗

Writes a graph proto to a file. The graph is written as a text proto unless `as_text` is `False`. ```python v = tf.Variable(0, name='my_variable') sess = tf.compat.v1.Session() tf.io.write_graph(sess.graph_def, '/tmp/my-model', 'train.pbtxt') ``` or ```python v = tf.Variable(0,

(graph_or_graph_def, logdir, name, as_text=True)

Source from the content-addressed store, hash-verified

29
30@tf_export('io.write_graph', v1=['io.write_graph', 'train.write_graph'])
31def write_graph(graph_or_graph_def, logdir, name, as_text=True):
32 """Writes a graph proto to a file.
33
34 The graph is written as a text proto unless `as_text` is `False`.
35
36 ```python
37 v = tf.Variable(0, name='my_variable')
38 sess = tf.compat.v1.Session()
39 tf.io.write_graph(sess.graph_def, '/tmp/my-model', 'train.pbtxt')
40 ```
41
42 or
43
44 ```python
45 v = tf.Variable(0, name='my_variable')
46 sess = tf.compat.v1.Session()
47 tf.io.write_graph(sess.graph, '/tmp/my-model', 'train.pbtxt')
48 ```
49
50 Args:
51 graph_or_graph_def: A `Graph` or a `GraphDef` protocol buffer.
52 logdir: Directory where to write the graph. This can refer to remote
53 filesystems, such as Google Cloud Storage (GCS).
54 name: Filename for the graph.
55 as_text: If `True`, writes the graph as an ASCII proto.
56
57 Returns:
58 The path of the output proto file.
59 """
60 if isinstance(graph_or_graph_def, ops.Graph):
61 graph_def = graph_or_graph_def.as_graph_def()
62 else:
63 graph_def = graph_or_graph_def
64
65 # gcs does not have the concept of directory at the moment.
66 if not file_io.file_exists(logdir) and not logdir.startswith('gs:'):
67 file_io.recursive_create_dir(logdir)
68 path = os.path.join(logdir, name)
69 if as_text:
70 file_io.atomic_write_string_to_file(path,
71 text_format.MessageToString(
72 graph_def, float_format=''))
73 else:
74 file_io.atomic_write_string_to_file(path, graph_def.SerializeToString())
75 return path

Callers 7

testFloatMethod · 0.50
testFreezeGraphMethod · 0.50
testPbtxtMethod · 0.50
testGraphDebugInfoMethod · 0.50
_saveFrozenGraphMethod · 0.50

Calls 3

as_graph_defMethod · 0.80
joinMethod · 0.45
SerializeToStringMethod · 0.45

Tested by 7

testFloatMethod · 0.40
testFreezeGraphMethod · 0.40
testPbtxtMethod · 0.40
testGraphDebugInfoMethod · 0.40
_saveFrozenGraphMethod · 0.40