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

Function RemoveAttribute

tensorflow/tools/graph_transforms/remove_attribute.cc:30–64  ·  view source on GitHub ↗

Deletes a given attribute from the specified nodes.

Source from the content-addressed store, hash-verified

28
29// Deletes a given attribute from the specified nodes.
30Status 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
66REGISTER_GRAPH_TRANSFORM("remove_attribute", RemoveAttribute);
67

Callers 1

TestRemoveAttributeMethod · 0.70

Calls 10

InvalidArgumentFunction · 0.85
attrMethod · 0.80
countMethod · 0.45
sizeMethod · 0.45
atMethod · 0.45
ClearMethod · 0.45
nodeMethod · 0.45
AddMethod · 0.45
opMethod · 0.45
eraseMethod · 0.45

Tested by 1

TestRemoveAttributeMethod · 0.56