ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Driver.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
18
19#include <arser/arser.h>
20#include <foder/FileLoader.h>
21
22#include <memory>
23#include <iostream>
24
25int entry(int argc, char **argv)
26{
28 arser.add_argument("circle").help("Source circle file path to convert");
29 arser.add_argument("recipe").help("Target recipe file path");
30
31 try
32 {
33 arser.parse(argc, argv);
34 }
35 catch (const std::runtime_error &err)
36 {
37 std::cout << err.what() << std::endl;
38 std::cout << arser;
39 return 255;
40 }
41
42 std::string circle_path = arser.get<std::string>("circle");
43 // Load TF lite model from a circle file
44 const foder::FileLoader fileLoader{circle_path};
45 std::vector<char> modelData = fileLoader.load();
46 const circle::Model *circlemodel = circle::GetModel(modelData.data());
47 if (circlemodel == nullptr)
48 {
49 std::cerr << "ERROR: Failed to load circle '" << circle_path << "'" << std::endl;
50 return 255;
51 }
52
53 // Generate ModelRecipe recipe
54 std::unique_ptr<circlechef::ModelRecipe> recipe = circlechef::generate_recipe(circlemodel);
55 if (recipe.get() == nullptr)
56 {
57 std::cerr << "ERROR: Failed to generate recipe" << std::endl;
58 return 255;
59 }
60
61 std::string recipe_path = arser.get<std::string>("recipe");
62 // Save to a file
63 bool result = circlechef::write_recipe(recipe_path, recipe);
64 if (!result)
65 {
66 std::cerr << "ERROR: Failed to write to recipe '" << recipe_path << "'" << std::endl;
67 return 255;
68 }
69 return 0;
70}
DataBuffer load(void) const
Definition FileLoader.h:39
int entry(int argc, char **argv)
Definition Driver.cpp:29
Definition arser.h:39
std::unique_ptr< ModelRecipe > generate_recipe(const circle::Model *model)
Create ModelRecipe from circle::Model.
bool write_recipe(const std::string &filename, std::unique_ptr< ModelRecipe > &recipe)
Write ModelRecipe to file with given name.