1 | /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. |
2 | |
3 | Licensed under the Apache License, Version 2.0 (the "License"); |
4 | you may not use this file except in compliance with the License. |
5 | You may obtain a copy of the License at |
6 | |
7 | http://www.apache.org/licenses/LICENSE-2.0 |
8 | |
9 | Unless required by applicable law or agreed to in writing, software |
10 | distributed under the License is distributed on an "AS IS" BASIS, |
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | See the License for the specific language governing permissions and |
13 | limitations under the License. |
14 | ==============================================================================*/ |
15 | #ifndef TENSORFLOW_LITE_TOCO_TOCO_TOOLING_H_ |
16 | #define TENSORFLOW_LITE_TOCO_TOCO_TOOLING_H_ |
17 | |
18 | #include <memory> |
19 | #include <string> |
20 | |
21 | #include "tensorflow/lite/toco/model.h" |
22 | #include "tensorflow/lite/toco/model_flags.pb.h" |
23 | #include "tensorflow/lite/toco/toco_flags.pb.h" |
24 | |
25 | namespace toco { |
26 | |
27 | // Imports the input file into a Model object. |
28 | std::unique_ptr<Model> Import(const TocoFlags& toco_flags, |
29 | const ModelFlags& model_flags, |
30 | const std::string& input_file_contents); |
31 | |
32 | // Transforms a Model. The resulting Model is ready to be passed |
33 | // to Export with the exact same toco_flags. |
34 | tensorflow::Status TransformWithStatus(const TocoFlags& toco_flags, |
35 | Model* model); |
36 | inline void Transform(const TocoFlags& toco_flags, Model* model) { |
37 | auto s = TransformWithStatus(toco_flags, model); |
38 | CHECK(s.ok()) << s.error_message(); |
39 | } |
40 | |
41 | // Exports the Model, which must be of the 'lowered' form returned by |
42 | // Transform, to a file of the format given by |
43 | // toco_flags.output_format(). |
44 | tensorflow::Status Export(const TocoFlags& toco_flags, const Model& model, |
45 | bool allow_custom_ops, |
46 | std::string* output_file_contents); |
47 | |
48 | // This if for backward-compatibility with internal tools. |
49 | inline void Export(const TocoFlags& toco_flags, const Model& model, |
50 | std::string* output_file_contents) { |
51 | auto status = Export(toco_flags, model, true, output_file_contents); |
52 | if (!status.ok()) { |
53 | LOG(QFATAL) << status.error_message(); |
54 | } |
55 | } |
56 | |
57 | } // namespace toco |
58 | |
59 | #endif // TENSORFLOW_LITE_TOCO_TOCO_TOOLING_H_ |
60 | |