Type-checks and possibly canonicalizes `graph_def`.
(graph_def, op_dict)
| 84 | |
| 85 | |
| 86 | def _ProcessGraphDefParam(graph_def, op_dict): |
| 87 | """Type-checks and possibly canonicalizes `graph_def`.""" |
| 88 | if not isinstance(graph_def, graph_pb2.GraphDef): |
| 89 | # `graph_def` could be a dynamically-created message, so try a duck-typed |
| 90 | # approach |
| 91 | try: |
| 92 | old_graph_def = graph_def |
| 93 | graph_def = graph_pb2.GraphDef() |
| 94 | graph_def.MergeFrom(old_graph_def) |
| 95 | except TypeError: |
| 96 | raise TypeError('graph_def must be a GraphDef proto.') |
| 97 | else: |
| 98 | # If we're using the graph_def provided by the caller, modify graph_def |
| 99 | # in-place to add attr defaults to the NodeDefs (this is visible to the |
| 100 | # caller). |
| 101 | # NOTE(skyewm): this is undocumented behavior that at least meta_graph.py |
| 102 | # depends on. It might make sense to move this to meta_graph.py and have |
| 103 | # import_graph_def not modify the graph_def argument (we'd have to make sure |
| 104 | # this doesn't break anything else.) |
| 105 | for node in graph_def.node: |
| 106 | if node.op not in op_dict: |
| 107 | # Assume unrecognized ops are functions for now. TF_ImportGraphDef will |
| 108 | # report an error if the op is actually missing. |
| 109 | continue |
| 110 | op_def = op_dict[node.op] |
| 111 | _SetDefaultAttrValues(node, op_def) |
| 112 | |
| 113 | return graph_def |
| 114 | |
| 115 | |
| 116 | def _ProcessInputMapParam(input_map): |
no test coverage detected