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

Function _read_file

tensorflow/python/framework/meta_graph.py:106–135  ·  view source on GitHub ↗

Reads a file containing `GraphDef` and returns the protocol buffer. Args: filename: `graph_def` filename including the path. Returns: A `GraphDef` protocol buffer. Raises: IOError: If the file doesn't exist, or cannot be successfully parsed.

(filename)

Source from the content-addressed store, hash-verified

104
105
106def _read_file(filename):
107 """Reads a file containing `GraphDef` and returns the protocol buffer.
108
109 Args:
110 filename: `graph_def` filename including the path.
111
112 Returns:
113 A `GraphDef` protocol buffer.
114
115 Raises:
116 IOError: If the file doesn't exist, or cannot be successfully parsed.
117 """
118 graph_def = graph_pb2.GraphDef()
119 if not file_io.file_exists(filename):
120 raise IOError("File %s does not exist." % filename)
121 # First try to read it as a binary file.
122 file_content = file_io.FileIO(filename, "rb").read()
123 try:
124 graph_def.ParseFromString(file_content)
125 return graph_def
126 except Exception: # pylint: disable=broad-except
127 pass
128
129 # Next try to read it as a text file.
130 try:
131 text_format.Merge(file_content, graph_def)
132 except text_format.ParseError as e:
133 raise IOError("Cannot parse file %s: %s." % (filename, str(e)))
134
135 return graph_def
136
137
138def ops_used_by_graph_def(graph_def):

Callers

nothing calls this directly

Calls 4

IOErrorFunction · 0.85
readMethod · 0.45
ParseFromStringMethod · 0.45
MergeMethod · 0.45

Tested by

no test coverage detected