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

Function RenameAttribute

tensorflow/tools/graph_transforms/rename_attribute.cc:29–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27namespace graph_transforms {
28
29Status RenameAttribute(const GraphDef& input_graph_def,
30 const TransformFuncContext& context,
31 GraphDef* output_graph_def) {
32 if (!context.params.count("old_attribute_name") ||
33 (context.params.at("old_attribute_name").size() != 1) ||
34 !context.params.count("new_attribute_name") ||
35 (context.params.at("new_attribute_name").size() != 1)) {
36 return errors::InvalidArgument(
37 "rename_attribute expects exactly one 'old_attribute_name' and one "
38 "'new_attribute_name' argument, e.g. "
39 "rename_attribute(old_attribute_name=foo, new_attribute_name=bar)");
40 }
41
42 string op_name;
43 if (context.params.count("op_name")) {
44 op_name = context.params.at("op_name")[0];
45 } else {
46 op_name = "*";
47 }
48
49 const string old_attribute_name = context.params.at("old_attribute_name")[0];
50 const string new_attribute_name = context.params.at("new_attribute_name")[0];
51 output_graph_def->Clear();
52 for (const NodeDef& node : input_graph_def.node()) {
53 NodeDef* new_node = output_graph_def->mutable_node()->Add();
54 *new_node = node;
55 if (((op_name == "*") || (op_name == node.op())) &&
56 (node.attr().count(old_attribute_name))) {
57 AttrValue attribute_value = node.attr().at(old_attribute_name);
58 new_node->mutable_attr()->erase(old_attribute_name);
59 new_node->mutable_attr()->insert({new_attribute_name, attribute_value});
60 }
61 }
62
63 return Status::OK();
64}
65
66REGISTER_GRAPH_TRANSFORM("rename_attribute", RenameAttribute);
67

Callers 1

TestRenameAttributeMethod · 0.85

Calls 11

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
insertMethod · 0.45

Tested by 1

TestRenameAttributeMethod · 0.68