[tflchef] Call tflchef from Driver (#2350)
author박세희/동작제어Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Wed, 21 Nov 2018 02:51:21 +0000 (11:51 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 21 Nov 2018 02:51:21 +0000 (11:51 +0900)
This will make Driver call tflchef tflite load and save functions

Signed-off-by: SaeHie Park <saehie.park@samsung.com>
contrib/tflchef/tools/reverse/CMakeLists.txt
contrib/tflchef/tools/reverse/Driver.cpp

index f6bbcb3..63cb36c 100644 (file)
@@ -1,2 +1,3 @@
 add_executable(tflchef-reverse Driver.cpp)
+target_link_libraries(tflchef-reverse tflchef_tflite)
 target_link_libraries(tflchef-reverse safemain)
index d570db5..5497564 100644 (file)
  * limitations under the License.
  */
 
+#include <tflchef/RawModel.h>
+#include <tflchef/RecipeChef.h>
+
+#include <memory>
 #include <iostream>
 
 int entry(int argc, char **argv)
@@ -26,9 +30,35 @@ int entry(int argc, char **argv)
     return 255;
   }
 
-  // TODO load tflite
+  // Load TF lite model from a tflite file
+  std::unique_ptr<tflchef::RawModel> rawmodel = tflchef::load_tflite(argv[1]);
+  if (rawmodel == nullptr)
+  {
+    std::cerr << "ERROR: Failed to load tflite '" << argv[1] << "'" << std::endl;
+    return 255;
+  }
+
+  const tflite::Model *tflmodel = rawmodel->model();
+  if (tflmodel == nullptr)
+  {
+    std::cerr << "ERROR: Failed to load tflite '" << argv[1] << "'" << std::endl;
+    return 255;
+  }
 
-  // TODO store to recipe
+  // Generate ModelRecipe recipe
+  std::unique_ptr<tflchef::ModelRecipe> recipe = tflchef::generate_recipe(tflmodel);
+  if (recipe.get() == nullptr)
+  {
+    std::cerr << "ERROR: Failed to generate recipe" << std::endl;
+    return 255;
+  }
 
+  // Save to a file
+  bool result = tflchef::write_recipe(argv[2], recipe);
+  if (!result)
+  {
+    std::cerr << "ERROR: Failed to write to recipe '" << argv[2] << "'" << std::endl;
+    return 255;
+  }
   return 0;
 }