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

Function read_meta_graph_file

tensorflow/python/framework/meta_graph.py:626–655  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

624
625
626def 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
658def import_scoped_meta_graph(meta_graph_or_file,

Calls 5

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

Tested by

no test coverage detected