[moco] remove unused node_names (#3553)
author박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Tue, 21 May 2019 05:46:17 +0000 (14:46 +0900)
committer박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Tue, 21 May 2019 05:46:17 +0000 (14:46 +0900)
This will remove 'not-used-anymore' node_names

Signed-off-by: SaeHie Park <saehie.park@samsung.com>
contrib/moco/lib/frontend/tf/src/Frontend.cpp
contrib/moco/lib/frontend/tf/src/GraphBuilderContext.cpp
contrib/moco/lib/frontend/tf/src/GraphBuilderContext.h
contrib/moco/lib/frontend/tf/src/GraphBuilderContext.test.cpp
contrib/moco/lib/frontend/tf/src/Op/Identity.cpp
contrib/moco/lib/frontend/tf/src/Op/Relu.cpp

index ea92d0d..30c782e 100644 (file)
@@ -102,10 +102,9 @@ void convert_graph(const moco::tf::ModelSignature &signature, tensorflow::GraphD
                    loco::Graph *graph)
 {
   auto nodes = stdex::make_unique<moco::tf::SymbolTable>();
-  auto input_names = stdex::make_unique<moco::tf::SymbolTable>();
   auto updates = stdex::make_unique<moco::tf::UpdateQueue>();
 
-  moco::tf::GraphBuilderContext gb_context(graph, nodes.get(), input_names.get(), updates.get());
+  moco::tf::GraphBuilderContext gb_context(graph, nodes.get(), updates.get());
 
   // Building a loco graph
   // 1. Convert all the nodes to loco::Node
index c318f39..e3344df 100644 (file)
@@ -48,49 +48,6 @@ loco::Node *SymbolTable::node(const std::string &node_name) const
   return iter->second;
 }
 
-void SymbolTable::list(loco::Node *node, const std::string &name)
-{
-  MapNodeNames_t::iterator iter = _nodenames.find(node);
-
-  if (iter == _nodenames.end())
-  {
-    // add a new vector for the first name
-    _nodenames[node] = {name};
-    return;
-  }
-
-  _nodenames[node].push_back(name);
-}
-
-unsigned SymbolTable::size(loco::Node *node)
-{
-  MapNodeNames_t::iterator iter = _nodenames.find(node);
-
-  if (iter == _nodenames.end())
-  {
-    return 0;
-  }
-
-  return iter->second.size();
-}
-
-const std::string &SymbolTable::name(loco::Node *node, unsigned index)
-{
-  MapNodeNames_t::iterator iter = _nodenames.find(node);
-
-  if (iter == _nodenames.end())
-  {
-    throw std::runtime_error{"Error: Cannot find names given node"};
-  }
-
-  if (index >= iter->second.size())
-  {
-    throw std::runtime_error{"Error: Invalid name index for given node"};
-  }
-
-  return iter->second.at(index);
-}
-
 void UpdateQueue::enroll(std::unique_ptr<GraphUpdate> &&update)
 {
   _queue.push_back(std::move(update));
index 64aee5b..315b90d 100644 (file)
@@ -46,27 +46,9 @@ public:
    */
   loco::Node *node(const std::string &node_name) const;
 
-  /**
-   * @brief  Registers multiple (appends) names for a node
-   *         Table is independent with registering with enroll()
-   */
-  void list(loco::Node *node, const std::string &name);
-  /**
-   * @brief  Returns number of listed(registered) names for a node
-   */
-  unsigned size(loco::Node *node);
-  /**
-   * @brief  Queries listed(registered) with node and index(from 0 to size-1)
-   *         Will throw runtime_error if node is not found or index is out of bounds
-   */
-  const std::string &name(loco::Node *node, unsigned index);
-
 private:
   using MapNameNode_t = std::map<std::string, loco::Node *>;
-  using MapNodeNames_t = std::map<loco::Node *, std::vector<std::string>>;
 
-  MapNameNode_t _namenode;
-  MapNodeNames_t _nodenames;
   MapNameNode_t _table;
 };
 
@@ -111,9 +93,8 @@ private:
 class GraphBuilderContext
 {
 public:
-  GraphBuilderContext(loco::Graph *g, SymbolTable *nodes, SymbolTable *input_names,
-                      UpdateQueue *updates)
-      : _g(g), _nodes(nodes), _input_names(input_names), _updates(updates)
+  GraphBuilderContext(loco::Graph *g, SymbolTable *nodes, UpdateQueue *updates)
+      : _g(g), _nodes(nodes), _updates(updates)
   {
     // DO NOTHING
   }
@@ -124,13 +105,11 @@ public:
 public:
   loco::Graph *graph() { return _g; }
   SymbolTable *nodes() { return _nodes; }
-  SymbolTable *input_names() { return _input_names; }
   UpdateQueue *updates() { return _updates; }
 
 private:
   loco::Graph *_g;
   SymbolTable *_nodes;
-  SymbolTable *_input_names;
   UpdateQueue *_updates;
 };
 
index d5c502d..885d227 100644 (file)
@@ -24,14 +24,12 @@ TEST(GraphBuilderContext, ctor)
 {
   auto graph = loco::make_graph();
   moco::tf::SymbolTable nodes;
-  moco::tf::SymbolTable input_names;
   moco::tf::UpdateQueue updates;
 
-  moco::tf::GraphBuilderContext context(graph.get(), &nodes, &input_names, &updates);
+  moco::tf::GraphBuilderContext context(graph.get(), &nodes, &updates);
 
   ASSERT_EQ(context.graph(), graph.get());
   ASSERT_EQ(context.nodes(), &nodes);
-  ASSERT_EQ(context.input_names(), &input_names);
   ASSERT_EQ(context.updates(), &updates);
 }
 
@@ -49,21 +47,3 @@ TEST(SymbolTable, node_name)
   // unregistered name should throw
   EXPECT_THROW(table.node(invalid), std::runtime_error);
 }
-
-TEST(SymbolTable, name_node)
-{
-  moco::tf::SymbolTable table;
-  loco::Push push_node;
-  std::string in1("in1");
-  std::string in2("in2");
-
-  ASSERT_EQ(table.size(&push_node), 0);
-
-  table.list(&push_node, in1);
-  table.list(&push_node, in2);
-  unsigned size = table.size(&push_node);
-  ASSERT_EQ(size, 2);
-  ASSERT_EQ(in1, table.name(&push_node, 0));
-  ASSERT_EQ(in2, table.name(&push_node, 1));
-  EXPECT_THROW(table.name(&push_node, 2), std::runtime_error);
-}
index e807bb3..2947c88 100644 (file)
@@ -71,7 +71,6 @@ void IdentityGraphBuilder::build(const tensorflow::NodeDef &node,
 
   loco::Graph *graph = context->graph();
   SymbolTable *nodes = context->nodes();
-  SymbolTable *input_names = context->input_names();
   UpdateQueue *updates = context->updates();
 
   // Create a "Forward" node for Identity
index 52fc68c..7cd9a0d 100644 (file)
@@ -60,7 +60,6 @@ void ReluGraphBuilder::build(const tensorflow::NodeDef &node, GraphBuilderContex
 
   loco::Graph *graph = context->graph();
   SymbolTable *nodes = context->nodes();
-  SymbolTable *input_names = context->input_names();
   UpdateQueue *updates = context->updates();
 
   // Create a "ReLU" node for Relu