Deletes a given attribute from the specified nodes.
| 28 | |
| 29 | // Deletes a given attribute from the specified nodes. |
| 30 | Status RemoveAttribute(const GraphDef& input_graph_def, |
| 31 | const TransformFuncContext& context, |
| 32 | GraphDef* output_graph_def) { |
| 33 | if (!context.params.count("attribute_name") || |
| 34 | (context.params.at("attribute_name").size() != 1)) { |
| 35 | return errors::InvalidArgument( |
| 36 | "remove_attribute expects exactly one 'attribute_name' " |
| 37 | "argument, e.g. remove_attribute(op_name=Mul, attribute_name=foo)"); |
| 38 | } |
| 39 | |
| 40 | string op_name; |
| 41 | if (context.params.count("op_name")) { |
| 42 | if (context.params.at("op_name").size() != 1) { |
| 43 | return errors::InvalidArgument( |
| 44 | "remove_attribute expects a single op_name argument, but found ", |
| 45 | context.params.at("op_name").size()); |
| 46 | } |
| 47 | op_name = context.params.at("op_name")[0]; |
| 48 | } else { |
| 49 | op_name = "*"; |
| 50 | } |
| 51 | |
| 52 | const string attribute_name = context.params.at("attribute_name")[0]; |
| 53 | output_graph_def->Clear(); |
| 54 | for (const NodeDef& node : input_graph_def.node()) { |
| 55 | NodeDef* new_node = output_graph_def->mutable_node()->Add(); |
| 56 | *new_node = node; |
| 57 | if (((op_name == "*") || (op_name == node.op())) && |
| 58 | (node.attr().count(attribute_name))) { |
| 59 | new_node->mutable_attr()->erase(attribute_name); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | return Status::OK(); |
| 64 | } |
| 65 | |
| 66 | REGISTER_GRAPH_TRANSFORM("remove_attribute", RemoveAttribute); |
| 67 |