[moco-tf] Rename file and GraphBuilder name for MaxPool (#5851)
author박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Thu, 25 Jul 2019 05:30:20 +0000 (14:30 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 25 Jul 2019 05:30:20 +0000 (14:30 +0900)
This will rename file and GraphBuilder name for MaxPool to follow TensorFlow GraphDef

Signed-off-by: SaeHie Park <saehie.park@samsung.com>
compiler/moco-tf/src/Op/MaxPool.cpp [moved from compiler/moco-tf/src/Op/MaxPool2D.cpp with 87% similarity]
compiler/moco-tf/src/Op/MaxPool.test.cpp [moved from compiler/moco-tf/src/Op/MaxPool2D.test.cpp with 86% similarity]

similarity index 87%
rename from compiler/moco-tf/src/Op/MaxPool2D.cpp
rename to compiler/moco-tf/src/Op/MaxPool.cpp
index 779a325..f147b59 100644 (file)
@@ -38,17 +38,17 @@ namespace tf
 /**
  * @brief GraphBuilder for MaxPool node
  */
-class MaxPool2DGraphBuilder final : public GraphBuilder
+class MaxPoolGraphBuilder final : public GraphBuilder
 {
 public:
   bool validate(const tensorflow::NodeDef &) const override;
   void build(const tensorflow::NodeDef &, GraphBuilderContext *) const override;
 };
 
-class MaxPool2DGraphUpdate final : public GraphUpdate
+class MaxPoolGraphUpdate final : public GraphUpdate
 {
 public:
-  MaxPool2DGraphUpdate(loco::FeatureEncode *node, const TensorName &&name)
+  MaxPoolGraphUpdate(loco::FeatureEncode *node, const TensorName &&name)
       : _encode_node(node), _input_name(name)
   {
   }
@@ -60,15 +60,14 @@ private:
   const TensorName _input_name;
 };
 
-bool MaxPool2DGraphBuilder::validate(const tensorflow::NodeDef &node) const
+bool MaxPoolGraphBuilder::validate(const tensorflow::NodeDef &node) const
 {
   // note: even though "data_format" is not entered when a model is written,
   //       TF seems to generate "data_format" field into a pb file
   return has_attrs(node, {"T", "data_format", "ksize", "padding", "strides"});
 }
 
-void MaxPool2DGraphBuilder::build(const tensorflow::NodeDef &node,
-                                  GraphBuilderContext *context) const
+void MaxPoolGraphBuilder::build(const tensorflow::NodeDef &node, GraphBuilderContext *context) const
 {
   assert(context != nullptr);
   assert(node.input_size() == 1);
@@ -105,7 +104,7 @@ void MaxPool2DGraphBuilder::build(const tensorflow::NodeDef &node,
     encode_node->encoder(std::move(enc));
   }
 
-  // MaxPool2D
+  // MaxPool
   {
     // let's convert attrs:
     //    TensorFlow attr : T,           data_format, ksize,   padding, strides
@@ -173,12 +172,12 @@ void MaxPool2DGraphBuilder::build(const tensorflow::NodeDef &node,
   tensor_names->enroll(output_name, decode_node);
 
   // Record ifm inputs to featureEncode_node
-  auto update = stdex::make_unique<MaxPool2DGraphUpdate>(encode_node, TensorName(node.input(0)));
+  auto update = stdex::make_unique<MaxPoolGraphUpdate>(encode_node, TensorName(node.input(0)));
 
   updates->enroll(std::move(update));
 }
 
-void MaxPool2DGraphUpdate::input(const SymbolTable *tensor_names) const
+void MaxPoolGraphUpdate::input(const SymbolTable *tensor_names) const
 {
   loco::Node *input_node = tensor_names->node(_input_name);
   _encode_node->input(input_node);
@@ -189,9 +188,9 @@ void MaxPool2DGraphUpdate::input(const SymbolTable *tensor_names) const
 
 #include "GraphBuilderRegistry.h"
 
-REGISTER_OP_BUILDER(MaxPool, MaxPool2DGraphBuilder)
+REGISTER_OP_BUILDER(MaxPool, MaxPoolGraphBuilder)
 
 // TODO Consider a case when TF MaxPool is for 3D.
 // MaxPool works for 2D and other Dimensions, such as 3D
-// So, in future, some other GraphBuilder decide if MaxPool2DGraphBuilder is used or
+// So, in future, some other GraphBuilder decide if MaxPoolGraphBuilder is used or
 // other GraphBuilder is used for TF MaxPool
similarity index 86%
rename from compiler/moco-tf/src/Op/MaxPool2D.test.cpp
rename to compiler/moco-tf/src/Op/MaxPool.test.cpp
index 73bf9d1..54656b5 100644 (file)
@@ -31,7 +31,7 @@ using namespace moco::tf::test;
 namespace
 {
 // clang-format off
-const char *maxpool2d_01_pbtxtdata = STRING_CONTENT(
+const char *maxpool_01_pbtxtdata = STRING_CONTENT(
 node {
   name: "const/float"
   op: "Const"
@@ -66,7 +66,7 @@ node {
   }
 }
 node {
-  name: "maxpool2d"
+  name: "maxpool"
   op: "MaxPool"
   input: "const/float"
   attr {
@@ -115,15 +115,15 @@ node {
 
 } // namespace
 
-TEST(TensorFlowImport, MaxPool2D_01)
+TEST(TensorFlowImport, MaxPool_01)
 {
   moco::tf::Importer importer;
   moco::tf::ModelSignature signature;
 
-  signature.add_output(moco::tf::TensorName("maxpool2d", 0));
+  signature.add_output(moco::tf::TensorName("maxpool", 0));
 
   tensorflow::GraphDef graph_def;
-  EXPECT_TRUE(parse_graphdef(maxpool2d_01_pbtxtdata, graph_def));
+  EXPECT_TRUE(parse_graphdef(maxpool_01_pbtxtdata, graph_def));
   std::unique_ptr<loco::Graph> graph = importer.import(signature, graph_def);
 
   // what to test:
@@ -133,12 +133,12 @@ TEST(TensorFlowImport, MaxPool2D_01)
   // - stride values should match
   // - window values should match
 
-  loco::MaxPool2D *maxpool_node =
+  loco::MaxPool2D *maxpool2d_node =
       moco::tf::test::find_first_node_bytype<loco::MaxPool2D>(graph.get());
-  ASSERT_NE(maxpool_node, nullptr);
+  ASSERT_NE(maxpool2d_node, nullptr);
 
-  loco::Node *previous_node = maxpool_node->ifm();
-  auto following_nodes = loco::succs(maxpool_node);
+  loco::Node *previous_node = maxpool2d_node->ifm();
+  auto following_nodes = loco::succs(maxpool2d_node);
   ASSERT_EQ(following_nodes.size(), 1);
   loco::Node *following_node = *following_nodes.begin();
   ASSERT_NE(following_node, nullptr);
@@ -150,7 +150,7 @@ TEST(TensorFlowImport, MaxPool2D_01)
   ASSERT_NE(dec_node, nullptr);
 
   // attrs inside MaxPool2D
-  auto maxpool2d = maxpool_node; // TODO remove this new variable
+  auto maxpool2d = maxpool2d_node; // TODO remove this new variable
 
   // stride
   ASSERT_EQ(maxpool2d->stride()->vertical(), 3);
@@ -161,15 +161,15 @@ TEST(TensorFlowImport, MaxPool2D_01)
   ASSERT_EQ(maxpool2d->window()->horizontal(), 3);
 }
 
-TEST(TensorFlowImport, MaxPool2D_02)
+TEST(TensorFlowImport, MaxPool_02)
 {
   moco::tf::Importer importer;
   moco::tf::ModelSignature signature;
 
-  signature.add_output(moco::tf::TensorName("maxpool2d", 0));
+  signature.add_output(moco::tf::TensorName("maxpool", 0));
 
   tensorflow::GraphDef graph_def;
-  EXPECT_TRUE(parse_graphdef(maxpool2d_01_pbtxtdata, graph_def));
+  EXPECT_TRUE(parse_graphdef(maxpool_01_pbtxtdata, graph_def));
   std::unique_ptr<loco::Graph> graph = importer.import(signature, graph_def);
 
   // what to test: Encoder and Decoder dimension order
@@ -179,12 +179,12 @@ TEST(TensorFlowImport, MaxPool2D_02)
   // - FeatureEncode encoder should encode Count-Height-Width-Depth order
   // - FeatureDecode decoder should decode Count-Height-Width-Depth order
 
-  loco::MaxPool2D *maxpool_node =
+  loco::MaxPool2D *maxpool2d_node =
       moco::tf::test::find_first_node_bytype<loco::MaxPool2D>(graph.get());
-  ASSERT_NE(maxpool_node, nullptr);
+  ASSERT_NE(maxpool2d_node, nullptr);
 
-  loco::Node *previous_node = maxpool_node->ifm();
-  auto following_nodes = loco::succs(maxpool_node);
+  loco::Node *previous_node = maxpool2d_node->ifm();
+  auto following_nodes = loco::succs(maxpool2d_node);
   ASSERT_EQ(following_nodes.size(), 1);
   loco::Node *following_node = *following_nodes.begin();
   ASSERT_NE(following_node, nullptr);