Replace protobuf CopyFrom with assignment

PiperOrigin-RevId: 157534272
This commit is contained in:
A. Unique TensorFlower 2017-05-30 17:23:50 -07:00 committed by TensorFlower Gardener
parent 96698f7fdc
commit 9501c41041
18 changed files with 34 additions and 35 deletions

View File

@ -2253,7 +2253,7 @@ static bool ExtendSessionGraphHelper(TF_Session* session, TF_Status* status) {
const auto num_nodes = graph.num_node_ids(); const auto num_nodes = graph.num_node_ids();
if (session->last_num_graph_nodes < num_nodes) { if (session->last_num_graph_nodes < num_nodes) {
GraphDef graph_def; GraphDef graph_def;
graph_def.mutable_versions()->CopyFrom(graph.versions()); *graph_def.mutable_versions() = graph.versions();
// Fill graph_def with nodes with ids in the range // Fill graph_def with nodes with ids in the range
// [session->last_num_graph_nodes, num_nodes), that is the nodes // [session->last_num_graph_nodes, num_nodes), that is the nodes
// added since the last TF_SessionRun() call. // added since the last TF_SessionRun() call.

View File

@ -341,7 +341,7 @@ Status ConvertSessionBundleToSavedModelBundle(
saved_model_bundle->session = std::move(session_bundle.session); saved_model_bundle->session = std::move(session_bundle.session);
// Copy the meta graph def from the SessionBundle to the SavedModelBundle. // Copy the meta graph def from the SessionBundle to the SavedModelBundle.
saved_model_bundle->meta_graph_def.CopyFrom(session_bundle.meta_graph_def); saved_model_bundle->meta_graph_def = session_bundle.meta_graph_def;
// Convert signatures from session-bundle to signature-defs in // Convert signatures from session-bundle to signature-defs in
// saved-model-bundle. // saved-model-bundle.

View File

@ -62,7 +62,7 @@ GraphTransferUtils::BuildRemoteFusedGraphExecuteInfo(
execute_info.set_executor_name("build_hexagon_remote_fused_graph_executor"); execute_info.set_executor_name("build_hexagon_remote_fused_graph_executor");
// copy graph // copy graph
execute_info.mutable_remote_graph()->CopyFrom(graph_def); *execute_info.mutable_remote_graph() = graph_def;
for (const std::pair<string, Tensor>& input : inputs) { for (const std::pair<string, Tensor>& input : inputs) {
execute_info.add_graph_input_node_name(input.first); execute_info.add_graph_input_node_name(input.first);

View File

@ -405,7 +405,7 @@ static void VersionTest(const VersionDef& versions, const string& error) {
{ {
// Prepare an empty checkpoint with some version information // Prepare an empty checkpoint with some version information
SavedTensorSlices sts; SavedTensorSlices sts;
sts.mutable_meta()->mutable_versions()->CopyFrom(versions); *sts.mutable_meta()->mutable_versions() = versions;
string contents; string contents;
EXPECT_TRUE(sts.SerializeToString(&contents)); EXPECT_TRUE(sts.SerializeToString(&contents));

View File

@ -93,7 +93,7 @@ Status FoldBatchNorms(const GraphDef& input_graph_def,
new_nodes->push_back(input_node); new_nodes->push_back(input_node);
NodeDef new_conv_node; NodeDef new_conv_node;
new_conv_node.CopyFrom(conv_node); new_conv_node = conv_node;
new_conv_node.set_name(mul_node.name()); new_conv_node.set_name(mul_node.name());
new_nodes->push_back(new_conv_node); new_nodes->push_back(new_conv_node);

View File

@ -61,7 +61,7 @@ Status ReplaceSendRecvs(const GraphDef& original_graph_def,
} }
} }
NodeDef new_node; NodeDef new_node;
new_node.CopyFrom(node); new_node = node;
new_node.mutable_input()->Clear(); new_node.mutable_input()->Clear();
for (const string& old_input : node.input()) { for (const string& old_input : node.input()) {
string input_prefix; string input_prefix;
@ -84,12 +84,12 @@ Status ReplaceSendRecvs(const GraphDef& original_graph_def,
string removed_node_name = entry.second; string removed_node_name = entry.second;
const NodeDef* removed_node = original_map[removed_node_name]; const NodeDef* removed_node = original_map[removed_node_name];
NodeDef new_node; NodeDef new_node;
new_node.CopyFrom(*removed_node); new_node = *removed_node;
nodes_to_add.push_back(new_node); nodes_to_add.push_back(new_node);
} }
for (const NodeDef& node : nodes_to_add) { for (const NodeDef& node : nodes_to_add) {
output_graph_def->mutable_node()->Add()->CopyFrom(node); *output_graph_def->mutable_node()->Add() = node;
} }
return Status::OK(); return Status::OK();
} }

View File

@ -198,7 +198,7 @@ Status FreezeRequantizationRanges(const GraphDef& input_graph_def,
inputs_to_rename[node.name() + ":1"] = max_node->name() + ":0"; inputs_to_rename[node.name() + ":1"] = max_node->name() + ":0";
} else { } else {
NodeDef* new_node = frozen_graph_def.mutable_node()->Add(); NodeDef* new_node = frozen_graph_def.mutable_node()->Add();
new_node->CopyFrom(node); *new_node = node;
} }
} }
return RenameNodeInputs(frozen_graph_def, inputs_to_rename, return RenameNodeInputs(frozen_graph_def, inputs_to_rename,

View File

@ -93,7 +93,7 @@ Status InsertLogging(const GraphDef& input_graph_def,
GraphDef logged_graph_def; GraphDef logged_graph_def;
for (const NodeDef& node : input_graph_def.node()) { for (const NodeDef& node : input_graph_def.node()) {
NodeDef* new_node = logged_graph_def.mutable_node()->Add(); NodeDef* new_node = logged_graph_def.mutable_node()->Add();
new_node->CopyFrom(node); *new_node = node;
if (node_outputs[node.name()].empty()) { if (node_outputs[node.name()].empty()) {
// There were no outputs found to this node, so skip it. // There were no outputs found to this node, so skip it.
continue; continue;

View File

@ -337,15 +337,14 @@ Status QuantizePlaceholders(const GraphDef& input_graph_def,
placeholder_graph_def.Clear(); placeholder_graph_def.Clear();
for (const NodeDef& node : input_graph_def.node()) { for (const NodeDef& node : input_graph_def.node()) {
if (node.op() != "Placeholder") { if (node.op() != "Placeholder") {
(placeholder_graph_def.mutable_node()->Add())->CopyFrom(node); *(placeholder_graph_def.mutable_node()->Add()) = node;
} else { } else {
string namespace_prefix = node.name() + "_eightbit"; string namespace_prefix = node.name() + "_eightbit";
NodeDef quantized_placeholder; NodeDef quantized_placeholder;
quantized_placeholder.CopyFrom(node); quantized_placeholder = node;
SetNodeAttr("dtype", DT_QUINT8, &quantized_placeholder); SetNodeAttr("dtype", DT_QUINT8, &quantized_placeholder);
(placeholder_graph_def.mutable_node()->Add()) *(placeholder_graph_def.mutable_node()->Add()) = quantized_placeholder;
->CopyFrom(quantized_placeholder);
NodeDef min_node; NodeDef min_node;
min_node.set_op("Const"); min_node.set_op("Const");
@ -354,7 +353,7 @@ Status QuantizePlaceholders(const GraphDef& input_graph_def,
Tensor min_tensor(DT_FLOAT, {}); Tensor min_tensor(DT_FLOAT, {});
min_tensor.flat<float>()(0) = input_min; min_tensor.flat<float>()(0) = input_min;
SetNodeTensorAttr<float>("value", min_tensor, &min_node); SetNodeTensorAttr<float>("value", min_tensor, &min_node);
(placeholder_graph_def.mutable_node()->Add())->CopyFrom(min_node); *(placeholder_graph_def.mutable_node()->Add()) = min_node;
NodeDef max_node; NodeDef max_node;
max_node.set_op("Const"); max_node.set_op("Const");
@ -363,7 +362,7 @@ Status QuantizePlaceholders(const GraphDef& input_graph_def,
Tensor max_tensor(DT_FLOAT, {}); Tensor max_tensor(DT_FLOAT, {});
max_tensor.flat<float>()(0) = input_max; max_tensor.flat<float>()(0) = input_max;
SetNodeTensorAttr<float>("value", max_tensor, &max_node); SetNodeTensorAttr<float>("value", max_tensor, &max_node);
(placeholder_graph_def.mutable_node()->Add())->CopyFrom(max_node); *(placeholder_graph_def.mutable_node()->Add()) = max_node;
const string rename_suffix = "__RENAMED_PLACEHOLDER__"; const string rename_suffix = "__RENAMED_PLACEHOLDER__";
NodeDef dequantize_node; NodeDef dequantize_node;
@ -374,7 +373,7 @@ Status QuantizePlaceholders(const GraphDef& input_graph_def,
AddNodeInput(node.name() + rename_suffix, &dequantize_node); AddNodeInput(node.name() + rename_suffix, &dequantize_node);
AddNodeInput(min_node.name(), &dequantize_node); AddNodeInput(min_node.name(), &dequantize_node);
AddNodeInput(max_node.name(), &dequantize_node); AddNodeInput(max_node.name(), &dequantize_node);
(placeholder_graph_def.mutable_node()->Add())->CopyFrom(dequantize_node); *(placeholder_graph_def.mutable_node()->Add()) = dequantize_node;
// First make sure that any internal references to the old placeholder // First make sure that any internal references to the old placeholder
// now point to the dequantize result. // now point to the dequantize result.
@ -519,7 +518,7 @@ Status MergeAdjacentRequantizes(const GraphDef& input_graph_def,
new_nodes->push_back(fake_requantize_max_node); new_nodes->push_back(fake_requantize_max_node);
NodeDef requantize_node; NodeDef requantize_node;
requantize_node.CopyFrom(fake_requantize_node); requantize_node = fake_requantize_node;
requantize_node.mutable_input()->Clear(); requantize_node.mutable_input()->Clear();
AddNodeInput(original_op_node.name() + ":0", &requantize_node); AddNodeInput(original_op_node.name() + ":0", &requantize_node);
AddNodeInput(original_op_node.name() + ":1", &requantize_node); AddNodeInput(original_op_node.name() + ":1", &requantize_node);
@ -568,7 +567,7 @@ Status HoistFakeQuants(const GraphDef& input_graph_def,
current_match = current_match.inputs[0]; current_match = current_match.inputs[0];
} }
NodeDef new_fake_quant_node; NodeDef new_fake_quant_node;
new_fake_quant_node.CopyFrom(fake_quant_node); new_fake_quant_node = fake_quant_node;
new_fake_quant_node.set_name(fake_quant_node.name() + "_hoisted"); new_fake_quant_node.set_name(fake_quant_node.name() + "_hoisted");
new_fake_quant_node.set_input( new_fake_quant_node.set_input(
0, linear_nodes[linear_nodes.size() - 2].input(0)); 0, linear_nodes[linear_nodes.size() - 2].input(0));

View File

@ -54,7 +54,7 @@ Status RemoveAttribute(const GraphDef& input_graph_def,
output_graph_def->Clear(); output_graph_def->Clear();
for (const NodeDef& node : input_graph_def.node()) { for (const NodeDef& node : input_graph_def.node()) {
NodeDef* new_node = output_graph_def->mutable_node()->Add(); NodeDef* new_node = output_graph_def->mutable_node()->Add();
new_node->CopyFrom(node); *new_node = node;
if (((op_name == "*") || (op_name == node.op())) && if (((op_name == "*") || (op_name == node.op())) &&
(node.attr().count(attribute_name))) { (node.attr().count(attribute_name))) {
new_node->mutable_attr()->erase(attribute_name); new_node->mutable_attr()->erase(attribute_name);

View File

@ -34,7 +34,7 @@ Status RemoveDevice(const GraphDef& input_graph_def,
output_graph_def->Clear(); output_graph_def->Clear();
for (const NodeDef& node : input_graph_def.node()) { for (const NodeDef& node : input_graph_def.node()) {
NodeDef* new_node = output_graph_def->mutable_node()->Add(); NodeDef* new_node = output_graph_def->mutable_node()->Add();
new_node->CopyFrom(node); *new_node = node;
new_node->set_device(""); new_node->set_device("");
} }

View File

@ -52,7 +52,7 @@ Status RenameAttribute(const GraphDef& input_graph_def,
output_graph_def->Clear(); output_graph_def->Clear();
for (const NodeDef& node : input_graph_def.node()) { for (const NodeDef& node : input_graph_def.node()) {
NodeDef* new_node = output_graph_def->mutable_node()->Add(); NodeDef* new_node = output_graph_def->mutable_node()->Add();
new_node->CopyFrom(node); *new_node = node;
if (((op_name == "*") || (op_name == node.op())) && if (((op_name == "*") || (op_name == node.op())) &&
(node.attr().count(old_attribute_name))) { (node.attr().count(old_attribute_name))) {
AttrValue attribute_value = node.attr().at(old_attribute_name); AttrValue attribute_value = node.attr().at(old_attribute_name);

View File

@ -45,7 +45,7 @@ Status RenameOp(const GraphDef& input_graph_def,
output_graph_def->Clear(); output_graph_def->Clear();
for (const NodeDef& node : input_graph_def.node()) { for (const NodeDef& node : input_graph_def.node()) {
NodeDef* new_node = output_graph_def->mutable_node()->Add(); NodeDef* new_node = output_graph_def->mutable_node()->Add();
new_node->CopyFrom(node); *new_node = node;
if (node.op() == old_op_name) { if (node.op() == old_op_name) {
new_node->set_op(new_op_name); new_node->set_op(new_op_name);
} }

View File

@ -31,7 +31,7 @@ Status SetDevice(const GraphDef& input_graph_def,
output_graph_def->Clear(); output_graph_def->Clear();
for (const NodeDef& node : input_graph_def.node()) { for (const NodeDef& node : input_graph_def.node()) {
NodeDef* new_node = output_graph_def->mutable_node()->Add(); NodeDef* new_node = output_graph_def->mutable_node()->Add();
new_node->CopyFrom(node); *new_node = node;
if (!if_default || (node.device().empty())) { if (!if_default || (node.device().empty())) {
new_node->set_device(new_device); new_node->set_device(new_device);
} }

View File

@ -190,7 +190,7 @@ Status StripUnusedNodes(const GraphDef& input_graph_def,
if (input_nodes.count(node.name())) { if (input_nodes.count(node.name())) {
NodeDef placeholder_node; NodeDef placeholder_node;
if (node.op() == "Placeholder") { if (node.op() == "Placeholder") {
placeholder_node.CopyFrom(node); placeholder_node = node;
} else { } else {
placeholder_node.set_op("Placeholder"); placeholder_node.set_op("Placeholder");
placeholder_node.set_name(node.name()); placeholder_node.set_name(node.name());

View File

@ -282,7 +282,7 @@ Status TransformGraph(const std::vector<string>& inputs,
} }
} }
// Copy over the library from the original input graph. // Copy over the library from the original input graph.
transformed_graph_def.mutable_library()->CopyFrom(graph_def->library()); *transformed_graph_def.mutable_library() = graph_def->library();
TF_RETURN_IF_ERROR(IsGraphValid(transformed_graph_def)); TF_RETURN_IF_ERROR(IsGraphValid(transformed_graph_def));
*graph_def = transformed_graph_def; *graph_def = transformed_graph_def;

View File

@ -146,7 +146,7 @@ void CopyNodeAttr(const NodeDef& source, const string& source_key,
const string& dest_key, NodeDef* dest) { const string& dest_key, NodeDef* dest) {
CHECK_NE(0, source.attr().count(source_key)) CHECK_NE(0, source.attr().count(source_key))
<< "No key '" << source_key << "' found in " << source.DebugString(); << "No key '" << source_key << "' found in " << source.DebugString();
(*(dest->mutable_attr()))[dest_key].CopyFrom(source.attr().at(source_key)); (*(dest->mutable_attr()))[dest_key] = source.attr().at(source_key);
} }
Tensor GetNodeTensorAttr(const NodeDef& node, const string& key) { Tensor GetNodeTensorAttr(const NodeDef& node, const string& key) {
@ -162,7 +162,7 @@ void FilterGraphDef(const GraphDef& input_graph_def,
output_graph_def->mutable_node()->Clear(); output_graph_def->mutable_node()->Clear();
for (const NodeDef& node : input_graph_def.node()) { for (const NodeDef& node : input_graph_def.node()) {
if (selector(node)) { if (selector(node)) {
output_graph_def->mutable_node()->Add()->CopyFrom(node); *output_graph_def->mutable_node()->Add() = node;
} }
} }
} }
@ -173,7 +173,7 @@ void RemoveAttributes(const GraphDef& input_graph_def,
output_graph_def->mutable_node()->Clear(); output_graph_def->mutable_node()->Clear();
for (const NodeDef& node : input_graph_def.node()) { for (const NodeDef& node : input_graph_def.node()) {
NodeDef* new_node = output_graph_def->mutable_node()->Add(); NodeDef* new_node = output_graph_def->mutable_node()->Add();
new_node->CopyFrom(node); *new_node = node;
for (const string& attribute : attributes) { for (const string& attribute : attributes) {
new_node->mutable_attr()->erase(attribute); new_node->mutable_attr()->erase(attribute);
} }
@ -237,7 +237,7 @@ Status SortByExecutionOrder(const GraphDef& input_graph_def,
ready.pop_back(); ready.pop_back();
++processed; ++processed;
const NodeDef& node_def(input_graph_def.node(o)); const NodeDef& node_def(input_graph_def.node(o));
output_graph_def->mutable_node()->Add()->CopyFrom(node_def); *output_graph_def->mutable_node()->Add() = node_def;
// Update pending_count for outputs. // Update pending_count for outputs.
for (size_t i = 0; i < outputs[o].size(); ++i) { for (size_t i = 0; i < outputs[o].size(); ++i) {
@ -446,18 +446,18 @@ Status ReplaceMatchingOpTypes(
MatchedNodesAsArray(*match, &old_nodes); MatchedNodesAsArray(*match, &old_nodes);
for (const NodeDef& old_node : old_nodes) { for (const NodeDef& old_node : old_nodes) {
NodeDef* added_node = output_graph_def->mutable_node()->Add(); NodeDef* added_node = output_graph_def->mutable_node()->Add();
added_node->CopyFrom(old_node); *added_node = old_node;
} }
} else { } else {
for (const NodeDef& new_node : new_nodes) { for (const NodeDef& new_node : new_nodes) {
NodeDef* added_node = output_graph_def->mutable_node()->Add(); NodeDef* added_node = output_graph_def->mutable_node()->Add();
added_node->CopyFrom(new_node); *added_node = new_node;
} }
} }
} else if (!matched_nodes.count(input_node.name())) { } else if (!matched_nodes.count(input_node.name())) {
// This node isn't part of any match, so just copy it over. // This node isn't part of any match, so just copy it over.
NodeDef* added_node = output_graph_def->mutable_node()->Add(); NodeDef* added_node = output_graph_def->mutable_node()->Add();
added_node->CopyFrom(input_node); *added_node = input_node;
} else { } else {
// Do nothing, because this is an internal part of a matching subgraph, // Do nothing, because this is an internal part of a matching subgraph,
// and so will have been replaced by a new replacement subgraph. // and so will have been replaced by a new replacement subgraph.
@ -481,7 +481,7 @@ Status RenameNodeInputs(const GraphDef& input_graph_def,
output_graph_def->Clear(); output_graph_def->Clear();
for (const NodeDef& node : input_graph_def.node()) { for (const NodeDef& node : input_graph_def.node()) {
NodeDef* new_node = output_graph_def->mutable_node()->Add(); NodeDef* new_node = output_graph_def->mutable_node()->Add();
new_node->CopyFrom(node); *new_node = node;
new_node->mutable_input()->Clear(); new_node->mutable_input()->Clear();
for (const string& input_name : node.input()) { for (const string& input_name : node.input()) {
std::set<string> already_visited; std::set<string> already_visited;

View File

@ -438,7 +438,7 @@ class TransformUtilsTest : public ::testing::Test {
const std::set<string>& output_nodes, const std::set<string>& output_nodes,
std::vector<NodeDef>* new_nodes) { std::vector<NodeDef>* new_nodes) {
NodeDef original_copy; NodeDef original_copy;
original_copy.CopyFrom(match.node); original_copy = match.node;
const string original_name = match.node.name(); const string original_name = match.node.name();
original_copy.set_name(original_name + "_before_identity"); original_copy.set_name(original_name + "_before_identity");
new_nodes->push_back(original_copy); new_nodes->push_back(original_copy);