[tflchef] Store ModelRecipe to file (#2352)
author박세희/동작제어Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Wed, 21 Nov 2018 05:10:39 +0000 (14:10 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 21 Nov 2018 05:10:39 +0000 (14:10 +0900)
This will implement storing ModelRecipe to a file

Signed-off-by: SaeHie Park <saehie.park@samsung.com>
contrib/tflchef/tflite/src/RecipeChef.cpp

index 7f0ae6d..51438cd 100644 (file)
@@ -16,6 +16,8 @@
 
 #include <tflchef/RecipeChef.h>
 
+#include <fstream>
+
 namespace tflchef
 {
 
@@ -29,7 +31,18 @@ std::unique_ptr<ModelRecipe> generate_recipe(const tflite::Model *model)
 
 bool write_recipe(const std::string &filename, std::unique_ptr<ModelRecipe> &recipe)
 {
-  // TODO fill this
+  std::fstream fo(filename, std::ios::binary | std::ios::out);
+
+  if (!fo.is_open())
+  {
+    throw std::runtime_error{"file store failed"};
+  }
+
+  // Note: SerializeToString() or SerializeToOstream() writes in binary mode
+  // DebugString() and Utf8DebugString() will print as a human readable text
+  fo << recipe->Utf8DebugString();
+
+  fo.close();
 
   return true;
 }