Removes unknown default attrs according to `producer_op_list`. Removes any unknown attrs in `graph_def` (i.e. attrs that do not appear in the OpDefs in `op_dict`) that have a default value in `producer_op_list`. Args: op_dict: dict mapping operation name to OpDef. producer_op_list: O
(op_dict, producer_op_list, graph_def)
| 143 | |
| 144 | |
| 145 | def _RemoveDefaultAttrs(op_dict, producer_op_list, graph_def): |
| 146 | """Removes unknown default attrs according to `producer_op_list`. |
| 147 | |
| 148 | Removes any unknown attrs in `graph_def` (i.e. attrs that do not appear in |
| 149 | the OpDefs in `op_dict`) that have a default value in `producer_op_list`. |
| 150 | |
| 151 | Args: |
| 152 | op_dict: dict mapping operation name to OpDef. |
| 153 | producer_op_list: OpList proto. |
| 154 | graph_def: GraphDef proto |
| 155 | """ |
| 156 | producer_op_dict = {op.name: op for op in producer_op_list.op} |
| 157 | for node in graph_def.node: |
| 158 | # Remove any default attr values that aren't in op_def. |
| 159 | if (node.op in producer_op_dict |
| 160 | # Some custom op registrations won't show up here. That's OK, attribute |
| 161 | # stripping just won't be available. |
| 162 | and node.op in op_dict): |
| 163 | op_def = op_dict[node.op] |
| 164 | producer_op_def = producer_op_dict[node.op] |
| 165 | # We make a copy of node.attr to iterate through since we may modify |
| 166 | # node.attr inside the loop. |
| 167 | for key in list(node.attr): |
| 168 | if _FindAttrInOpDef(key, op_def) is None: |
| 169 | # No attr_def in consumer, look in producer. |
| 170 | attr_def = _FindAttrInOpDef(key, producer_op_def) |
| 171 | if (attr_def and attr_def.HasField('default_value') and |
| 172 | node.attr[key] == attr_def.default_value): |
| 173 | # Unknown attr had default value in producer, delete it so it can be |
| 174 | # understood by consumer. |
| 175 | del node.attr[key] |
| 176 | |
| 177 | |
| 178 | def _ConvertInputMapValues(name, input_map): |
no test coverage detected