Create a `NodeDef` proto with export_scope stripped. Args: from_node_def: A `node_def_pb2.NodeDef` protocol buffer. export_scope: A `string` representing the name scope to remove. unbound_inputs: An array of unbound input names if they exist. clear_devices: Boolean which controls
(from_node_def, export_scope, unbound_inputs, clear_devices=False)
| 56 | |
| 57 | |
| 58 | def _node_def(from_node_def, export_scope, unbound_inputs, clear_devices=False): |
| 59 | """Create a `NodeDef` proto with export_scope stripped. |
| 60 | |
| 61 | Args: |
| 62 | from_node_def: A `node_def_pb2.NodeDef` protocol buffer. |
| 63 | export_scope: A `string` representing the name scope to remove. |
| 64 | unbound_inputs: An array of unbound input names if they exist. |
| 65 | clear_devices: Boolean which controls whether to clear device information |
| 66 | from node_def. Default false. |
| 67 | |
| 68 | Returns: |
| 69 | A `node_def_pb2.NodeDef` protocol buffer. |
| 70 | """ |
| 71 | node_def = copy.deepcopy(from_node_def) |
| 72 | for i, v in enumerate(node_def.input): |
| 73 | if (export_scope and |
| 74 | not node_def.input[i].lstrip("^").startswith(export_scope)): |
| 75 | # Adds "$unbound_inputs_" prefix to the unbound name so they are easily |
| 76 | # identifiable. |
| 77 | node_def.input[i] = re.sub(r"([\^]|^)(.*)", |
| 78 | r"\1" + _UNBOUND_INPUT_PREFIX + r"\2", |
| 79 | compat.as_str(v)) |
| 80 | unbound_inputs.append(node_def.input[i]) |
| 81 | else: |
| 82 | node_def.input[i] = ops.strip_name_scope(v, export_scope) |
| 83 | node_def.name = compat.as_bytes( |
| 84 | ops.strip_name_scope(from_node_def.name, export_scope)) |
| 85 | for k, v in six.iteritems(from_node_def.attr): |
| 86 | if k == "_class": |
| 87 | new_s = [compat.as_bytes( |
| 88 | ops.strip_name_scope(s, export_scope)) for s in v.list.s |
| 89 | if not export_scope or |
| 90 | compat.as_str(s).split("@")[1].startswith(export_scope)] |
| 91 | node_def.attr[k].CopyFrom(attr_value_pb2.AttrValue( |
| 92 | list=attr_value_pb2.AttrValue.ListValue(s=new_s))) |
| 93 | elif node_def.op in ("Enter", "RefEnter") and k == "frame_name": |
| 94 | if not export_scope or compat.as_str(v.s).startswith(export_scope): |
| 95 | new_s = compat.as_bytes(ops.strip_name_scope(v.s, export_scope)) |
| 96 | node_def.attr[k].CopyFrom(attr_value_pb2.AttrValue(s=new_s)) |
| 97 | else: |
| 98 | node_def.attr[k].CopyFrom(v) |
| 99 | |
| 100 | if clear_devices: |
| 101 | node_def.device = "" |
| 102 | |
| 103 | return node_def |
| 104 | |
| 105 | |
| 106 | def _read_file(filename): |
no test coverage detected