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 #include <cstdio>
16 #include <memory>
17 #include <string>
18
19 #include "tensorflow/lite/toco/model_cmdline_flags.h"
20 #include "tensorflow/lite/toco/toco_cmdline_flags.h"
21 #include "tensorflow/lite/toco/toco_convert.h"
22
main(int argc,char ** argv)23 int main(int argc, char** argv) {
24 toco::string msg;
25 toco::ParsedTocoFlags parsed_toco_flags;
26 toco::ParsedModelFlags parsed_model_flags;
27
28 // If no args were specified, give a help string to be helpful.
29 int* effective_argc = &argc;
30 char** effective_argv = argv;
31 if (argc == 1) {
32 // No arguments, so manufacture help argv.
33 static int dummy_argc = 2;
34 static char* dummy_argv[] = {argv[0], const_cast<char*>("--help")};
35 effective_argc = &dummy_argc;
36 effective_argv = dummy_argv;
37 }
38
39 // Parse toco flags and command flags in sequence, each one strips off args,
40 // giving InitGoogle a chance to handle all remaining arguments.
41 bool toco_success = toco::ParseTocoFlagsFromCommandLineFlags(
42 effective_argc, effective_argv, &msg, &parsed_toco_flags);
43 bool model_success = toco::ParseModelFlagsFromCommandLineFlags(
44 effective_argc, effective_argv, &msg, &parsed_model_flags);
45 if (!toco_success || !model_success || !msg.empty()) {
46 fprintf(stderr, "%s", msg.c_str());
47 fflush(stderr);
48 return 1;
49 }
50 toco::port::InitGoogle(argv[0], effective_argc, &effective_argv, true);
51 auto status = toco::Convert(parsed_toco_flags, parsed_model_flags);
52 if (!status.ok()) {
53 fprintf(stderr, "%s\n", status.error_message().c_str());
54 fflush(stderr);
55 return 1;
56 }
57 return 0;
58 }
59