aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/tools/graph_transforms
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <gardener@tensorflow.org>2018-04-04 12:08:49 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-04-04 12:11:49 -0700
commit13e103b8f0dcc89673dd0d3d589b976c05c37a09 (patch)
tree3debee5abeae72842052b360124504c5a62e9779 /tensorflow/tools/graph_transforms
parentbd540c8c45bf66a9c14af38a272840b47731b91a (diff)
Replaced calls to deprecated tensorflow::StringPiece methods with their
tensorflow::str_util equivalents. This will allow the deprecated methods to be removed. PiperOrigin-RevId: 191627087
Diffstat (limited to 'tensorflow/tools/graph_transforms')
-rw-r--r--tensorflow/tools/graph_transforms/backports_test.cc3
-rw-r--r--tensorflow/tools/graph_transforms/fold_constants_test.cc5
-rw-r--r--tensorflow/tools/graph_transforms/freeze_requantization_ranges.cc9
-rw-r--r--tensorflow/tools/graph_transforms/insert_logging.cc3
-rw-r--r--tensorflow/tools/graph_transforms/sparsify_gather.cc7
-rw-r--r--tensorflow/tools/graph_transforms/transform_graph_test.cc8
-rw-r--r--tensorflow/tools/graph_transforms/transform_utils.cc7
7 files changed, 22 insertions, 20 deletions
diff --git a/tensorflow/tools/graph_transforms/backports_test.cc b/tensorflow/tools/graph_transforms/backports_test.cc
index ab9a61afa7..80a954e062 100644
--- a/tensorflow/tools/graph_transforms/backports_test.cc
+++ b/tensorflow/tools/graph_transforms/backports_test.cc
@@ -20,6 +20,7 @@ limitations under the License.
#include "tensorflow/cc/ops/standard_ops.h"
#include "tensorflow/core/framework/tensor_testutil.h"
#include "tensorflow/core/lib/core/status_test_util.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/test.h"
#include "tensorflow/core/platform/test_benchmark.h"
#include "tensorflow/core/public/session.h"
@@ -191,7 +192,7 @@ TEST(BackportTensorArrayV3Test, TestBackportTensorArrayV3Subtypes) {
std::map<string, const NodeDef*> node_lookup;
MapNamesToNodes(result, &node_lookup);
ASSERT_EQ(1, node_lookup.count("v3_node"));
- EXPECT_TRUE(StringPiece(node_lookup.at("v3_node")->op()).ends_with("V2"));
+ EXPECT_TRUE(str_util::EndsWith(node_lookup.at("v3_node")->op(), "V2"));
}
}
diff --git a/tensorflow/tools/graph_transforms/fold_constants_test.cc b/tensorflow/tools/graph_transforms/fold_constants_test.cc
index 6bfdfe43f5..a082399a87 100644
--- a/tensorflow/tools/graph_transforms/fold_constants_test.cc
+++ b/tensorflow/tools/graph_transforms/fold_constants_test.cc
@@ -24,6 +24,7 @@ limitations under the License.
#include "tensorflow/core/framework/tensor_shape.pb.h"
#include "tensorflow/core/framework/tensor_testutil.h"
#include "tensorflow/core/lib/core/status_test_util.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/test.h"
#include "tensorflow/core/platform/test_benchmark.h"
#include "tensorflow/core/public/session.h"
@@ -209,10 +210,10 @@ class ConstantFoldingTest : public ::testing::Test {
for (const NodeDef& node : graph_def.node()) {
const StringPiece name(node.name());
const int occurrence_count = folded_node_map.count(node.name());
- if (name.ends_with("expect_removed")) {
+ if (str_util::EndsWith(name, "expect_removed")) {
EXPECT_EQ(0, occurrence_count) << "node.name()=" << node.name();
}
- if (name.ends_with("expect_remains")) {
+ if (str_util::EndsWith(name, "expect_remains")) {
EXPECT_EQ(1, occurrence_count) << "node.name()=" << node.name();
}
}
diff --git a/tensorflow/tools/graph_transforms/freeze_requantization_ranges.cc b/tensorflow/tools/graph_transforms/freeze_requantization_ranges.cc
index 2436c7e4a2..f401723808 100644
--- a/tensorflow/tools/graph_transforms/freeze_requantization_ranges.cc
+++ b/tensorflow/tools/graph_transforms/freeze_requantization_ranges.cc
@@ -40,8 +40,8 @@ Status ExtractMinMaxRecords(const string& log_file_name,
for (const string& file_line : file_lines) {
// We expect to find a line with components separated by semicolons, so to
// start make sure that the basic structure is in place/
- StringPiece line(file_line);
- if (!line.contains(print_suffix + ";" + requant_prefix)) {
+ if (!str_util::StrContains(file_line,
+ print_suffix + ";" + requant_prefix)) {
continue;
}
std::vector<string> line_parts = str_util::Split(file_line, ';');
@@ -53,8 +53,7 @@ Status ExtractMinMaxRecords(const string& log_file_name,
bool min_max_found = false;
int min_max_index;
for (int i = 1; i < line_parts.size(); ++i) {
- StringPiece line_part(line_parts[i]);
- if (line_part.starts_with(requant_prefix)) {
+ if (str_util::StartsWith(line_parts[i], requant_prefix)) {
min_max_found = true;
min_max_index = i;
}
@@ -90,7 +89,7 @@ Status ExtractMinMaxRecords(const string& log_file_name,
continue;
}
StringPiece name_string = line_parts[min_max_index - 1];
- if (!name_string.ends_with(print_suffix)) {
+ if (!str_util::EndsWith(name_string, print_suffix)) {
continue;
}
string name =
diff --git a/tensorflow/tools/graph_transforms/insert_logging.cc b/tensorflow/tools/graph_transforms/insert_logging.cc
index e1ee2b420b..377665448c 100644
--- a/tensorflow/tools/graph_transforms/insert_logging.cc
+++ b/tensorflow/tools/graph_transforms/insert_logging.cc
@@ -19,6 +19,7 @@ limitations under the License.
#include "tensorflow/core/graph/graph_constructor.h"
#include "tensorflow/core/graph/node_builder.h"
#include "tensorflow/core/graph/subgraph.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/init_main.h"
#include "tensorflow/core/public/session.h"
#include "tensorflow/core/util/command_line_flags.h"
@@ -101,7 +102,7 @@ Status InsertLogging(const GraphDef& input_graph_def,
const bool op_matches = (ops.count(node.op()) > 0);
bool prefix_matches = false;
for (const string& prefix : prefixes) {
- if (StringPiece(node.name()).starts_with(prefix)) {
+ if (str_util::StartsWith(node.name(), prefix)) {
prefix_matches = true;
}
}
diff --git a/tensorflow/tools/graph_transforms/sparsify_gather.cc b/tensorflow/tools/graph_transforms/sparsify_gather.cc
index 701e350fc3..cc82100148 100644
--- a/tensorflow/tools/graph_transforms/sparsify_gather.cc
+++ b/tensorflow/tools/graph_transforms/sparsify_gather.cc
@@ -22,6 +22,7 @@ limitations under the License.
#include "tensorflow/core/graph/graph_constructor.h"
#include "tensorflow/core/graph/node_builder.h"
#include "tensorflow/core/graph/subgraph.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/init_main.h"
#include "tensorflow/core/public/session.h"
#include "tensorflow/core/util/command_line_flags.h"
@@ -88,7 +89,7 @@ void CreateConstNode(const Tensor& tensor, const string& name,
string GetMonolithicTensorKey(const string& tensor_slice_name) {
std::vector<string> names = Split(tensor_slice_name, "/");
- if (StringPiece(names[names.size() - 1]).starts_with("part_")) {
+ if (str_util::StartsWith(names[names.size() - 1], "part_")) {
CHECK_GE(names.size(), 2);
names.pop_back();
}
@@ -102,8 +103,8 @@ Status ObtainTensorSlice(const GraphDef& input_graph_def,
for (const auto& node : input_graph_def.node()) {
std::vector<string> node_name_parts = Split(node.name(), "/");
if (node_name_parts.size() == 2 &&
- StringPiece(node_name_parts[0]).starts_with("save") &&
- StringPiece(node_name_parts[1]).starts_with("Assign") &&
+ str_util::StartsWith(node_name_parts[0], "save") &&
+ str_util::StartsWith(node_name_parts[1], "Assign") &&
node.input(0) == target_name) {
restore_node_name = node.input(1);
break;
diff --git a/tensorflow/tools/graph_transforms/transform_graph_test.cc b/tensorflow/tools/graph_transforms/transform_graph_test.cc
index bc2412fcbd..b276229aa4 100644
--- a/tensorflow/tools/graph_transforms/transform_graph_test.cc
+++ b/tensorflow/tools/graph_transforms/transform_graph_test.cc
@@ -22,6 +22,7 @@ limitations under the License.
#include "tensorflow/core/framework/tensor_testutil.h"
#include "tensorflow/core/lib/core/status_test_util.h"
#include "tensorflow/core/lib/io/path.h"
+#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/test.h"
#include "tensorflow/core/platform/test_benchmark.h"
#include "tensorflow/core/public/session.h"
@@ -112,12 +113,11 @@ class TransformGraphTest : public ::testing::Test {
graph_transforms::MapNamesToNodes(out_graph_def, &out_node_map);
for (const NodeDef& node : out_graph_def.node()) {
- const StringPiece name(node.name());
const int occurrence_count = out_node_map.count(node.name());
- if (name.ends_with("expect_removed")) {
+ if (str_util::EndsWith(node.name(), "expect_removed")) {
EXPECT_EQ(0, occurrence_count) << "node.name()=" << node.name();
}
- if (name.ends_with("expect_remains")) {
+ if (str_util::EndsWith(node.name(), "expect_remains")) {
EXPECT_EQ(1, occurrence_count) << "node.name()=" << node.name();
}
}
@@ -139,7 +139,7 @@ class TransformGraphTest : public ::testing::Test {
Status no_such_status =
TransformGraph({}, {}, {{"test_no_such_transform", {}}}, &graph_def);
EXPECT_TRUE(
- StringPiece(no_such_status.ToString()).contains("not recognized"));
+ str_util::StrContains(no_such_status.ToString(), "not recognized"));
}
void TestParseTransformParameters() {
diff --git a/tensorflow/tools/graph_transforms/transform_utils.cc b/tensorflow/tools/graph_transforms/transform_utils.cc
index 55f28a9e1d..367048965d 100644
--- a/tensorflow/tools/graph_transforms/transform_utils.cc
+++ b/tensorflow/tools/graph_transforms/transform_utils.cc
@@ -88,7 +88,7 @@ void NodeNamePartsFromInput(const string& input_name, string* prefix,
*suffix = ":" + input_parts[1];
}
StringPiece node_name_piece(input_parts[0]);
- if (node_name_piece.Consume("^")) {
+ if (str_util::ConsumePrefix(&node_name_piece, "^")) {
*prefix = "^";
} else {
*prefix = "";
@@ -200,8 +200,7 @@ Status SortByExecutionOrder(const GraphDef& input_graph_def,
// for merge only wait for one non-control input.
int32 num_control_edges = 0;
for (int i = 0; i < node_def.input_size(); ++i) {
- StringPiece input_name(node_def.input(i));
- if (input_name.starts_with("^")) {
+ if (str_util::StartsWith(node_def.input(i), "^")) {
num_control_edges++;
}
}
@@ -504,7 +503,7 @@ Status RenameNodeInputs(const GraphDef& input_graph_def,
const string& dest_name = input_to_rename.second;
bool is_match;
string match_name;
- if (StringPiece(source_name).ends_with(":*")) {
+ if (str_util::EndsWith(source_name, ":*")) {
is_match = true;
string prefix;
string unused_node_name;