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)
| 104 | |
| 105 | |
| 106 | def _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 | |
| 138 | def ops_used_by_graph_def(graph_def): |
nothing calls this directly
no test coverage detected