2 * Copyright (c) 2021 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.
19 #include <foder/FileLoader.h>
21 #include <luci/Importer.h>
22 #include <luci/CircleExporter.h>
23 #include <luci/CircleFileExpContract.h>
30 std::unique_ptr<luci::Module> getModule(std::string &input_path)
32 // Load model from the file
33 foder::FileLoader file_loader{input_path};
34 std::vector<char> model_data = file_loader.load();
37 flatbuffers::Verifier verifier{reinterpret_cast<uint8_t *>(model_data.data()), model_data.size()};
38 if (!circle::VerifyModelBuffer(verifier))
40 std::cerr << "ERROR: Invalid input file '" << input_path << "'" << std::endl;
44 const circle::Model *circle_model = circle::GetModel(model_data.data());
45 if (circle_model == nullptr)
47 std::cerr << "ERROR: Failed to load circle '" << input_path << "'" << std::endl;
51 // Import from input Circle file
52 luci::Importer importer;
54 return importer.importModule(circle_model);
57 bool exportModule(luci::Module *module, std::string &output_path)
59 luci::CircleExporter exporter;
61 luci::CircleFileExpContract contract(module, output_path);
63 if (!exporter.invoke(&contract))
65 std::cerr << "ERROR: Failed to export '" << output_path << "'" << std::endl;
72 } // namespace opselector