[moco/tf] Dump ShapeInferenceData for outputs (#3695)
author박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Mon, 10 Jun 2019 07:29:11 +0000 (16:29 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 10 Jun 2019 07:29:11 +0000 (16:29 +0900)
This will dump ShapeInferenceData for output nodes with moco log library

Signed-off-by: SaeHie Park <saehie.park@samsung.com>
contrib/moco/lib/CMakeLists.txt
contrib/moco/lib/frontend/tf/CMakeLists.txt
contrib/moco/lib/frontend/tf/src/Frontend.cpp

index 4dcc379..b5f2dff 100644 (file)
@@ -1 +1,2 @@
+add_subdirectory(log)
 add_subdirectory(frontend)
index 73b6cd1..6c6e4a7 100644 (file)
@@ -23,6 +23,7 @@ target_link_libraries(moco_tf_frontend PUBLIC moco_tf_proto)
 target_link_libraries(moco_tf_frontend PUBLIC loco)
 target_link_libraries(moco_tf_frontend PRIVATE stdex)
 target_link_libraries(moco_tf_frontend PRIVATE cwrap)
+target_link_libraries(moco_tf_frontend PRIVATE moco_log)
 
 if(NOT ENABLE_TEST)
   return()
index eddc76a..88f4714 100644 (file)
 #include "GraphBuilderRegistry.h"
 #include "Transforms.h"
 
+#include "Annotations/ShapeInferenceData.h"
+
+#include <moco/Log.h>
+
 #include <loco/IR/Verifier.h>
 #include <cwrap/Fildes.h>
 #include <stdex/Memory.h>
@@ -222,6 +226,37 @@ void convert_graph(const moco::tf::ModelSignature &signature, tensorflow::GraphD
   assert(loco::valid(graph));
 }
 
+void dump_shapeinferencedata(loco::Node *node, const std::string &name)
+{
+  LOGGER(node_shapeinferencedata);
+
+  const moco::tf::ShapeInferenceData *shapedata = node->annot<moco::tf::ShapeInferenceData>();
+  if (shapedata == nullptr)
+  {
+    INFO(node_shapeinferencedata) << "ShapeInferenceData is null for " << name << ":" << node
+                                  << std::endl;
+  }
+  else
+  {
+    std::stringstream ss;
+
+    ss << "ShapeInferenceData for " << name << ":" << node;
+    ss << " rank(" << shapedata->rank() << ") [";
+    for (uint32_t index = 0; index < shapedata->rank(); ++index)
+    {
+      if (index)
+        ss << ",";
+      if (shapedata->dim(index).known())
+        ss << shapedata->dim(index).value();
+      else
+        ss << "?";
+    }
+    ss << "]";
+
+    INFO(node_shapeinferencedata) << ss.str() << std::endl;
+  }
+}
+
 void transform_graph(loco::Graph *graph)
 {
   std::vector<std::unique_ptr<moco::tf::Transform>> prepare;
@@ -262,6 +297,16 @@ void transform_graph(loco::Graph *graph)
 
   } while (changed);
 
+  // TODO would be better to run this code only when log is enabled
+  {
+    for (uint32_t i = 0; i < graph->outputs()->size(); ++i)
+    {
+      loco::Node *node = graph->outputs()->at(i)->node();
+      std::string name = "Output(" + std::to_string(i) + ")";
+      dump_shapeinferencedata(node, name);
+    }
+  }
+
   // Run finalize to cleanup temporary annotations
   for (auto &tr : finalize)
   {