Reads a file containing `MetaGraphDef` and returns the protocol buffer. Args: filename: `meta_graph_def` filename including the path. Returns: A `MetaGraphDef` protocol buffer. Raises: IOError: If the file doesn't exist, or cannot be successfully parsed.
(filename)
| 624 | |
| 625 | |
| 626 | def read_meta_graph_file(filename): |
| 627 | """Reads a file containing `MetaGraphDef` and returns the protocol buffer. |
| 628 | |
| 629 | Args: |
| 630 | filename: `meta_graph_def` filename including the path. |
| 631 | |
| 632 | Returns: |
| 633 | A `MetaGraphDef` protocol buffer. |
| 634 | |
| 635 | Raises: |
| 636 | IOError: If the file doesn't exist, or cannot be successfully parsed. |
| 637 | """ |
| 638 | meta_graph_def = meta_graph_pb2.MetaGraphDef() |
| 639 | if not file_io.file_exists(filename): |
| 640 | raise IOError("File %s does not exist." % filename) |
| 641 | # First try to read it as a binary file. |
| 642 | file_content = file_io.FileIO(filename, "rb").read() |
| 643 | try: |
| 644 | meta_graph_def.ParseFromString(file_content) |
| 645 | return meta_graph_def |
| 646 | except Exception: # pylint: disable=broad-except |
| 647 | pass |
| 648 | |
| 649 | # Next try to read it as a text file. |
| 650 | try: |
| 651 | text_format.Merge(file_content.decode("utf-8"), meta_graph_def) |
| 652 | except text_format.ParseError as e: |
| 653 | raise IOError("Cannot parse file %s: %s." % (filename, str(e))) |
| 654 | |
| 655 | return meta_graph_def |
| 656 | |
| 657 | |
| 658 | def import_scoped_meta_graph(meta_graph_or_file, |
no test coverage detected