2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <tflchef/RecipeChef.h>
19 #include <arser/arser.h>
20 #include <foder/FileLoader.h>
25 int entry(int argc, char **argv)
28 arser.add_argument("tflite")
29 .type(arser::DataType::STR)
30 .help("Source tflite file path to convert");
31 arser.add_argument("recipe").type(arser::DataType::STR).help("Target recipe file path");
35 arser.parse(argc, argv);
37 catch (const std::runtime_error &err)
39 std::cout << err.what() << std::endl;
44 std::string tflite_path = arser.get<std::string>("tflite");
45 // Load TF lite model from a tflite file
46 const foder::FileLoader fileLoader{tflite_path};
47 std::vector<char> modelData = fileLoader.load();
48 const tflite::Model *tflmodel = tflite::GetModel(modelData.data());
49 if (tflmodel == nullptr)
51 std::cerr << "ERROR: Failed to load tflite '" << tflite_path << "'" << std::endl;
55 // Generate ModelRecipe recipe
56 std::unique_ptr<tflchef::ModelRecipe> recipe = tflchef::generate_recipe(tflmodel);
57 if (recipe.get() == nullptr)
59 std::cerr << "ERROR: Failed to generate recipe" << std::endl;
63 std::string recipe_path = arser.get<std::string>("recipe");
65 bool result = tflchef::write_recipe(recipe_path, recipe);
68 std::cerr << "ERROR: Failed to write to recipe '" << recipe_path << "'" << std::endl;